1 #include "otsdaq/TableCore/TableViewColumnInfo.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/Macros/StringMacros.h"
10 #include "otsdaq/TableCore/TableView.h"
19 const std::string TableViewColumnInfo::TYPE_DATA =
"Data";
20 const std::string TableViewColumnInfo::TYPE_UNIQUE_DATA =
"UniqueData";
21 const std::string TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA =
"UniqueGroupData";
22 const std::string TableViewColumnInfo::TYPE_MULTILINE_DATA =
"MultilineData";
23 const std::string TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA =
"FixedChoiceData";
24 const std::string TableViewColumnInfo::TYPE_BITMAP_DATA =
"BitMap";
26 const std::string TableViewColumnInfo::TYPE_ON_OFF =
"OnOff";
27 const std::string TableViewColumnInfo::TYPE_TRUE_FALSE =
"TrueFalse";
28 const std::string TableViewColumnInfo::TYPE_YES_NO =
"YesNo";
30 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK =
"ChildLink";
31 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_UID =
"ChildLinkUID";
32 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID =
"ChildLinkGroupID";
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_STRING =
"STRING";
41 const std::string TableViewColumnInfo::DATATYPE_TIME =
"TIMESTAMP WITH TIMEZONE";
43 const std::string TableViewColumnInfo::TYPE_VALUE_YES =
"Yes";
44 const std::string TableViewColumnInfo::TYPE_VALUE_NO =
"No";
45 const std::string TableViewColumnInfo::TYPE_VALUE_TRUE =
"True";
46 const std::string TableViewColumnInfo::TYPE_VALUE_FALSE =
"False";
47 const std::string TableViewColumnInfo::TYPE_VALUE_ON =
"On";
48 const std::string TableViewColumnInfo::TYPE_VALUE_OFF =
"Off";
50 const std::string TableViewColumnInfo::DATATYPE_STRING_DEFAULT =
"DEFAULT";
51 const std::string TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT =
"No Comment";
52 const std::string TableViewColumnInfo::DATATYPE_BOOL_DEFAULT =
"0";
53 const std::string TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT =
"0";
55 const std::string TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT =
"";
56 const std::string TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT =
"";
58 const std::string TableViewColumnInfo::DATATYPE_TIME_DEFAULT =
"0";
59 const std::string TableViewColumnInfo::DATATYPE_LINK_DEFAULT =
"NO_LINK";
61 const std::string TableViewColumnInfo::COL_NAME_STATUS =
"Status";
62 const std::string TableViewColumnInfo::COL_NAME_ENABLED =
"Enabled";
63 const std::string TableViewColumnInfo::COL_NAME_PRIORITY =
"Priority";
64 const std::string TableViewColumnInfo::COL_NAME_COMMENT =
"CommentDescription";
65 const std::string TableViewColumnInfo::COL_NAME_AUTHOR =
"Author";
66 const std::string TableViewColumnInfo::COL_NAME_CREATION =
"RecordInsertionTime";
74 TableViewColumnInfo::TableViewColumnInfo(
const std::string& type,
75 const std::string& name,
76 const std::string& storageName,
77 const std::string& dataType,
78 const std::string* defaultValue,
79 const std::string& dataChoicesCSV,
80 const std::string* minValue,
81 const std::string* maxValue,
82 std::string* capturedExceptionString)
85 , storageName_(storageName)
86 , dataType_( dataType ==
"VARCHAR2" ? DATATYPE_STRING
88 , defaultValue_(defaultValue ? *defaultValue
89 : getDefaultDefaultValue(type_, dataType_))
91 dataChoices_(getDataChoicesFromString(dataChoicesCSV))
92 , minValue_(minValue ? ((*minValue) ==
"null" ?
"" : (*minValue))
93 : getMinDefaultValue(dataType_))
96 maxValue_(maxValue ? ((*maxValue) ==
"null" ?
"" : (*maxValue))
97 : getMaxDefaultValue(dataType_))
103 if((type_ !=
TYPE_UID) && (type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) &&
104 (type_ != TYPE_UNIQUE_GROUP_DATA) && (type_ != TYPE_MULTILINE_DATA) &&
105 (type_ != TYPE_FIXED_CHOICE_DATA) && (type_ != TYPE_BITMAP_DATA) &&
106 (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
107 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
110 __SS__ <<
"The type for column " << name_ <<
" is " << type_
111 <<
", while the only accepted types are: " << TYPE_DATA <<
" "
112 << TYPE_UNIQUE_DATA <<
" " << TYPE_UNIQUE_GROUP_DATA <<
" "
113 << TYPE_MULTILINE_DATA <<
" " << TYPE_FIXED_CHOICE_DATA <<
" " <<
TYPE_UID
114 <<
" " << TYPE_ON_OFF <<
" " << TYPE_TRUE_FALSE <<
" " << TYPE_YES_NO
115 <<
" " << TYPE_START_CHILD_LINK <<
"-* " << TYPE_START_CHILD_LINK_UID
116 <<
"-* " << TYPE_START_CHILD_LINK_GROUP_ID <<
"-* " << TYPE_START_GROUP_ID
117 <<
"-* " << std::endl;
118 if(capturedExceptionString)
119 *capturedExceptionString = ss.str();
123 else if(capturedExceptionString)
124 *capturedExceptionString =
"";
128 for(
unsigned int i = 0; i < type_.size(); ++i)
129 if(!((type_[i] >=
'A' && type_[i] <=
'Z') ||
130 (type_[i] >=
'a' && type_[i] <=
'z') ||
131 (type_[i] >=
'0' && type_[i] <=
'9') ||
132 (type_[i] ==
'-' || type_[i] ==
'_' || type_[i] ==
'.' || type_[i] ==
' ')))
134 __SS__ <<
"The column type for column " << name_ <<
" is '" << type_
135 <<
"'. Column types must contain only letters, numbers, "
136 <<
"dashes, underscores, periods, and spaces." << std::endl;
137 if(capturedExceptionString)
138 *capturedExceptionString += ss.str();
145 (dataType_ != DATATYPE_TIME))
147 __SS__ <<
"The data type for column " << name_ <<
" is " << dataType_
149 << DATATYPE_STRING <<
" " << DATATYPE_TIME << std::endl;
150 if(capturedExceptionString)
151 *capturedExceptionString += ss.str();
156 if(dataType_.size() == 0)
158 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_
159 <<
"'. Data types must contain at least 1 character." << std::endl;
160 if(capturedExceptionString)
161 *capturedExceptionString += ss.str();
168 for(
unsigned int i = 0; i < dataType_.size(); ++i)
169 if(!((dataType_[i] >=
'A' && dataType_[i] <=
'Z') ||
170 (dataType_[i] >=
'a' && dataType_[i] <=
'z') ||
171 (dataType_[i] >=
'0' && dataType_[i] <=
'9') ||
172 (dataType_[i] ==
'-' || dataType_[i] ==
'_' || dataType_[i] ==
' ')))
174 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_
175 <<
"'. Data types must contain only letters, numbers, "
176 <<
"dashes, underscores, and spaces." << std::endl;
177 if(capturedExceptionString)
178 *capturedExceptionString += ss.str();
183 if(name_.size() == 0)
185 __SS__ <<
"There is a column named " << name_
186 <<
"'. Column names must contain at least 1 character." << std::endl;
187 if(capturedExceptionString)
188 *capturedExceptionString += ss.str();
195 for(
unsigned int i = 0; i < name_.size(); ++i)
196 if(!((name_[i] >=
'A' && name_[i] <=
'Z') ||
197 (name_[i] >=
'a' && name_[i] <=
'z') ||
198 (name_[i] >=
'0' && name_[i] <=
'9') ||
199 (name_[i] ==
'-' || name_[i] ==
'_')))
201 __SS__ <<
"There is a column named " << name_
202 <<
"'. Column names must contain only letters, numbers, "
203 <<
"dashes, and underscores." << std::endl;
204 if(capturedExceptionString)
205 *capturedExceptionString += ss.str();
210 if(storageName_.size() == 0)
212 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_
213 <<
"'. Storage names must contain at least 1 character." << std::endl;
214 if(capturedExceptionString)
215 *capturedExceptionString += ss.str();
222 for(
unsigned int i = 0; i < storageName_.size(); ++i)
223 if(!((storageName_[i] >=
'A' && storageName_[i] <=
'Z') ||
224 (storageName_[i] >=
'0' && storageName_[i] <=
'9') ||
225 (storageName_[i] ==
'-' || storageName_[i] ==
'_')))
227 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_
228 <<
"'. Storage names must contain only capital letters, numbers,"
229 <<
"dashes, and underscores." << std::endl;
230 if(capturedExceptionString)
231 *capturedExceptionString += ss.str();
258 catch(std::runtime_error& e)
260 if(capturedExceptionString)
261 *capturedExceptionString += e.what();
270 std::vector<std::string> TableViewColumnInfo::getDataChoicesFromString(
271 const std::string& dataChoicesCSV)
const
273 std::vector<std::string> dataChoices;
277 std::istringstream f(dataChoicesCSV);
279 while(getline(f, s,
','))
288 void TableViewColumnInfo::extractBitMapInfo()
291 if(type_ == TYPE_BITMAP_DATA)
295 bitMapInfoP_ =
new BitMapInfo();
320 if(dataChoices_.size() < 16)
322 __SS__ <<
"The Bit-Map data parameters for column " << name_
323 <<
" should be size 16, but is size " << dataChoices_.size()
324 <<
". Bit-Map parameters should be rows, cols, cellBitSize, and min, "
330 sscanf(dataChoices_[0].c_str(),
"%u", &(bitMapInfoP_->numOfRows_));
331 sscanf(dataChoices_[1].c_str(),
"%u", &(bitMapInfoP_->numOfColumns_));
332 sscanf(dataChoices_[2].c_str(),
"%u", &(bitMapInfoP_->cellBitSize_));
334 sscanf(dataChoices_[3].c_str(),
"%lu", &(bitMapInfoP_->minValue_));
335 sscanf(dataChoices_[4].c_str(),
"%lu", &(bitMapInfoP_->maxValue_));
336 sscanf(dataChoices_[5].c_str(),
"%lu", &(bitMapInfoP_->stepValue_));
338 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
339 bitMapInfoP_->minColor_ = dataChoices_[7];
340 bitMapInfoP_->midColor_ = dataChoices_[8];
341 bitMapInfoP_->maxColor_ = dataChoices_[9];
342 bitMapInfoP_->absMinColor_ = dataChoices_[10];
343 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
345 bitMapInfoP_->rowsAscending_ = dataChoices_[12] ==
"Yes" ? 1 : 0;
346 bitMapInfoP_->colsAscending_ = dataChoices_[13] ==
"Yes" ? 1 : 0;
347 bitMapInfoP_->snakeRows_ = dataChoices_[14] ==
"Yes" ? 1 : 0;
348 bitMapInfoP_->snakeCols_ = dataChoices_[15] ==
"Yes" ? 1 : 0;
354 TableViewColumnInfo::TableViewColumnInfo(
void) {}
357 TableViewColumnInfo::TableViewColumnInfo(
361 , storageName_(c.storageName_)
362 , dataType_(c.dataType_)
363 , defaultValue_(c.defaultValue_)
364 , dataChoices_(c.dataChoices_)
365 , minValue_(c.minValue_)
366 , maxValue_(c.maxValue_)
377 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR " << std::endl;
382 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
383 "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
384 "and initialize another TableViewColumnInfo, rather than assigning to "
385 "an existing TableViewColumnInfo. Crashing now."
387 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
388 "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
389 "and initialize another TableViewColumnInfo, rather than assigning to "
390 "an existing TableViewColumnInfo. Crashing now."
392 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
393 "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
394 "and initialize another TableViewColumnInfo, rather than assigning to "
395 "an existing TableViewColumnInfo. Crashing now."
397 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
398 "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
399 "and initialize another TableViewColumnInfo, rather than assigning to "
400 "an existing TableViewColumnInfo. Crashing now."
402 __COUT__ <<
"OPERATOR= COPY CONSTRUCTOR CANNOT BE USED - TableViewColumnInfo is a "
403 "const class. SO YOUR CODE IS WRONG! You should probably instantiate "
404 "and initialize another TableViewColumnInfo, rather than assigning to "
405 "an existing TableViewColumnInfo. Crashing now."
426 TableViewColumnInfo::~TableViewColumnInfo(
void)
433 const std::string& TableViewColumnInfo::getType(
void)
const {
return type_; }
436 const std::string& TableViewColumnInfo::getDefaultValue(
void)
const
438 return defaultValue_;
440 const std::string& TableViewColumnInfo::getMinValue(
void)
const {
return minValue_; }
441 const std::string& TableViewColumnInfo::getMaxValue(
void)
const {
return maxValue_; }
444 const std::string& TableViewColumnInfo::getDefaultDefaultValue(
445 const std::string& type,
const std::string& dataType)
447 if(dataType == TableViewColumnInfo::DATATYPE_STRING)
449 if(type == TableViewColumnInfo::TYPE_ON_OFF ||
450 type == TableViewColumnInfo::TYPE_TRUE_FALSE ||
451 type == TableViewColumnInfo::TYPE_YES_NO)
453 TableViewColumnInfo::DATATYPE_BOOL_DEFAULT);
455 return (TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
456 else if(type == TableViewColumnInfo::TYPE_COMMENT)
457 return (TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
459 return (TableViewColumnInfo::DATATYPE_STRING_DEFAULT);
462 return (TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
463 else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
464 return (TableViewColumnInfo::DATATYPE_TIME_DEFAULT);
467 __SS__ <<
"\tUnrecognized View data type: " << dataType << std::endl;
468 __COUT_ERR__ <<
"\n" << ss.str();
477 if(dataType == TableViewColumnInfo::DATATYPE_STRING)
479 DATATYPE_NUMBER_MIN_DEFAULT);
483 return (TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT);
486 else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
487 return (TableViewColumnInfo::DATATYPE_NUMBER_MIN_DEFAULT);
490 __SS__ <<
"\tUnrecognized View data type: " << dataType << std::endl;
491 __COUT_ERR__ <<
"\n" << ss.str();
500 if(dataType == TableViewColumnInfo::DATATYPE_STRING)
501 return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
505 return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
507 else if(dataType == TableViewColumnInfo::DATATYPE_TIME)
508 return (TableViewColumnInfo::DATATYPE_NUMBER_MAX_DEFAULT);
511 __SS__ <<
"\tUnrecognized View data type: " << dataType << std::endl;
512 __COUT_ERR__ <<
"\n" << ss.str();
518 std::vector<std::string> TableViewColumnInfo::getAllTypesForGUI(
void)
520 std::vector<std::string> all;
521 all.push_back(TYPE_DATA);
522 all.push_back(TYPE_UNIQUE_DATA);
523 all.push_back(TYPE_UNIQUE_GROUP_DATA);
524 all.push_back(TYPE_FIXED_CHOICE_DATA);
525 all.push_back(TYPE_MULTILINE_DATA);
526 all.push_back(TYPE_BITMAP_DATA);
527 all.push_back(TYPE_ON_OFF);
528 all.push_back(TYPE_TRUE_FALSE);
529 all.push_back(TYPE_YES_NO);
530 all.push_back(TYPE_START_CHILD_LINK_UID);
531 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
532 all.push_back(TYPE_START_CHILD_LINK);
533 all.push_back(TYPE_START_GROUP_ID);
538 std::vector<std::string> TableViewColumnInfo::getAllDataTypesForGUI(
void)
540 std::vector<std::string> all;
541 all.push_back(DATATYPE_STRING);
543 all.push_back(DATATYPE_TIME);
549 std::map<std::pair<std::string, std::string>, std::string>
552 std::map<std::pair<std::string, std::string>, std::string> all;
554 DATATYPE_NUMBER_DEFAULT;
555 all[std::pair<std::string, std::string>(DATATYPE_TIME,
"*")] = DATATYPE_TIME_DEFAULT;
557 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_ON_OFF)] =
558 DATATYPE_BOOL_DEFAULT;
559 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_TRUE_FALSE)] =
560 DATATYPE_BOOL_DEFAULT;
561 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_YES_NO)] =
562 DATATYPE_BOOL_DEFAULT;
564 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_START_CHILD_LINK)] =
565 DATATYPE_LINK_DEFAULT;
566 all[std::pair<std::string, std::string>(DATATYPE_STRING,
"*")] =
567 DATATYPE_STRING_DEFAULT;
575 return (type_ == TYPE_ON_OFF || type_ == TYPE_TRUE_FALSE || type_ == TYPE_YES_NO);
586 const std::string& TableViewColumnInfo::getName(
void)
const {
return name_; }
589 const std::string& TableViewColumnInfo::getStorageName(
void)
const
595 const std::string& TableViewColumnInfo::getDataType(
void)
const {
return dataType_; }
598 const std::vector<std::string>& TableViewColumnInfo::getDataChoices(
void)
const
609 return *bitMapInfoP_;
613 __SS__ <<
"getBitMapInfo request for non-BitMap column of type: " << getType()
615 __COUT_ERR__ <<
"\n" << ss.str();
626 return (type.find(TYPE_START_CHILD_LINK) == 0 &&
627 type.length() > TYPE_START_CHILD_LINK.length() &&
628 type[TYPE_START_CHILD_LINK.length()] ==
'-');
637 return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
638 type_.length() > TYPE_START_CHILD_LINK.length() &&
639 type_[TYPE_START_CHILD_LINK.length()] ==
'-');
648 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
649 type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
650 type_[TYPE_START_CHILD_LINK_UID.length()] ==
'-');
659 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
660 type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
661 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] ==
'-');
670 return (type_.find(TYPE_START_GROUP_ID) == 0 &&
671 type_.length() > TYPE_START_GROUP_ID.length() &&
672 type_[TYPE_START_GROUP_ID.length()] ==
'-');
685 return type_.substr(TYPE_START_CHILD_LINK.length() + 1);
687 return type_.substr(TYPE_START_CHILD_LINK_UID.length() + 1);
689 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length() + 1);
691 return type_.substr(TYPE_START_GROUP_ID.length() + 1);
695 << (
"Requesting a Link Index from a column that is not a child link member!")
697 __COUT_ERR__ << ss.str();
bool isChildLinkUID(void) const
static const std::string DATATYPE_NUMBER
static std::map< std::pair< std::string, std::string >, std::string > getAllDefaultsForGUI(void)
map of datatype,type to default value
std::string getChildLinkIndex(void) const
getChildLinkIndex
bool isChildLink(void) const
TableViewColumnInfo & operator=(const TableViewColumnInfo &c)
assignment operator because of bitmap pointer
bool isUID(void) const
isUID
bool isGroupID(void) const
static const std::string TYPE_UID
NOTE: Do NOT put '-' in static const TYPEs because it will mess up javascript handling in the web gui...
static const std::string & getMaxDefaultValue(const std::string &dataType)
function to get max default value
const BitMapInfo & getBitMapInfo(void) const
uses dataChoices CSV fields if type is TYPE_BITMAP_DATA
static const std::string & getMinDefaultValue(const std::string &dataType)
function to get min default value
bool isBoolType(void) const
TODO check if min and max values need a function called getallminmaxforgui or something like that for...
bool isNumberDataType(void) const
isNumberDataType
bool isChildLinkGroupID(void) const
static std::string decodeURIComponent(const std::string &data)
static std::string stackTrace(void)
< uses dataChoices CSV fields if type is TYPE_BITMAP_DATA