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";
56 ViewColumnInfo::ViewColumnInfo(
const std::string &type,
const std::string &name,
57 const std::string &storageName,
const std::string &dataType,
58 const std::string &dataChoicesCSV, std::string *capturedExceptionString)
61 , storageName_(storageName)
62 , dataType_ (dataType)
66 if((type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) && (type_ != TYPE_UID) &&
67 (type_ != TYPE_MULTILINE_DATA) && (type_ != TYPE_FIXED_CHOICE_DATA) &&
68 (type_ != TYPE_BITMAP_DATA) &&
69 (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
70 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
73 !isChildLinkGroupID() &&
76 __SS__ <<
"The type for column " << name_ <<
" is " << type_ <<
77 ", while the only accepted types are: " <<
79 TYPE_UNIQUE_DATA <<
" " <<
80 TYPE_MULTILINE_DATA <<
" " <<
81 TYPE_FIXED_CHOICE_DATA <<
" " <<
84 TYPE_TRUE_FALSE <<
" " <<
86 TYPE_START_CHILD_LINK <<
"-* " <<
87 TYPE_START_CHILD_LINK_UID <<
"-* " <<
88 TYPE_START_CHILD_LINK_GROUP_ID <<
"-* " <<
89 TYPE_START_GROUP_ID <<
"-* " << std::endl;
90 if(capturedExceptionString) *capturedExceptionString = ss.str();
91 else throw std::runtime_error(ss.str());
93 else if(capturedExceptionString) *capturedExceptionString =
"";
97 for(
unsigned int i=0;i<type_.size();++i)
99 (type_[i] >=
'A' && type_[i] <=
'Z') ||
100 (type_[i] >=
'a' && type_[i] <=
'z') ||
101 (type_[i] >=
'0' && type_[i] <=
'9') ||
102 (type_[i] ==
'-' || type_[i] <=
'_' || type_[i] <=
'.')
105 __SS__ <<
"The data type for column " << name_ <<
" is '" << type_ <<
106 "'. Data types must contain only letters, numbers," <<
107 "dashes, underscores, and periods." << std::endl;
108 if(capturedExceptionString) *capturedExceptionString += ss.str();
109 else throw std::runtime_error(ss.str());
114 if((dataType_ != DATATYPE_NUMBER) &&
115 (dataType_ != DATATYPE_STRING) &&
116 (dataType_ != DATATYPE_TIME))
118 __SS__ <<
"The data type for column " << name_ <<
" is " << dataType_ <<
119 ", while the only accepted types are: " <<
120 DATATYPE_NUMBER <<
" " <<
121 DATATYPE_STRING <<
" " <<
122 DATATYPE_TIME << std::endl;
123 if(capturedExceptionString) *capturedExceptionString += ss.str();
124 else throw std::runtime_error(ss.str());
128 if(dataType_.size() == 0)
130 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
131 "'. Data types must contain at least 1 character." << std::endl;
132 if(capturedExceptionString) *capturedExceptionString += ss.str();
133 else throw std::runtime_error(ss.str());
138 for(
unsigned int i=0;i<dataType_.size();++i)
140 (dataType_[i] >=
'A' && dataType_[i] <=
'Z') ||
141 (dataType_[i] >=
'a' && dataType_[i] <=
'z') ||
142 (dataType_[i] >=
'0' && dataType_[i] <=
'9') ||
143 (dataType_[i] ==
'-' || dataType_[i] <=
'_')
146 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
147 "'. Data types must contain only letters, numbers," <<
148 "dashes, and underscores." << std::endl;
149 if(capturedExceptionString) *capturedExceptionString += ss.str();
150 else throw std::runtime_error(ss.str());
153 if(name_.size() == 0)
155 __SS__ <<
"There is a column named " << name_ <<
156 "'. Column names must contain at least 1 character." << std::endl;
157 if(capturedExceptionString) *capturedExceptionString += ss.str();
158 else throw std::runtime_error(ss.str());
163 for(
unsigned int i=0;i<name_.size();++i)
165 (name_[i] >=
'A' && name_[i] <=
'Z') ||
166 (name_[i] >=
'a' && name_[i] <=
'z') ||
167 (name_[i] >=
'0' && name_[i] <=
'9') ||
168 (name_[i] ==
'-' || name_[i] <=
'_')
171 __SS__ <<
"There is a column named " << name_ <<
172 "'. Column names must contain only letters, numbers," <<
173 "dashes, and underscores." << std::endl;
174 if(capturedExceptionString) *capturedExceptionString += ss.str();
175 else throw std::runtime_error(ss.str());
179 if(storageName_.size() == 0)
181 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
182 "'. Storage names must contain at least 1 character." << std::endl;
183 if(capturedExceptionString) *capturedExceptionString += ss.str();
184 else throw std::runtime_error(ss.str());
189 for(
unsigned int i=0;i<storageName_.size();++i)
191 (storageName_[i] >=
'A' && storageName_[i] <=
'Z') ||
192 (storageName_[i] >=
'0' && storageName_[i] <=
'9') ||
193 (storageName_[i] ==
'-' || storageName_[i] <=
'_')
196 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
197 "'. Storage names must contain only capital letters, numbers," <<
198 "dashes, and underscores." << std::endl;
199 if(capturedExceptionString) *capturedExceptionString += ss.str();
200 else throw std::runtime_error(ss.str());
206 std::istringstream f(dataChoicesCSV);
208 while (getline(f, s,
',')) dataChoices_.push_back(
209 ConfigurationView::decodeURIComponent(s));
218 catch(std::runtime_error &e)
220 if(capturedExceptionString) *capturedExceptionString += e.what();
228 void ViewColumnInfo::extractBitMapInfo()
231 if(type_ == TYPE_BITMAP_DATA)
233 if(bitMapInfoP_)
delete bitMapInfoP_;
234 bitMapInfoP_ =
new BitMapInfo();
260 if(dataChoices_.size() < 16)
262 __SS__ <<
"The Bit-Map data parameters for column " << name_ <<
263 " should be size 16, but is size " << dataChoices_.size() <<
264 ". Bit-Map parameters should be rows, cols, cellBitSize, and min, mid, max color." <<
266 throw std::runtime_error(ss.str());
269 sscanf(dataChoices_[0].c_str(),
"%u",&(bitMapInfoP_->numOfRows_));
270 sscanf(dataChoices_[1].c_str(),
"%u",&(bitMapInfoP_->numOfColumns_));
271 sscanf(dataChoices_[2].c_str(),
"%u",&(bitMapInfoP_->cellBitSize_));
273 sscanf(dataChoices_[3].c_str(),
"%lu",&(bitMapInfoP_->minValue_));
274 sscanf(dataChoices_[4].c_str(),
"%lu",&(bitMapInfoP_->maxValue_));
275 sscanf(dataChoices_[5].c_str(),
"%lu",&(bitMapInfoP_->stepValue_));
277 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
278 bitMapInfoP_->minColor_ = dataChoices_[7];
279 bitMapInfoP_->midColor_ = dataChoices_[8];
280 bitMapInfoP_->maxColor_ = dataChoices_[9];
281 bitMapInfoP_->absMinColor_ = dataChoices_[10];
282 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
284 bitMapInfoP_->rowsAscending_ = dataChoices_[12] ==
"Yes"?1:0;
285 bitMapInfoP_->colsAscending_ = dataChoices_[13] ==
"Yes"?1:0;
286 bitMapInfoP_->snakeRows_ = dataChoices_[14] ==
"Yes"?1:0;
287 bitMapInfoP_->snakeCols_ = dataChoices_[15] ==
"Yes"?1:0;
293 ViewColumnInfo::ViewColumnInfo(
void){}
299 ,storageName_(c.storageName_)
300 ,dataType_(c.dataType_)
301 ,dataChoices_(c.dataChoices_)
312 retColInfo->type_ = c.type_;
313 retColInfo->name_ = c.name_;
314 retColInfo->storageName_ = c.storageName_;
315 retColInfo->dataType_ = c.dataType_;
316 retColInfo->dataChoices_ = c.dataChoices_;
317 retColInfo->bitMapInfoP_ = 0;
320 retColInfo->extractBitMapInfo();
326 ViewColumnInfo::~ViewColumnInfo(
void)
328 if(bitMapInfoP_)
delete bitMapInfoP_;
332 const std::string& ViewColumnInfo::getType(
void)
const
338 const std::string& ViewColumnInfo::getDefaultValue(
void)
const
340 if(getDataType() == ViewColumnInfo::DATATYPE_STRING)
342 if(getType() == ViewColumnInfo::TYPE_ON_OFF ||
343 getType() == ViewColumnInfo::TYPE_TRUE_FALSE ||
344 getType() == ViewColumnInfo::TYPE_YES_NO)
345 return (ViewColumnInfo::DATATYPE_BOOL_DEFAULT);
346 else if(isChildLink())
347 return (ViewColumnInfo::DATATYPE_LINK_DEFAULT);
348 else if(getType() == ViewColumnInfo::TYPE_COMMENT)
349 return (ViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
351 return (ViewColumnInfo::DATATYPE_STRING_DEFAULT);
353 else if(getDataType() == ViewColumnInfo::DATATYPE_NUMBER)
354 return (ViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
355 else if(getDataType() == ViewColumnInfo::DATATYPE_TIME)
356 return (ViewColumnInfo::DATATYPE_TIME_DEFAULT);
359 __SS__ <<
"\tUnrecognized View data type: " << getDataType() << std::endl;
360 __MOUT_ERR__ <<
"\n" << ss.str();
361 throw std::runtime_error(ss.str());
366 std::vector<std::string> ViewColumnInfo::getAllTypesForGUI(
void)
368 std::vector<std::string> all;
369 all.push_back(TYPE_DATA);
370 all.push_back(TYPE_UNIQUE_DATA);
371 all.push_back(TYPE_FIXED_CHOICE_DATA);
372 all.push_back(TYPE_MULTILINE_DATA);
373 all.push_back(TYPE_BITMAP_DATA);
374 all.push_back(TYPE_ON_OFF);
375 all.push_back(TYPE_TRUE_FALSE);
376 all.push_back(TYPE_YES_NO);
377 all.push_back(TYPE_START_CHILD_LINK_UID);
378 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
379 all.push_back(TYPE_START_CHILD_LINK);
380 all.push_back(TYPE_START_GROUP_ID);
385 std::vector<std::string> ViewColumnInfo::getAllDataTypesForGUI(
void)
387 std::vector<std::string> all;
388 all.push_back(DATATYPE_STRING);
389 all.push_back(DATATYPE_NUMBER);
390 all.push_back(DATATYPE_TIME);
396 std::map<std::pair<std::string,std::string>,std::string> ViewColumnInfo::getAllDefaultsForGUI(
void)
398 std::map<std::pair<std::string,std::string>,std::string> all;
399 all[std::pair<std::string,std::string>(DATATYPE_NUMBER,
"*")] = DATATYPE_NUMBER_DEFAULT;
400 all[std::pair<std::string,std::string>(DATATYPE_TIME,
"*")] = DATATYPE_TIME_DEFAULT;
402 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_ON_OFF)] = DATATYPE_BOOL_DEFAULT;
403 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_TRUE_FALSE)] = DATATYPE_BOOL_DEFAULT;
404 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_YES_NO)] = DATATYPE_BOOL_DEFAULT;
406 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_START_CHILD_LINK)] = DATATYPE_LINK_DEFAULT;
407 all[std::pair<std::string,std::string>(DATATYPE_STRING,
"*")] = DATATYPE_STRING_DEFAULT;
412 const std::string& ViewColumnInfo::getName(
void)
const
418 const std::string& ViewColumnInfo::getStorageName(
void)
const
424 const std::string& ViewColumnInfo::getDataType(
void)
const
430 const std::vector<std::string>& ViewColumnInfo::getDataChoices(
void)
const
440 if(bitMapInfoP_)
return *bitMapInfoP_;
444 __SS__ <<
"getBitMapInfo request for non-BitMap column of type: " << getType() << std::endl;
445 __MOUT_ERR__ <<
"\n" << ss.str();
446 throw std::runtime_error(ss.str());
455 const bool ViewColumnInfo::isChildLink(
void)
const
457 return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
458 type_.length() > TYPE_START_CHILD_LINK.length() &&
459 type_[TYPE_START_CHILD_LINK.length()] ==
'-');
466 const bool ViewColumnInfo::isChildLinkUID(
void)
const
468 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
469 type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
470 type_[TYPE_START_CHILD_LINK_UID.length()] ==
'-');
477 const bool ViewColumnInfo::isChildLinkGroupID(
void)
const
479 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
480 type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
481 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] ==
'-');
488 const bool ViewColumnInfo::isGroupID(
void)
const
490 return (type_.find(TYPE_START_GROUP_ID) == 0 &&
491 type_.length() > TYPE_START_GROUP_ID.length() &&
492 type_[TYPE_START_GROUP_ID.length()] ==
'-');
497 std::string ViewColumnInfo::getChildLinkIndex (
void)
const
501 return type_.substr(TYPE_START_CHILD_LINK.length()+1);
502 else if(isChildLinkUID())
503 return type_.substr(TYPE_START_CHILD_LINK_UID.length()+1);
504 else if(isChildLinkGroupID())
505 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length()+1);
507 return type_.substr(TYPE_START_GROUP_ID.length()+1);
509 throw std::runtime_error(
"Requesting a Link Index from a column that is not a child link member!");