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