00001 #include "otsdaq-core/ConfigurationDataFormats/ViewColumnInfo.h"
00002 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00003 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationView.h"
00004
00005 #include <iostream>
00006 #include <sstream>
00007 #include <stdexcept>
00008
00009 using namespace ots;
00010
00011
00012 const std::string ViewColumnInfo::TYPE_UID = "UID";
00013
00014 const std::string ViewColumnInfo::TYPE_DATA = "Data";
00015 const std::string ViewColumnInfo::TYPE_UNIQUE_DATA = "UniqueData";
00016 const std::string ViewColumnInfo::TYPE_MULTILINE_DATA = "MultilineData";
00017 const std::string ViewColumnInfo::TYPE_FIXED_CHOICE_DATA = "FixedChoiceData";
00018 const std::string ViewColumnInfo::TYPE_BITMAP_DATA = "BitMap";
00019
00020 const std::string ViewColumnInfo::TYPE_ON_OFF = "OnOff";
00021 const std::string ViewColumnInfo::TYPE_TRUE_FALSE = "TrueFalse";
00022 const std::string ViewColumnInfo::TYPE_YES_NO = "YesNo";
00023
00024 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK = "ChildLink";
00025 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK_UID = "ChildLinkUID";
00026 const std::string ViewColumnInfo::TYPE_START_CHILD_LINK_GROUP_ID = "ChildLinkGroupID";
00027 const std::string ViewColumnInfo::TYPE_START_GROUP_ID = "GroupID";
00028 const std::string ViewColumnInfo::TYPE_COMMENT = "Comment";
00029 const std::string ViewColumnInfo::TYPE_AUTHOR = "Author";
00030 const std::string ViewColumnInfo::TYPE_TIMESTAMP = "Timestamp";
00031
00032
00033 const std::string ViewColumnInfo::DATATYPE_NUMBER = "NUMBER";
00034 const std::string ViewColumnInfo::DATATYPE_STRING = "VARCHAR2";
00035 const std::string ViewColumnInfo::DATATYPE_TIME = "TIMESTAMP WITH TIMEZONE";
00036
00037 const std::string ViewColumnInfo::TYPE_VALUE_YES = "Yes";
00038 const std::string ViewColumnInfo::TYPE_VALUE_NO = "No";
00039 const std::string ViewColumnInfo::TYPE_VALUE_TRUE = "True";
00040 const std::string ViewColumnInfo::TYPE_VALUE_FALSE = "False";
00041 const std::string ViewColumnInfo::TYPE_VALUE_ON = "On";
00042 const std::string ViewColumnInfo::TYPE_VALUE_OFF = "Off";
00043
00044 const std::string ViewColumnInfo::DATATYPE_STRING_DEFAULT = "DEFAULT";
00045 const std::string ViewColumnInfo::DATATYPE_COMMENT_DEFAULT = "No Comment";
00046 const std::string ViewColumnInfo::DATATYPE_BOOL_DEFAULT = "0";
00047 const std::string ViewColumnInfo::DATATYPE_NUMBER_DEFAULT = "0";
00048 const std::string ViewColumnInfo::DATATYPE_TIME_DEFAULT = "0";
00049 const std::string ViewColumnInfo::DATATYPE_LINK_DEFAULT = "NO_LINK";
00050
00051 const std::string ViewColumnInfo::COL_NAME_STATUS = "Status";
00052
00053
00054
00055
00056
00057
00058 ViewColumnInfo::ViewColumnInfo(const std::string &type, const std::string &name,
00059 const std::string &storageName, const std::string &dataType,
00060 const std::string &dataChoicesCSV, std::string *capturedExceptionString)
00061 : type_ (type)
00062 , name_ (name)
00063 , storageName_(storageName)
00064 , dataType_ (dataType)
00065 , bitMapInfoP_(0)
00066 {
00067
00068 if((type_ != TYPE_DATA) && (type_ != TYPE_UNIQUE_DATA) && (type_ != TYPE_UID) &&
00069 (type_ != TYPE_MULTILINE_DATA) && (type_ != TYPE_FIXED_CHOICE_DATA) &&
00070 (type_ != TYPE_BITMAP_DATA) &&
00071 (type_ != TYPE_ON_OFF) && (type_ != TYPE_TRUE_FALSE) && (type_ != TYPE_YES_NO) &&
00072 (type_ != TYPE_COMMENT) && (type_ != TYPE_AUTHOR) && (type_ != TYPE_TIMESTAMP) &&
00073 !isChildLink() &&
00074 !isChildLinkUID() &&
00075 !isChildLinkGroupID() &&
00076 !isGroupID() )
00077 {
00078 __SS__ << "The type for column " << name_ << " is " << type_ <<
00079 ", while the only accepted types are: " <<
00080 TYPE_DATA << " " <<
00081 TYPE_UNIQUE_DATA << " " <<
00082 TYPE_MULTILINE_DATA << " " <<
00083 TYPE_FIXED_CHOICE_DATA << " " <<
00084 TYPE_UID << " " <<
00085 TYPE_ON_OFF << " " <<
00086 TYPE_TRUE_FALSE << " " <<
00087 TYPE_YES_NO << " " <<
00088 TYPE_START_CHILD_LINK << "-* " <<
00089 TYPE_START_CHILD_LINK_UID << "-* " <<
00090 TYPE_START_CHILD_LINK_GROUP_ID << "-* " <<
00091 TYPE_START_GROUP_ID << "-* " << std::endl;
00092 if(capturedExceptionString) *capturedExceptionString = ss.str();
00093 else throw std::runtime_error(ss.str());
00094 }
00095 else if(capturedExceptionString) *capturedExceptionString = "";
00096
00097
00098
00099 for(unsigned int i=0;i<type_.size();++i)
00100 if(!(
00101 (type_[i] >= 'A' && type_[i] <= 'Z') ||
00102 (type_[i] >= 'a' && type_[i] <= 'z') ||
00103 (type_[i] >= '0' && type_[i] <= '9') ||
00104 (type_[i] == '-' || type_[i] <= '_' || type_[i] <= '.')
00105 ))
00106 {
00107 __SS__ << "The data type for column " << name_ << " is '" << type_ <<
00108 "'. Data types must contain only letters, numbers," <<
00109 "dashes, underscores, and periods." << std::endl;
00110 if(capturedExceptionString) *capturedExceptionString += ss.str();
00111 else throw std::runtime_error(ss.str());
00112 }
00113
00114
00115
00116 if((dataType_ != DATATYPE_NUMBER) &&
00117 (dataType_ != DATATYPE_STRING) &&
00118 (dataType_ != DATATYPE_TIME))
00119 {
00120 __SS__ << "The data type for column " << name_ << " is " << dataType_ <<
00121 ", while the only accepted types are: " <<
00122 DATATYPE_NUMBER << " " <<
00123 DATATYPE_STRING << " " <<
00124 DATATYPE_TIME << std::endl;
00125 if(capturedExceptionString) *capturedExceptionString += ss.str();
00126 else throw std::runtime_error(ss.str());
00127 }
00128
00129
00130 if(dataType_.size() == 0)
00131 {
00132 __SS__ << "The data type for column " << name_ << " is '" << dataType_ <<
00133 "'. Data types must contain at least 1 character." << std::endl;
00134 if(capturedExceptionString) *capturedExceptionString += ss.str();
00135 else throw std::runtime_error(ss.str());
00136 }
00137
00138
00139
00140 for(unsigned int i=0;i<dataType_.size();++i)
00141 if(!(
00142 (dataType_[i] >= 'A' && dataType_[i] <= 'Z') ||
00143 (dataType_[i] >= 'a' && dataType_[i] <= 'z') ||
00144 (dataType_[i] >= '0' && dataType_[i] <= '9') ||
00145 (dataType_[i] == '-' || dataType_[i] <= '_')
00146 ))
00147 {
00148 __SS__ << "The data type for column " << name_ << " is '" << dataType_ <<
00149 "'. Data types must contain only letters, numbers," <<
00150 "dashes, and underscores." << std::endl;
00151 if(capturedExceptionString) *capturedExceptionString += ss.str();
00152 else throw std::runtime_error(ss.str());
00153 }
00154
00155 if(name_.size() == 0)
00156 {
00157 __SS__ << "There is a column named " << name_ <<
00158 "'. Column names must contain at least 1 character." << std::endl;
00159 if(capturedExceptionString) *capturedExceptionString += ss.str();
00160 else throw std::runtime_error(ss.str());
00161 }
00162
00163
00164
00165 for(unsigned int i=0;i<name_.size();++i)
00166 if(!(
00167 (name_[i] >= 'A' && name_[i] <= 'Z') ||
00168 (name_[i] >= 'a' && name_[i] <= 'z') ||
00169 (name_[i] >= '0' && name_[i] <= '9') ||
00170 (name_[i] == '-' || name_[i] <= '_')
00171 ))
00172 {
00173 __SS__ << "There is a column named " << name_ <<
00174 "'. Column names must contain only letters, numbers," <<
00175 "dashes, and underscores." << std::endl;
00176 if(capturedExceptionString) *capturedExceptionString += ss.str();
00177 else throw std::runtime_error(ss.str());
00178 }
00179
00180
00181 if(storageName_.size() == 0)
00182 {
00183 __SS__ << "The storage name for column " << name_ << " is '" << storageName_ <<
00184 "'. Storage names must contain at least 1 character." << std::endl;
00185 if(capturedExceptionString) *capturedExceptionString += ss.str();
00186 else throw std::runtime_error(ss.str());
00187 }
00188
00189
00190
00191 for(unsigned int i=0;i<storageName_.size();++i)
00192 if(!(
00193 (storageName_[i] >= 'A' && storageName_[i] <= 'Z') ||
00194 (storageName_[i] >= '0' && storageName_[i] <= '9') ||
00195 (storageName_[i] == '-' || storageName_[i] <= '_')
00196 ))
00197 {
00198 __SS__ << "The storage name for column " << name_ << " is '" << storageName_ <<
00199 "'. Storage names must contain only capital letters, numbers," <<
00200 "dashes, and underscores." << std::endl;
00201 if(capturedExceptionString) *capturedExceptionString += ss.str();
00202 else throw std::runtime_error(ss.str());
00203 }
00204
00205
00206
00207 {
00208 std::istringstream f(dataChoicesCSV);
00209 std::string s;
00210 while (getline(f, s, ',')) dataChoices_.push_back(
00211 ConfigurationView::decodeURIComponent(s));
00212
00213
00214 }
00215
00216 try
00217 {
00218 extractBitMapInfo();
00219 }
00220 catch(std::runtime_error &e)
00221 {
00222 if(capturedExceptionString) *capturedExceptionString += e.what();
00223 else throw;
00224 }
00225
00226
00227 }
00228
00229
00230 void ViewColumnInfo::extractBitMapInfo()
00231 {
00232
00233 if(type_ == TYPE_BITMAP_DATA)
00234 {
00235 if(bitMapInfoP_) delete bitMapInfoP_;
00236 bitMapInfoP_ = new BitMapInfo();
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 if(dataChoices_.size() < 16)
00263 {
00264 __SS__ << "The Bit-Map data parameters for column " << name_ <<
00265 " should be size 16, but is size " << dataChoices_.size() <<
00266 ". Bit-Map parameters should be rows, cols, cellBitSize, and min, mid, max color." <<
00267 std::endl;
00268 throw std::runtime_error(ss.str());
00269 }
00270
00271 sscanf(dataChoices_[0].c_str(),"%u",&(bitMapInfoP_->numOfRows_));
00272 sscanf(dataChoices_[1].c_str(),"%u",&(bitMapInfoP_->numOfColumns_));
00273 sscanf(dataChoices_[2].c_str(),"%u",&(bitMapInfoP_->cellBitSize_));
00274
00275 sscanf(dataChoices_[3].c_str(),"%lu",&(bitMapInfoP_->minValue_));
00276 sscanf(dataChoices_[4].c_str(),"%lu",&(bitMapInfoP_->maxValue_));
00277 sscanf(dataChoices_[5].c_str(),"%lu",&(bitMapInfoP_->stepValue_));
00278
00279 bitMapInfoP_->aspectRatio_ = dataChoices_[6];
00280 bitMapInfoP_->minColor_ = dataChoices_[7];
00281 bitMapInfoP_->midColor_ = dataChoices_[8];
00282 bitMapInfoP_->maxColor_ = dataChoices_[9];
00283 bitMapInfoP_->absMinColor_ = dataChoices_[10];
00284 bitMapInfoP_->absMaxColor_ = dataChoices_[11];
00285
00286 bitMapInfoP_->rowsAscending_ = dataChoices_[12] == "Yes"?1:0;
00287 bitMapInfoP_->colsAscending_ = dataChoices_[13] == "Yes"?1:0;
00288 bitMapInfoP_->snakeRows_ = dataChoices_[14] == "Yes"?1:0;
00289 bitMapInfoP_->snakeCols_ = dataChoices_[15] == "Yes"?1:0;
00290 }
00291 }
00292
00293
00294
00295 ViewColumnInfo::ViewColumnInfo(void){}
00296
00297
00298 ViewColumnInfo::ViewColumnInfo(const ViewColumnInfo& c)
00299 :type_(c.type_)
00300 ,name_(c.name_)
00301 ,storageName_(c.storageName_)
00302 ,dataType_(c.dataType_)
00303 ,dataChoices_(c.dataChoices_)
00304 ,bitMapInfoP_(0)
00305 {
00306
00307 extractBitMapInfo();
00308 }
00309
00310
00311 ViewColumnInfo& ViewColumnInfo::operator=(const ViewColumnInfo& c)
00312 {
00313 ViewColumnInfo *retColInfo = new ViewColumnInfo();
00314 retColInfo->type_ = c.type_;
00315 retColInfo->name_ = c.name_;
00316 retColInfo->storageName_ = c.storageName_;
00317 retColInfo->dataType_ = c.dataType_;
00318 retColInfo->dataChoices_ = c.dataChoices_;
00319 retColInfo->bitMapInfoP_ = 0;
00320
00321
00322 retColInfo->extractBitMapInfo();
00323
00324 return *retColInfo;
00325 }
00326
00327
00328 ViewColumnInfo::~ViewColumnInfo(void)
00329 {
00330 if(bitMapInfoP_) delete bitMapInfoP_;
00331 }
00332
00333
00334 const std::string& ViewColumnInfo::getType(void) const
00335 {
00336 return type_;
00337 }
00338
00339
00340 const std::string& ViewColumnInfo::getDefaultValue(void) const
00341 {
00342 if(getDataType() == ViewColumnInfo::DATATYPE_STRING)
00343 {
00344 if(getType() == ViewColumnInfo::TYPE_ON_OFF ||
00345 getType() == ViewColumnInfo::TYPE_TRUE_FALSE ||
00346 getType() == ViewColumnInfo::TYPE_YES_NO)
00347 return (ViewColumnInfo::DATATYPE_BOOL_DEFAULT);
00348 else if(isChildLink())
00349 return (ViewColumnInfo::DATATYPE_LINK_DEFAULT);
00350 else if(getType() == ViewColumnInfo::TYPE_COMMENT)
00351 return (ViewColumnInfo::DATATYPE_COMMENT_DEFAULT);
00352 else
00353 return (ViewColumnInfo::DATATYPE_STRING_DEFAULT);
00354 }
00355 else if(getDataType() == ViewColumnInfo::DATATYPE_NUMBER)
00356 return (ViewColumnInfo::DATATYPE_NUMBER_DEFAULT);
00357 else if(getDataType() == ViewColumnInfo::DATATYPE_TIME)
00358 return (ViewColumnInfo::DATATYPE_TIME_DEFAULT);
00359 else
00360 {
00361 __SS__ << "\tUnrecognized View data type: " << getDataType() << std::endl;
00362 __COUT_ERR__ << "\n" << ss.str();
00363 throw std::runtime_error(ss.str());
00364 }
00365 }
00366
00367
00368 std::vector<std::string> ViewColumnInfo::getAllTypesForGUI(void)
00369 {
00370 std::vector<std::string> all;
00371 all.push_back(TYPE_DATA);
00372 all.push_back(TYPE_UNIQUE_DATA);
00373 all.push_back(TYPE_FIXED_CHOICE_DATA);
00374 all.push_back(TYPE_MULTILINE_DATA);
00375 all.push_back(TYPE_BITMAP_DATA);
00376 all.push_back(TYPE_ON_OFF);
00377 all.push_back(TYPE_TRUE_FALSE);
00378 all.push_back(TYPE_YES_NO);
00379 all.push_back(TYPE_START_CHILD_LINK_UID);
00380 all.push_back(TYPE_START_CHILD_LINK_GROUP_ID);
00381 all.push_back(TYPE_START_CHILD_LINK);
00382 all.push_back(TYPE_START_GROUP_ID);
00383 return all;
00384 }
00385
00386
00387 std::vector<std::string> ViewColumnInfo::getAllDataTypesForGUI(void)
00388 {
00389 std::vector<std::string> all;
00390 all.push_back(DATATYPE_STRING);
00391 all.push_back(DATATYPE_NUMBER);
00392 all.push_back(DATATYPE_TIME);
00393 return all;
00394 }
00395
00396
00397
00398 std::map<std::pair<std::string,std::string>,std::string> ViewColumnInfo::getAllDefaultsForGUI(void)
00399 {
00400 std::map<std::pair<std::string,std::string>,std::string> all;
00401 all[std::pair<std::string,std::string>(DATATYPE_NUMBER,"*")] = DATATYPE_NUMBER_DEFAULT;
00402 all[std::pair<std::string,std::string>(DATATYPE_TIME,"*")] = DATATYPE_TIME_DEFAULT;
00403
00404 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_ON_OFF)] = DATATYPE_BOOL_DEFAULT;
00405 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_TRUE_FALSE)] = DATATYPE_BOOL_DEFAULT;
00406 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_YES_NO)] = DATATYPE_BOOL_DEFAULT;
00407
00408 all[std::pair<std::string,std::string>(DATATYPE_STRING,TYPE_START_CHILD_LINK)] = DATATYPE_LINK_DEFAULT;
00409 all[std::pair<std::string,std::string>(DATATYPE_STRING,"*")] = DATATYPE_STRING_DEFAULT;
00410 return all;
00411 }
00412
00413
00414 const std::string& ViewColumnInfo::getName(void) const
00415 {
00416 return name_;
00417 }
00418
00419
00420 const std::string& ViewColumnInfo::getStorageName(void) const
00421 {
00422 return storageName_;
00423 }
00424
00425
00426 const std::string& ViewColumnInfo::getDataType(void) const
00427 {
00428 return dataType_;
00429 }
00430
00431
00432 const std::vector<std::string>& ViewColumnInfo::getDataChoices(void) const
00433 {
00434 return dataChoices_;
00435 }
00436
00437
00438
00439
00440 const ViewColumnInfo::BitMapInfo& ViewColumnInfo::getBitMapInfo(void) const
00441 {
00442 if(bitMapInfoP_) return *bitMapInfoP_;
00443
00444
00445 {
00446 __SS__ << "getBitMapInfo request for non-BitMap column of type: " << getType() << std::endl;
00447 __COUT_ERR__ << "\n" << ss.str();
00448 throw std::runtime_error(ss.str());
00449 }
00450
00451 }
00452
00453
00454
00455
00456
00457 const bool ViewColumnInfo::isChildLink(void) const
00458 {
00459 return (type_.find(TYPE_START_CHILD_LINK) == 0 &&
00460 type_.length() > TYPE_START_CHILD_LINK.length() &&
00461 type_[TYPE_START_CHILD_LINK.length()] == '-');
00462 }
00463
00464
00465
00466
00467
00468 const bool ViewColumnInfo::isChildLinkUID(void) const
00469 {
00470 return (type_.find(TYPE_START_CHILD_LINK_UID) == 0 &&
00471 type_.length() > TYPE_START_CHILD_LINK_UID.length() &&
00472 type_[TYPE_START_CHILD_LINK_UID.length()] == '-');
00473 }
00474
00475
00476
00477
00478
00479 const bool ViewColumnInfo::isChildLinkGroupID(void) const
00480 {
00481 return (type_.find(TYPE_START_CHILD_LINK_GROUP_ID) == 0 &&
00482 type_.length() > TYPE_START_CHILD_LINK_GROUP_ID.length() &&
00483 type_[TYPE_START_CHILD_LINK_GROUP_ID.length()] == '-');
00484 }
00485
00486
00487
00488
00489
00490 const bool ViewColumnInfo::isGroupID(void) const
00491 {
00492 return (type_.find(TYPE_START_GROUP_ID) == 0 &&
00493 type_.length() > TYPE_START_GROUP_ID.length() &&
00494 type_[TYPE_START_GROUP_ID.length()] == '-');
00495 }
00496
00497
00498
00499 std::string ViewColumnInfo::getChildLinkIndex (void) const
00500 {
00501
00502 if(isChildLink())
00503 return type_.substr(TYPE_START_CHILD_LINK.length()+1);
00504 else if(isChildLinkUID())
00505 return type_.substr(TYPE_START_CHILD_LINK_UID.length()+1);
00506 else if(isChildLinkGroupID())
00507 return type_.substr(TYPE_START_CHILD_LINK_GROUP_ID.length()+1);
00508 else if(isGroupID())
00509 return type_.substr(TYPE_START_GROUP_ID.length()+1);
00510 else
00511 {
00512 __SS__ << ("Requesting a Link Index from a column that is not a child link member!") << std::endl;
00513 __COUT_ERR__ << ss.str();
00514 throw std::runtime_error(ss.str());
00515 }
00516 }
00517
00518