1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
3 #include "otsdaq-core/ConfigurationDataFormats/ConfigurationGroupKey.h"
4 #include "otsdaq-core/ProgressBar/ProgressBar.h"
13 #define __MF_SUBJECT__ "ConfigurationManager"
15 const std::string ConfigurationManager::READONLY_USER =
"READONLY_USER";
17 const std::string ConfigurationManager::XDAQ_CONTEXT_CONFIG_NAME =
"XDAQContextConfiguration";
20 const std::string ConfigurationManager::ACTIVE_GROUP_FILENAME = ((getenv(
"SERVICE_DATA_PATH") == NULL)?(std::string(getenv(
"USER_DATA"))+
"/ServiceData"):(std::string(getenv(
"SERVICE_DATA_PATH")))) +
"/ActiveConfigurationGroups.cfg";
21 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
22 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
24 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT =
"Context";
25 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE =
"Backbone";
26 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE =
"Iterate";
27 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION =
"Configuration";
29 const std::set<std::string> ConfigurationManager::contextMemberNames_ = {ConfigurationManager::XDAQ_CONTEXT_CONFIG_NAME,
"XDAQApplicationConfiguration",
"XDAQApplicationPropertyConfiguration",
"DesktopIconConfiguration",
"MessageFacilityConfiguration",
"TheSupervisorConfiguration",
"StateMachineConfiguration",
"DesktopWindowParameterConfiguration"};
30 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = {
"GroupAliasesConfiguration",
"VersionAliasesConfiguration"};
31 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = {
"IterateConfiguration",
"IterationPlanConfiguration",
"IterationTargetConfiguration",
32 "IterationCommandBeginLabelConfiguration",
"IterationCommandChooseFSMConfiguration",
"IterationCommandConfigureAliasConfiguration",
"IterationCommandConfigureGroupConfiguration",
"IterationCommandExecuteFEMacroConfiguration",
"IterationCommandExecuteMacroConfiguration",
"IterationCommandModifyGroupConfiguration",
"IterationCommandRepeatLabelConfiguration",
"IterationCommandRunConfiguration"};
35 ConfigurationManager::ConfigurationManager()
38 , theConfigurationGroupKey_ (0)
39 , theContextGroupKey_ (0)
40 , theBackboneGroupKey_ (0)
41 , theConfigurationGroup_ (
"")
42 , theContextGroup_ (
"")
43 , theBackboneGroup_ (
"")
45 theInterface_ = ConfigurationInterface::getInstance(
false);
59 groupMetadataTable_.setConfigurationName(ConfigurationInterface::GROUP_METADATA_TABLE_NAME);
61 std::vector<ViewColumnInfo>* colInfo =
62 groupMetadataTable_.getMockupViewP()->getColumnsInfoP();
66 ViewColumnInfo::TYPE_UID,
69 ViewColumnInfo::DATATYPE_NUMBER,
73 ViewColumnInfo::TYPE_COMMENT,
75 "COMMENT_DESCRIPTION",
76 ViewColumnInfo::DATATYPE_STRING,
80 ViewColumnInfo::TYPE_AUTHOR,
83 ViewColumnInfo::DATATYPE_STRING,
87 ViewColumnInfo::TYPE_TIMESTAMP,
89 "GROUP_CREATION_TIME",
90 ViewColumnInfo::DATATYPE_TIME,
93 auto tmpVersion = groupMetadataTable_.createTemporaryView();
94 groupMetadataTable_.setActiveView(tmpVersion);
96 groupMetadataTable_.getViewP()->addRow();
104 ConfigurationManager::ConfigurationManager(
const std::string& username)
107 username_ = username;
111 ConfigurationManager::~ConfigurationManager()
120 void ConfigurationManager::init(std::string *accumulatedErrors)
122 if(accumulatedErrors) *accumulatedErrors =
"";
127 if(theInterface_->getMode() ==
false)
131 restoreActiveConfigurationGroups(accumulatedErrors?
true:
false);
133 catch(std::runtime_error &e)
135 if(accumulatedErrors) *accumulatedErrors = e.what();
146 void ConfigurationManager::restoreActiveConfigurationGroups(
bool throwErrors)
148 destroyConfigurationGroup(
"",
true);
150 std::string fn = ACTIVE_GROUP_FILENAME;
151 FILE *fp = fopen(fn.c_str(),
"r");
153 __COUT__ <<
"ACTIVE_GROUP_FILENAME = " << ACTIVE_GROUP_FILENAME << std::endl;
154 __COUT__ <<
"ARTDAQ_DATABASE_URI = " << std::string(getenv(
"ARTDAQ_DATABASE_URI")) << std::endl;
163 std::string groupName;
164 std::string errorStr =
"";
169 while(fgets(tmp,500,fp))
174 sscanf(tmp,
"%s",strVal);
175 for(
unsigned int j=0;j<strlen(strVal);++j)
177 (strVal[j] >=
'a' && strVal[j] <=
'z') ||
178 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
179 (strVal[j] >=
'0' && strVal[j] <=
'9')))
182 __COUT_INFO__ <<
"Illegal character found, so skipping!" << std::endl;
192 sscanf(tmp,
"%s",strVal);
194 for(
unsigned int j=0;j<strlen(strVal);++j)
196 (strVal[j] >=
'0' && strVal[j] <=
'9')))
199 __COUT_INFO__ <<
"Illegal character found, so skipping!" << std::endl;
211 __COUT__ <<
"illegal group accorging to ConfigurationGroupKey::getFullGroupString..." << std::endl;
222 catch(std::runtime_error &e)
224 ss <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
225 groupName <<
"_v" << strVal <<
"'" << std::endl;
226 ss << e.what() << std::endl;
228 errorStr += ss.str();
232 ss <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
233 groupName <<
"_v" << strVal <<
"'" << std::endl;
235 errorStr += ss.str();
241 if(throwErrors && errorStr !=
"")
243 __COUT_INFO__ <<
"\n" << ss.str();
244 throw std::runtime_error(errorStr);
253 void ConfigurationManager::destroyConfigurationGroup(
const std::string& theGroup,
bool onlyDeactivate)
256 bool isContext = theGroup ==
"" || theGroup == theContextGroup_;
257 bool isBackbone = theGroup ==
"" || theGroup == theBackboneGroup_;
258 bool isIterate = theGroup ==
"" || theGroup == theIterateGroup_;
259 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationGroup_;
261 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
263 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << std::endl;
264 __COUT_ERR__ << ss.str();
265 throw std::runtime_error(ss.str());
268 std::string dbgHeader = onlyDeactivate?
"Deactivating":
"Destroying";
272 __COUT__ << dbgHeader <<
" Context group: " << theGroup << std::endl;
274 __COUT__ << dbgHeader <<
" Backbone group: " << theGroup << std::endl;
276 __COUT__ << dbgHeader <<
" Iterate group: " << theGroup << std::endl;
278 __COUT__ << dbgHeader <<
" Configuration group: " << theGroup << std::endl;
281 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
282 for(
auto it = nameToConfigurationMap_.begin(); it != nameToConfigurationMap_.end(); )
284 contextFindIt = contextMemberNames_.find(it->first);
285 backboneFindIt = backboneMemberNames_.find(it->first);
286 iterateFindIt = iterateMemberNames_.find(it->first);
287 if(theGroup ==
"" || (
288 (isContext && contextFindIt != contextMemberNames_.end()) ||
289 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
290 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
291 (!isContext && !isBackbone &&
292 contextFindIt == contextMemberNames_.end() &&
293 backboneFindIt == backboneMemberNames_.end()&&
294 iterateFindIt == iterateMemberNames_.end())))
303 it->second->deactivate();
309 nameToConfigurationMap_.erase(it++);
318 theConfigurationGroup_ =
"";
319 if(theConfigurationGroupKey_ != 0)
321 __COUT__ <<
"Destroying Configuration Key: " << *theConfigurationGroupKey_ << std::endl;
322 theConfigurationGroupKey_.reset();
329 theBackboneGroup_ =
"";
330 if(theBackboneGroupKey_ != 0)
332 __COUT__ <<
"Destroying Backbone Key: " << *theBackboneGroupKey_ << std::endl;
333 theBackboneGroupKey_.reset();
338 theIterateGroup_ =
"";
339 if(theIterateGroupKey_ != 0)
341 __COUT__ <<
"Destroying Iterate Key: " << *theIterateGroupKey_ << std::endl;
342 theIterateGroupKey_.reset();
347 theContextGroup_ =
"";
348 if(theContextGroupKey_ != 0)
350 __COUT__ <<
"Destroying Context Key: " << *theContextGroupKey_ << std::endl;
351 theContextGroupKey_.reset();
357 void ConfigurationManager::destroy(
void)
362 destroyConfigurationGroup();
372 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
374 return groupTypeId==CONTEXT_TYPE?
375 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT:
376 (groupTypeId==BACKBONE_TYPE?
377 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE:
378 (groupTypeId==ITERATE_TYPE?
379 ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE:
380 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
390 int ConfigurationManager::getTypeOfGroup(
391 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
394 bool isContext =
true;
395 bool isBackbone =
true;
396 bool isIterate =
true;
398 bool inContext =
false;
399 bool inBackbone =
false;
400 bool inIterate =
false;
401 unsigned int matchCount = 0;
403 for(
auto &memberPair:memberMap)
408 for(
auto &contextMemberString:contextMemberNames_)
409 if(memberPair.first == contextMemberString)
421 __SS__ <<
"This group is an incomplete match to a Context group.\n";
422 __COUT_ERR__ <<
"\n" << ss.str();
423 ss <<
"\nTo be a Context group, the members must exactly match" <<
424 "the following members:\n";
426 for(
auto &memberName:contextMemberNames_)
427 ss << ++i <<
". " << memberName <<
"\n";
428 throw std::runtime_error(ss.str());
434 for(
auto &backboneMemberString:backboneMemberNames_)
435 if(memberPair.first == backboneMemberString)
447 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
448 __COUT_ERR__ <<
"\n" << ss.str();
449 ss <<
"\nTo be a Backbone group, the members must exactly match" <<
450 "the following members:\n";
452 for(
auto &memberName:backboneMemberNames_)
453 ss << ++i <<
". " << memberName <<
"\n";
455 throw std::runtime_error(ss.str());
461 for(
auto &iterateMemberString:iterateMemberNames_)
462 if(memberPair.first == iterateMemberString)
474 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
475 __COUT_ERR__ <<
"\n" << ss.str();
476 ss <<
"\nTo be a Iterate group, the members must exactly match" <<
477 "the following members:\n";
479 for(
auto &memberName:iterateMemberNames_)
480 ss << ++i <<
". " << memberName <<
"\n";
482 throw std::runtime_error(ss.str());
487 if(isContext && matchCount != contextMemberNames_.size())
489 __SS__ <<
"This group is an incomplete match to a Context group: " <<
490 " Size=" << matchCount <<
" but should be " << contextMemberNames_.size() <<
492 __COUT_ERR__ <<
"\n" << ss.str();
493 ss <<
"\nThe members currently are...\n";
495 for(
auto &memberPair:memberMap)
496 ss << ++i <<
". " << memberPair.first <<
"\n";
497 ss <<
"\nThe expected Context members are...\n";
499 for(
auto &memberName:contextMemberNames_)
500 ss << ++i <<
". " << memberName <<
"\n";
502 throw std::runtime_error(ss.str());
505 if(isBackbone && matchCount != backboneMemberNames_.size())
507 __SS__ <<
"This group is an incomplete match to a Backbone group: " <<
508 " Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() <<
510 __COUT_ERR__ <<
"\n" << ss.str();
511 ss <<
"\nThe members currently are...\n";
513 for(
auto &memberPair:memberMap)
514 ss << ++i <<
". " << memberPair.first <<
"\n";
515 ss <<
"\nThe expected Backbone members are...\n";
517 for(
auto &memberName:backboneMemberNames_)
518 ss << ++i <<
". " << memberName <<
"\n";
520 throw std::runtime_error(ss.str());
523 if(isIterate && matchCount != iterateMemberNames_.size())
525 __SS__ <<
"This group is an incomplete match to a Iterate group: " <<
526 " Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() <<
528 __COUT_ERR__ <<
"\n" << ss.str();
529 ss <<
"\nThe members currently are...\n";
531 for(
auto &memberPair:memberMap)
532 ss << ++i <<
". " << memberPair.first <<
"\n";
533 ss <<
"\nThe expected Iterate members are...\n";
535 for(
auto &memberName:iterateMemberNames_)
536 ss << ++i <<
". " << memberName <<
"\n";
538 throw std::runtime_error(ss.str());
541 return isContext?CONTEXT_TYPE:(isBackbone?BACKBONE_TYPE:(isIterate?ITERATE_TYPE:CONFIGURATION_TYPE));
547 const std::string& ConfigurationManager::getTypeNameOfGroup(
548 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
550 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
559 void ConfigurationManager::dumpActiveConfiguration(
560 const std::string &filePath,
const std::string &dumpType)
const
562 time_t rawtime = time(0);
563 __COUT__ <<
"filePath = " << filePath << std::endl;
564 __COUT__ <<
"dumpType = " << dumpType << std::endl;
568 fs.open(filePath, std::fstream::out | std::fstream::trunc);
579 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath <<
" could not be opened!" << __E__;
580 __COUT_ERR__ << ss.str();
581 throw std::runtime_error(ss.str());
587 (*out) <<
"#################################" << std::endl;
588 (*out) <<
"This is an ots configuration dump.\n\n" << std::endl;
589 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t" << getenv(
"ARTDAQ_DATABASE_URI") << std::endl;
590 (*out) <<
"\nOriginal location of dump: \t" << filePath << std::endl;
591 (*out) <<
"Type of dump: \t" << dumpType << std::endl;
592 (*out) <<
"Linux time for dump: \t" << rawtime << std::endl;
595 struct tm * timeinfo = localtime (&rawtime);
597 strftime(buffer,100,
"%c %Z",timeinfo);
598 (*out) <<
"Display time for dump: \t" << buffer << std::endl;
609 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
610 cfgMgr->getActiveConfigurationGroups();
612 (*out) <<
"\n\n************************" << std::endl;
613 (*out) <<
"Active Groups:" << std::endl;
614 for(
auto &group:activeGroups)
616 (*out) <<
"\t" << group.first <<
" := " <<
617 group.second.first <<
" (" <<
618 group.second.second <<
")" << std::endl;
623 std::map<std::string, ConfigurationVersion> activeTables =
624 cfgMgr->getActiveVersions();
626 (*out) <<
"\n\n************************" << std::endl;
627 (*out) <<
"Active Tables:" << std::endl;
628 (*out) <<
"Active Tables count = " << activeTables.size() << std::endl;
631 for(
auto &table:activeTables)
633 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" <<
634 table.second << std::endl;
639 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
640 cfgMgr->getActiveConfigurationGroups();
641 (*out) <<
"\n\n************************" << std::endl;
642 (*out) <<
"Active Group Members:" << std::endl;
644 for(
auto &group:activeGroups)
646 (*out) <<
"\t" << group.first <<
" := " <<
647 group.second.first <<
" (" <<
648 group.second.second <<
")" << std::endl;
650 if(group.second.first ==
"")
652 (*out) <<
"\t" <<
"Empty group name. Assuming no active group." << __E__;
657 cfgMgr->theInterface_->getConfigurationGroupMembers(
658 ConfigurationGroupKey::getFullGroupString(
660 group.second.second));
662 (*out) <<
"\tMember table count = " << memberMap.size() << std::endl;
663 tableCount += memberMap.size();
666 for(
auto &member:memberMap)
668 (*out) <<
"\t\t" << ++i <<
". " << member.first <<
"-v" <<
669 member.second << std::endl;
672 (*out) <<
"\nActive Group Members total table count = " << tableCount << std::endl;
676 std::map<std::string, ConfigurationVersion> activeTables =
677 cfgMgr->getActiveVersions();
679 (*out) <<
"\n\n************************" << std::endl;
680 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
681 <<
"):" << std::endl;
683 for(
auto &table:activeTables)
685 (*out) <<
"\n\n==============================================================================" << std::endl;
686 (*out) <<
"==============================================================================" << std::endl;
687 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" <<
688 table.second << std::endl;
690 cfgMgr->nameToConfigurationMap_.find(table.first)->second->print(*out);
696 if(dumpType ==
"GroupKeys")
698 localDumpActiveGroups(
this,out);
700 else if(dumpType ==
"TableVersions")
702 localDumpActiveTables(
this,out);
704 else if(dumpType ==
"GroupKeysAndTableVersions")
706 localDumpActiveGroups(
this,out);
707 localDumpActiveTables(
this,out);
709 else if(dumpType ==
"All")
711 localDumpActiveGroups(
this,out);
712 localDumpActiveGroupMembers(
this,out);
713 localDumpActiveTables(
this,out);
714 localDumpActiveTableContents(
this,out);
718 __SS__ <<
"Invalid dump type '" << dumpType <<
719 "' given during dumpActiveConfiguration(). Valid types are as follows:\n" <<
722 "GroupKeys" <<
", " <<
723 "TableVersions" <<
", " <<
724 "GroupsKeysAndTableVersions" <<
", " <<
727 "\n\nPlease change the State Machine configuration to a valid dump type." <<
729 throw std::runtime_error(ss.str());
740 void ConfigurationManager::loadMemberMap(
741 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
746 for(
auto &memberPair:memberMap)
756 tmpConfigBasePtr = 0;
757 if(nameToConfigurationMap_.find(memberPair.first) != nameToConfigurationMap_.end())
758 tmpConfigBasePtr = nameToConfigurationMap_[memberPair.first];
760 theInterface_->get(tmpConfigBasePtr,
769 nameToConfigurationMap_[memberPair.first] = tmpConfigBasePtr;
770 if(nameToConfigurationMap_[memberPair.first]->getViewP())
776 __SS__ << nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
777 ": View version not activated properly!";
778 throw std::runtime_error(ss.str());
799 void ConfigurationManager::loadConfigurationGroup(
800 const std::string &configGroupName,
803 std::map<std::string, ConfigurationVersion> *groupMembers,
805 std::string *accumulatedTreeErrors,
806 std::string *groupComment,
807 std::string *groupAuthor,
808 std::string *groupCreateTime,
809 bool doNotLoadMember,
810 std::string *groupTypeString)
813 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
814 if(groupComment) *groupComment =
"NO COMMENT FOUND";
815 if(groupAuthor) *groupAuthor =
"NO AUTHOR FOUND";
816 if(groupCreateTime) *groupCreateTime =
"0";
817 if(groupTypeString) *groupTypeString =
"UNKNOWN";
848 theInterface_->getConfigurationGroupMembers(
849 ConfigurationGroupKey::getFullGroupString(configGroupName,configGroupKey),
853 if(progressBar) progressBar->step();
856 auto metaTablePair = memberMap.find(groupMetadataTable_.getConfigurationName());
862 memberMap.erase(metaTablePair);
864 if(groupMembers) *groupMembers = memberMap;
867 while(groupMetadataTable_.getView().getNumberOfRows())
868 groupMetadataTable_.getViewP()->deleteRow(0);
871 theInterface_->fill(&groupMetadataTable_,metaTablePair->second);
873 catch(
const std::runtime_error& e)
875 __COUT_WARN__ <<
"Ignoring metadata error: " << e.what() << __E__;
879 __COUT_WARN__ <<
"Ignoring unnkown metadata error. " << __E__;
883 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
885 groupMetadataTable_.print();
886 __SS__ <<
"groupMetadataTable_ has wrong number of rows! Must be 1." << std::endl;
887 __COUT_ERR__ <<
"\n" << ss.str();
889 if(groupComment) *groupComment =
"NO COMMENT FOUND";
890 if(groupAuthor) *groupAuthor =
"NO AUTHOR FOUND";
891 if(groupCreateTime) *groupCreateTime =
"0";
896 groupType = getTypeOfGroup(memberMap);
897 *groupTypeString = convertGroupTypeIdToName(groupType);
906 if(groupComment) *groupComment = groupMetadataTable_.getView().getValueAsString(0,1);
907 if(groupAuthor) *groupAuthor = groupMetadataTable_.getView().getValueAsString(0,2);
908 if(groupCreateTime) *groupCreateTime = groupMetadataTable_.getView().getValueAsString(0,3);
910 else if(groupMembers) *groupMembers = memberMap;
912 if(progressBar) progressBar->step();
919 groupType = getTypeOfGroup(memberMap);
920 *groupTypeString = convertGroupTypeIdToName(groupType);
935 if(doNotLoadMember)
return;
939 if(!groupTypeString) groupType = getTypeOfGroup(memberMap);
942 __COUT__ <<
"------------------------------------- init start \t [for all plug-ins in " <<
943 convertGroupTypeIdToName(groupType) <<
" group '" <<
944 configGroupName <<
"(" << configGroupKey <<
")" <<
"']" << std::endl;
948 std::string groupToDeactivate =
949 groupType==CONTEXT_TYPE?theContextGroup_:
950 (groupType==BACKBONE_TYPE?theBackboneGroup_:
951 (groupType==ITERATE_TYPE?
952 theIterateGroup_:theConfigurationGroup_));
955 if(groupToDeactivate !=
"")
958 destroyConfigurationGroup(groupToDeactivate,
true);
977 if(progressBar) progressBar->step();
982 loadMemberMap(memberMap);
984 if(progressBar) progressBar->step();
986 if(accumulatedTreeErrors)
990 getChildren(&memberMap, accumulatedTreeErrors);
991 if(*accumulatedTreeErrors !=
"")
993 __COUT_ERR__ <<
"Errors detected while loading Configuration Group: " << configGroupName <<
994 "(" << configGroupKey <<
"). Aborting." << std::endl;
999 if(progressBar) progressBar->step();
1004 for(
auto &memberPair:memberMap)
1007 if(ConfigurationInterface::isVersionTrackingEnabled() &&
1008 memberPair.second.isScratchVersion())
1010 __SS__ <<
"Error while activating member Table '" <<
1011 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
1012 "-v" << memberPair.second <<
1013 " for Configuration Group '" << configGroupName <<
1014 "(" << configGroupKey <<
")'. When version tracking is enabled, Scratch views" <<
1015 " are not allowed! Please only use unique, persistent versions when version tracking is enabled."
1017 __COUT_ERR__ <<
"\n" << ss.str();
1018 throw std::runtime_error(ss.str());
1026 nameToConfigurationMap_[memberPair.first]->init(
this);
1028 catch(std::runtime_error& e)
1030 __SS__ <<
"Error detected calling " <<
1031 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
1032 ".init()!\n\n " << e.what() << std::endl;
1033 throw std::runtime_error(ss.str());
1037 __SS__ <<
"Error detected calling " <<
1038 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
1039 ".init()!\n\n " << std::endl;
1040 throw std::runtime_error(ss.str());
1045 if(progressBar) progressBar->step();
1053 if(groupType == CONTEXT_TYPE)
1057 theContextGroup_ = configGroupName;
1058 theContextGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1060 else if(groupType == BACKBONE_TYPE)
1064 theBackboneGroup_ = configGroupName;
1065 theBackboneGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1067 else if(groupType == ITERATE_TYPE)
1071 theIterateGroup_ = configGroupName;
1072 theIterateGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1078 theConfigurationGroup_ = configGroupName;
1079 theConfigurationGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1083 if(progressBar) progressBar->step();
1086 __COUT__ <<
"------------------------------------- init complete \t [for all plug-ins in " <<
1087 convertGroupTypeIdToName(groupType) <<
" group '" <<
1088 configGroupName <<
"(" << configGroupKey <<
")" <<
"']" << std::endl;
1100 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getActiveConfigurationGroups(
void)
const
1103 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > retMap;
1105 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1106 std::pair<std::string,ConfigurationGroupKey>(theContextGroup_ ,theContextGroupKey_ ?*theContextGroupKey_ :
ConfigurationGroupKey());
1107 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
1108 std::pair<std::string,ConfigurationGroupKey>(theBackboneGroup_ ,theBackboneGroupKey_ ?*theBackboneGroupKey_ :
ConfigurationGroupKey());
1109 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
1110 std::pair<std::string,ConfigurationGroupKey>(theIterateGroup_ ,theIterateGroupKey_ ?*theIterateGroupKey_ :
ConfigurationGroupKey());
1111 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1112 std::pair<std::string,ConfigurationGroupKey>(theConfigurationGroup_,theConfigurationGroupKey_?*theConfigurationGroupKey_:
ConfigurationGroupKey());
1117 const std::string& ConfigurationManager::getActiveGroupName(
const std::string& type)
const
1119 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1120 return theConfigurationGroup_;
1121 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1122 return theContextGroup_;
1123 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1124 return theBackboneGroup_;
1125 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1126 return theIterateGroup_;
1128 __SS__ <<
"Invalid type requested '" << type <<
"'" << std::endl;
1129 __COUT_ERR__ << ss.str();
1130 throw std::runtime_error(ss.str());
1136 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1138 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1140 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1142 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1145 __SS__ <<
"Invalid type requested '" << type <<
"'" << std::endl;
1146 __COUT_ERR__ << ss.str();
1147 throw std::runtime_error(ss.str());
1152 const std::string &contextUID,
const std::string &applicationUID)
const
1155 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
1161 const std::string &contextUID,
const std::string &applicationUID)
const
1164 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
1166 "/LinkToApplicationConfiguration/" + applicationUID);
1171 const std::string &contextUID,
const std::string &applicationUID)
const
1174 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
1176 "/LinkToApplicationConfiguration/" + applicationUID +
1177 "/LinkToSupervisorConfiguration");
1182 bool doNotThrowOnBrokenUIDLinks)
const
1187 if(nodeString.length() < 1)
1189 __SS__ << (
"Invalid empty node name") << std::endl;
1190 __COUT_ERR__ << ss.str();
1191 throw std::runtime_error(ss.str());
1195 unsigned int startingIndex = 0;
1196 while(startingIndex < nodeString.length() &&
1197 nodeString[startingIndex] ==
'/') ++startingIndex;
1199 std::string nodeName = nodeString.substr(startingIndex, nodeString.find(
'/',startingIndex)-startingIndex);
1201 if(nodeName.length() < 1)
1211 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
1217 if(childPath.length() > 1)
1218 return configTree.getNode(childPath,doNotThrowOnBrokenUIDLinks);
1225 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree &node,
const std::string &startPath)
const
1228 std::string path =
"/";
1238 std::vector<std::pair<std::string,ConfigurationTree> > ConfigurationManager::getChildren(
1239 std::map<std::string, ConfigurationVersion> *memberMap,
1240 std::string *accumulatedTreeErrors)
const
1242 std::vector<std::pair<std::string,ConfigurationTree> > retMap;
1243 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
1245 if(!memberMap || memberMap->empty())
1247 for(
auto &configPair:nameToConfigurationMap_)
1251 if(configPair.second->isActive())
1256 if(accumulatedTreeErrors)
1260 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1261 newNode.getChildren();
1262 for(
auto &newNodeChild: newNodeChildren)
1264 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1265 newNodeChild.second.getChildren();
1267 for(
auto &twoDeepChild: twoDeepChildren)
1271 if(twoDeepChild.second.isLinkNode() &&
1272 twoDeepChild.second.isDisconnected() &&
1273 twoDeepChild.second.getDisconnectedTableName() !=
1274 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1275 *accumulatedTreeErrors +=
"\n\nAt node '" +
1276 configPair.first +
"' with entry UID '" +
1277 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1278 twoDeepChild.first +
"'" +
1279 " that points to table named '" +
1280 twoDeepChild.second.getDisconnectedTableName() +
1285 catch(std::runtime_error &e)
1287 *accumulatedTreeErrors +=
"\n\nAt node '" +
1288 configPair.first +
"' error detected descending through children:\n" +
1293 retMap.push_back(std::pair<std::string,ConfigurationTree>(configPair.first,
1303 for(
auto &memberPair: *memberMap)
1305 auto mapIt = nameToConfigurationMap_.find(memberPair.first);
1306 if(mapIt == nameToConfigurationMap_.end())
1308 __SS__ <<
"Get Children with member map requires a child '" <<
1309 memberPair.first <<
"' that is not present!" << std::endl;
1310 throw std::runtime_error(ss.str());
1312 if(!(*mapIt).second->isActive())
1314 __SS__ <<
"Get Children with member map requires a child '" <<
1315 memberPair.first <<
"' that is not active!" << std::endl;
1316 throw std::runtime_error(ss.str());
1321 if(accumulatedTreeErrors)
1325 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1326 newNode.getChildren();
1327 for(
auto &newNodeChild: newNodeChildren)
1329 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1330 newNodeChild.second.getChildren();
1332 for(
auto &twoDeepChild: twoDeepChildren)
1336 if(twoDeepChild.second.isLinkNode() &&
1337 twoDeepChild.second.isDisconnected() &&
1338 twoDeepChild.second.getDisconnectedTableName() !=
1339 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1341 *accumulatedTreeErrors +=
"\n\nAt node '" +
1342 memberPair.first +
"' with entry UID '" +
1343 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1344 twoDeepChild.first +
"'" +
1345 " that points to table named '" +
1346 twoDeepChild.second.getDisconnectedTableName() +
1352 for(
auto &searchMemberPair: *memberMap)
1353 if(searchMemberPair.first ==
1354 twoDeepChild.second.getDisconnectedTableName())
1355 { found =
true;
break;}
1357 *accumulatedTreeErrors +=
1358 std::string(
"\nNote: It may be safe to ignore this error ") +
1359 "since the link's target table " +
1360 twoDeepChild.second.getDisconnectedTableName() +
1361 " is not a member of this group (and may not be loaded yet).";
1366 catch(std::runtime_error &e)
1368 *accumulatedTreeErrors +=
"\n\nAt node '" +
1369 memberPair.first +
"' error detected descending through children:\n" +
1374 retMap.push_back(std::pair<std::string,ConfigurationTree>(memberPair.first,
1387 const ConfigurationBase* ConfigurationManager::getConfigurationByName(
const std::string &configurationName)
const
1389 std::map<std::string, ConfigurationBase*>::const_iterator it;
1390 if((it = nameToConfigurationMap_.find(configurationName)) == nameToConfigurationMap_.end())
1392 __SS__ <<
"\n\nCan not find configuration named '" <<
1393 configurationName <<
1394 "'\n\n\n\nYou need to load the configuration before it can be used." <<
1395 " It probably is missing from the member list of the Configuration Group that was loaded.\n" <<
1396 "\nYou may need to enter wiz mode to remedy the situation, use the following:\n" <<
1397 "\n\t StartOTS.sh --wiz" <<
1403 throw std::runtime_error(ss.str());
1414 if(!theBackboneGroupKey_)
1416 __COUT_WARN__ <<
"getConfigurationGroupKey() Failed! No active backbone currently." << std::endl;
1421 loadConfigurationGroup(theBackboneGroup_,*theBackboneGroupKey_);
1423 return *theBackboneGroupKey_;
1441 std::pair<std::string, ConfigurationGroupKey> ConfigurationManager::getConfigurationGroupFromAlias(
1442 std::string systemAlias,
ProgressBar* progressBar)
1452 if(progressBar) progressBar->step();
1454 if(systemAlias.find(
"GROUP:") == 0)
1456 if(progressBar) progressBar->step();
1458 unsigned int i = strlen(
"GROUP:");
1459 unsigned int j = systemAlias.find(
':',i);
1461 if(progressBar) progressBar->step();
1463 return std::pair<std::string, ConfigurationGroupKey>(
1464 systemAlias.substr(i,j-i),
1471 loadConfigurationBackbone();
1473 if(progressBar) progressBar->step();
1478 ConfigurationTree entry = getNode(
"GroupAliasesConfiguration").getNode(systemAlias);
1480 if(progressBar) progressBar->step();
1482 return std::pair<std::string, ConfigurationGroupKey>(entry.getNode(
"GroupName").getValueAsString(),
ConfigurationGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1489 if(progressBar) progressBar->step();
1496 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getGroupAliasesConfiguration(
void)
1498 restoreActiveConfigurationGroups();
1501 std::map<std::string ,
1504 std::vector<std::pair<std::string,ConfigurationTree> > entries = getNode(
"GroupAliasesConfiguration").getChildren();
1505 for(
auto &entryPair: entries)
1507 retMap[entryPair.first] = std::pair<std::string, ConfigurationGroupKey>(
1508 entryPair.second.getNode(
"GroupName").getValueAsString(),
1517 std::map<std::string, ConfigurationVersion> ConfigurationManager::getActiveVersions(
void)
const
1519 std::map<std::string, ConfigurationVersion> retMap;
1520 for(
auto &config:nameToConfigurationMap_)
1525 if(config.second && config.second->isActive())
1528 retMap.insert(std::pair<std::string, ConfigurationVersion>(config.first, config.second->getViewVersion()));
1556 std::shared_ptr<ConfigurationGroupKey> ConfigurationManager::makeTheConfigurationGroupKey(
ConfigurationGroupKey key)
1558 if(theConfigurationGroupKey_)
1560 if(*theConfigurationGroupKey_ != key)
1561 destroyConfigurationGroup();
1563 return theConfigurationGroupKey_;
1569 std::string ConfigurationManager::encodeURIComponent(
const std::string &sourceStr)
1571 std::string retStr =
"";
1573 for(
const auto &c:sourceStr)
1575 (c >=
'a' && c <=
'z') ||
1576 (c >=
'A' && c <=
'Z') ||
1577 (c >=
'0' && c <=
'9') )
1581 sprintf(encodeStr,
"%%%2.2X",c);
1582 retStr += encodeStr;
1588 const std::set<std::string>& ConfigurationManager::getContextMemberNames()
1589 {
return ConfigurationManager::contextMemberNames_; }
1591 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
1592 {
return ConfigurationManager::backboneMemberNames_; }
1594 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
1595 {
return ConfigurationManager::iterateMemberNames_; }