1 #include "otsdaq-core/ConfigurationDataFormats/ViewColumnInfo.h"
2 #include "otsdaq-core/Macros/CoutMacros.h"
3 #include "otsdaq-core/Macros/StringMacros.h"
4 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationView.h"
13 const std::string ViewColumnInfo::TYPE_UID =
"UID";
15 const std::string ViewColumnInfo::TYPE_DATA =
"Data";
16 const std::string ViewColumnInfo::TYPE_UNIQUE_DATA =
"UniqueData";
17 const std::string ViewColumnInfo::TYPE_MULTILINE_DATA =
"MultilineData";
18 const std::string ViewColumnInfo::TYPE_FIXED_CHOICE_DATA =
"FixedChoiceData";
19 const std::string ViewColumnInfo::TYPE_BITMAP_DATA =
"BitMap";
21 const std::string ViewColumnInfo::TYPE_ON_OFF =
"OnOff";
22 const std::string ViewColumnInfo::TYPE_TRUE_FALSE =
"TrueFalse";
23 const std::string ViewColumnInfo::TYPE_YES_NO =
"YesNo";
25 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK =
"ChildLink";
26 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK_UID =
"ChildLinkUID";
27 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID =
"ChildLinkGroupID";
28 const std::string ViewColumnInfo::TYPE_START_GROUP_ID =
"GroupID";
29 const std::string ViewColumnInfo::TYPE_COMMENT =
"Comment";
30 const std::string ViewColumnInfo::TYPE_AUTHOR =
"Author";
31 const std::string ViewColumnInfo::TYPE_TIMESTAMP =
"Timestamp";
34 const std::string ViewColumnInfo::DATATYPE_NUMBER =
"NUMBER";
35 const std::string ViewColumnInfo::DATATYPE_STRING =
"VARCHAR2";
36 const std::string ViewColumnInfo::DATATYPE_TIME =
"TIMESTAMP WITH TIMEZONE";
38 const std::string ViewColumnInfo::TYPE_VALUE_YES =
"Yes";
39 const std::string ViewColumnInfo::TYPE_VALUE_NO =
"No";
40 const std::string ViewColumnInfo::TYPE_VALUE_TRUE =
"True";
41 const std::string ViewColumnInfo::TYPE_VALUE_FALSE =
"False";
42 const std::string ViewColumnInfo::TYPE_VALUE_ON =
"On";
43 const std::string ViewColumnInfo::TYPE_VALUE_OFF =
"Off";
45 const std::string ViewColumnInfo::DATATYPE_STRING_DEFAULT =
"DEFAULT";
46 const std::string ViewColumnInfo::DATATYPE_COMMENT_DEFAULT =
"No Comment";
47 const std::string ViewColumnInfo::DATATYPE_BOOL_DEFAULT =
"0";
48 const std::string ViewColumnInfo::DATATYPE_NUMBER_DEFAULT =
"0";
49 const std::string ViewColumnInfo::DATATYPE_TIME_DEFAULT =
"0";
50 const std::string ViewColumnInfo::DATATYPE_LINK_DEFAULT =
"NO_LINK";
52 const std::string ViewColumnInfo::COL_NAME_STATUS =
"Status";
53 const std::string ViewColumnInfo::COL_NAME_PRIORITY =
"Priority";
60 ViewColumnInfo::ViewColumnInfo(
const std::string &type,
const std::string &name,
61 const std::string &storageName,
const std::string &dataType,
62 const std::string &dataChoicesCSV, std::string *capturedExceptionString)
65 , storageName_(storageName)
66 , dataType_ (dataType)
70 if((type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) && (type_ != TYPE_UID) &&
71 (type_ != TYPE_MULTILINE_DATA) && (type_ != TYPE_FIXED_CHOICE_DATA) &&
72 (type_ != TYPE_BITMAP_DATA) &&
73 (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
74 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
77 !isChildLinkGroupID() &&
80 __SS__ <<
"The type for column " << name_ <<
" is " << type_ <<
81 ", while the only accepted types are: " <<
83 TYPE_UNIQUE_DATA <<
" " <<
84 TYPE_MULTILINE_DATA <<
" " <<
85 TYPE_FIXED_CHOICE_DATA <<
" " <<
88 TYPE_TRUE_FALSE <<
" " <<
90 TYPE_START_CHILD_LINK <<
"-* " <<
91 TYPE_START_CHILD_LINK_UID <<
"-* " <<
92 TYPE_START_CHILD_LINK_GROUP_ID <<
"-* " <<
93 TYPE_START_GROUP_ID <<
"-* " << std::endl;
94 if(capturedExceptionString) *capturedExceptionString = ss.str();
95 else throw std::runtime_error(ss.str());
97 else if(capturedExceptionString) *capturedExceptionString =
"";
101 for(
unsigned int i=0;i<type_.size();++i)
103 (type_[i] >=
'A' && type_[i] <=
'Z') ||
104 (type_[i] >=
'a' && type_[i] <=
'z') ||
105 (type_[i] >=
'0' && type_[i] <=
'9') ||
106 (type_[i] ==
'-' || type_[i] <=
'_' || type_[i] <=
'.')
109 __SS__ <<
"The data type for column " << name_ <<
" is '" << type_ <<
110 "'. Data types must contain only letters, numbers," <<
111 "dashes, underscores, and periods." << std::endl;
112 if(capturedExceptionString) *capturedExceptionString += ss.str();
113 else throw std::runtime_error(ss.str());
118 if((dataType_ != DATATYPE_NUMBER) &&
119 (dataType_ != DATATYPE_STRING) &&
120 (dataType_ != DATATYPE_TIME))
122 __SS__ <<
"The data type for column " << name_ <<
" is " << dataType_ <<
123 ", while the only accepted types are: " <<
124 DATATYPE_NUMBER <<
" " <<
125 DATATYPE_STRING <<
" " <<
126 DATATYPE_TIME << std::endl;
127 if(capturedExceptionString) *capturedExceptionString += ss.str();
128 else throw std::runtime_error(ss.str());
132 if(dataType_.size() == 0)
134 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
135 "'. Data types must contain at least 1 character." << std::endl;
136 if(capturedExceptionString) *capturedExceptionString += ss.str();
137 else throw std::runtime_error(ss.str());
142 for(
unsigned int i=0;i<dataType_.size();++i)
144 (dataType_[i] >=
'A' && dataType_[i] <=
'Z') ||
145 (dataType_[i] >=
'a' && dataType_[i] <=
'z') ||
146 (dataType_[i] >=
'0' && dataType_[i] <=
'9') ||
147 (dataType_[i] ==
'-' || dataType_[i] <=
'_')
150 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
151 "'. Data types must contain only letters, numbers," <<
152 "dashes, and underscores." << std::endl;
153 if(capturedExceptionString) *capturedExceptionString += ss.str();
154 else throw std::runtime_error(ss.str());
157 if(name_.size() == 0)
159 __SS__ <<
"There is a column named " << name_ <<
160 "'. Column names must contain at least 1 character." << std::endl;
161 if(capturedExceptionString) *capturedExceptionString += ss.str();
162 else throw std::runtime_error(ss.str());
167 for(
unsigned int i=0;i<name_.size();++i)
169 (name_[i] >=
'A' && name_[i] <=
'Z') ||
170 (name_[i] >=
'a' && name_[i] <=
'z') ||
171 (name_[i] >=
'0' && name_[i] <=
'9') ||
172 (name_[i] ==
'-' || name_[i] <=
'_')
175 __SS__ <<
"There is a column named " << name_ <<
176 "'. Column names must contain only letters, numbers," <<
177 "dashes, and underscores." << std::endl;
178 if(capturedExceptionString) *capturedExceptionString += ss.str();
179 else throw std::runtime_error(ss.str());
183 if(storageName_.size() == 0)
185 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
186 "'. Storage names must contain at least 1 character." << std::endl;
187 if(capturedExceptionString) *capturedExceptionString += ss.str();
188 else throw std::runtime_error(ss.str());
193 for(
unsigned int i=0;i<storageName_.size();++i)
195 (storageName_[i] >=
'A' && storageName_[i] <=
'Z') ||
196 (storageName_[i] >=
'0' && storageName_[i] <=
'9') ||
197 (storageName_[i] ==
'-' || storageName_[i] <=
'_')
200 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
201 "'. Storage names must contain only capital letters, numbers," <<
202 "dashes, and underscores." << std::endl;
203 if(capturedExceptionString) *capturedExceptionString += ss.str();
204 else throw std::runtime_error(ss.str());
210 std::istringstream f(dataChoicesCSV);
212 while (getline(f, s,
',')) dataChoices_.push_back(
213 StringMacros::decodeURIComponent(s));
222 catch(std::runtime_error &e)
224 if(capturedExceptionString) *capturedExceptionString += e.what();
232 void ViewColumnInfo::extractBitMapInfo()
235 if(type_ == TYPE_BITMAP_DATA)
237 if(bitMapInfoP_)
delete bitMapInfoP_;
238 bitMapInfoP_ =
new BitMapInfo();
264 if(dataChoices_.size() < 16)
266 __SS__ <<
"The Bit-Map data parameters for column " << name_ <<
267 " should be size 16, but is size " << dataChoices_.size() <<
268 ". Bit-Map parameters should be rows, cols, cellBitSize, and min, mid, max color." <<
270 throw std::runtime_error(ss.str());
273 sscanf(dataChoices_[0].c_str(),
"%u",&(bitMapInfoP_->numOfRows_));
274 sscanf(dataChoices_[1].c_str(),
"%u",&(bitMapInfoP_->numOfColumns_));
275 sscanf(dataChoices_[2].c_str(),
"%u",&(bitMapInfoP_->cellBitSize_));
277 sscanf(dataChoices_[3].c_str(),
"%lu",&(bitMapInfoP_->minValue_));
278 sscanf(dataChoices_[4].c_str(),
"%lu",&(bitMapInfoP_->maxValue_));
279 sscanf(dataChoices_[5].c_str(),
"%lu",&(bitMapInfoP_->stepValue_));
281 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
282 bitMapInfoP_->minColor_ = dataChoices_[7];
283 bitMapInfoP_->midColor_ = dataChoices_[8];
284 bitMapInfoP_->maxColor_ = dataChoices_[9];
285 bitMapInfoP_->absMinColor_ = dataChoices_[10];
286 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
288 bitMapInfoP_->rowsAscending_ = dataChoices_[12] ==
"Yes"?1:0;
289 bitMapInfoP_->colsAscending_ = dataChoices_[13] ==
"Yes"?1:0;
290 bitMapInfoP_->snakeRows_ = dataChoices_[14] ==
"Yes"?1:0;
291 bitMapInfoP_->snakeCols_ = dataChoices_[15] ==
"Yes"?1:0;
297 ViewColumnInfo::ViewColumnInfo(
void){}
303 ,storageName_(c.storageName_)
304 ,dataType_(c.dataType_)
305 ,dataChoices_(c.dataChoices_)
316 retColInfo->type_ = c.type_;
317 retColInfo->name_ = c.name_;
318 retColInfo->storageName_ = c.storageName_;
319 retColInfo->dataType_ = c.dataType_;
320 retColInfo->dataChoices_ = c.dataChoices_;
321 retColInfo->bitMapInfoP_ = 0;
324 retColInfo->extractBitMapInfo();
330 ViewColumnInfo::~ViewColumnInfo(
void)
332 if(bitMapInfoP_)
delete bitMapInfoP_;
336 const std::string& ViewColumnInfo::getType(
void)
const
342 const std::string& ViewColumnInfo::getDefaultValue(
void)
const
344 if(getDataType() == ViewColumnInfo::DATATYPE_STRING)
346 if(getType() == ViewColumnInfo::TYPE_ON_OFF ||
347 getType() == ViewColumnInfo::TYPE_TRUE_FALSE ||
348 getType() == ViewColumnInfo::TYPE_YES_NO)
349 return (ViewColumnInfo::DATATYPE_BOOL_DEFAULT);
350 else if(isChildLink())
351 return (ViewColumnInfo::DATATYPE_LINK_DEFAULT);
352 else if(getType() == ViewColumnInfo::TYPE_COMMENT)
353 return (ViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
355 return (ViewColumnInfo::DATATYPE_STRING_DEFAULT);
357 else if(getDataType() == ViewColumnInfo::DATATYPE_NUMBER)
358 return (ViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
359 else if(getDataType() == ViewColumnInfo::DATATYPE_TIME)
360 return (ViewColumnInfo::DATATYPE_TIME_DEFAULT);
363 __SS__ <<
"\tUnrecognized View data type: " << getDataType() << std::endl;
364 __COUT_ERR__ <<
"\n" << ss.str();
365 throw std::runtime_error(ss.str());
370 std::vector<std::string> ViewColumnInfo::getAllTypesForGUI(
void)
372 std::vector<std::string> all;
373 all.push_back(TYPE_DATA);
374 all.push_back(TYPE_UNIQUE_DATA);
375 all.push_back(TYPE_FIXED_CHOICE_DATA);
376 all.push_back(TYPE_MULTILINE_DATA);
377 all.push_back(TYPE_BITMAP_DATA);
378 all.push_back(TYPE_ON_OFF);
379 all.push_back(TYPE_TRUE_FALSE);
380 all.push_back(TYPE_YES_NO);
381 all.push_back(TYPE_START_CHILD_LINK_UID);
382 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
383 all.push_back(TYPE_START_CHILD_LINK);
384 all.push_back(TYPE_START_GROUP_ID);
389 std::vector<std::string> ViewColumnInfo::getAllDataTypesForGUI(
void)
391 std::vector<std::string> all;
392 all.push_back(DATATYPE_STRING);
393 all.push_back(DATATYPE_NUMBER);
394 all.push_back(DATATYPE_TIME);
400 std::map<std::pair<std::string,std::string>,std::string> ViewColumnInfo::getAllDefaultsForGUI(
void)
402 std::map<std::pair<std::string,std::string>,std::string> all;
403 all[std::pair<std::string,std::string>(DATATYPE_NUMBER,
"*")] = DATATYPE_NUMBER_DEFAULT;
404 all[std::pair<std::string,std::string>(DATATYPE_TIME,
"*")] = DATATYPE_TIME_DEFAULT;
406 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_ON_OFF)] = DATATYPE_BOOL_DEFAULT;
407 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_TRUE_FALSE)] = DATATYPE_BOOL_DEFAULT;
408 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_YES_NO)] = DATATYPE_BOOL_DEFAULT;
410 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_START_CHILD_LINK)] = DATATYPE_LINK_DEFAULT;
411 all[std::pair<std::string,std::string>(DATATYPE_STRING,
"*")] = DATATYPE_STRING_DEFAULT;
416 const std::string& ViewColumnInfo::getName(
void)
const
422 const std::string& ViewColumnInfo::getStorageName(
void)
const
428 const std::string& ViewColumnInfo::getDataType(
void)
const
434 const std::vector<std::string>& ViewColumnInfo::getDataChoices(
void)
const
444 if(bitMapInfoP_)
return *bitMapInfoP_;
448 __SS__ <<
"getBitMapInfo request for non-BitMap column of type: " << getType() << std::endl;
449 __COUT_ERR__ <<
"\n" << ss.str();
450 throw std::runtime_error(ss.str());
459 const bool ViewColumnInfo::isChildLink(
void)
const
461 return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
462 type_.length() > TYPE_START_CHILD_LINK.length() &&
463 type_[TYPE_START_CHILD_LINK.length()] ==
'-');
470 const bool ViewColumnInfo::isChildLinkUID(
void)
const
472 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
473 type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
474 type_[TYPE_START_CHILD_LINK_UID.length()] ==
'-');
481 const bool ViewColumnInfo::isChildLinkGroupID(
void)
const
483 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
484 type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
485 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] ==
'-');
492 const bool ViewColumnInfo::isGroupID(
void)
const
494 return (type_.find(TYPE_START_GROUP_ID) == 0 &&
495 type_.length() > TYPE_START_GROUP_ID.length() &&
496 type_[TYPE_START_GROUP_ID.length()] ==
'-');
501 std::string ViewColumnInfo::getChildLinkIndex (
void)
const
505 return type_.substr(TYPE_START_CHILD_LINK.length()+1);
506 else if(isChildLinkUID())
507 return type_.substr(TYPE_START_CHILD_LINK_UID.length()+1);
508 else if(isChildLinkGroupID())
509 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length()+1);
511 return type_.substr(TYPE_START_GROUP_ID.length()+1);
514 __SS__ << (
"Requesting a Link Index from a column that is not a child link member!") << std::endl;
515 __COUT_ERR__ << ss.str();
516 throw std::runtime_error(ss.str());