1 #include "otsdaq-core/ConfigurationDataFormats/ViewColumnInfo.h"
2 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
3 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationView.h"
12 const std::string ViewColumnInfo::TYPE_UID =
"UID";
14 const std::string ViewColumnInfo::TYPE_DATA =
"Data";
15 const std::string ViewColumnInfo::TYPE_UNIQUE_DATA =
"UniqueData";
16 const std::string ViewColumnInfo::TYPE_MULTILINE_DATA =
"MultilineData";
17 const std::string ViewColumnInfo::TYPE_FIXED_CHOICE_DATA =
"FixedChoiceData";
18 const std::string ViewColumnInfo::TYPE_BITMAP_DATA =
"BitMap";
20 const std::string ViewColumnInfo::TYPE_ON_OFF =
"OnOff";
21 const std::string ViewColumnInfo::TYPE_TRUE_FALSE =
"TrueFalse";
22 const std::string ViewColumnInfo::TYPE_YES_NO =
"YesNo";
24 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK =
"ChildLink";
25 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK_UID =
"ChildLinkUID";
26 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID =
"ChildLinkGroupID";
27 const std::string ViewColumnInfo::TYPE_START_GROUP_ID =
"GroupID";
28 const std::string ViewColumnInfo::TYPE_COMMENT =
"Comment";
29 const std::string ViewColumnInfo::TYPE_AUTHOR =
"Author";
30 const std::string ViewColumnInfo::TYPE_TIMESTAMP =
"Timestamp";
33 const std::string ViewColumnInfo::DATATYPE_NUMBER =
"NUMBER";
34 const std::string ViewColumnInfo::DATATYPE_STRING =
"VARCHAR2";
35 const std::string ViewColumnInfo::DATATYPE_TIME =
"TIMESTAMP WITH TIMEZONE";
37 const std::string ViewColumnInfo::TYPE_VALUE_YES =
"Yes";
38 const std::string ViewColumnInfo::TYPE_VALUE_NO =
"No";
39 const std::string ViewColumnInfo::TYPE_VALUE_TRUE =
"True";
40 const std::string ViewColumnInfo::TYPE_VALUE_FALSE =
"False";
41 const std::string ViewColumnInfo::TYPE_VALUE_ON =
"On";
42 const std::string ViewColumnInfo::TYPE_VALUE_OFF =
"Off";
44 const std::string ViewColumnInfo::DATATYPE_STRING_DEFAULT =
"DEFAULT";
45 const std::string ViewColumnInfo::DATATYPE_COMMENT_DEFAULT =
"No Comment";
46 const std::string ViewColumnInfo::DATATYPE_BOOL_DEFAULT =
"0";
47 const std::string ViewColumnInfo::DATATYPE_NUMBER_DEFAULT =
"0";
48 const std::string ViewColumnInfo::DATATYPE_TIME_DEFAULT =
"0";
49 const std::string ViewColumnInfo::DATATYPE_LINK_DEFAULT =
"NO_LINK";
51 const std::string ViewColumnInfo::COL_NAME_STATUS =
"Status";
58 ViewColumnInfo::ViewColumnInfo(
const std::string &type,
const std::string &name,
59 const std::string &storageName,
const std::string &dataType,
60 const std::string &dataChoicesCSV, std::string *capturedExceptionString)
63 , storageName_(storageName)
64 , dataType_ (dataType)
68 if((type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) && (type_ != TYPE_UID) &&
69 (type_ != TYPE_MULTILINE_DATA) && (type_ != TYPE_FIXED_CHOICE_DATA) &&
70 (type_ != TYPE_BITMAP_DATA) &&
71 (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
72 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
75 !isChildLinkGroupID() &&
78 __SS__ <<
"The type for column " << name_ <<
" is " << type_ <<
79 ", while the only accepted types are: " <<
81 TYPE_UNIQUE_DATA <<
" " <<
82 TYPE_MULTILINE_DATA <<
" " <<
83 TYPE_FIXED_CHOICE_DATA <<
" " <<
86 TYPE_TRUE_FALSE <<
" " <<
88 TYPE_START_CHILD_LINK <<
"-* " <<
89 TYPE_START_CHILD_LINK_UID <<
"-* " <<
90 TYPE_START_CHILD_LINK_GROUP_ID <<
"-* " <<
91 TYPE_START_GROUP_ID <<
"-* " << std::endl;
92 if(capturedExceptionString) *capturedExceptionString = ss.str();
93 else throw std::runtime_error(ss.str());
95 else if(capturedExceptionString) *capturedExceptionString =
"";
99 for(
unsigned int i=0;i<type_.size();++i)
101 (type_[i] >=
'A' && type_[i] <=
'Z') ||
102 (type_[i] >=
'a' && type_[i] <=
'z') ||
103 (type_[i] >=
'0' && type_[i] <=
'9') ||
104 (type_[i] ==
'-' || type_[i] <=
'_' || type_[i] <=
'.')
107 __SS__ <<
"The data type for column " << name_ <<
" is '" << type_ <<
108 "'. Data types must contain only letters, numbers," <<
109 "dashes, underscores, and periods." << std::endl;
110 if(capturedExceptionString) *capturedExceptionString += ss.str();
111 else throw std::runtime_error(ss.str());
116 if((dataType_ != DATATYPE_NUMBER) &&
117 (dataType_ != DATATYPE_STRING) &&
118 (dataType_ != DATATYPE_TIME))
120 __SS__ <<
"The data type for column " << name_ <<
" is " << dataType_ <<
121 ", while the only accepted types are: " <<
122 DATATYPE_NUMBER <<
" " <<
123 DATATYPE_STRING <<
" " <<
124 DATATYPE_TIME << std::endl;
125 if(capturedExceptionString) *capturedExceptionString += ss.str();
126 else throw std::runtime_error(ss.str());
130 if(dataType_.size() == 0)
132 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
133 "'. Data types must contain at least 1 character." << std::endl;
134 if(capturedExceptionString) *capturedExceptionString += ss.str();
135 else throw std::runtime_error(ss.str());
140 for(
unsigned int i=0;i<dataType_.size();++i)
142 (dataType_[i] >=
'A' && dataType_[i] <=
'Z') ||
143 (dataType_[i] >=
'a' && dataType_[i] <=
'z') ||
144 (dataType_[i] >=
'0' && dataType_[i] <=
'9') ||
145 (dataType_[i] ==
'-' || dataType_[i] <=
'_')
148 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
149 "'. Data types must contain only letters, numbers," <<
150 "dashes, and underscores." << std::endl;
151 if(capturedExceptionString) *capturedExceptionString += ss.str();
152 else throw std::runtime_error(ss.str());
155 if(name_.size() == 0)
157 __SS__ <<
"There is a column named " << name_ <<
158 "'. Column names must contain at least 1 character." << std::endl;
159 if(capturedExceptionString) *capturedExceptionString += ss.str();
160 else throw std::runtime_error(ss.str());
165 for(
unsigned int i=0;i<name_.size();++i)
167 (name_[i] >=
'A' && name_[i] <=
'Z') ||
168 (name_[i] >=
'a' && name_[i] <=
'z') ||
169 (name_[i] >=
'0' && name_[i] <=
'9') ||
170 (name_[i] ==
'-' || name_[i] <=
'_')
173 __SS__ <<
"There is a column named " << name_ <<
174 "'. Column names must contain only letters, numbers," <<
175 "dashes, and underscores." << std::endl;
176 if(capturedExceptionString) *capturedExceptionString += ss.str();
177 else throw std::runtime_error(ss.str());
181 if(storageName_.size() == 0)
183 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
184 "'. Storage names must contain at least 1 character." << std::endl;
185 if(capturedExceptionString) *capturedExceptionString += ss.str();
186 else throw std::runtime_error(ss.str());
191 for(
unsigned int i=0;i<storageName_.size();++i)
193 (storageName_[i] >=
'A' && storageName_[i] <=
'Z') ||
194 (storageName_[i] >=
'0' && storageName_[i] <=
'9') ||
195 (storageName_[i] ==
'-' || storageName_[i] <=
'_')
198 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
199 "'. Storage names must contain only capital letters, numbers," <<
200 "dashes, and underscores." << std::endl;
201 if(capturedExceptionString) *capturedExceptionString += ss.str();
202 else throw std::runtime_error(ss.str());
208 std::istringstream f(dataChoicesCSV);
210 while (getline(f, s,
',')) dataChoices_.push_back(
211 ConfigurationView::decodeURIComponent(s));
220 catch(std::runtime_error &e)
222 if(capturedExceptionString) *capturedExceptionString += e.what();
230 void ViewColumnInfo::extractBitMapInfo()
233 if(type_ == TYPE_BITMAP_DATA)
235 if(bitMapInfoP_)
delete bitMapInfoP_;
236 bitMapInfoP_ =
new BitMapInfo();
262 if(dataChoices_.size() < 16)
264 __SS__ <<
"The Bit-Map data parameters for column " << name_ <<
265 " should be size 16, but is size " << dataChoices_.size() <<
266 ". Bit-Map parameters should be rows, cols, cellBitSize, and min, mid, max color." <<
268 throw std::runtime_error(ss.str());
271 sscanf(dataChoices_[0].c_str(),
"%u",&(bitMapInfoP_->numOfRows_));
272 sscanf(dataChoices_[1].c_str(),
"%u",&(bitMapInfoP_->numOfColumns_));
273 sscanf(dataChoices_[2].c_str(),
"%u",&(bitMapInfoP_->cellBitSize_));
275 sscanf(dataChoices_[3].c_str(),
"%lu",&(bitMapInfoP_->minValue_));
276 sscanf(dataChoices_[4].c_str(),
"%lu",&(bitMapInfoP_->maxValue_));
277 sscanf(dataChoices_[5].c_str(),
"%lu",&(bitMapInfoP_->stepValue_));
279 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
280 bitMapInfoP_->minColor_ = dataChoices_[7];
281 bitMapInfoP_->midColor_ = dataChoices_[8];
282 bitMapInfoP_->maxColor_ = dataChoices_[9];
283 bitMapInfoP_->absMinColor_ = dataChoices_[10];
284 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
286 bitMapInfoP_->rowsAscending_ = dataChoices_[12] ==
"Yes"?1:0;
287 bitMapInfoP_->colsAscending_ = dataChoices_[13] ==
"Yes"?1:0;
288 bitMapInfoP_->snakeRows_ = dataChoices_[14] ==
"Yes"?1:0;
289 bitMapInfoP_->snakeCols_ = dataChoices_[15] ==
"Yes"?1:0;
295 ViewColumnInfo::ViewColumnInfo(
void){}
301 ,storageName_(c.storageName_)
302 ,dataType_(c.dataType_)
303 ,dataChoices_(c.dataChoices_)
314 retColInfo->type_ = c.type_;
315 retColInfo->name_ = c.name_;
316 retColInfo->storageName_ = c.storageName_;
317 retColInfo->dataType_ = c.dataType_;
318 retColInfo->dataChoices_ = c.dataChoices_;
319 retColInfo->bitMapInfoP_ = 0;
322 retColInfo->extractBitMapInfo();
328 ViewColumnInfo::~ViewColumnInfo(
void)
330 if(bitMapInfoP_)
delete bitMapInfoP_;
334 const std::string& ViewColumnInfo::getType(
void)
const
340 const std::string& ViewColumnInfo::getDefaultValue(
void)
const
342 if(getDataType() == ViewColumnInfo::DATATYPE_STRING)
344 if(getType() == ViewColumnInfo::TYPE_ON_OFF ||
345 getType() == ViewColumnInfo::TYPE_TRUE_FALSE ||
346 getType() == ViewColumnInfo::TYPE_YES_NO)
347 return (ViewColumnInfo::DATATYPE_BOOL_DEFAULT);
348 else if(isChildLink())
349 return (ViewColumnInfo::DATATYPE_LINK_DEFAULT);
350 else if(getType() == ViewColumnInfo::TYPE_COMMENT)
351 return (ViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
353 return (ViewColumnInfo::DATATYPE_STRING_DEFAULT);
355 else if(getDataType() == ViewColumnInfo::DATATYPE_NUMBER)
356 return (ViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
357 else if(getDataType() == ViewColumnInfo::DATATYPE_TIME)
358 return (ViewColumnInfo::DATATYPE_TIME_DEFAULT);
361 __SS__ <<
"\tUnrecognized View data type: " << getDataType() << std::endl;
362 __COUT_ERR__ <<
"\n" << ss.str();
363 throw std::runtime_error(ss.str());
368 std::vector<std::string> ViewColumnInfo::getAllTypesForGUI(
void)
370 std::vector<std::string> all;
371 all.push_back(TYPE_DATA);
372 all.push_back(TYPE_UNIQUE_DATA);
373 all.push_back(TYPE_FIXED_CHOICE_DATA);
374 all.push_back(TYPE_MULTILINE_DATA);
375 all.push_back(TYPE_BITMAP_DATA);
376 all.push_back(TYPE_ON_OFF);
377 all.push_back(TYPE_TRUE_FALSE);
378 all.push_back(TYPE_YES_NO);
379 all.push_back(TYPE_START_CHILD_LINK_UID);
380 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
381 all.push_back(TYPE_START_CHILD_LINK);
382 all.push_back(TYPE_START_GROUP_ID);
387 std::vector<std::string> ViewColumnInfo::getAllDataTypesForGUI(
void)
389 std::vector<std::string> all;
390 all.push_back(DATATYPE_STRING);
391 all.push_back(DATATYPE_NUMBER);
392 all.push_back(DATATYPE_TIME);
398 std::map<std::pair<std::string,std::string>,std::string> ViewColumnInfo::getAllDefaultsForGUI(
void)
400 std::map<std::pair<std::string,std::string>,std::string> all;
401 all[std::pair<std::string,std::string>(DATATYPE_NUMBER,
"*")] = DATATYPE_NUMBER_DEFAULT;
402 all[std::pair<std::string,std::string>(DATATYPE_TIME,
"*")] = DATATYPE_TIME_DEFAULT;
404 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_ON_OFF)] = DATATYPE_BOOL_DEFAULT;
405 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_TRUE_FALSE)] = DATATYPE_BOOL_DEFAULT;
406 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_YES_NO)] = DATATYPE_BOOL_DEFAULT;
408 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_START_CHILD_LINK)] = DATATYPE_LINK_DEFAULT;
409 all[std::pair<std::string,std::string>(DATATYPE_STRING,
"*")] = DATATYPE_STRING_DEFAULT;
414 const std::string& ViewColumnInfo::getName(
void)
const
420 const std::string& ViewColumnInfo::getStorageName(
void)
const
426 const std::string& ViewColumnInfo::getDataType(
void)
const
432 const std::vector<std::string>& ViewColumnInfo::getDataChoices(
void)
const
442 if(bitMapInfoP_)
return *bitMapInfoP_;
446 __SS__ <<
"getBitMapInfo request for non-BitMap column of type: " << getType() << std::endl;
447 __COUT_ERR__ <<
"\n" << ss.str();
448 throw std::runtime_error(ss.str());
457 const bool ViewColumnInfo::isChildLink(
void)
const
459 return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
460 type_.length() > TYPE_START_CHILD_LINK.length() &&
461 type_[TYPE_START_CHILD_LINK.length()] ==
'-');
468 const bool ViewColumnInfo::isChildLinkUID(
void)
const
470 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
471 type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
472 type_[TYPE_START_CHILD_LINK_UID.length()] ==
'-');
479 const bool ViewColumnInfo::isChildLinkGroupID(
void)
const
481 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
482 type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
483 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] ==
'-');
490 const bool ViewColumnInfo::isGroupID(
void)
const
492 return (type_.find(TYPE_START_GROUP_ID) == 0 &&
493 type_.length() > TYPE_START_GROUP_ID.length() &&
494 type_[TYPE_START_GROUP_ID.length()] ==
'-');
499 std::string ViewColumnInfo::getChildLinkIndex (
void)
const
503 return type_.substr(TYPE_START_CHILD_LINK.length()+1);
504 else if(isChildLinkUID())
505 return type_.substr(TYPE_START_CHILD_LINK_UID.length()+1);
506 else if(isChildLinkGroupID())
507 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length()+1);
509 return type_.substr(TYPE_START_GROUP_ID.length()+1);
512 __SS__ << (
"Requesting a Link Index from a column that is not a child link member!") << std::endl;
513 __COUT_ERR__ << ss.str();
514 throw std::runtime_error(ss.str());