$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h" 00002 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h" //All configurable objects are included here 00003 #include "otsdaq-core/ProgressBar/ProgressBar.h" 00004 00005 #include <fstream> // std::ofstream 00006 00007 #include "otsdaq-core/TableCore/TableGroupKey.h" 00008 00009 using namespace ots; 00010 00011 #undef __MF_SUBJECT__ 00012 #define __MF_SUBJECT__ "ConfigurationManager" 00013 00014 const std::string ConfigurationManager::READONLY_USER = "READONLY_USER"; 00015 00016 const std::string ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME = "XDAQContextTable"; 00017 const std::string ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME = 00018 "XDAQApplicationTable"; 00019 const std::string ConfigurationManager::GROUP_ALIASES_TABLE_NAME = "GroupAliasesTable"; 00020 const std::string ConfigurationManager::VERSION_ALIASES_TABLE_NAME = 00021 "VersionAliasesTable"; 00022 00023 // added env check for otsdaq_flatten_active_to_version to function 00024 const std::string ConfigurationManager::ACTIVE_GROUPS_FILENAME = 00025 ((getenv("SERVICE_DATA_PATH") == NULL) 00026 ? (std::string(getenv("USER_DATA")) + "/ServiceData") 00027 : (std::string(getenv("SERVICE_DATA_PATH")))) + 00028 "/ActiveTableGroups.cfg"; 00029 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE = "ALIAS:"; 00030 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS = "Scratch"; 00031 00032 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT = "Context"; 00033 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE = "Backbone"; 00034 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE = "Iterate"; 00035 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION = "Configuration"; 00036 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN = "Unknown"; 00037 00038 const uint8_t ConfigurationManager::METADATA_COL_ALIASES = 1; 00039 const uint8_t ConfigurationManager::METADATA_COL_COMMENT = 2; 00040 const uint8_t ConfigurationManager::METADATA_COL_AUTHOR = 3; 00041 const uint8_t ConfigurationManager::METADATA_COL_TIMESTAMP = 4; 00042 00043 const std::set<std::string> ConfigurationManager::contextMemberNames_ = { 00044 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME, 00045 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME, 00046 "XDAQApplicationPropertyTable", 00047 "DesktopIconTable", 00048 "MessageFacilityTable", 00049 "GatewaySupervisorTable", 00050 "StateMachineTable", 00051 "DesktopWindowParameterTable"}; 00052 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = { 00053 ConfigurationManager::GROUP_ALIASES_TABLE_NAME, 00054 ConfigurationManager::VERSION_ALIASES_TABLE_NAME}; 00055 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = { 00056 "IterateTable", 00057 "IterationPlanTable", 00058 "IterationTargetTable", 00059 /*command specific tables*/ "IterationCommandBeginLabelTable", 00060 "IterationCommandChooseFSMTable", 00061 "IterationCommandConfigureAliasTable", 00062 "IterationCommandConfigureGroupTable", 00063 "IterationCommandExecuteFEMacroTable", 00064 "IterationCommandExecuteMacroTable", 00065 "IterationCommandMacroDimensionalLoopTable", 00066 "IterationCommandMacroDimensionalLoopParameterTable", 00067 "IterationCommandModifyGroupTable", 00068 "IterationCommandRepeatLabelTable", 00069 "IterationCommandRunTable"}; 00070 00071 //============================================================================== 00072 ConfigurationManager::ConfigurationManager() 00073 : username_(ConfigurationManager::READONLY_USER) 00074 , theInterface_(0) 00075 , theConfigurationTableGroupKey_(0) 00076 , theContextTableGroupKey_(0) 00077 , theBackboneTableGroupKey_(0) 00078 , theConfigurationTableGroup_("") 00079 , theContextTableGroup_("") 00080 , theBackboneTableGroup_("") 00081 { 00082 theInterface_ = ConfigurationInterface::getInstance(false); // false to use artdaq DB 00083 // NOTE: in ConfigurationManagerRW using false currently.. think about consistency! 00084 // FIXME 00085 00086 // initialize special group metadata table 00087 { 00088 // Note: "TableGroupMetadata" should never be in conflict 00089 // because all other tables end in "...Table" 00090 00091 // This is a table called TableGroupMetadata 00092 // with 4 fields: 00093 // - GroupAliases 00094 // - GroupAuthor 00095 // - GroupCreationTime 00096 // - CommentDescription 00097 00098 groupMetadataTable_.setTableName( 00099 ConfigurationInterface::GROUP_METADATA_TABLE_NAME); 00100 std::vector<TableViewColumnInfo>* colInfo = 00101 groupMetadataTable_.getMockupViewP()->getColumnsInfoP(); 00102 00103 colInfo->push_back(TableViewColumnInfo( 00104 TableViewColumnInfo::TYPE_UID, // just to make init() happy 00105 "UnusedUID", 00106 "UNUSED_UID", 00107 TableViewColumnInfo::DATATYPE_NUMBER, 00108 "", 00109 0)); 00110 colInfo->push_back(TableViewColumnInfo(TableViewColumnInfo::TYPE_DATA, 00111 "GroupAliases", 00112 "GROUP_ALIASES", 00113 TableViewColumnInfo::DATATYPE_STRING, 00114 "", 00115 0)); 00116 colInfo->push_back(TableViewColumnInfo( 00117 TableViewColumnInfo::TYPE_COMMENT, // just to make init() happy 00118 "CommentDescription", 00119 "COMMENT_DESCRIPTION", 00120 TableViewColumnInfo::DATATYPE_STRING, 00121 "", 00122 0)); 00123 colInfo->push_back(TableViewColumnInfo( 00124 TableViewColumnInfo::TYPE_AUTHOR, // just to make init() happy 00125 "GroupAuthor", 00126 "AUTHOR", 00127 TableViewColumnInfo::DATATYPE_STRING, 00128 "", 00129 0)); 00130 colInfo->push_back(TableViewColumnInfo(TableViewColumnInfo::TYPE_TIMESTAMP, 00131 "GroupCreationTime", 00132 "GROUP_CREATION_TIME", 00133 TableViewColumnInfo::DATATYPE_TIME, 00134 "", 00135 0)); 00136 auto tmpVersion = groupMetadataTable_.createTemporaryView(); 00137 groupMetadataTable_.setActiveView(tmpVersion); 00138 // only need this one and only row for all time 00139 groupMetadataTable_.getViewP()->addRow(); 00140 } 00141 00142 init(); 00143 } // end constructor() 00144 00145 //============================================================================== 00146 ConfigurationManager::ConfigurationManager(const std::string& username) 00147 : ConfigurationManager() 00148 { 00149 username_ = username; 00150 } // end constructor(username) 00151 00152 //============================================================================== 00153 ConfigurationManager::~ConfigurationManager() { destroy(); } 00154 00155 //============================================================================== 00156 // init 00157 // if accumulatedErrors is not null.. fill it with errors 00158 // else throw errors (but do not ask restoreActiveTableGroups to throw errors) 00159 void ConfigurationManager::init(std::string* accumulatedErrors) 00160 { 00161 if(accumulatedErrors) 00162 *accumulatedErrors = ""; 00163 00164 // destroy(); 00165 00166 // once Interface is false (using artdaq db) .. then can cTableGroupce_->getMode() == 00167 // false) 00168 { 00169 try 00170 { 00171 restoreActiveTableGroups(accumulatedErrors ? true : false); 00172 } 00173 catch(std::runtime_error& e) 00174 { 00175 if(accumulatedErrors) 00176 *accumulatedErrors = e.what(); 00177 else 00178 throw; 00179 } 00180 } 00181 } // end init() 00182 00183 //============================================================================== 00184 // restoreActiveTableGroups 00185 // load the active groups from file 00186 // Note: this should be used by the Supervisor to maintain 00187 // the same configurationGroups surviving software system restarts 00188 void ConfigurationManager::restoreActiveTableGroups( 00189 bool throwErrors, const std::string& pathToActiveGroupsFile) 00190 { 00191 destroyTableGroup("", true); // deactivate all 00192 00193 std::string fn = 00194 pathToActiveGroupsFile == "" ? ACTIVE_GROUPS_FILENAME : pathToActiveGroupsFile; 00195 FILE* fp = fopen(fn.c_str(), "r"); 00196 00197 __COUT__ << "ACTIVE_GROUPS_FILENAME = " << fn << __E__; 00198 __COUT__ << "ARTDAQ_DATABASE_URI = " << std::string(getenv("ARTDAQ_DATABASE_URI")) 00199 << __E__; 00200 00201 if(!fp) 00202 { 00203 __COUT_WARN__ << "No active groups file found at " << fn << __E__; 00204 return; 00205 } 00206 00207 //__COUT__ << "throwErrors: " << throwErrors << __E__; 00208 00209 char tmp[500]; 00210 char strVal[500]; 00211 00212 std::string groupName; 00213 std::string errorStr = ""; 00214 bool skip; 00215 00216 __SS__; 00217 00218 while(fgets(tmp, 500, fp)) // for(int i=0;i<4;++i) 00219 { 00220 // fgets(tmp,500,fp); 00221 00222 skip = false; 00223 sscanf(tmp, "%s", strVal); // sscanf to remove '\n' 00224 for(unsigned int j = 0; j < strlen(strVal); ++j) 00225 if(!((strVal[j] >= 'a' && strVal[j] <= 'z') || 00226 (strVal[j] >= 'A' && strVal[j] <= 'Z') || 00227 (strVal[j] >= '0' && strVal[j] <= '9'))) 00228 { 00229 strVal[j] = '\0'; 00230 __COUT_INFO__ << "Illegal character found, so skipping!" << __E__; 00231 00232 skip = true; 00233 break; 00234 } 00235 00236 if(skip) 00237 continue; 00238 00239 groupName = strVal; 00240 fgets(tmp, 500, fp); 00241 sscanf(tmp, "%s", strVal); // sscanf to remove '\n' 00242 00243 for(unsigned int j = 0; j < strlen(strVal); ++j) 00244 if(!((strVal[j] >= '0' && strVal[j] <= '9'))) 00245 { 00246 strVal[j] = '\0'; 00247 00248 if(groupName.size() > 3) // notify if seems like a real group name 00249 __COUT_INFO__ 00250 << "Skipping active group with illegal character in name." 00251 << __E__; 00252 00253 skip = true; 00254 break; 00255 } 00256 00257 if(skip) 00258 continue; 00259 00260 try 00261 { 00262 TableGroupKey::getFullGroupString(groupName, TableGroupKey(strVal)); 00263 } 00264 catch(...) 00265 { 00266 __COUT__ << "illegal group according to TableGroupKey::getFullGroupString..." 00267 << __E__; 00268 skip = true; 00269 } 00270 00271 if(skip) 00272 continue; 00273 00274 try 00275 { 00276 // load and doActivate 00277 loadTableGroup(groupName, TableGroupKey(strVal), true); 00278 } 00279 catch(std::runtime_error& e) 00280 { 00281 ss << "Failed to load group in ConfigurationManager::init() with name '" 00282 << groupName << "(" << strVal << ")'" << __E__; 00283 ss << e.what() << __E__; 00284 00285 errorStr += ss.str(); 00286 } 00287 catch(...) 00288 { 00289 ss << "Failed to load group in ConfigurationManager::init() with name '" 00290 << groupName << "(" << strVal << ")'" << __E__; 00291 00292 errorStr += ss.str(); 00293 } 00294 } 00295 00296 fclose(fp); 00297 00298 if(throwErrors && errorStr != "") 00299 { 00300 __COUT_INFO__ << "\n" << ss.str(); 00301 __THROW__(errorStr); 00302 } 00303 else if(errorStr != "") 00304 __COUT_INFO__ << "\n" << ss.str(); 00305 00306 } // end restoreActiveTableGroups() 00307 00308 //============================================================================== 00309 // destroyTableGroup 00310 // destroy all if theGroup == "" 00311 // else destroy that group 00312 // if onlyDeactivate, then don't delete, just deactivate view 00313 void ConfigurationManager::destroyTableGroup(const std::string& theGroup, 00314 bool onlyDeactivate) 00315 { 00316 // delete 00317 bool isContext = theGroup == "" || theGroup == theContextTableGroup_; 00318 bool isBackbone = theGroup == "" || theGroup == theBackboneTableGroup_; 00319 bool isIterate = theGroup == "" || theGroup == theIterateTableGroup_; 00320 bool isConfiguration = theGroup == "" || theGroup == theConfigurationTableGroup_; 00321 00322 if(!isContext && !isBackbone && !isIterate && !isConfiguration) 00323 { 00324 __SS__ << "Invalid configuration group to destroy: " << theGroup << __E__; 00325 __COUT_ERR__ << ss.str(); 00326 __SS_THROW__; 00327 } 00328 00329 std::string dbgHeader = onlyDeactivate ? "Deactivating" : "Destroying"; 00330 if(theGroup != "") 00331 { 00332 if(isContext) 00333 __COUT__ << dbgHeader << " Context group: " << theGroup << __E__; 00334 if(isBackbone) 00335 __COUT__ << dbgHeader << " Backbone group: " << theGroup << __E__; 00336 if(isIterate) 00337 __COUT__ << dbgHeader << " Iterate group: " << theGroup << __E__; 00338 if(isConfiguration) 00339 __COUT__ << dbgHeader << " Configuration group: " << theGroup << __E__; 00340 } 00341 00342 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt; 00343 for(auto it = nameToTableMap_.begin(); it != nameToTableMap_.end(); 00344 /*no increment*/) 00345 { 00346 contextFindIt = contextMemberNames_.find(it->first); 00347 backboneFindIt = backboneMemberNames_.find(it->first); 00348 iterateFindIt = iterateMemberNames_.find(it->first); 00349 if(theGroup == "" || 00350 ((isContext && contextFindIt != contextMemberNames_.end()) || 00351 (isBackbone && backboneFindIt != backboneMemberNames_.end()) || 00352 (isIterate && iterateFindIt != iterateMemberNames_.end()) || 00353 (!isContext && !isBackbone && contextFindIt == contextMemberNames_.end() && 00354 backboneFindIt == backboneMemberNames_.end() && 00355 iterateFindIt == iterateMemberNames_.end()))) 00356 { 00357 //__COUT__ << "\t" << it->first << __E__; 00358 // if(it->second->isActive()) 00359 // __COUT__ << "\t\t..._v" << it->second->getViewVersion() << __E__; 00360 00361 if(onlyDeactivate) // only deactivate 00362 { 00363 it->second->deactivate(); 00364 ++it; 00365 } 00366 else // else, delete/erase 00367 { 00368 delete it->second; 00369 nameToTableMap_.erase(it++); 00370 } 00371 } 00372 else 00373 ++it; 00374 } 00375 00376 if(isConfiguration) 00377 { 00378 theConfigurationTableGroup_ = ""; 00379 if(theConfigurationTableGroupKey_ != 0) 00380 { 00381 __COUT__ << "Destroying Configuration Key: " 00382 << *theConfigurationTableGroupKey_ << __E__; 00383 theConfigurationTableGroupKey_.reset(); 00384 } 00385 00386 // theDACStreams_.clear(); 00387 } 00388 if(isBackbone) 00389 { 00390 theBackboneTableGroup_ = ""; 00391 if(theBackboneTableGroupKey_ != 0) 00392 { 00393 __COUT__ << "Destroying Backbone Key: " << *theBackboneTableGroupKey_ 00394 << __E__; 00395 theBackboneTableGroupKey_.reset(); 00396 } 00397 } 00398 if(isIterate) 00399 { 00400 theIterateTableGroup_ = ""; 00401 if(theIterateTableGroupKey_ != 0) 00402 { 00403 __COUT__ << "Destroying Iterate Key: " << *theIterateTableGroupKey_ << __E__; 00404 theIterateTableGroupKey_.reset(); 00405 } 00406 } 00407 if(isContext) 00408 { 00409 theContextTableGroup_ = ""; 00410 if(theContextTableGroupKey_ != 0) 00411 { 00412 __COUT__ << "Destroying Context Key: " << *theContextTableGroupKey_ << __E__; 00413 theContextTableGroupKey_.reset(); 00414 } 00415 } 00416 } 00417 00418 //============================================================================== 00419 void ConfigurationManager::destroy(void) 00420 { 00421 // NOTE: Moved to ConfigurationGUISupervisor [FIXME is this correct?? should we use 00422 // shared_ptr??] 00423 // if( ConfigurationInterface::getInstance(true) != 0 ) 00424 // delete theInterface_; 00425 destroyTableGroup(); 00426 } 00427 00428 //============================================================================== 00429 // convertGroupTypeIdToName 00430 // return translation: 00431 // 0 for context 00432 // 1 for backbone 00433 // 2 for configuration (others) 00434 const std::string& ConfigurationManager::convertGroupTypeIdToName(int groupTypeId) 00435 { 00436 return groupTypeId == CONTEXT_TYPE 00437 ? ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT 00438 : (groupTypeId == BACKBONE_TYPE 00439 ? ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE 00440 : (groupTypeId == ITERATE_TYPE 00441 ? ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE 00442 : ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)); 00443 } 00444 00445 //============================================================================== 00446 // getTypeOfGroup 00447 // return 00448 // CONTEXT_TYPE for context 00449 // BACKBONE_TYPE for backbone 00450 // ITERATE_TYPE for iterate 00451 // CONFIGURATION_TYPE for configuration (others) 00452 int ConfigurationManager::getTypeOfGroup( 00453 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap) 00454 { 00455 bool isContext = true; 00456 bool isBackbone = true; 00457 bool isIterate = true; 00458 bool inGroup; 00459 bool inContext = false; 00460 bool inBackbone = false; 00461 bool inIterate = false; 00462 unsigned int matchCount = 0; 00463 00464 for(auto& memberPair : memberMap) 00465 { 00466 //__COUT__ << "Member name: = "<< memberPair.first << __E__; 00468 inGroup = false; // check context 00469 for(auto& contextMemberString : contextMemberNames_) 00470 if(memberPair.first == contextMemberString) 00471 { 00472 inGroup = true; 00473 inContext = true; 00474 ++matchCount; 00475 break; 00476 } 00477 if(!inGroup) 00478 { 00479 isContext = false; 00480 if(inContext) // there was a member in context! 00481 { 00482 __SS__ << "This group is an incomplete match to a Context group.\n"; 00483 __COUT_ERR__ << "\n" << ss.str(); 00484 ss << "\nTo be a Context group, the members must exactly match " 00485 << "the following members:\n"; 00486 int i = 0; 00487 for(const auto& memberName : contextMemberNames_) 00488 ss << ++i << ". " << memberName << "\n"; 00489 ss << "\nThe members are as follows::\n"; 00490 i = 0; 00491 for(const auto& memberPairTmp : memberMap) 00492 ss << ++i << ". " << memberPairTmp.first << "\n"; 00493 __SS_THROW__; 00494 } 00495 } 00496 00498 inGroup = false; // check backbone 00499 for(auto& backboneMemberString : backboneMemberNames_) 00500 if(memberPair.first == backboneMemberString) 00501 { 00502 inGroup = true; 00503 inBackbone = true; 00504 ++matchCount; 00505 break; 00506 } 00507 if(!inGroup) 00508 { 00509 isBackbone = false; 00510 if(inBackbone) // there was a member in backbone! 00511 { 00512 __SS__ << "This group is an incomplete match to a Backbone group.\n"; 00513 __COUT_ERR__ << "\n" << ss.str(); 00514 ss << "\nTo be a Backbone group, the members must exactly match " 00515 << "the following members:\n"; 00516 int i = 0; 00517 for(auto& memberName : backboneMemberNames_) 00518 ss << ++i << ". " << memberName << "\n"; 00519 ss << "\nThe members are as follows::\n"; 00520 i = 0; 00521 for(const auto& memberPairTmp : memberMap) 00522 ss << ++i << ". " << memberPairTmp.first << "\n"; 00523 //__COUT_ERR__ << "\n" << ss.str(); 00524 __SS_THROW__; 00525 } 00526 } 00527 00529 inGroup = false; // check iterate 00530 for(auto& iterateMemberString : iterateMemberNames_) 00531 if(memberPair.first == iterateMemberString) 00532 { 00533 inGroup = true; 00534 inIterate = true; 00535 ++matchCount; 00536 break; 00537 } 00538 if(!inGroup) 00539 { 00540 isIterate = false; 00541 if(inIterate) // there was a member in iterate! 00542 { 00543 __SS__ << "This group is an incomplete match to a Iterate group.\n"; 00544 __COUT_ERR__ << "\n" << ss.str(); 00545 ss << "\nTo be a Iterate group, the members must exactly match " 00546 << "the following members:\n"; 00547 int i = 0; 00548 for(auto& memberName : iterateMemberNames_) 00549 ss << ++i << ". " << memberName << "\n"; 00550 ss << "\nThe members are as follows::\n"; 00551 i = 0; 00552 for(const auto& memberPairTmp : memberMap) 00553 ss << ++i << ". " << memberPairTmp.first << "\n"; 00554 //__COUT_ERR__ << "\n" << ss.str(); 00555 __SS_THROW__; 00556 } 00557 } 00558 } 00559 00560 if(isContext && matchCount != contextMemberNames_.size()) 00561 { 00562 __SS__ << "This group is an incomplete match to a Context group: " 00563 << " Size=" << matchCount << " but should be " 00564 << contextMemberNames_.size() << __E__; 00565 __COUT_ERR__ << "\n" << ss.str(); 00566 ss << "\nThe members currently are...\n"; 00567 int i = 0; 00568 for(auto& memberPair : memberMap) 00569 ss << ++i << ". " << memberPair.first << "\n"; 00570 ss << "\nThe expected Context members are...\n"; 00571 i = 0; 00572 for(auto& memberName : contextMemberNames_) 00573 ss << ++i << ". " << memberName << "\n"; 00574 //__COUT_ERR__ << "\n" << ss.str(); 00575 __SS_THROW__; 00576 } 00577 00578 if(isBackbone && matchCount != backboneMemberNames_.size()) 00579 { 00580 __SS__ << "This group is an incomplete match to a Backbone group: " 00581 << " Size=" << matchCount << " but should be " 00582 << backboneMemberNames_.size() << __E__; 00583 __COUT_ERR__ << "\n" << ss.str(); 00584 ss << "\nThe members currently are...\n"; 00585 int i = 0; 00586 for(auto& memberPair : memberMap) 00587 ss << ++i << ". " << memberPair.first << "\n"; 00588 ss << "\nThe expected Backbone members are...\n"; 00589 i = 0; 00590 for(auto& memberName : backboneMemberNames_) 00591 ss << ++i << ". " << memberName << "\n"; 00592 //__COUT_ERR__ << "\n" << ss.str(); 00593 __SS_THROW__; 00594 } 00595 00596 if(isIterate && matchCount != iterateMemberNames_.size()) 00597 { 00598 __SS__ << "This group is an incomplete match to a Iterate group: " 00599 << " Size=" << matchCount << " but should be " 00600 << backboneMemberNames_.size() << __E__; 00601 __COUT_ERR__ << "\n" << ss.str(); 00602 ss << "\nThe members currently are...\n"; 00603 int i = 0; 00604 for(auto& memberPair : memberMap) 00605 ss << ++i << ". " << memberPair.first << "\n"; 00606 ss << "\nThe expected Iterate members are...\n"; 00607 i = 0; 00608 for(auto& memberName : iterateMemberNames_) 00609 ss << ++i << ". " << memberName << "\n"; 00610 //__COUT_ERR__ << "\n" << ss.str(); 00611 __SS_THROW__; 00612 } 00613 00614 return isContext ? CONTEXT_TYPE 00615 : (isBackbone ? BACKBONE_TYPE 00616 : (isIterate ? ITERATE_TYPE : CONFIGURATION_TYPE)); 00617 } 00618 00619 //============================================================================== 00620 // getTypeNameOfGroup 00621 // return string for group type 00622 const std::string& ConfigurationManager::getTypeNameOfGroup( 00623 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap) 00624 { 00625 return convertGroupTypeIdToName(getTypeOfGroup(memberMap)); 00626 } 00627 00628 //============================================================================== 00629 // loadMemberMap 00630 // loads tables given by name/version pairs in memberMap 00631 // Note: does not activate them. 00632 // 00633 // if filePath == "", then output to cout 00634 void ConfigurationManager::dumpActiveConfiguration(const std::string& filePath, 00635 const std::string& dumpType) 00636 { 00637 time_t rawtime = time(0); 00638 __COUT__ << "filePath = " << filePath << __E__; 00639 __COUT__ << "dumpType = " << dumpType << __E__; 00640 00641 std::ofstream fs; 00642 fs.open(filePath, std::fstream::out | std::fstream::trunc); 00643 00644 std::ostream* out; 00645 00646 // if file was valid use it, else default to cout 00647 if(fs.is_open()) 00648 out = &fs; 00649 else 00650 { 00651 if(filePath != "") 00652 { 00653 __SS__ << "Invalid file path to dump active configuration. File " << filePath 00654 << " could not be opened!" << __E__; 00655 __COUT_ERR__ << ss.str(); 00656 __SS_THROW__; 00657 } 00658 out = &(std::cout); 00659 } 00660 00661 (*out) << "#################################" << __E__; 00662 (*out) << "This is an ots configuration dump.\n\n" << __E__; 00663 (*out) << "Source database is $ARTDAQ_DATABASE_URI = \t" 00664 << getenv("ARTDAQ_DATABASE_URI") << __E__; 00665 (*out) << "\nOriginal location of dump: \t" << filePath << __E__; 00666 (*out) << "Type of dump: \t" << dumpType << __E__; 00667 (*out) << "Linux time for dump: \t" << rawtime << __E__; 00668 00669 { 00670 struct tm* timeinfo = localtime(&rawtime); 00671 char buffer[100]; 00672 strftime(buffer, 100, "%c %Z", timeinfo); 00673 (*out) << "Display time for dump: \t" << buffer << __E__; 00674 } 00675 00676 // define local "lambda" functions 00677 // active groups 00678 // active tables 00679 // active group members 00680 // active table contents 00681 00682 auto localDumpActiveGroups = [](const ConfigurationManager* cfgMgr, 00683 std::ostream* out) { 00684 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups = 00685 cfgMgr->getActiveTableGroups(); 00686 00687 (*out) << "\n\n************************" << __E__; 00688 (*out) << "Active Groups:" << __E__; 00689 for(auto& group : activeGroups) 00690 { 00691 (*out) << "\t" << group.first << " := " << group.second.first << " (" 00692 << group.second.second << ")" << __E__; 00693 } 00694 }; 00695 00696 auto localDumpActiveTables = [](const ConfigurationManager* cfgMgr, 00697 std::ostream* out) { 00698 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions(); 00699 00700 (*out) << "\n\n************************" << __E__; 00701 (*out) << "Active Tables:" << __E__; 00702 (*out) << "Active Tables count = " << activeTables.size() << __E__; 00703 00704 unsigned int i = 0; 00705 for(auto& table : activeTables) 00706 { 00707 (*out) << "\t" << ++i << ". " << table.first << "-v" << table.second << __E__; 00708 } 00709 }; 00710 00711 auto localDumpActiveGroupMembers = [](ConfigurationManager* cfgMgr, 00712 std::ostream* out) { 00713 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups = 00714 cfgMgr->getActiveTableGroups(); 00715 (*out) << "\n\n************************" << __E__; 00716 (*out) << "Active Group Members:" << __E__; 00717 int tableCount = 0; 00718 for(auto& group : activeGroups) 00719 { 00720 (*out) << "\t" << group.first << " := " << group.second.first << " (" 00721 << group.second.second << ")" << __E__; 00722 00723 if(group.second.first == "") 00724 { 00725 (*out) << "\t" 00726 << "Empty group name. Assuming no active group." << __E__; 00727 continue; 00728 } 00729 00730 std::map<std::string /*name*/, TableVersion /*version*/> memberMap; 00731 std::map<std::string /*name*/, std::string /*alias*/> groupAliases; 00732 std::string groupComment; 00733 std::string groupAuthor; 00734 std::string groupCreateTime; 00735 time_t groupCreateTime_t; 00736 00737 cfgMgr->loadTableGroup(group.second.first, 00738 group.second.second, 00739 false /*doActivate*/, 00740 &memberMap /*memberMap*/, 00741 0 /*progressBar*/, 00742 0 /*accumulateErrors*/, 00743 &groupComment, 00744 &groupAuthor, 00745 &groupCreateTime, 00746 true /*doNotLoadMember*/, 00747 0 /*groupTypeString*/, 00748 &groupAliases); 00749 00750 (*out) << "\t\tGroup Comment: \t" << groupComment << __E__; 00751 (*out) << "\t\tGroup Author: \t" << groupAuthor << __E__; 00752 00753 sscanf(groupCreateTime.c_str(), "%ld", &groupCreateTime_t); 00754 (*out) << "\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t) << __E__; 00755 (*out) << "\t\tGroup Aliases: \t" << StringMacros::mapToString(groupAliases) 00756 << __E__; 00757 00758 (*out) << "\t\tMember table count = " << memberMap.size() << __E__; 00759 tableCount += memberMap.size(); 00760 00761 unsigned int i = 0; 00762 for(auto& member : memberMap) 00763 { 00764 (*out) << "\t\t\t" << ++i << ". " << member.first << "-v" << member.second 00765 << __E__; 00766 } 00767 } 00768 (*out) << "\nActive Group Members total table count = " << tableCount << __E__; 00769 }; 00770 00771 auto localDumpActiveTableContents = [](const ConfigurationManager* cfgMgr, 00772 std::ostream* out) { 00773 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions(); 00774 00775 (*out) << "\n\n************************" << __E__; 00776 (*out) << "Active Table Contents (table count = " << activeTables.size() 00777 << "):" << __E__; 00778 unsigned int i = 0; 00779 for(auto& table : activeTables) 00780 { 00781 (*out) << "\n\n==============================================================" 00782 "================" 00783 << __E__; 00784 (*out) << "==================================================================" 00785 "============" 00786 << __E__; 00787 (*out) << "\t" << ++i << ". " << table.first << "-v" << table.second << __E__; 00788 00789 cfgMgr->nameToTableMap_.find(table.first)->second->print(*out); 00790 } 00791 }; 00792 00793 if(dumpType == "GroupKeys") 00794 { 00795 localDumpActiveGroups(this, out); 00796 } 00797 else if(dumpType == "TableVersions") 00798 { 00799 localDumpActiveTables(this, out); 00800 } 00801 else if(dumpType == "GroupKeysAndTableVersions") 00802 { 00803 localDumpActiveGroups(this, out); 00804 localDumpActiveTables(this, out); 00805 } 00806 else if(dumpType == "All") 00807 { 00808 localDumpActiveGroups(this, out); 00809 localDumpActiveGroupMembers(this, out); 00810 localDumpActiveTables(this, out); 00811 localDumpActiveTableContents(this, out); 00812 } 00813 else 00814 { 00815 __SS__ 00816 << "Invalid dump type '" << dumpType 00817 << "' given during dumpActiveConfiguration(). Valid types are as follows:\n" 00818 << 00819 00820 // List all choices 00821 "GroupKeys" 00822 << ", " 00823 << "TableVersions" 00824 << ", " 00825 << "GroupsKeysAndTableVersions" 00826 << ", " 00827 << "All" 00828 << 00829 00830 "\n\nPlease change the State Machine configuration to a valid dump type." 00831 << __E__; 00832 __SS_THROW__; 00833 } 00834 00835 if(fs.is_open()) 00836 fs.close(); 00837 } 00838 00839 //============================================================================== 00840 // loadMemberMap 00841 // loads tables given by name/version pairs in memberMap 00842 // Note: does not activate them. 00843 void ConfigurationManager::loadMemberMap( 00844 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap) 00845 { 00846 TableBase* tmpConfigBasePtr; 00847 // for each member 00848 // get() 00849 for(auto& memberPair : memberMap) 00850 { 00851 //__COUT__ << "\tMember config " << memberPair.first << ":" << 00852 // memberPair.second << __E__; 00853 00854 // get the proper temporary pointer 00855 // use 0 if doesn't exist yet. 00856 // Note: do not want to give nameToTableMap_[memberPair.first] 00857 // in case there is failure in get... (exceptions may be thrown) 00858 // Note: Default constructor is called by Map, i.e. 00859 // nameToTableMap_[memberPair.first] = 0; //create pointer and set to 0 00860 tmpConfigBasePtr = 0; 00861 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end()) 00862 tmpConfigBasePtr = nameToTableMap_[memberPair.first]; 00863 00864 theInterface_->get(tmpConfigBasePtr, // configurationPtr 00865 memberPair.first, // tableName 00866 0, // groupKey 00867 0, // groupName 00868 false, // dontFill=false to fill 00869 memberPair.second, // version 00870 false // resetTable 00871 ); 00872 00873 nameToTableMap_[memberPair.first] = tmpConfigBasePtr; 00874 if(nameToTableMap_[memberPair.first]->getViewP()) 00875 { 00876 //__COUT__ << "\t\tActivated version: " << 00877 // nameToTableMap_[memberPair.first]->getViewVersion() << __E__; 00878 } 00879 else 00880 { 00881 __SS__ << nameToTableMap_[memberPair.first]->getTableName() 00882 << ": View version not activated properly!"; 00883 __SS_THROW__; 00884 } 00885 } 00886 } // end loadMemberMap() 00887 00888 //============================================================================== 00889 // loadTableGroup 00890 // load all members of configuration group 00891 // if doActivate 00892 // DOES set theConfigurationTableGroup_, theContextTableGroup_, or 00893 // theBackboneTableGroup_ on success this also happens with 00894 // ConfigurationManagerRW::activateTableGroup for each member 00895 // configBase->init() 00896 // 00897 // if progressBar != 0, then do step handling, for finer granularity 00898 // 00899 // if(doNotLoadMember) return memberMap; //this is useful if just getting group metadata 00900 // else NOTE: active views are changed! (when loading member map) 00901 // 00902 // throws exception on failure. 00903 // map<name , TableVersion > 00904 void ConfigurationManager::loadTableGroup( 00905 const std::string& groupName, 00906 TableGroupKey groupKey, 00907 bool doActivate /*=false*/, 00908 std::map<std::string, TableVersion>* groupMembers, 00909 ProgressBar* progressBar, 00910 std::string* accumulatedTreeErrors, 00911 std::string* groupComment, 00912 std::string* groupAuthor, 00913 std::string* groupCreateTime, 00914 bool doNotLoadMember /*=false*/, 00915 std::string* groupTypeString, 00916 std::map<std::string /*name*/, std::string /*alias*/>* groupAliases) try 00917 { 00918 // clear to defaults 00919 if(groupComment) 00920 *groupComment = "NO COMMENT FOUND"; 00921 if(groupAuthor) 00922 *groupAuthor = "NO AUTHOR FOUND"; 00923 if(groupCreateTime) 00924 *groupCreateTime = "0"; 00925 if(groupTypeString) 00926 *groupTypeString = "UNKNOWN"; 00927 00928 // if(groupName == "defaultConfig") 00929 // { //debug active versions 00930 // std::map<std::string, TableVersion> allActivePairs = getActiveVersions(); 00931 // for(auto& activePair: allActivePairs) 00932 // { 00933 // __COUT__ << "Active table = " << 00934 // activePair.first << "-v" << 00935 // getTableByName(activePair.first)->getView().getVersion() << 00936 // __E__; 00937 // } 00938 // } 00939 00940 // load all members of configuration group 00941 // if doActivate 00942 // determine the type configuration 00943 // deactivate all of that type (invalidate active view) 00944 // 00945 // for each member 00946 // get() 00947 // if doActivate, configBase->init() 00948 // 00949 // if doActivate 00950 // set theConfigurationTableGroup_, theContextTableGroup_, or 00951 // theBackboneTableGroup_ on success 00952 00953 // __COUT_INFO__ << "Loading Table Group: " << groupName << 00954 // "(" << groupKey << ")" << __E__; 00955 00956 std::map<std::string /*name*/, TableVersion /*version*/> memberMap = 00957 theInterface_->getTableGroupMembers( 00958 TableGroupKey::getFullGroupString(groupName, groupKey), 00959 true /*include meta data table*/); 00960 std::map<std::string /*name*/, std::string /*alias*/> aliasMap; 00961 00962 if(progressBar) 00963 progressBar->step(); 00964 00965 // remove meta data table and extract info 00966 auto metaTablePair = memberMap.find(groupMetadataTable_.getTableName()); 00967 if(metaTablePair != memberMap.end()) 00968 { 00969 //__COUT__ << "Found group meta data. v" << metaTablePair->second << __E__; 00970 00971 memberMap.erase(metaTablePair); // remove from member map that is returned 00972 00973 // clear table 00974 while(groupMetadataTable_.getView().getNumberOfRows()) 00975 groupMetadataTable_.getViewP()->deleteRow(0); 00976 00977 // retrieve metadata from database 00978 try 00979 { 00980 theInterface_->fill(&groupMetadataTable_, metaTablePair->second); 00981 } 00982 catch(const std::runtime_error& e) 00983 { 00984 __COUT_WARN__ << "Ignoring metadata error: " << e.what() << __E__; 00985 } 00986 catch(...) 00987 { 00988 __COUT_WARN__ << "Ignoring unknown metadata error. " << __E__; 00989 } 00990 00991 // check that there is only 1 row 00992 if(groupMetadataTable_.getView().getNumberOfRows() != 1) 00993 { 00994 if(groupMembers) 00995 *groupMembers = memberMap; // copy for return 00996 00997 groupMetadataTable_.print(); 00998 __SS__ << "Ignoring that groupMetadataTable_ has wrong number of rows! Must " 00999 "be 1. Going with anonymous defaults." 01000 << __E__; 01001 __COUT_ERR__ << "\n" << ss.str(); 01002 01003 // fix metadata table 01004 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1) 01005 groupMetadataTable_.getViewP()->deleteRow(0); 01006 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0) 01007 groupMetadataTable_.getViewP()->addRow(); 01008 01009 if(groupComment) 01010 *groupComment = "NO COMMENT FOUND"; 01011 if(groupAuthor) 01012 *groupAuthor = "NO AUTHOR FOUND"; 01013 if(groupCreateTime) 01014 *groupCreateTime = "0"; 01015 01016 int groupType = -1; 01017 if(groupTypeString) // do before exit case 01018 { 01019 groupType = getTypeOfGroup(memberMap); 01020 *groupTypeString = convertGroupTypeIdToName(groupType); 01021 } 01022 return; // memberMap; 01023 } 01024 01025 // groupMetadataTable_.print(); 01026 01027 // extract fields 01028 StringMacros::getMapFromString(groupMetadataTable_.getView().getValueAsString( 01029 0, ConfigurationManager::METADATA_COL_ALIASES), 01030 aliasMap); 01031 if(groupAliases) 01032 *groupAliases = aliasMap; 01033 if(groupComment) 01034 *groupComment = groupMetadataTable_.getView().getValueAsString( 01035 0, ConfigurationManager::METADATA_COL_COMMENT); 01036 if(groupAuthor) 01037 *groupAuthor = groupMetadataTable_.getView().getValueAsString( 01038 0, ConfigurationManager::METADATA_COL_AUTHOR); 01039 if(groupCreateTime) 01040 *groupCreateTime = groupMetadataTable_.getView().getValueAsString( 01041 0, ConfigurationManager::METADATA_COL_TIMESTAMP); 01042 01043 // modify members based on aliases 01044 { 01045 std::map<std::string /*table*/, std::map<std::string /*alias*/, TableVersion>> 01046 versionAliases; 01047 if(aliasMap.size()) // load version aliases 01048 { 01049 __COUTV__(StringMacros::mapToString(aliasMap)); 01050 versionAliases = ConfigurationManager::getVersionAliases(); 01051 __COUTV__(StringMacros::mapToString(versionAliases)); 01052 } 01053 01054 // convert alias to version 01055 for(auto& aliasPair : aliasMap) 01056 { 01057 // check for alias table in member names 01058 if(memberMap.find(aliasPair.first) != memberMap.end()) 01059 { 01060 __COUT__ << "Group member '" << aliasPair.first 01061 << "' was found in group member map!" << __E__; 01062 __COUT__ << "Looking for alias '" << aliasPair.second 01063 << "' in active version aliases..." << __E__; 01064 01065 if(versionAliases.find(aliasPair.first) == versionAliases.end() || 01066 versionAliases[aliasPair.first].find(aliasPair.second) == 01067 versionAliases[aliasPair.first].end()) 01068 { 01069 __SS__ << "Group '" << groupName << "(" << groupKey 01070 << ")' requires table version alias '" << aliasPair.first 01071 << ":" << aliasPair.second 01072 << ",' which was not found in the active Backbone!" 01073 << __E__; 01074 __SS_THROW__; 01075 } 01076 01077 memberMap[aliasPair.first] = 01078 versionAliases[aliasPair.first][aliasPair.second]; 01079 __COUT__ << "Version alias translated to " << aliasPair.first 01080 << __E__; 01081 } 01082 } 01083 } 01084 } 01085 01086 if(groupMembers) 01087 *groupMembers = memberMap; // copy map for return 01088 01089 if(progressBar) 01090 progressBar->step(); 01091 01092 //__COUT__ << "memberMap loaded size = " << memberMap.size() << __E__; 01093 01094 int groupType = -1; 01095 try 01096 { 01097 if(groupTypeString) // do before exit case 01098 { 01099 groupType = getTypeOfGroup(memberMap); 01100 *groupTypeString = convertGroupTypeIdToName(groupType); 01101 } 01102 01103 // if(groupName == "defaultConfig") 01104 // { //debug active versions 01105 // std::map<std::string, TableVersion> allActivePairs = 01106 // getActiveVersions(); for(auto& activePair: allActivePairs) 01107 // { 01108 // __COUT__ << "Active table = " << 01109 // activePair.first << "-v" << 01110 // getTableByName(activePair.first)->getView().getVersion() 01111 //<< __E__; 01112 // } 01113 // } 01114 01115 if(doNotLoadMember) 01116 return; // memberMap; //this is useful if just getting group metadata 01117 01118 // if not already done, determine the type configuration group 01119 if(!groupTypeString) 01120 groupType = getTypeOfGroup(memberMap); 01121 01122 if(doActivate) 01123 __COUT__ << "------------------------------------- init start \t [for all " 01124 "plug-ins in " 01125 << convertGroupTypeIdToName(groupType) << " group '" << groupName 01126 << "(" << groupKey << ")" 01127 << "']" << __E__; 01128 01129 if(doActivate) 01130 { 01131 std::string groupToDeactivate = 01132 groupType == ConfigurationManager::CONTEXT_TYPE 01133 ? theContextTableGroup_ 01134 : (groupType == ConfigurationManager::BACKBONE_TYPE 01135 ? theBackboneTableGroup_ 01136 : (groupType == ConfigurationManager::ITERATE_TYPE 01137 ? theIterateTableGroup_ 01138 : theConfigurationTableGroup_)); 01139 01140 // deactivate all of that type (invalidate active view) 01141 if(groupToDeactivate != "") // deactivate only if pre-existing group 01142 { 01143 //__COUT__ << "groupToDeactivate '" << groupToDeactivate << "'" << 01144 // __E__; 01145 destroyTableGroup(groupToDeactivate, true); 01146 } 01147 // else 01148 // { 01149 // //Getting here, is kind of strange: 01150 // // - this group may have only been partially loaded before? 01151 // } 01152 } 01153 // if(groupName == "defaultConfig") 01154 // { //debug active versions 01155 // std::map<std::string, TableVersion> allActivePairs = 01156 // getActiveVersions(); for(auto& activePair: allActivePairs) 01157 // { 01158 // __COUT__ << "Active table = " << 01159 // activePair.first << "-v" << 01160 // getTableByName(activePair.first)->getView().getVersion() 01161 //<< __E__; 01162 // } 01163 // } 01164 01165 if(progressBar) 01166 progressBar->step(); 01167 01168 //__COUT__ << "Activating chosen group:" << __E__; 01169 01170 loadMemberMap(memberMap); 01171 01172 if(progressBar) 01173 progressBar->step(); 01174 01175 if(accumulatedTreeErrors) 01176 { 01177 //__COUT__ << "Checking chosen group for tree errors..." << __E__; 01178 01179 getChildren(&memberMap, accumulatedTreeErrors); 01180 if(*accumulatedTreeErrors != "") 01181 { 01182 __COUT_ERR__ << "Errors detected while loading Table Group: " << groupName 01183 << "(" << groupKey << "). Aborting." << __E__; 01184 return; // memberMap; //return member name map to version 01185 } 01186 } 01187 01188 if(progressBar) 01189 progressBar->step(); 01190 01191 // for each member 01192 // if doActivate, configBase->init() 01193 if(doActivate) 01194 for(auto& memberPair : memberMap) 01195 { 01196 // do NOT allow activating Scratch versions if tracking is ON! 01197 if(ConfigurationInterface::isVersionTrackingEnabled() && 01198 memberPair.second.isScratchVersion()) 01199 { 01200 __SS__ << "Error while activating member Table '" 01201 << nameToTableMap_[memberPair.first]->getTableName() << "-v" 01202 << memberPair.second << " for Table Group '" << groupName 01203 << "(" << groupKey 01204 << ")'. When version tracking is enabled, Scratch views" 01205 << " are not allowed! Please only use unique, persistent " 01206 "versions when version tracking is enabled." 01207 << __E__; 01208 __COUT_ERR__ << "\n" << ss.str(); 01209 __SS_THROW__; 01210 } 01211 01212 // attempt to init using the configuration's specific init 01213 // this could be risky user code, try and catch 01214 try 01215 { 01216 nameToTableMap_[memberPair.first]->init(this); 01217 } 01218 catch(std::runtime_error& e) 01219 { 01220 __SS__ << "Error detected calling " 01221 << nameToTableMap_[memberPair.first]->getTableName() 01222 << ".init()!\n\n " << e.what() << __E__; 01223 __SS_THROW__; 01224 } 01225 catch(...) 01226 { 01227 __SS__ << "Unknown Error detected calling " 01228 << nameToTableMap_[memberPair.first]->getTableName() 01229 << ".init()!\n\n " << __E__; 01230 __SS_THROW__; 01231 } 01232 } 01233 01234 if(progressBar) 01235 progressBar->step(); 01236 01237 // if doActivate 01238 // set theConfigurationTableGroup_, theContextTableGroup_, or 01239 // theBackboneTableGroup_ on 01240 // success 01241 01242 if(doActivate) 01243 { 01244 if(groupType == ConfigurationManager::CONTEXT_TYPE) // 01245 { 01246 // __COUT_INFO__ << "Type=Context, Group loaded: " << 01247 // groupName 01248 //<< 01249 // "(" << groupKey << ")" << __E__; 01250 theContextTableGroup_ = groupName; 01251 theContextTableGroupKey_ = 01252 std::shared_ptr<TableGroupKey>(new TableGroupKey(groupKey)); 01253 } 01254 else if(groupType == ConfigurationManager::BACKBONE_TYPE) 01255 { 01256 // __COUT_INFO__ << "Type=Backbone, Group loaded: " << 01257 // groupName << 01258 // "(" << groupKey << ")" << __E__; 01259 theBackboneTableGroup_ = groupName; 01260 theBackboneTableGroupKey_ = 01261 std::shared_ptr<TableGroupKey>(new TableGroupKey(groupKey)); 01262 } 01263 else if(groupType == ConfigurationManager::ITERATE_TYPE) 01264 { 01265 // __COUT_INFO__ << "Type=Iterate, Group loaded: " << 01266 // groupName 01267 //<< 01268 // "(" << groupKey << ")" << __E__; 01269 theIterateTableGroup_ = groupName; 01270 theIterateTableGroupKey_ = 01271 std::shared_ptr<TableGroupKey>(new TableGroupKey(groupKey)); 01272 } 01273 else // is theConfigurationTableGroup_ 01274 { 01275 // __COUT_INFO__ << "Type=Configuration, Group loaded: " << 01276 // groupName << 01277 // "(" << groupKey << ")" << __E__; 01278 theConfigurationTableGroup_ = groupName; 01279 theConfigurationTableGroupKey_ = 01280 std::shared_ptr<TableGroupKey>(new TableGroupKey(groupKey)); 01281 } 01282 } 01283 01284 if(progressBar) 01285 progressBar->step(); 01286 01287 if(doActivate) 01288 __COUT__ << "------------------------------------- init complete \t [for all " 01289 "plug-ins in " 01290 << convertGroupTypeIdToName(groupType) << " group '" << groupName 01291 << "(" << groupKey << ")" 01292 << "']" << __E__; 01293 } // end failed group load try 01294 catch(...) 01295 { 01296 // save group name and key of failed load attempt 01297 lastFailedGroupLoad_[convertGroupTypeIdToName(groupType)] = 01298 std::pair<std::string, TableGroupKey>(groupName, TableGroupKey(groupKey)); 01299 01300 try 01301 { 01302 throw; 01303 } 01304 catch(const std::runtime_error& e) 01305 { 01306 __SS__ << "Error occurred while loading table group '" << groupName << "(" 01307 << groupKey << ")': \n" 01308 << e.what() << __E__; 01309 __COUT_WARN__ << ss.str(); 01310 if(accumulatedTreeErrors) 01311 *accumulatedTreeErrors += ss.str(); 01312 else 01313 __SS_THROW__; 01314 } 01315 catch(...) 01316 { 01317 __SS__ << "An unknown error occurred while loading table group '" << groupName 01318 << "(" << groupKey << ")." << __E__; 01319 __COUT_WARN__ << ss.str(); 01320 if(accumulatedTreeErrors) 01321 *accumulatedTreeErrors += ss.str(); 01322 else 01323 __SS_THROW__; 01324 } 01325 } 01326 01327 return; 01328 } 01329 catch(...) 01330 { 01331 // save group name and key of failed load attempt 01332 lastFailedGroupLoad_[ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN] = 01333 std::pair<std::string, TableGroupKey>(groupName, TableGroupKey(groupKey)); 01334 01335 try 01336 { 01337 throw; 01338 } 01339 catch(const std::runtime_error& e) 01340 { 01341 __SS__ << "Error occurred while loading table group: " << e.what() << __E__; 01342 __COUT_WARN__ << ss.str(); 01343 if(accumulatedTreeErrors) 01344 *accumulatedTreeErrors += ss.str(); 01345 else 01346 __SS_THROW__; 01347 } 01348 catch(...) 01349 { 01350 __SS__ << "An unknown error occurred while loading table group." << __E__; 01351 __COUT_WARN__ << ss.str(); 01352 if(accumulatedTreeErrors) 01353 *accumulatedTreeErrors += ss.str(); 01354 else 01355 __SS_THROW__; 01356 } 01357 } // end loadTableGroup() 01358 01359 //============================================================================== 01360 // getActiveTableGroups 01361 // get the active table groups map 01362 // map<type, pair <groupName , TableGroupKey> > 01363 // 01364 // Note: invalid TableGroupKey means no active group currently 01365 std::map<std::string, std::pair<std::string, TableGroupKey>> 01366 ConfigurationManager::getActiveTableGroups(void) const 01367 { 01368 // map<type, pair <groupName , TableGroupKey> > 01369 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap; 01370 01371 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] = 01372 std::pair<std::string, TableGroupKey>( 01373 theContextTableGroup_, 01374 theContextTableGroupKey_ ? *theContextTableGroupKey_ : TableGroupKey()); 01375 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] = 01376 std::pair<std::string, TableGroupKey>( 01377 theBackboneTableGroup_, 01378 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ : TableGroupKey()); 01379 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] = 01380 std::pair<std::string, TableGroupKey>( 01381 theIterateTableGroup_, 01382 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ : TableGroupKey()); 01383 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] = 01384 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_, 01385 theConfigurationTableGroupKey_ 01386 ? *theConfigurationTableGroupKey_ 01387 : TableGroupKey()); 01388 return retMap; 01389 } // end getActiveTableGroups() 01390 01391 //============================================================================== 01392 const std::string& ConfigurationManager::getActiveGroupName(const std::string& type) const 01393 { 01394 if(type == "" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION) 01395 return theConfigurationTableGroup_; 01396 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT) 01397 return theContextTableGroup_; 01398 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE) 01399 return theBackboneTableGroup_; 01400 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE) 01401 return theIterateTableGroup_; 01402 01403 __SS__ << "Invalid type requested '" << type << "'" << __E__; 01404 __COUT_ERR__ << ss.str(); 01405 __SS_THROW__; 01406 } 01407 01408 //============================================================================== 01409 TableGroupKey ConfigurationManager::getActiveGroupKey(const std::string& type) const 01410 { 01411 if(type == "" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION) 01412 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_ 01413 : TableGroupKey(); 01414 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT) 01415 return theContextTableGroupKey_ ? *theContextTableGroupKey_ : TableGroupKey(); 01416 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE) 01417 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ : TableGroupKey(); 01418 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE) 01419 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ : TableGroupKey(); 01420 01421 __SS__ << "Invalid type requested '" << type << "'" << __E__; 01422 __COUT_ERR__ << ss.str(); 01423 __SS_THROW__; 01424 } 01425 01426 //============================================================================== 01427 ConfigurationTree ConfigurationManager::getContextNode( 01428 const std::string& contextUID, const std::string& applicationUID) const 01429 { 01430 return getNode("/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() + "/" + 01431 contextUID); 01432 } 01433 01434 //============================================================================== 01435 ConfigurationTree ConfigurationManager::getSupervisorNode( 01436 const std::string& contextUID, const std::string& applicationUID) const 01437 { 01438 return getNode("/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() + "/" + 01439 contextUID + "/LinkToApplicationTable/" + applicationUID); 01440 } 01441 01442 //============================================================================== 01443 ConfigurationTree ConfigurationManager::getSupervisorTableNode( 01444 const std::string& contextUID, const std::string& applicationUID) const 01445 { 01446 return getNode("/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() + "/" + 01447 contextUID + "/LinkToApplicationTable/" + applicationUID + 01448 "/LinkToSupervisorTable"); 01449 } 01450 01451 //============================================================================== 01452 ConfigurationTree ConfigurationManager::getNode(const std::string& nodeString, 01453 bool doNotThrowOnBrokenUIDLinks) const 01454 { 01455 //__COUT__ << "nodeString=" << nodeString << " " << nodeString.length() << __E__; 01456 01457 // get nodeName (in case of / syntax) 01458 if(nodeString.length() < 1) 01459 { 01460 __SS__ << ("Invalid empty node name") << __E__; 01461 __COUT_ERR__ << ss.str(); 01462 __SS_THROW__; 01463 } 01464 01465 // ignore multiple starting slashes 01466 unsigned int startingIndex = 0; 01467 while(startingIndex < nodeString.length() && nodeString[startingIndex] == '/') 01468 ++startingIndex; 01469 01470 std::string nodeName = nodeString.substr( 01471 startingIndex, nodeString.find('/', startingIndex) - startingIndex); 01472 //__COUT__ << "nodeName=" << nodeName << " " << nodeName.length() << __E__; 01473 if(nodeName.length() < 1) 01474 { 01475 // return root node 01476 return ConfigurationTree(this, 0); 01477 01478 // __SS__ << "Invalid node name: " << nodeName << __E__; 01479 // __COUT_ERR__ << ss.str(); 01480 // __SS_THROW__; 01481 } 01482 01483 std::string childPath = nodeString.substr(nodeName.length() + startingIndex); 01484 01485 //__COUT__ << "childPath=" << childPath << " " << childPath.length() << __E__; 01486 01487 ConfigurationTree configTree(this, getTableByName(nodeName)); 01488 01489 if(childPath.length() > 1) 01490 return configTree.getNode(childPath, doNotThrowOnBrokenUIDLinks); 01491 else 01492 return configTree; 01493 } 01494 01495 //============================================================================== 01496 // getFirstPathToNode 01497 std::string ConfigurationManager::getFirstPathToNode(const ConfigurationTree& node, 01498 const std::string& startPath) const 01499 // void ConfigurationManager::getFirstPathToNode(const ConfigurationTree &node, const 01500 // ConfigurationTree &startNode) const 01501 { 01502 std::string path = "/"; 01503 return path; 01504 } 01505 01506 //============================================================================== 01507 // getChildren 01508 // if memberMap is passed then only consider children in the map 01509 // 01510 // if accumulatedTreeErrors is non null, check for disconnects occurs. 01511 // check is 2 levels deep which should get to the links starting at tables. 01512 std::vector<std::pair<std::string, ConfigurationTree>> ConfigurationManager::getChildren( 01513 std::map<std::string, TableVersion>* memberMap, 01514 std::string* accumulatedTreeErrors) const 01515 { 01516 std::vector<std::pair<std::string, ConfigurationTree>> retMap; 01517 if(accumulatedTreeErrors) 01518 *accumulatedTreeErrors = ""; 01519 01520 if(!memberMap || memberMap->empty()) // return all present active members 01521 { 01522 for(auto& configPair : nameToTableMap_) 01523 { 01524 //__COUT__ << configPair.first << " " << (int)(configPair.second?1:0) << 01525 // __E__; 01526 01527 if(configPair.second->isActive()) // only consider if active 01528 { 01529 ConfigurationTree newNode(this, configPair.second); 01530 01531 if(accumulatedTreeErrors) // check for disconnects 01532 { 01533 try 01534 { 01535 std::vector<std::pair<std::string, ConfigurationTree>> 01536 newNodeChildren = newNode.getChildren(); 01537 for(auto& newNodeChild : newNodeChildren) 01538 { 01539 std::vector<std::pair<std::string, ConfigurationTree>> 01540 twoDeepChildren = newNodeChild.second.getChildren(); 01541 01542 for(auto& twoDeepChild : twoDeepChildren) 01543 { 01544 //__COUT__ << configPair.first << " " << 01545 // newNodeChild.first << " " << twoDeepChild.first 01546 // << __E__; 01547 if(twoDeepChild.second.isLinkNode() && 01548 twoDeepChild.second.isDisconnected() && 01549 twoDeepChild.second.getDisconnectedTableName() != 01550 TableViewColumnInfo::DATATYPE_LINK_DEFAULT) 01551 *accumulatedTreeErrors += 01552 "\n\nAt node '" + configPair.first + 01553 "' with entry UID '" + newNodeChild.first + 01554 "' there is a disconnected child node at link " 01555 "column '" + 01556 twoDeepChild.first + "'" + 01557 " that points to table named '" + 01558 twoDeepChild.second.getDisconnectedTableName() + 01559 "' ..."; 01560 } 01561 } 01562 } 01563 catch(std::runtime_error& e) 01564 { 01565 *accumulatedTreeErrors += 01566 "\n\nAt node '" + configPair.first + 01567 "' error detected descending through children:\n" + e.what(); 01568 } 01569 } 01570 01571 retMap.push_back( 01572 std::pair<std::string, ConfigurationTree>(configPair.first, newNode)); 01573 } 01574 01575 //__COUT__ << configPair.first << __E__; 01576 } 01577 } 01578 else // return only members from the member map (they must be present and active!) 01579 { 01580 for(auto& memberPair : *memberMap) 01581 { 01582 auto mapIt = nameToTableMap_.find(memberPair.first); 01583 if(mapIt == nameToTableMap_.end()) 01584 { 01585 __SS__ << "Get Children with member map requires a child '" 01586 << memberPair.first << "' that is not present!" << __E__; 01587 __SS_THROW__; 01588 } 01589 if(!(*mapIt).second->isActive()) 01590 { 01591 __SS__ << "Get Children with member map requires a child '" 01592 << memberPair.first << "' that is not active!" << __E__; 01593 __SS_THROW__; 01594 } 01595 01596 ConfigurationTree newNode(this, (*mapIt).second); 01597 01598 if(accumulatedTreeErrors) // check for disconnects 01599 { 01600 try 01601 { 01602 std::vector<std::pair<std::string, ConfigurationTree>> 01603 newNodeChildren = newNode.getChildren(); 01604 for(auto& newNodeChild : newNodeChildren) 01605 { 01606 std::vector<std::pair<std::string, ConfigurationTree>> 01607 twoDeepChildren = newNodeChild.second.getChildren(); 01608 01609 for(auto& twoDeepChild : twoDeepChildren) 01610 { 01611 //__COUT__ << memberPair.first << " " << newNodeChild.first << 01612 //" " << twoDeepChild.first << __E__; 01613 if(twoDeepChild.second.isLinkNode() && 01614 twoDeepChild.second.isDisconnected() && 01615 twoDeepChild.second.getDisconnectedTableName() != 01616 TableViewColumnInfo::DATATYPE_LINK_DEFAULT) 01617 { 01618 *accumulatedTreeErrors += 01619 "\n\nAt node '" + memberPair.first + 01620 "' with entry UID '" + newNodeChild.first + 01621 "' there is a disconnected child node at link column " 01622 "'" + 01623 twoDeepChild.first + "'" + 01624 " that points to table named '" + 01625 twoDeepChild.second.getDisconnectedTableName() + 01626 "' ..."; 01627 01628 // check if disconnected table is in group, if not 01629 // software error 01630 01631 bool found = false; 01632 for(auto& searchMemberPair : *memberMap) 01633 if(searchMemberPair.first == 01634 twoDeepChild.second.getDisconnectedTableName()) 01635 { 01636 found = true; 01637 break; 01638 } 01639 if(!found) 01640 *accumulatedTreeErrors += 01641 std::string( 01642 "\nNote: It may be safe to ignore this " 01643 "error ") + 01644 "since the link's target table " + 01645 twoDeepChild.second.getDisconnectedTableName() + 01646 " is not a member of this group (and may not be " 01647 "loaded yet)."; 01648 } 01649 } 01650 } 01651 } 01652 catch(std::runtime_error& e) 01653 { 01654 *accumulatedTreeErrors += 01655 "\n\nAt node '" + memberPair.first + 01656 "' error detected descending through children:\n" + e.what(); 01657 } 01658 } 01659 01660 retMap.push_back( 01661 std::pair<std::string, ConfigurationTree>(memberPair.first, newNode)); 01662 } 01663 } 01664 01665 return retMap; 01666 } 01667 01668 //============================================================================== 01669 // getTableByName 01670 // Get read-only pointer to configuration. 01671 // If Read/Write access is needed use ConfigurationManagerWithWriteAccess 01672 // (For general use, Write access should be avoided) 01673 const TableBase* ConfigurationManager::getTableByName(const std::string& tableName) const 01674 { 01675 std::map<std::string, TableBase*>::const_iterator it; 01676 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end()) 01677 { 01678 __SS__ << "\n\nCan not find configuration named '" << tableName 01679 << "'\n\n\n\nYou need to load the configuration before it can be used." 01680 << " It probably is missing from the member list of the Table " 01681 "Group that was loaded.\n" 01682 << "\nYou may need to enter wiz mode to remedy the situation, use the " 01683 "following:\n" 01684 << "\n\t StartOTS.sh --wiz" 01685 << "\n\n\n\n" 01686 << __E__; 01687 01688 // prints out too often, so only throw 01689 // if(tableName != TableViewColumnInfo::DATATYPE_LINK_DEFAULT) 01690 // __COUT_WARN__ << "\n" << ss.str(); 01691 __SS_ONLY_THROW__; 01692 } 01693 return it->second; 01694 } 01695 01696 //============================================================================== 01697 // loadConfigurationBackbone 01698 // loads the active backbone configuration group 01699 // returns the active group key that was loaded 01700 TableGroupKey ConfigurationManager::loadConfigurationBackbone() 01701 { 01702 if(!theBackboneTableGroupKey_) // no active backbone 01703 { 01704 __COUT_WARN__ << "getTableGroupKey() Failed! No active backbone currently." 01705 << __E__; 01706 return TableGroupKey(); 01707 } 01708 01709 // may already be loaded, but that's ok, load anyway to be sure 01710 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_); 01711 01712 return *theBackboneTableGroupKey_; 01713 } 01714 01715 // Getters 01716 //============================================================================== 01717 // getTableGroupKey 01718 // use backbone to determine default key for systemAlias. 01719 // - runType translates to group key alias, 01720 // which maps to a group name and key pair 01721 // 01722 // NOTE: temporary special aliases are also allowed 01723 // with the following format: 01724 // GROUP:<name>:<key> 01725 // 01726 // return INVALID on failure 01727 // else, pair<group name , TableGroupKey> 01728 std::pair<std::string, TableGroupKey> ConfigurationManager::getTableGroupFromAlias( 01729 std::string systemAlias, ProgressBar* progressBar) 01730 { 01731 // steps 01732 // check if special alias 01733 // if so, parse and return name/key 01734 // else, load active backbone 01735 // find runType in Group Aliases table 01736 // return key 01737 01738 if(progressBar) 01739 progressBar->step(); 01740 01741 if(systemAlias.find("GROUP:") == 0) 01742 { 01743 if(progressBar) 01744 progressBar->step(); 01745 01746 unsigned int i = strlen("GROUP:"); 01747 unsigned int j = systemAlias.find(':', i); 01748 01749 if(progressBar) 01750 progressBar->step(); 01751 if(j > i) // success 01752 return std::pair<std::string, TableGroupKey>( 01753 systemAlias.substr(i, j - i), TableGroupKey(systemAlias.substr(j + 1))); 01754 else // failure 01755 return std::pair<std::string, TableGroupKey>("", TableGroupKey()); 01756 } 01757 01758 loadConfigurationBackbone(); 01759 01760 if(progressBar) 01761 progressBar->step(); 01762 01763 try 01764 { 01765 // find runType in Group Aliases table 01766 ConfigurationTree entry = 01767 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getNode(systemAlias); 01768 01769 if(progressBar) 01770 progressBar->step(); 01771 01772 return std::pair<std::string, TableGroupKey>( 01773 entry.getNode("GroupName").getValueAsString(), 01774 TableGroupKey(entry.getNode("GroupKey").getValueAsString())); 01775 } 01776 catch(...) 01777 { 01778 } 01779 01780 // on failure, here 01781 01782 if(progressBar) 01783 progressBar->step(); 01784 01785 return std::pair<std::string, TableGroupKey>("", TableGroupKey()); 01786 } 01787 01788 //============================================================================== 01789 std::map<std::string /*groupAlias*/, std::pair<std::string /*groupName*/, TableGroupKey>> 01790 ConfigurationManager::getActiveGroupAliases(void) 01791 { 01792 restoreActiveTableGroups(); // make sure the active configuration backbone is 01793 // loaded! 01794 // loadConfigurationBackbone(); 01795 01796 std::map<std::string /*groupAlias*/, 01797 std::pair<std::string /*groupName*/, TableGroupKey>> 01798 retMap; 01799 01800 std::vector<std::pair<std::string, ConfigurationTree>> entries = 01801 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getChildren(); 01802 for(auto& entryPair : entries) 01803 { 01804 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>( 01805 entryPair.second.getNode("GroupName").getValueAsString(), 01806 TableGroupKey(entryPair.second.getNode("GroupKey").getValueAsString())); 01807 } 01808 return retMap; 01809 } 01810 01811 //============================================================================== 01812 // getVersionAliases() 01813 // get version aliases organized by table, for currently active backbone tables 01814 std::map<std::string /*table name*/, 01815 std::map<std::string /*version alias*/, TableVersion /*aliased version*/>> 01816 ConfigurationManager::getVersionAliases(void) const 01817 { 01818 //__COUT__ << "getVersionAliases()" << __E__; 01819 01820 std::map<std::string /*table name*/, 01821 std::map<std::string /*version alias*/, TableVersion /*aliased version*/>> 01822 retMap; 01823 01824 std::map<std::string, TableVersion> activeVersions = getActiveVersions(); 01825 std::string versionAliasesTableName = 01826 ConfigurationManager::VERSION_ALIASES_TABLE_NAME; 01827 if(activeVersions.find(versionAliasesTableName) == activeVersions.end()) 01828 { 01829 __SS__ << "Active version of VersionAliases missing!" 01830 << "Make sure you have a valid active Backbone Group." << __E__; 01831 __COUT_WARN__ << "\n" << ss.str(); 01832 return retMap; 01833 } 01834 01835 __COUT__ << "activeVersions[\"" << versionAliasesTableName 01836 << "\"]=" << activeVersions[versionAliasesTableName] << __E__; 01837 01838 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs = 01839 getNode(versionAliasesTableName).getChildren(); 01840 01841 // create map 01842 // add the first of each tableName, versionAlias pair encountered 01843 // ignore any repeats (Note: this also prevents overwriting of Scratch alias) 01844 std::string tableName, versionAlias; 01845 for(auto& aliasNodePair : aliasNodePairs) 01846 { 01847 tableName = aliasNodePair.second.getNode("TableName").getValueAsString(); 01848 versionAlias = aliasNodePair.second.getNode("VersionAlias").getValueAsString(); 01849 01850 if(retMap.find(tableName) != retMap.end() && 01851 retMap[tableName].find(versionAlias) != retMap[tableName].end()) 01852 continue; // skip repeats (Note: this also prevents overwriting of Scratch 01853 // alias) 01854 01855 // else add version to map 01856 retMap[tableName][versionAlias] = 01857 TableVersion(aliasNodePair.second.getNode("Version").getValueAsString()); 01858 } 01859 01860 return retMap; 01861 } // end getVersionAliases() 01862 01863 //============================================================================== 01864 // getActiveVersions 01865 std::map<std::string, TableVersion> ConfigurationManager::getActiveVersions(void) const 01866 { 01867 std::map<std::string, TableVersion> retMap; 01868 for(auto& config : nameToTableMap_) 01869 { 01870 //__COUT__ << config.first << __E__; 01871 01872 // check configuration pointer is not null and that there is an active view 01873 if(config.second && config.second->isActive()) 01874 { 01875 //__COUT__ << config.first << "_v" << config.second->getViewVersion() << 01876 // __E__; 01877 retMap.insert(std::pair<std::string, TableVersion>( 01878 config.first, config.second->getViewVersion())); 01879 } 01880 } 01881 return retMap; 01882 } 01883 01885 // const DACStream& ConfigurationManager::getDACStream(std::string fecName) 01886 //{ 01887 // 01888 // //fixme/todo this is called before setupAll so it breaks! 01889 // //==================================================== 01890 // const DetectorConfiguration* detectorConfiguration = 01891 //__GET_CONFIG__(DetectorConfiguration); for(auto& type : 01892 // detectorConfiguration->getDetectorTypes()) theDACsConfigurations_[type] = 01893 //(DACsTableBase*)(getTableByName(type + "DACsConfiguration")); 01894 // //==================================================== 01895 // 01896 // theDACStreams_[fecName].makeStream(fecName, 01897 // __GET_CONFIG__(DetectorConfiguration), 01898 // __GET_CONFIG__(DetectorToFEConfiguration), 01899 // theDACsConfigurations_, 01900 // __GET_CONFIG__(MaskConfiguration));//, theTrimConfiguration_); 01901 // 01902 // __COUT__ << "Done with DAC stream!" << __E__; 01903 // return theDACStreams_[fecName]; 01904 //} 01905 01906 //============================================================================== 01907 std::shared_ptr<TableGroupKey> ConfigurationManager::makeTheTableGroupKey( 01908 TableGroupKey key) 01909 { 01910 if(theConfigurationTableGroupKey_) 01911 { 01912 if(*theConfigurationTableGroupKey_ != key) 01913 destroyTableGroup(); 01914 else 01915 return theConfigurationTableGroupKey_; 01916 } 01917 return std::shared_ptr<TableGroupKey>(new TableGroupKey(key)); 01918 } 01919 01920 //============================================================================== 01921 std::string ConfigurationManager::encodeURIComponent(const std::string& sourceStr) 01922 { 01923 std::string retStr = ""; 01924 char encodeStr[4]; 01925 for(const auto& c : sourceStr) 01926 if((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) 01927 retStr += c; 01928 else 01929 { 01930 sprintf(encodeStr, "%%%2.2X", c); 01931 retStr += encodeStr; 01932 } 01933 return retStr; 01934 } 01935 01936 //============================================================================== 01937 const std::set<std::string>& ConfigurationManager::getContextMemberNames() 01938 { 01939 return ConfigurationManager::contextMemberNames_; 01940 } 01941 //============================================================================== 01942 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames() 01943 { 01944 return ConfigurationManager::backboneMemberNames_; 01945 } 01946 //============================================================================== 01947 const std::set<std::string>& ConfigurationManager::getIterateMemberNames() 01948 { 01949 return ConfigurationManager::iterateMemberNames_; 01950 }