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 #define CORE_TABLE_INFO_FILENAME ((getenv("SERVICE_DATA_PATH") == NULL)?(std::string(getenv("USER_DATA"))+"/ServiceData"):(std::string(getenv("SERVICE_DATA_PATH")))) + "/CoreTableInfoNames.dat"
27 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT =
"Context";
28 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE =
"Backbone";
29 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE =
"Iterate";
30 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION =
"Configuration";
34 ConfigurationManager::ConfigurationManager()
37 , theConfigurationGroupKey_ (0)
38 , theContextGroupKey_ (0)
39 , theBackboneGroupKey_ (0)
40 , theConfigurationGroup_ (
"")
41 , theContextGroup_ (
"")
42 , theBackboneGroup_ (
"")
43 , contextMemberNames_ ({XDAQ_CONTEXT_CONFIG_NAME,
"XDAQApplicationConfiguration",
"XDAQApplicationPropertyConfiguration",
"DesktopIconConfiguration",
"MessageFacilityConfiguration",
"TheSupervisorConfiguration",
"StateMachineConfiguration",
"DesktopWindowParameterConfiguration"})
44 , backboneMemberNames_ ({
"GroupAliasesConfiguration",
"VersionAliasesConfiguration"})
45 , iterateMemberNames_ ({
"IterateConfiguration",
"IterationPlanConfiguration",
"IterationTargetConfiguration",
46 "IterationCommandBeginLabelConfiguration",
"IterationCommandChooseFSMConfiguration",
"IterationCommandConfigureAliasConfiguration",
"IterationCommandConfigureGroupConfiguration",
"IterationCommandExecuteFEMacroConfiguration",
"IterationCommandExecuteMacroConfiguration",
"IterationCommandModifyGroupConfiguration",
"IterationCommandRepeatLabelConfiguration",
"IterationCommandRunConfiguration"})
48 theInterface_ = ConfigurationInterface::getInstance(
false);
62 groupMetadataTable_.setConfigurationName(ConfigurationInterface::GROUP_METADATA_TABLE_NAME);
64 std::vector<ViewColumnInfo>* colInfo =
65 groupMetadataTable_.getMockupViewP()->getColumnsInfoP();
69 ViewColumnInfo::TYPE_UID,
72 ViewColumnInfo::DATATYPE_NUMBER,
76 ViewColumnInfo::TYPE_COMMENT,
78 "COMMENT_DESCRIPTION",
79 ViewColumnInfo::DATATYPE_STRING,
83 ViewColumnInfo::TYPE_AUTHOR,
86 ViewColumnInfo::DATATYPE_STRING,
90 ViewColumnInfo::TYPE_TIMESTAMP,
92 "GROUP_CREATION_TIME",
93 ViewColumnInfo::DATATYPE_TIME,
96 auto tmpVersion = groupMetadataTable_.createTemporaryView();
97 groupMetadataTable_.setActiveView(tmpVersion);
99 groupMetadataTable_.getViewP()->addRow();
104 FILE * fp = fopen((CORE_TABLE_INFO_FILENAME).c_str(),
"w");
107 for(
const auto &name:contextMemberNames_)
108 fprintf(fp,
"%s\n",name.c_str());
109 for(
const auto &name:backboneMemberNames_)
110 fprintf(fp,
"%s\n",name.c_str());
111 for(
const auto &name:iterateMemberNames_)
112 fprintf(fp,
"%s\n",name.c_str());
117 __SS__ <<
"Failed to open core table info file: " << CORE_TABLE_INFO_FILENAME << std::endl;
118 __COUT_ERR__ <<
"\n" << ss.str();
119 throw std::runtime_error(ss.str());
127 ConfigurationManager::ConfigurationManager(
const std::string& username)
130 username_ = username;
134 ConfigurationManager::~ConfigurationManager()
143 void ConfigurationManager::init(std::string *accumulatedErrors)
145 if(accumulatedErrors) *accumulatedErrors =
"";
150 if(theInterface_->getMode() ==
false)
154 restoreActiveConfigurationGroups(accumulatedErrors?
true:
false);
156 catch(std::runtime_error &e)
158 if(accumulatedErrors) *accumulatedErrors = e.what();
169 void ConfigurationManager::restoreActiveConfigurationGroups(
bool throwErrors)
171 destroyConfigurationGroup(
"",
true);
173 std::string fn = ACTIVE_GROUP_FILENAME;
174 FILE *fp = fopen(fn.c_str(),
"r");
176 __COUT__ <<
"ACTIVE_GROUP_FILENAME = " << ACTIVE_GROUP_FILENAME << std::endl;
177 __COUT__ <<
"ARTDAQ_DATABASE_URI = " << std::string(getenv(
"ARTDAQ_DATABASE_URI")) << std::endl;
186 std::string groupName;
187 std::string errorStr =
"";
192 while(fgets(tmp,500,fp))
197 sscanf(tmp,
"%s",strVal);
198 for(
unsigned int j=0;j<strlen(strVal);++j)
200 (strVal[j] >=
'a' && strVal[j] <=
'z') ||
201 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
202 (strVal[j] >=
'0' && strVal[j] <=
'9')))
205 __COUT_INFO__ <<
"Illegal character found, so skipping!" << std::endl;
215 sscanf(tmp,
"%s",strVal);
217 for(
unsigned int j=0;j<strlen(strVal);++j)
219 (strVal[j] >=
'0' && strVal[j] <=
'9')))
222 __COUT_INFO__ <<
"Illegal character found, so skipping!" << std::endl;
234 __COUT__ <<
"illegal group accorging to ConfigurationGroupKey::getFullGroupString..." << std::endl;
245 catch(std::runtime_error &e)
247 ss <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
248 groupName <<
"_v" << strVal <<
"'" << std::endl;
249 ss << e.what() << std::endl;
251 errorStr += ss.str();
255 ss <<
"Failed to load config group in ConfigurationManager::init() with name '" <<
256 groupName <<
"_v" << strVal <<
"'" << std::endl;
258 errorStr += ss.str();
264 if(throwErrors && errorStr !=
"")
266 __COUT_INFO__ <<
"\n" << ss.str();
267 throw std::runtime_error(errorStr);
276 void ConfigurationManager::destroyConfigurationGroup(
const std::string& theGroup,
bool onlyDeactivate)
279 bool isContext = theGroup ==
"" || theGroup == theContextGroup_;
280 bool isBackbone = theGroup ==
"" || theGroup == theBackboneGroup_;
281 bool isIterate = theGroup ==
"" || theGroup == theIterateGroup_;
282 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationGroup_;
284 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
286 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << std::endl;
287 __COUT_ERR__ << ss.str();
288 throw std::runtime_error(ss.str());
291 std::string dbgHeader = onlyDeactivate?
"Deactivating":
"Destroying";
295 __COUT__ << dbgHeader <<
" Context group: " << theGroup << std::endl;
297 __COUT__ << dbgHeader <<
" Backbone group: " << theGroup << std::endl;
299 __COUT__ << dbgHeader <<
" Iterate group: " << theGroup << std::endl;
301 __COUT__ << dbgHeader <<
" Configuration group: " << theGroup << std::endl;
304 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
305 for(
auto it = nameToConfigurationMap_.begin(); it != nameToConfigurationMap_.end(); )
307 contextFindIt = contextMemberNames_.find(it->first);
308 backboneFindIt = backboneMemberNames_.find(it->first);
309 iterateFindIt = iterateMemberNames_.find(it->first);
310 if(theGroup ==
"" || (
311 (isContext && contextFindIt != contextMemberNames_.end()) ||
312 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
313 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
314 (!isContext && !isBackbone &&
315 contextFindIt == contextMemberNames_.end() &&
316 backboneFindIt == backboneMemberNames_.end()&&
317 iterateFindIt == iterateMemberNames_.end())))
326 it->second->deactivate();
332 nameToConfigurationMap_.erase(it++);
341 theConfigurationGroup_ =
"";
342 if(theConfigurationGroupKey_ != 0)
344 __COUT__ <<
"Destroying Configuration Key: " << *theConfigurationGroupKey_ << std::endl;
345 theConfigurationGroupKey_.reset();
352 theBackboneGroup_ =
"";
353 if(theBackboneGroupKey_ != 0)
355 __COUT__ <<
"Destroying Backbone Key: " << *theBackboneGroupKey_ << std::endl;
356 theBackboneGroupKey_.reset();
361 theIterateGroup_ =
"";
362 if(theIterateGroupKey_ != 0)
364 __COUT__ <<
"Destroying Iterate Key: " << *theIterateGroupKey_ << std::endl;
365 theIterateGroupKey_.reset();
370 theContextGroup_ =
"";
371 if(theContextGroupKey_ != 0)
373 __COUT__ <<
"Destroying Context Key: " << *theContextGroupKey_ << std::endl;
374 theContextGroupKey_.reset();
380 void ConfigurationManager::destroy(
void)
385 destroyConfigurationGroup();
395 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
397 return groupTypeId==CONTEXT_TYPE?
398 ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT:
399 (groupTypeId==BACKBONE_TYPE?
400 ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE:
401 (groupTypeId==ITERATE_TYPE?
402 ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE:
403 ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
413 int ConfigurationManager::getTypeOfGroup(
414 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
417 bool isContext =
true;
418 bool isBackbone =
true;
419 bool isIterate =
true;
421 bool inContext =
false;
422 bool inBackbone =
false;
423 bool inIterate =
false;
424 unsigned int matchCount = 0;
426 for(
auto &memberPair:memberMap)
431 for(
auto &contextMemberString:contextMemberNames_)
432 if(memberPair.first == contextMemberString)
444 __SS__ <<
"This group is an incomplete match to a Context group.\n";
445 __COUT_ERR__ <<
"\n" << ss.str();
446 ss <<
"\nTo be a Context group, the members must exactly match" <<
447 "the following members:\n";
449 for(
auto &memberName:contextMemberNames_)
450 ss << ++i <<
". " << memberName <<
"\n";
451 throw std::runtime_error(ss.str());
457 for(
auto &backboneMemberString:backboneMemberNames_)
458 if(memberPair.first == backboneMemberString)
470 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
471 __COUT_ERR__ <<
"\n" << ss.str();
472 ss <<
"\nTo be a Backbone group, the members must exactly match" <<
473 "the following members:\n";
475 for(
auto &memberName:backboneMemberNames_)
476 ss << ++i <<
". " << memberName <<
"\n";
478 throw std::runtime_error(ss.str());
484 for(
auto &iterateMemberString:iterateMemberNames_)
485 if(memberPair.first == iterateMemberString)
497 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
498 __COUT_ERR__ <<
"\n" << ss.str();
499 ss <<
"\nTo be a Iterate group, the members must exactly match" <<
500 "the following members:\n";
502 for(
auto &memberName:iterateMemberNames_)
503 ss << ++i <<
". " << memberName <<
"\n";
505 throw std::runtime_error(ss.str());
510 if(isContext && matchCount != contextMemberNames_.size())
512 __SS__ <<
"This group is an incomplete match to a Context group: " <<
513 " Size=" << matchCount <<
" but should be " << contextMemberNames_.size() <<
515 __COUT_ERR__ <<
"\n" << ss.str();
516 ss <<
"\nThe members currently are...\n";
518 for(
auto &memberPair:memberMap)
519 ss << ++i <<
". " << memberPair.first <<
"\n";
520 ss <<
"\nThe expected Context members are...\n";
522 for(
auto &memberName:contextMemberNames_)
523 ss << ++i <<
". " << memberName <<
"\n";
525 throw std::runtime_error(ss.str());
528 if(isBackbone && matchCount != backboneMemberNames_.size())
530 __SS__ <<
"This group is an incomplete match to a Backbone group: " <<
531 " Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() <<
533 __COUT_ERR__ <<
"\n" << ss.str();
534 ss <<
"\nThe members currently are...\n";
536 for(
auto &memberPair:memberMap)
537 ss << ++i <<
". " << memberPair.first <<
"\n";
538 ss <<
"\nThe expected Backbone members are...\n";
540 for(
auto &memberName:backboneMemberNames_)
541 ss << ++i <<
". " << memberName <<
"\n";
543 throw std::runtime_error(ss.str());
546 if(isIterate && matchCount != iterateMemberNames_.size())
548 __SS__ <<
"This group is an incomplete match to a Iterate group: " <<
549 " Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() <<
551 __COUT_ERR__ <<
"\n" << ss.str();
552 ss <<
"\nThe members currently are...\n";
554 for(
auto &memberPair:memberMap)
555 ss << ++i <<
". " << memberPair.first <<
"\n";
556 ss <<
"\nThe expected Iterate members are...\n";
558 for(
auto &memberName:iterateMemberNames_)
559 ss << ++i <<
". " << memberName <<
"\n";
561 throw std::runtime_error(ss.str());
564 return isContext?CONTEXT_TYPE:(isBackbone?BACKBONE_TYPE:(isIterate?ITERATE_TYPE:CONFIGURATION_TYPE));
570 const std::string& ConfigurationManager::getTypeNameOfGroup(
571 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
573 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
580 void ConfigurationManager::dumpActiveConfiguration(
581 const std::string &filePath,
const std::string &dumpType)
const
583 time_t rawtime = time(0);
584 __COUT__ <<
"filePath = " << filePath << std::endl;
585 __COUT__ <<
"dumpType = " << dumpType << std::endl;
589 fs.open(filePath, std::fstream::out | std::fstream::trunc);
600 (*out) <<
"#################################" << std::endl;
601 (*out) <<
"This is an ots configuration dump.\n\n" << std::endl;
602 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t" << getenv(
"ARTDAQ_DATABASE_URI") << std::endl;
603 (*out) <<
"\nOriginal location of dump: \t" << filePath << std::endl;
604 (*out) <<
"Type of dump: \t" << dumpType << std::endl;
605 (*out) <<
"Linux time for dump: \t" << rawtime << std::endl;
608 struct tm * timeinfo = localtime (&rawtime);
610 strftime(buffer,100,
"%c %Z",timeinfo);
611 (*out) <<
"Display time for dump: \t" << buffer << std::endl;
622 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
623 cfgMgr->getActiveConfigurationGroups();
625 (*out) <<
"\n\n************************" << std::endl;
626 (*out) <<
"Active Groups:" << std::endl;
627 for(
auto &group:activeGroups)
629 (*out) <<
"\t" << group.first <<
" := " <<
630 group.second.first <<
" (" <<
631 group.second.second <<
")" << std::endl;
636 std::map<std::string, ConfigurationVersion> activeTables =
637 cfgMgr->getActiveVersions();
639 (*out) <<
"\n\n************************" << std::endl;
640 (*out) <<
"Active Tables:" << std::endl;
641 (*out) <<
"Active Tables count = " << activeTables.size() << std::endl;
644 for(
auto &table:activeTables)
646 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" <<
647 table.second << std::endl;
652 std::map<std::string, std::pair<std::string, ConfigurationGroupKey>> activeGroups =
653 cfgMgr->getActiveConfigurationGroups();
654 (*out) <<
"\n\n************************" << std::endl;
655 (*out) <<
"Active Group Members:" << std::endl;
657 for(
auto &group:activeGroups)
659 (*out) <<
"\t" << group.first <<
" := " <<
660 group.second.first <<
" (" <<
661 group.second.second <<
")" << std::endl;
664 cfgMgr->theInterface_->getConfigurationGroupMembers(
665 ConfigurationGroupKey::getFullGroupString(
667 group.second.second));
669 (*out) <<
"\tMember table count = " << memberMap.size() << std::endl;
670 tableCount += memberMap.size();
673 for(
auto &member:memberMap)
675 (*out) <<
"\t\t" << ++i <<
". " << member.first <<
"-v" <<
676 member.second << std::endl;
679 (*out) <<
"\nActive Group Members total table count = " << tableCount << std::endl;
683 std::map<std::string, ConfigurationVersion> activeTables =
684 cfgMgr->getActiveVersions();
686 (*out) <<
"\n\n************************" << std::endl;
687 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
688 <<
"):" << std::endl;
690 for(
auto &table:activeTables)
692 (*out) <<
"\n\n==============================================================================" << std::endl;
693 (*out) <<
"==============================================================================" << std::endl;
694 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" <<
695 table.second << std::endl;
697 cfgMgr->nameToConfigurationMap_.find(table.first)->second->print(*out);
703 if(dumpType ==
"GroupKeys")
705 localDumpActiveGroups(
this,out);
707 else if(dumpType ==
"TableVersions")
709 localDumpActiveTables(
this,out);
711 else if(dumpType ==
"GroupKeysAndTableVersions")
713 localDumpActiveGroups(
this,out);
714 localDumpActiveTables(
this,out);
716 else if(dumpType ==
"All")
718 localDumpActiveGroups(
this,out);
719 localDumpActiveGroupMembers(
this,out);
720 localDumpActiveTables(
this,out);
721 localDumpActiveTableContents(
this,out);
725 __SS__ <<
"Invalid dump type '" << dumpType <<
726 "' given during dumpActiveConfiguration(). Valid types are as follows:\n" <<
729 "GroupKeys" <<
", " <<
730 "TableVersions" <<
", " <<
731 "GroupsKeysAndTableVersions" <<
", " <<
734 "\n\nPlease change the State Machine configuration to a valid dump type." <<
736 throw std::runtime_error(ss.str());
747 void ConfigurationManager::loadMemberMap(
748 const std::map<std::string /*name*/, ConfigurationVersion /*version*/> &memberMap)
753 for(
auto &memberPair:memberMap)
763 tmpConfigBasePtr = 0;
764 if(nameToConfigurationMap_.find(memberPair.first) != nameToConfigurationMap_.end())
765 tmpConfigBasePtr = nameToConfigurationMap_[memberPair.first];
767 theInterface_->get(tmpConfigBasePtr,
776 nameToConfigurationMap_[memberPair.first] = tmpConfigBasePtr;
777 if(nameToConfigurationMap_[memberPair.first]->getViewP())
783 __SS__ << nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
784 ": View version not activated properly!";
785 throw std::runtime_error(ss.str());
805 std::map<std::string, ConfigurationVersion> ConfigurationManager::loadConfigurationGroup(
806 const std::string &configGroupName,
810 std::string *accumulatedTreeErrors,
811 std::string *groupComment,
812 std::string *groupAuthor,
813 std::string *groupCreateTime,
814 bool doNotLoadMember,
815 std::string *groupTypeString)
817 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
818 if(groupComment) *groupComment =
"";
819 if(groupAuthor) *groupAuthor =
"";
820 if(groupCreateTime) *groupCreateTime =
"";
821 if(groupTypeString) *groupTypeString =
"";
835 __COUT_INFO__ <<
"Loading Configuration Group: " << configGroupName <<
836 "(" << configGroupKey <<
")" << std::endl;
839 theInterface_->getConfigurationGroupMembers(
840 ConfigurationGroupKey::getFullGroupString(configGroupName,configGroupKey),
844 if(progressBar) progressBar->step();
847 auto metaTablePair = memberMap.find(groupMetadataTable_.getConfigurationName());
854 while(groupMetadataTable_.getView().getNumberOfRows())
855 groupMetadataTable_.getViewP()->deleteRow(0);
856 theInterface_->fill(&groupMetadataTable_,metaTablePair->second);
858 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
860 groupMetadataTable_.print();
861 __SS__ <<
"groupMetadataTable_ has wrong number of rows! Must be 1." << std::endl;
862 __COUT_ERR__ <<
"\n" << ss.str();
863 throw std::runtime_error(ss.str());
867 memberMap.erase(metaTablePair);
870 if(groupComment) *groupComment = groupMetadataTable_.getView().getValueAsString(0,1);
871 if(groupAuthor) *groupAuthor = groupMetadataTable_.getView().getValueAsString(0,2);
872 if(groupCreateTime) *groupCreateTime = groupMetadataTable_.getView().getValueAsString(0,3);
875 if(progressBar) progressBar->step();
877 __COUT__ <<
"memberMap loaded size = " << memberMap.size() << std::endl;
882 groupType = getTypeOfGroup(memberMap);
883 *groupTypeString = convertGroupTypeIdToName(groupType);
886 if(doNotLoadMember)
return memberMap;
889 __COUT__ <<
"------------------------------------- loadConfigurationGroup start" << std::endl;
893 if(!groupTypeString) groupType = getTypeOfGroup(memberMap);
897 std::string groupToDeactivate =
898 groupType==CONTEXT_TYPE?theContextGroup_:
899 (groupType==BACKBONE_TYPE?theBackboneGroup_:
900 (groupType==ITERATE_TYPE?
901 theIterateGroup_:theConfigurationGroup_));
904 if(groupToDeactivate !=
"")
906 __COUT__ <<
"groupToDeactivate '" << groupToDeactivate <<
"'" << std::endl;
907 destroyConfigurationGroup(groupToDeactivate,
true);
916 if(progressBar) progressBar->step();
921 loadMemberMap(memberMap);
923 if(progressBar) progressBar->step();
925 if(accumulatedTreeErrors)
927 __COUT__ <<
"Checking chosen group for tree errors..." << std::endl;
929 getChildren(&memberMap, accumulatedTreeErrors);
930 if(*accumulatedTreeErrors !=
"")
932 __COUT_ERR__ <<
"Errors detected while loading Configuration Group: " << configGroupName <<
933 "(" << configGroupKey <<
"). Aborting." << std::endl;
938 if(progressBar) progressBar->step();
943 for(
auto &memberPair:memberMap)
946 if(ConfigurationInterface::isVersionTrackingEnabled() &&
947 memberPair.second.isScratchVersion())
949 __SS__ <<
"Error while activating member Table '" <<
950 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
951 "-v" << memberPair.second <<
952 " for Configuration Group '" << configGroupName <<
953 "(" << configGroupKey <<
")'. When version tracking is enabled, Scratch views" <<
954 " are not allowed! Please only use unique, persistent versions when version tracking is enabled."
956 __COUT_ERR__ <<
"\n" << ss.str();
957 throw std::runtime_error(ss.str());
965 nameToConfigurationMap_[memberPair.first]->init(
this);
967 catch(std::runtime_error& e)
969 __SS__ <<
"Error detected calling " <<
970 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
971 ".init()!\n\n " << e.what() << std::endl;
972 throw std::runtime_error(ss.str());
976 __SS__ <<
"Error detected calling " <<
977 nameToConfigurationMap_[memberPair.first]->getConfigurationName() <<
978 ".init()!\n\n " << std::endl;
979 throw std::runtime_error(ss.str());
984 if(progressBar) progressBar->step();
992 if(groupType == CONTEXT_TYPE)
994 __COUT_INFO__ <<
"Type=Context, Group loaded: " << configGroupName <<
995 "(" << configGroupKey <<
")" << std::endl;
996 theContextGroup_ = configGroupName;
997 theContextGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
999 else if(groupType == BACKBONE_TYPE)
1001 __COUT_INFO__ <<
"Type=Backbone, Group loaded: " << configGroupName <<
1002 "(" << configGroupKey <<
")" << std::endl;
1003 theBackboneGroup_ = configGroupName;
1004 theBackboneGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1006 else if(groupType == ITERATE_TYPE)
1008 __COUT_INFO__ <<
"Type=Iterate, Group loaded: " << configGroupName <<
1009 "(" << configGroupKey <<
")" << std::endl;
1010 theIterateGroup_ = configGroupName;
1011 theIterateGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1015 __COUT_INFO__ <<
"Type=Configuration, Group loaded: " << configGroupName <<
1016 "(" << configGroupKey <<
")" << std::endl;
1017 theConfigurationGroup_ = configGroupName;
1018 theConfigurationGroupKey_ = std::shared_ptr<ConfigurationGroupKey>(
new ConfigurationGroupKey(configGroupKey));
1022 if(progressBar) progressBar->step();
1025 __COUT__ <<
"------------------------------------- loadConfigurationGroup end" << std::endl;
1037 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getActiveConfigurationGroups(
void)
const
1040 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > retMap;
1042 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1043 std::pair<std::string,ConfigurationGroupKey>(theContextGroup_ ,theContextGroupKey_ ?*theContextGroupKey_ :
ConfigurationGroupKey());
1044 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
1045 std::pair<std::string,ConfigurationGroupKey>(theBackboneGroup_ ,theBackboneGroupKey_ ?*theBackboneGroupKey_ :
ConfigurationGroupKey());
1046 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
1047 std::pair<std::string,ConfigurationGroupKey>(theIterateGroup_ ,theIterateGroupKey_ ?*theIterateGroupKey_ :
ConfigurationGroupKey());
1048 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1049 std::pair<std::string,ConfigurationGroupKey>(theConfigurationGroup_,theConfigurationGroupKey_?*theConfigurationGroupKey_:
ConfigurationGroupKey());
1054 const std::string& ConfigurationManager::getActiveGroupName(
const std::string& type)
const
1056 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1057 return theConfigurationGroup_;
1058 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1059 return theContextGroup_;
1060 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1061 return theBackboneGroup_;
1062 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1063 return theIterateGroup_;
1065 __SS__ <<
"Invalid type requested '" << type <<
"'" << std::endl;
1066 __COUT_ERR__ << ss.str();
1067 throw std::runtime_error(ss.str());
1073 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1075 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1077 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1079 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1082 __SS__ <<
"Invalid type requested '" << type <<
"'" << std::endl;
1083 __COUT_ERR__ << ss.str();
1084 throw std::runtime_error(ss.str());
1090 const std::string &contextUID,
const std::string &applicationUID)
const
1093 "/" + getConfigurationByName(XDAQ_CONTEXT_CONFIG_NAME)->getConfigurationName() +
1095 "/LinkToApplicationConfiguration/" + applicationUID +
1096 "/LinkToSupervisorConfiguration");
1101 bool doNotThrowOnBrokenUIDLinks)
const
1106 if(nodeString.length() < 1)
1108 __SS__ << (
"Invalid empty node name") << std::endl;
1109 __COUT_ERR__ << ss.str();
1110 throw std::runtime_error(ss.str());
1114 unsigned int startingIndex = 0;
1115 while(startingIndex < nodeString.length() &&
1116 nodeString[startingIndex] ==
'/') ++startingIndex;
1118 std::string nodeName = nodeString.substr(startingIndex, nodeString.find(
'/',startingIndex)-startingIndex);
1120 if(nodeName.length() < 1)
1122 __SS__ <<
"Invalid node name: " << nodeName << std::endl;
1123 __COUT_ERR__ << ss.str();
1124 throw std::runtime_error(ss.str());
1127 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
1133 if(childPath.length() > 1)
1134 return configTree.getNode(childPath,doNotThrowOnBrokenUIDLinks);
1141 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree &node,
const std::string &startPath)
const
1144 std::string path =
"/";
1154 std::vector<std::pair<std::string,ConfigurationTree> > ConfigurationManager::getChildren(
1155 std::map<std::string, ConfigurationVersion> *memberMap,
1156 std::string *accumulatedTreeErrors)
const
1158 std::vector<std::pair<std::string,ConfigurationTree> > retMap;
1159 if(accumulatedTreeErrors) *accumulatedTreeErrors =
"";
1161 if(!memberMap || memberMap->empty())
1163 for(
auto &configPair:nameToConfigurationMap_)
1167 if(configPair.second->isActive())
1172 if(accumulatedTreeErrors)
1176 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1177 newNode.getChildren();
1178 for(
auto &newNodeChild: newNodeChildren)
1180 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1181 newNodeChild.second.getChildren();
1183 for(
auto &twoDeepChild: twoDeepChildren)
1187 if(twoDeepChild.second.isLinkNode() &&
1188 twoDeepChild.second.isDisconnected() &&
1189 twoDeepChild.second.getDisconnectedTableName() !=
1190 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1191 *accumulatedTreeErrors +=
"\n\nAt node '" +
1192 configPair.first +
"' with entry UID '" +
1193 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1194 twoDeepChild.first +
"'" +
1195 " that points to table named '" +
1196 twoDeepChild.second.getDisconnectedTableName() +
1201 catch(std::runtime_error &e)
1203 *accumulatedTreeErrors +=
"\n\nAt node '" +
1204 configPair.first +
"' error detected descending through children:\n" +
1209 retMap.push_back(std::pair<std::string,ConfigurationTree>(configPair.first,
1219 for(
auto &memberPair: *memberMap)
1221 auto mapIt = nameToConfigurationMap_.find(memberPair.first);
1222 if(mapIt == nameToConfigurationMap_.end())
1224 __SS__ <<
"Get Children with member map requires a child '" <<
1225 memberPair.first <<
"' that is not present!" << std::endl;
1226 throw std::runtime_error(ss.str());
1228 if(!(*mapIt).second->isActive())
1230 __SS__ <<
"Get Children with member map requires a child '" <<
1231 memberPair.first <<
"' that is not active!" << std::endl;
1232 throw std::runtime_error(ss.str());
1237 if(accumulatedTreeErrors)
1241 std::vector<std::pair<std::string,ConfigurationTree> > newNodeChildren =
1242 newNode.getChildren();
1243 for(
auto &newNodeChild: newNodeChildren)
1245 std::vector<std::pair<std::string,ConfigurationTree> > twoDeepChildren =
1246 newNodeChild.second.getChildren();
1248 for(
auto &twoDeepChild: twoDeepChildren)
1252 if(twoDeepChild.second.isLinkNode() &&
1253 twoDeepChild.second.isDisconnected() &&
1254 twoDeepChild.second.getDisconnectedTableName() !=
1255 ViewColumnInfo::DATATYPE_LINK_DEFAULT)
1257 *accumulatedTreeErrors +=
"\n\nAt node '" +
1258 memberPair.first +
"' with entry UID '" +
1259 newNodeChild.first +
"' there is a disconnected child node at link column '" +
1260 twoDeepChild.first +
"'" +
1261 " that points to table named '" +
1262 twoDeepChild.second.getDisconnectedTableName() +
1268 for(
auto &searchMemberPair: *memberMap)
1269 if(searchMemberPair.first ==
1270 twoDeepChild.second.getDisconnectedTableName())
1271 { found =
true;
break;}
1273 *accumulatedTreeErrors +=
1274 std::string(
"\nNote: It may be safe to ignore this error ") +
1275 "since the link's target table " +
1276 twoDeepChild.second.getDisconnectedTableName() +
1277 " is not a member of this group (and may not be loaded yet).";
1282 catch(std::runtime_error &e)
1284 *accumulatedTreeErrors +=
"\n\nAt node '" +
1285 memberPair.first +
"' error detected descending through children:\n" +
1290 retMap.push_back(std::pair<std::string,ConfigurationTree>(memberPair.first,
1303 const ConfigurationBase* ConfigurationManager::getConfigurationByName(
const std::string &configurationName)
const
1305 std::map<std::string, ConfigurationBase*>::const_iterator it;
1306 if((it = nameToConfigurationMap_.find(configurationName)) == nameToConfigurationMap_.end())
1308 __SS__ <<
"\n\nCan not find configuration named '" <<
1309 configurationName <<
1310 "'\n\n\n\nYou need to load the configuration before it can be used." <<
1311 " It probably is missing from the member list of the Configuration Group that was loaded.\n" <<
1312 "\nYou may need to enter wiz mode to remedy the situation, use the following:\n" <<
1313 "\n\t StartOTS.sh --wiz" <<
1319 throw std::runtime_error(ss.str());
1330 if(!theBackboneGroupKey_)
1332 __COUT_WARN__ <<
"getConfigurationGroupKey() Failed! No active backbone currently." << std::endl;
1337 loadConfigurationGroup(theBackboneGroup_,*theBackboneGroupKey_);
1339 return *theBackboneGroupKey_;
1357 std::pair<std::string, ConfigurationGroupKey> ConfigurationManager::getConfigurationGroupFromAlias(
1358 std::string systemAlias,
ProgressBar* progressBar)
1368 if(progressBar) progressBar->step();
1370 if(systemAlias.find(
"GROUP:") == 0)
1372 if(progressBar) progressBar->step();
1374 unsigned int i = strlen(
"GROUP:");
1375 unsigned int j = systemAlias.find(
':',i);
1377 if(progressBar) progressBar->step();
1379 return std::pair<std::string, ConfigurationGroupKey>(
1380 systemAlias.substr(i,j-i),
1387 loadConfigurationBackbone();
1389 if(progressBar) progressBar->step();
1394 ConfigurationTree entry = getNode(
"GroupAliasesConfiguration").getNode(systemAlias);
1396 if(progressBar) progressBar->step();
1398 return std::pair<std::string, ConfigurationGroupKey>(entry.getNode(
"GroupName").getValueAsString(),
ConfigurationGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1405 if(progressBar) progressBar->step();
1412 std::map<std::string, std::pair<std::string, ConfigurationGroupKey> > ConfigurationManager::getGroupAliasesConfiguration(
void)
1414 restoreActiveConfigurationGroups();
1417 std::map<std::string ,
1420 std::vector<std::pair<std::string,ConfigurationTree> > entries = getNode(
"GroupAliasesConfiguration").getChildren();
1421 for(
auto &entryPair: entries)
1423 retMap[entryPair.first] = std::pair<std::string, ConfigurationGroupKey>(
1424 entryPair.second.getNode(
"GroupName").getValueAsString(),
1433 std::map<std::string, ConfigurationVersion> ConfigurationManager::getActiveVersions(
void)
const
1435 std::map<std::string, ConfigurationVersion> retMap;
1436 for(
auto &config:nameToConfigurationMap_)
1441 if(config.second && config.second->isActive())
1444 retMap.insert(std::pair<std::string, ConfigurationVersion>(config.first, config.second->getViewVersion()));
1472 std::shared_ptr<ConfigurationGroupKey> ConfigurationManager::makeTheConfigurationGroupKey(
ConfigurationGroupKey key)
1474 if(theConfigurationGroupKey_)
1476 if(*theConfigurationGroupKey_ != key)
1477 destroyConfigurationGroup();
1479 return theConfigurationGroupKey_;
1485 std::string ConfigurationManager::encodeURIComponent(
const std::string &sourceStr)
1487 std::string retStr =
"";
1489 for(
const auto &c:sourceStr)
1491 (c >=
'a' && c <=
'z') ||
1492 (c >=
'A' && c <=
'Z') ||
1493 (c >=
'0' && c <=
'9') )
1497 sprintf(encodeStr,
"%%%2.2X",c);
1498 retStr += encodeStr;