1 #include "otsdaq/TableCore/TableViewColumnInfo.h"
3 #include "otsdaq/Macros/CoutMacros.h"
4 #include "otsdaq/Macros/StringMacros.h"
10 #include "otsdaq/TableCore/TableView.h"
18 const std::string TableViewColumnInfo::TYPE_UID =
"UID";
20 const std::string TableViewColumnInfo::TYPE_DATA =
"Data";
21 const std::string TableViewColumnInfo::TYPE_UNIQUE_DATA =
"UniqueData";
22 const std::string TableViewColumnInfo::TYPE_UNIQUE_GROUP_DATA =
"UniqueGroupData";
23 const std::string TableViewColumnInfo::TYPE_MULTILINE_DATA =
"MultilineData";
24 const std::string TableViewColumnInfo::TYPE_FIXED_CHOICE_DATA =
"FixedChoiceData";
25 const std::string TableViewColumnInfo::TYPE_BITMAP_DATA =
"BitMap";
27 const std::string TableViewColumnInfo::TYPE_ON_OFF =
"OnOff";
28 const std::string TableViewColumnInfo::TYPE_TRUE_FALSE =
"TrueFalse";
29 const std::string TableViewColumnInfo::TYPE_YES_NO =
"YesNo";
31 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK =
"ChildLink";
32 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_UID =
"ChildLinkUID";
33 const std::string TableViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID =
"ChildLinkGroupID";
34 const std::string TableViewColumnInfo::TYPE_START_GROUP_ID =
"GroupID";
35 const std::string TableViewColumnInfo::TYPE_COMMENT =
"Comment";
36 const std::string TableViewColumnInfo::TYPE_AUTHOR =
"Author";
37 const std::string TableViewColumnInfo::TYPE_TIMESTAMP =
"Timestamp";
41 const std::string TableViewColumnInfo::DATATYPE_NUMBER =
"NUMBER";
42 const std::string TableViewColumnInfo::DATATYPE_STRING =
"STRING";
43 const std::string TableViewColumnInfo::DATATYPE_TIME =
"TIMESTAMP WITH TIMEZONE";
45 const std::string TableViewColumnInfo::TYPE_VALUE_YES =
"Yes";
46 const std::string TableViewColumnInfo::TYPE_VALUE_NO =
"No";
47 const std::string TableViewColumnInfo::TYPE_VALUE_TRUE =
"True";
48 const std::string TableViewColumnInfo::TYPE_VALUE_FALSE =
"False";
49 const std::string TableViewColumnInfo::TYPE_VALUE_ON =
"On";
50 const std::string TableViewColumnInfo::TYPE_VALUE_OFF =
"Off";
52 const std::string TableViewColumnInfo::DATATYPE_STRING_DEFAULT =
"DEFAULT";
53 const std::string TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT =
"No Comment";
54 const std::string TableViewColumnInfo::DATATYPE_BOOL_DEFAULT =
"0";
55 const std::string TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT =
"0";
56 const std::string TableViewColumnInfo::DATATYPE_TIME_DEFAULT =
"0";
57 const std::string TableViewColumnInfo::DATATYPE_LINK_DEFAULT =
"NO_LINK";
59 const std::string TableViewColumnInfo::COL_NAME_STATUS =
"Status";
60 const std::string TableViewColumnInfo::COL_NAME_ENABLED =
"Enabled";
61 const std::string TableViewColumnInfo::COL_NAME_PRIORITY =
"Priority";
62 const std::string TableViewColumnInfo::COL_NAME_COMMENT =
"CommentDescription";
63 const std::string TableViewColumnInfo::COL_NAME_AUTHOR =
"Author";
64 const std::string TableViewColumnInfo::COL_NAME_CREATION =
"RecordInsertionTime";
72 TableViewColumnInfo::TableViewColumnInfo(
const std::string& type,
73 const std::string& name,
74 const std::string& storageName,
75 const std::string& dataType,
76 const std::string& dataChoicesCSV,
77 std::string* capturedExceptionString)
78 : type_(type), name_(name), storageName_(storageName), dataType_(dataType), bitMapInfoP_(0)
81 if ((type_ != TYPE_UID) && (type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) && (type_ != TYPE_UNIQUE_GROUP_DATA) && (type_ != TYPE_MULTILINE_DATA) &&
82 (type_ != TYPE_FIXED_CHOICE_DATA) && (type_ != TYPE_BITMAP_DATA) && (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
83 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) && !isChildLink() && !isChildLinkUID() && !isChildLinkGroupID() &&
86 __SS__ <<
"The type for column " << name_ <<
" is " << type_ <<
", while the only accepted types are: " << TYPE_DATA <<
" " << TYPE_UNIQUE_DATA <<
" "
87 << TYPE_UNIQUE_GROUP_DATA <<
" " << TYPE_MULTILINE_DATA <<
" " << TYPE_FIXED_CHOICE_DATA <<
" " << TYPE_UID <<
" " << TYPE_ON_OFF <<
" "
88 << TYPE_TRUE_FALSE <<
" " << TYPE_YES_NO <<
" " << TYPE_START_CHILD_LINK <<
"-* " << TYPE_START_CHILD_LINK_UID <<
"-* "
89 << TYPE_START_CHILD_LINK_GROUP_ID <<
"-* " << TYPE_START_GROUP_ID <<
"-* " << std::endl;
90 if (capturedExceptionString)
91 *capturedExceptionString = ss.str();
95 else if (capturedExceptionString)
96 *capturedExceptionString =
"";
100 for (
unsigned int i = 0; i < type_.size(); ++i)
101 if (!((type_[i] >=
'A' && type_[i] <=
'Z') || (type_[i] >=
'a' && type_[i] <=
'z') || (type_[i] >=
'0' && type_[i] <=
'9') ||
102 (type_[i] ==
'-' || type_[i] ==
'_' || type_[i] ==
'.' || type_[i] ==
' ')))
104 __SS__ <<
"The column type for column " << name_ <<
" is '" << type_ <<
"'. Column types must contain only letters, numbers, "
105 <<
"dashes, underscores, periods, and spaces." << std::endl;
106 if (capturedExceptionString)
107 *capturedExceptionString += ss.str();
115 if (dataType_ ==
"VARCHAR2")
116 dataType_ = DATATYPE_STRING;
118 if ((dataType_ != DATATYPE_NUMBER) && (dataType_ != DATATYPE_STRING) && (dataType_ != DATATYPE_TIME))
120 __SS__ <<
"The data type for column " << name_ <<
" is " << dataType_ <<
", while the only accepted types are: " << DATATYPE_NUMBER <<
" "
121 << DATATYPE_STRING <<
" " << DATATYPE_TIME << std::endl;
122 if (capturedExceptionString)
123 *capturedExceptionString += ss.str();
128 if (dataType_.size() == 0)
130 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
"'. Data types must contain at least 1 character." << std::endl;
131 if (capturedExceptionString)
132 *capturedExceptionString += ss.str();
139 for (
unsigned int i = 0; i < dataType_.size(); ++i)
140 if (!((dataType_[i] >=
'A' && dataType_[i] <=
'Z') || (dataType_[i] >=
'a' && dataType_[i] <=
'z') || (dataType_[i] >=
'0' && dataType_[i] <=
'9') ||
141 (dataType_[i] ==
'-' || dataType_[i] ==
'_' || dataType_[i] ==
' ')))
143 __SS__ <<
"The data type for column " << name_ <<
" is '" << dataType_ <<
"'. Data types must contain only letters, numbers, "
144 <<
"dashes, underscores, and spaces." << std::endl;
145 if (capturedExceptionString)
146 *capturedExceptionString += ss.str();
151 if (name_.size() == 0)
153 __SS__ <<
"There is a column named " << name_ <<
"'. Column names must contain at least 1 character." << std::endl;
154 if (capturedExceptionString)
155 *capturedExceptionString += ss.str();
162 for (
unsigned int i = 0; i < name_.size(); ++i)
163 if (!((name_[i] >=
'A' && name_[i] <=
'Z') || (name_[i] >=
'a' && name_[i] <=
'z') || (name_[i] >=
'0' && name_[i] <=
'9') ||
164 (name_[i] ==
'-' || name_[i] ==
'_')))
166 __SS__ <<
"There is a column named " << name_ <<
"'. Column names must contain only letters, numbers, "
167 <<
"dashes, and underscores." << std::endl;
168 if (capturedExceptionString)
169 *capturedExceptionString += ss.str();
174 if (storageName_.size() == 0)
176 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
"'. Storage names must contain at least 1 character." << std::endl;
177 if (capturedExceptionString)
178 *capturedExceptionString += ss.str();
185 for (
unsigned int i = 0; i < storageName_.size(); ++i)
186 if (!((storageName_[i] >=
'A' && storageName_[i] <=
'Z') || (storageName_[i] >=
'0' && storageName_[i] <=
'9') ||
187 (storageName_[i] ==
'-' || storageName_[i] ==
'_')))
189 __SS__ <<
"The storage name for column " << name_ <<
" is '" << storageName_ <<
"'. Storage names must contain only capital letters, numbers,"
190 <<
"dashes, and underscores." << std::endl;
191 if (capturedExceptionString)
192 *capturedExceptionString += ss.str();
200 std::istringstream f(dataChoicesCSV);
202 while (getline(f, s,
','))
203 dataChoices_.push_back(StringMacros::decodeURIComponent(s));
212 catch (std::runtime_error & e)
214 if (capturedExceptionString)
215 *capturedExceptionString += e.what();
224 void TableViewColumnInfo::extractBitMapInfo()
227 if (type_ == TYPE_BITMAP_DATA)
231 bitMapInfoP_ =
new BitMapInfo();
256 if (dataChoices_.size() < 16)
258 __SS__ <<
"The Bit-Map data parameters for column " << name_ <<
" should be size 16, but is size " << dataChoices_.size()
259 <<
". Bit-Map parameters should be rows, cols, cellBitSize, and min, "
265 sscanf(dataChoices_[0].c_str(),
"%u", &(bitMapInfoP_->numOfRows_));
266 sscanf(dataChoices_[1].c_str(),
"%u", &(bitMapInfoP_->numOfColumns_));
267 sscanf(dataChoices_[2].c_str(),
"%u", &(bitMapInfoP_->cellBitSize_));
269 sscanf(dataChoices_[3].c_str(),
"%lu", &(bitMapInfoP_->minValue_));
270 sscanf(dataChoices_[4].c_str(),
"%lu", &(bitMapInfoP_->maxValue_));
271 sscanf(dataChoices_[5].c_str(),
"%lu", &(bitMapInfoP_->stepValue_));
273 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
274 bitMapInfoP_->minColor_ = dataChoices_[7];
275 bitMapInfoP_->midColor_ = dataChoices_[8];
276 bitMapInfoP_->maxColor_ = dataChoices_[9];
277 bitMapInfoP_->absMinColor_ = dataChoices_[10];
278 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
280 bitMapInfoP_->rowsAscending_ = dataChoices_[12] ==
"Yes" ? 1 : 0;
281 bitMapInfoP_->colsAscending_ = dataChoices_[13] ==
"Yes" ? 1 : 0;
282 bitMapInfoP_->snakeRows_ = dataChoices_[14] ==
"Yes" ? 1 : 0;
283 bitMapInfoP_->snakeCols_ = dataChoices_[15] ==
"Yes" ? 1 : 0;
289 TableViewColumnInfo::TableViewColumnInfo(
void) {}
293 : type_(c.type_), name_(c.name_), storageName_(c.storageName_), dataType_(c.dataType_), dataChoices_(c.dataChoices_), bitMapInfoP_(0)
303 retColInfo->type_ = c.type_;
304 retColInfo->name_ = c.name_;
305 retColInfo->storageName_ = c.storageName_;
306 retColInfo->dataType_ = c.dataType_;
307 retColInfo->dataChoices_ = c.dataChoices_;
308 retColInfo->bitMapInfoP_ = 0;
311 retColInfo->extractBitMapInfo();
317 TableViewColumnInfo::~TableViewColumnInfo(
void)
324 const std::string& TableViewColumnInfo::getType(
void)
const {
return type_; }
327 const std::string& TableViewColumnInfo::getDefaultValue(
void)
const
329 if (getDataType() == TableViewColumnInfo::DATATYPE_STRING)
331 if (getType() == TableViewColumnInfo::TYPE_ON_OFF || getType() == TableViewColumnInfo::TYPE_TRUE_FALSE || getType() == TableViewColumnInfo::TYPE_YES_NO)
332 return (TableViewColumnInfo::DATATYPE_BOOL_DEFAULT);
333 else if (isChildLink())
334 return (TableViewColumnInfo::DATATYPE_LINK_DEFAULT);
335 else if (getType() == TableViewColumnInfo::TYPE_COMMENT)
336 return (TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
338 return (TableViewColumnInfo::DATATYPE_STRING_DEFAULT);
340 else if (getDataType() == TableViewColumnInfo::DATATYPE_NUMBER)
341 return (TableViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
342 else if (getDataType() == TableViewColumnInfo::DATATYPE_TIME)
343 return (TableViewColumnInfo::DATATYPE_TIME_DEFAULT);
346 __SS__ <<
"\tUnrecognized View data type: " << getDataType() << std::endl;
347 __COUT_ERR__ <<
"\n" << ss.str();
353 std::vector<std::string> TableViewColumnInfo::getAllTypesForGUI(
void)
355 std::vector<std::string> all;
356 all.push_back(TYPE_DATA);
357 all.push_back(TYPE_UNIQUE_DATA);
358 all.push_back(TYPE_UNIQUE_GROUP_DATA);
359 all.push_back(TYPE_FIXED_CHOICE_DATA);
360 all.push_back(TYPE_MULTILINE_DATA);
361 all.push_back(TYPE_BITMAP_DATA);
362 all.push_back(TYPE_ON_OFF);
363 all.push_back(TYPE_TRUE_FALSE);
364 all.push_back(TYPE_YES_NO);
365 all.push_back(TYPE_START_CHILD_LINK_UID);
366 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
367 all.push_back(TYPE_START_CHILD_LINK);
368 all.push_back(TYPE_START_GROUP_ID);
373 std::vector<std::string> TableViewColumnInfo::getAllDataTypesForGUI(
void)
375 std::vector<std::string> all;
376 all.push_back(DATATYPE_STRING);
377 all.push_back(DATATYPE_NUMBER);
378 all.push_back(DATATYPE_TIME);
384 std::map<std::pair<std::string, std::string>, std::string> TableViewColumnInfo::getAllDefaultsForGUI(
void)
386 std::map<std::pair<std::string, std::string>, std::string> all;
387 all[std::pair<std::string, std::string>(DATATYPE_NUMBER,
"*")] = DATATYPE_NUMBER_DEFAULT;
388 all[std::pair<std::string, std::string>(DATATYPE_TIME,
"*")] = DATATYPE_TIME_DEFAULT;
390 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_ON_OFF)] = DATATYPE_BOOL_DEFAULT;
391 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_TRUE_FALSE)] = DATATYPE_BOOL_DEFAULT;
392 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_YES_NO)] = DATATYPE_BOOL_DEFAULT;
394 all[std::pair<std::string, std::string>(DATATYPE_STRING, TYPE_START_CHILD_LINK)] = DATATYPE_LINK_DEFAULT;
395 all[std::pair<std::string, std::string>(DATATYPE_STRING,
"*")] = DATATYPE_STRING_DEFAULT;
401 bool TableViewColumnInfo::isBoolType(
void)
const
403 return (type_ == TYPE_ON_OFF || type_ == TYPE_TRUE_FALSE || type_ == TYPE_YES_NO);
408 bool TableViewColumnInfo::isNumberDataType(
void)
const {
return (dataType_ == DATATYPE_NUMBER); }
411 const std::string& TableViewColumnInfo::getName(
void)
const {
return name_; }
414 const std::string& TableViewColumnInfo::getStorageName(
void)
const {
return storageName_; }
417 const std::string& TableViewColumnInfo::getDataType(
void)
const {
return dataType_; }
420 const std::vector<std::string>& TableViewColumnInfo::getDataChoices(
void)
const {
return dataChoices_; }
428 return *bitMapInfoP_;
432 __SS__ <<
"getBitMapInfo request for non-BitMap column of type: " << getType() << std::endl;
433 __COUT_ERR__ <<
"\n" << ss.str();
442 bool TableViewColumnInfo::isChildLink(
void)
const
444 return (type_.find(TYPE_START_CHILD_LINK) == 0 && type_.length() > TYPE_START_CHILD_LINK.length() && type_[TYPE_START_CHILD_LINK.length()] ==
'-');
451 bool TableViewColumnInfo::isChildLinkUID(
void)
const
453 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 && type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
454 type_[TYPE_START_CHILD_LINK_UID.length()] ==
'-');
461 bool TableViewColumnInfo::isChildLinkGroupID(
void)
const
463 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 && type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
464 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] ==
'-');
471 bool TableViewColumnInfo::isGroupID(
void)
const
473 return (type_.find(TYPE_START_GROUP_ID) == 0 && type_.length() > TYPE_START_GROUP_ID.length() && type_[TYPE_START_GROUP_ID.length()] ==
'-');
478 bool TableViewColumnInfo::isUID(
void)
const {
return (type_ == TYPE_UID); }
482 std::string TableViewColumnInfo::getChildLinkIndex(
void)
const
486 return type_.substr(TYPE_START_CHILD_LINK.length() + 1);
487 else if (isChildLinkUID())
488 return type_.substr(TYPE_START_CHILD_LINK_UID.length() + 1);
489 else if (isChildLinkGroupID())
490 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length() + 1);
491 else if (isGroupID())
492 return type_.substr(TYPE_START_GROUP_ID.length() + 1);
495 __SS__ << (
"Requesting a Link Index from a column that is not a child link member!") << std::endl;
496 __COUT_ERR__ << ss.str();