1 #include "otsdaq/TableCore/TableViewColumnInfo.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/Macros/StringMacros.h"
10 #include "otsdaq/TableCore/TableView.h"
16 const std::string TableViewColumnInfo::TYPE_UID =
"UID";
18 const std::string TableViewColumnInfo::TYPE_DATA =
"Data";
19 const std::string TableViewColumnInfo::TYPE_UNIQUE_DATA =
"UniqueData";
20 const std::string TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA =
"UniqueGroupData";
21 const std::string TableViewColumnInfo::TYPE_MULTILINE_DATA =
"MultilineData";
22 const std::string TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA =
"FixedChoiceData";
23 const std::string TableViewColumnInfo::TYPE_BITMAP_DATA =
"BitMap";
25 const std::string TableViewColumnInfo::TYPE_ON_OFF =
"OnOff";
26 const std::string TableViewColumnInfo::TYPE_TRUE_FALSE =
"TrueFalse";
27 const std::string TableViewColumnInfo::TYPE_YES_NO =
"YesNo";
29 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK =
"ChildLink";
30 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_UID =
"ChildLinkUID";
31 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID =
33 const std::string TableViewColumnInfo::TYPE_START_GROUP_ID =
"GroupID";
34 const std::string TableViewColumnInfo::TYPE_COMMENT =
"Comment";
35 const std::string TableViewColumnInfo::TYPE_AUTHOR =
"Author";
36 const std::string TableViewColumnInfo::TYPE_TIMESTAMP =
"Timestamp";
40 const std::string TableViewColumnInfo::DATATYPE_NUMBER =
"NUMBER";
41 const std::string TableViewColumnInfo::DATATYPE_STRING =
"VARCHAR2";
42 const std::string TableViewColumnInfo::DATATYPE_TIME =
"TIMESTAMP WITH TIMEZONE";
44 const std::string TableViewColumnInfo::TYPE_VALUE_YES =
"Yes";
45 const std::string TableViewColumnInfo::TYPE_VALUE_NO =
"No";
46 const std::string TableViewColumnInfo::TYPE_VALUE_TRUE =
"True";
47 const std::string TableViewColumnInfo::TYPE_VALUE_FALSE =
"False";
48 const std::string TableViewColumnInfo::TYPE_VALUE_ON =
"On";
49 const std::string TableViewColumnInfo::TYPE_VALUE_OFF =
"Off";
51 const std::string TableViewColumnInfo::DATATYPE_STRING_DEFAULT =
"DEFAULT";
52 const std::string TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT =
"No Comment";
53 const std::string TableViewColumnInfo::DATATYPE_BOOL_DEFAULT =
"0";
54 const std::string TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT =
"0";
55 const std::string TableViewColumnInfo::DATATYPE_TIME_DEFAULT =
"0";
56 const std::string TableViewColumnInfo::DATATYPE_LINK_DEFAULT =
"NO_LINK";
58 const std::string TableViewColumnInfo::COL_NAME_STATUS =
"Status";
59 const std::string TableViewColumnInfo::COL_NAME_ENABLED =
"Enabled";
60 const std::string TableViewColumnInfo::COL_NAME_PRIORITY =
"Priority";
61 const std::string TableViewColumnInfo::COL_NAME_COMMENT =
"CommentDescription";
67 TableViewColumnInfo::TableViewColumnInfo(
const std::string& type,
68 const std::string& name,
69 const std::string& storageName,
70 const std::string& dataType,
71 const std::string& dataChoicesCSV,
72 std::string* capturedExceptionString)
75 , storageName_(storageName)
80 if((type_ != TYPE_UID) && (type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) &&
81 (type_ != TYPE_UNIQUE_GROUP_DATA) && (type_ != TYPE_MULTILINE_DATA) &&
82 (type_ != TYPE_FIXED_CHOICE_DATA) && (type_ != TYPE_BITMAP_DATA) &&
83 (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
84 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
85 !isChildLink() && !isChildLinkUID() && !isChildLinkGroupID() && !isGroupID())
87 __SS__ <<
"The type for column " << name_ <<
" is " << type_
88 <<
", while the only accepted types are: " << TYPE_DATA <<
" "
89 << TYPE_UNIQUE_DATA <<
" " << TYPE_UNIQUE_GROUP_DATA <<
" "
90 << TYPE_MULTILINE_DATA <<
" " << TYPE_FIXED_CHOICE_DATA <<
" " << TYPE_UID
91 <<
" " << TYPE_ON_OFF <<
" " << TYPE_TRUE_FALSE <<
" " << TYPE_YES_NO
92 <<
" " << TYPE_START_CHILD_LINK <<
"-* " << TYPE_START_CHILD_LINK_UID
93 <<
"-* " << TYPE_START_CHILD_LINK_GROUP_ID <<
"-* " << TYPE_START_GROUP_ID
94 <<
"-* " << std::endl;
95 if(capturedExceptionString)
96 *capturedExceptionString = ss.str();
100 else if(capturedExceptionString)
101 *capturedExceptionString =
"";
105 for(
unsigned int i = 0; i < type_.size(); ++i)
106 if(!((type_[i] >=
'A' && type_[i] <=
'Z') ||
107 (type_[i] >=
'a' && type_[i] <=
'z') ||
108 (type_[i] >=
'0' && type_[i] <=
'9') ||
109 (type_[i] ==
'-' || type_[i] <=
'_' || type_[i] <=
'.')))
111 __SS__ <<
"The data type for column " << name_ <<
" is '" << type_
112 <<
"'. Data types must contain only letters, numbers,"
113 <<
"dashes, underscores, and periods." << std::endl;
114 if(capturedExceptionString)
115 *capturedExceptionString += ss.str();
121 if((dataType_ != DATATYPE_NUMBER) && (dataType_ != DATATYPE_STRING) &&
122 (dataType_ != DATATYPE_TIME))
124 __SS__ <<
"The data type for column " << name_ <<
" is " << dataType_
125 <<
", while the only accepted types are: " << DATATYPE_NUMBER <<
" "
126 << DATATYPE_STRING <<
" " << DATATYPE_TIME << std::endl;
127 if(capturedExceptionString)
128 *capturedExceptionString += ss.str();
133 if(dataType_.size() == 0)
135 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_
136 <<
"'. Data types must contain at least 1 character." << std::endl;
137 if(capturedExceptionString)
138 *capturedExceptionString += ss.str();
145 for(
unsigned int i = 0; i < dataType_.size(); ++i)
146 if(!((dataType_[i] >=
'A' && dataType_[i] <=
'Z') ||
147 (dataType_[i] >=
'a' && dataType_[i] <=
'z') ||
148 (dataType_[i] >=
'0' && dataType_[i] <=
'9') ||
149 (dataType_[i] ==
'-' || dataType_[i] <=
'_')))
151 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_
152 <<
"'. Data types must contain only letters, numbers,"
153 <<
"dashes, and underscores." << std::endl;
154 if(capturedExceptionString)
155 *capturedExceptionString += ss.str();
160 if(name_.size() == 0)
162 __SS__ <<
"There is a column named " << name_
163 <<
"'. Column names must contain at least 1 character." << std::endl;
164 if(capturedExceptionString)
165 *capturedExceptionString += ss.str();
172 for(
unsigned int i = 0; i < name_.size(); ++i)
173 if(!((name_[i] >=
'A' && name_[i] <=
'Z') ||
174 (name_[i] >=
'a' && name_[i] <=
'z') ||
175 (name_[i] >=
'0' && name_[i] <=
'9') ||
176 (name_[i] ==
'-' || name_[i] <=
'_')))
178 __SS__ <<
"There is a column named " << name_
179 <<
"'. Column names must contain only letters, numbers,"
180 <<
"dashes, and underscores." << std::endl;
181 if(capturedExceptionString)
182 *capturedExceptionString += ss.str();
187 if(storageName_.size() == 0)
189 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_
190 <<
"'. Storage names must contain at least 1 character." << std::endl;
191 if(capturedExceptionString)
192 *capturedExceptionString += ss.str();
199 for(
unsigned int i = 0; i < storageName_.size(); ++i)
200 if(!((storageName_[i] >=
'A' && storageName_[i] <=
'Z') ||
201 (storageName_[i] >=
'0' && storageName_[i] <=
'9') ||
202 (storageName_[i] ==
'-' || storageName_[i] <=
'_')))
204 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_
205 <<
"'. Storage names must contain only capital letters, numbers,"
206 <<
"dashes, and underscores." << std::endl;
207 if(capturedExceptionString)
208 *capturedExceptionString += ss.str();
216 std::istringstream f(dataChoicesCSV);
218 while(getline(f, s,
','))
219 dataChoices_.push_back(StringMacros::decodeURIComponent(s));
228 catch(std::runtime_error& e)
230 if(capturedExceptionString)
231 *capturedExceptionString += e.what();
240 void TableViewColumnInfo::extractBitMapInfo()
243 if(type_ == TYPE_BITMAP_DATA)
247 bitMapInfoP_ =
new BitMapInfo();
272 if(dataChoices_.size() < 16)
274 __SS__ <<
"The Bit-Map data parameters for column " << name_
275 <<
" should be size 16, but is size " << dataChoices_.size()
276 <<
". Bit-Map parameters should be rows, cols, cellBitSize, and min, "
282 sscanf(dataChoices_[0].c_str(),
"%u", &(bitMapInfoP_->numOfRows_));
283 sscanf(dataChoices_[1].c_str(),
"%u", &(bitMapInfoP_->numOfColumns_));
284 sscanf(dataChoices_[2].c_str(),
"%u", &(bitMapInfoP_->cellBitSize_));
286 sscanf(dataChoices_[3].c_str(),
"%lu", &(bitMapInfoP_->minValue_));
287 sscanf(dataChoices_[4].c_str(),
"%lu", &(bitMapInfoP_->maxValue_));
288 sscanf(dataChoices_[5].c_str(),
"%lu", &(bitMapInfoP_->stepValue_));
290 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
291 bitMapInfoP_->minColor_ = dataChoices_[7];
292 bitMapInfoP_->midColor_ = dataChoices_[8];
293 bitMapInfoP_->maxColor_ = dataChoices_[9];
294 bitMapInfoP_->absMinColor_ = dataChoices_[10];
295 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
297 bitMapInfoP_->rowsAscending_ = dataChoices_[12] ==
"Yes" ? 1 : 0;
298 bitMapInfoP_->colsAscending_ = dataChoices_[13] ==
"Yes" ? 1 : 0;
299 bitMapInfoP_->snakeRows_ = dataChoices_[14] ==
"Yes" ? 1 : 0;
300 bitMapInfoP_->snakeCols_ = dataChoices_[15] ==
"Yes" ? 1 : 0;
306 TableViewColumnInfo::TableViewColumnInfo(
void) {}
309 TableViewColumnInfo::TableViewColumnInfo(
313 , storageName_(c.storageName_)
314 , dataType_(c.dataType_)
315 , dataChoices_(c.dataChoices_)
327 retColInfo->type_ = c.type_;
328 retColInfo->name_ = c.name_;
329 retColInfo->storageName_ = c.storageName_;
330 retColInfo->dataType_ = c.dataType_;
331 retColInfo->dataChoices_ = c.dataChoices_;
332 retColInfo->bitMapInfoP_ = 0;
335 retColInfo->extractBitMapInfo();
341 TableViewColumnInfo::~TableViewColumnInfo(
void)
348 const std::string& TableViewColumnInfo::getType(
void)
const {
return type_; }
351 const std::string& TableViewColumnInfo::getDefaultValue(
void)
const
353 if(getDataType() == TableViewColumnInfo::DATATYPE_STRING)
355 if(getType() == TableViewColumnInfo::TYPE_ON_OFF ||
356 getType() == TableViewColumnInfo::TYPE_TRUE_FALSE ||
357 getType() == TableViewColumnInfo::TYPE_YES_NO)
359 TableViewColumnInfo::DATATYPE_BOOL_DEFAULT);
360 else if(isChildLink())
361 return (TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
362 else if(getType() == TableViewColumnInfo::TYPE_COMMENT)
363 return (TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
365 return (TableViewColumnInfo::DATATYPE_STRING_DEFAULT);
367 else if(getDataType() == TableViewColumnInfo::DATATYPE_NUMBER)
368 return (TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
369 else if(getDataType() == TableViewColumnInfo::DATATYPE_TIME)
370 return (TableViewColumnInfo::DATATYPE_TIME_DEFAULT);
373 __SS__ <<
"\tUnrecognized View data type: " << getDataType() << std::endl;
374 __COUT_ERR__ <<
"\n" << ss.str();
380 std::vector<std::string> TableViewColumnInfo::getAllTypesForGUI(
void)
382 std::vector<std::string> all;
383 all.push_back(TYPE_DATA);
384 all.push_back(TYPE_UNIQUE_DATA);
385 all.push_back(TYPE_UNIQUE_GROUP_DATA);
386 all.push_back(TYPE_FIXED_CHOICE_DATA);
387 all.push_back(TYPE_MULTILINE_DATA);
388 all.push_back(TYPE_BITMAP_DATA);
389 all.push_back(TYPE_ON_OFF);
390 all.push_back(TYPE_TRUE_FALSE);
391 all.push_back(TYPE_YES_NO);
392 all.push_back(TYPE_START_CHILD_LINK_UID);
393 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
394 all.push_back(TYPE_START_CHILD_LINK);
395 all.push_back(TYPE_START_GROUP_ID);
400 std::vector<std::string> TableViewColumnInfo::getAllDataTypesForGUI(
void)
402 std::vector<std::string> all;
403 all.push_back(DATATYPE_STRING);
404 all.push_back(DATATYPE_NUMBER);
405 all.push_back(DATATYPE_TIME);
411 std::map<std::pair<std::string, std::string>, std::string>
412 TableViewColumnInfo::getAllDefaultsForGUI(
void)
414 std::map<std::pair<std::string, std::string>, std::string> all;
415 all[std::pair<std::string, std::string>(DATATYPE_NUMBER,
"*")] =
416 DATATYPE_NUMBER_DEFAULT;
417 all[std::pair<std::string, std::string>(DATATYPE_TIME,
"*")] = DATATYPE_TIME_DEFAULT;
419 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_ON_OFF)] =
420 DATATYPE_BOOL_DEFAULT;
421 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_TRUE_FALSE)] =
422 DATATYPE_BOOL_DEFAULT;
423 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_YES_NO)] =
424 DATATYPE_BOOL_DEFAULT;
426 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_START_CHILD_LINK)] =
427 DATATYPE_LINK_DEFAULT;
428 all[std::pair<std::string, std::string>(DATATYPE_STRING,
"*")] =
429 DATATYPE_STRING_DEFAULT;
435 const bool TableViewColumnInfo::isBoolType(
void)
const
437 return (type_ == TYPE_ON_OFF || type_ == TYPE_TRUE_FALSE || type_ == TYPE_YES_NO);
442 const bool TableViewColumnInfo::isNumberDataType(
void)
const
444 return (dataType_ == DATATYPE_NUMBER);
448 const std::string& TableViewColumnInfo::getName(
void)
const {
return name_; }
451 const std::string& TableViewColumnInfo::getStorageName(
void)
const
457 const std::string& TableViewColumnInfo::getDataType(
void)
const {
return dataType_; }
460 const std::vector<std::string>& TableViewColumnInfo::getDataChoices(
void)
const
471 return *bitMapInfoP_;
475 __SS__ <<
"getBitMapInfo request for non-BitMap column of type: " << getType()
477 __COUT_ERR__ <<
"\n" << ss.str();
486 const bool TableViewColumnInfo::isChildLink(
void)
const
488 return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
489 type_.length() > TYPE_START_CHILD_LINK.length() &&
490 type_[TYPE_START_CHILD_LINK.length()] ==
'-');
497 const bool TableViewColumnInfo::isChildLinkUID(
void)
const
499 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
500 type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
501 type_[TYPE_START_CHILD_LINK_UID.length()] ==
'-');
508 const bool TableViewColumnInfo::isChildLinkGroupID(
void)
const
510 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
511 type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
512 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] ==
'-');
519 const bool TableViewColumnInfo::isGroupID(
void)
const
521 return (type_.find(TYPE_START_GROUP_ID) == 0 &&
522 type_.length() > TYPE_START_GROUP_ID.length() &&
523 type_[TYPE_START_GROUP_ID.length()] ==
'-');
528 const bool TableViewColumnInfo::isUID(
void)
const {
return (type_ == TYPE_UID); }
532 std::string TableViewColumnInfo::getChildLinkIndex(
void)
const
536 return type_.substr(TYPE_START_CHILD_LINK.length() + 1);
537 else if(isChildLinkUID())
538 return type_.substr(TYPE_START_CHILD_LINK_UID.length() + 1);
539 else if(isChildLinkGroupID())
540 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length() + 1);
542 return type_.substr(TYPE_START_GROUP_ID.length() + 1);
546 << (
"Requesting a Link Index from a column that is not a child link member!")
548 __COUT_ERR__ << ss.str();