1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "artdaq/Application/LoadParameterSet.hh"
3 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
4 #include "otsdaq/ProgressBar/ProgressBar.h"
8 #include "otsdaq/TableCore/TableGroupKey.h"
13 #define __MF_SUBJECT__ "ConfigurationManager"
15 const std::string ConfigurationManager::READONLY_USER =
"READONLY_USER";
17 const std::string ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME =
"XDAQContextTable";
18 const std::string ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME =
19 "XDAQApplicationTable";
20 const std::string ConfigurationManager::GROUP_ALIASES_TABLE_NAME =
"GroupAliasesTable";
21 const std::string ConfigurationManager::VERSION_ALIASES_TABLE_NAME =
22 "VersionAliasesTable";
25 const std::string ConfigurationManager::ACTIVE_GROUPS_FILENAME =
26 ((getenv(
"SERVICE_DATA_PATH") == NULL)
27 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
28 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
29 "/ActiveTableGroups.cfg";
30 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
31 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
33 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT =
"Context";
34 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE =
"Backbone";
35 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE =
"Iterate";
36 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION =
"Configuration";
37 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN =
"Unknown";
39 const uint8_t ConfigurationManager::METADATA_COL_ALIASES = 1;
40 const uint8_t ConfigurationManager::METADATA_COL_COMMENT = 2;
41 const uint8_t ConfigurationManager::METADATA_COL_AUTHOR = 3;
42 const uint8_t ConfigurationManager::METADATA_COL_TIMESTAMP = 4;
44 const std::set<std::string> ConfigurationManager::contextMemberNames_ = {
45 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
46 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
47 "XDAQApplicationPropertyTable",
49 "MessageFacilityTable",
50 "GatewaySupervisorTable",
52 "DesktopWindowParameterTable"};
53 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = {
54 ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
55 ConfigurationManager::VERSION_ALIASES_TABLE_NAME};
56 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = {
59 "IterationTargetTable",
60 "IterationCommandBeginLabelTable",
61 "IterationCommandChooseFSMTable",
62 "IterationCommandConfigureAliasTable",
63 "IterationCommandConfigureGroupTable",
64 "IterationCommandExecuteFEMacroTable",
65 "IterationCommandExecuteMacroTable",
66 "IterationCommandMacroDimensionalLoopTable",
67 "IterationCommandMacroDimensionalLoopParameterTable",
68 "IterationCommandModifyGroupTable",
69 "IterationCommandRepeatLabelTable",
70 "IterationCommandRunTable"};
73 ConfigurationManager::ConfigurationManager(
bool initForWriteAccess ,
74 bool doInitializeFromFhicl )
77 , theConfigurationTableGroupKey_(0)
78 , theContextTableGroupKey_(0)
79 , theBackboneTableGroupKey_(0)
80 , theConfigurationTableGroup_(
"")
81 , theContextTableGroup_(
"")
82 , theBackboneTableGroup_(
"")
84 theInterface_ = ConfigurationInterface::getInstance(
false);
98 groupMetadataTable_.setTableName(
99 ConfigurationInterface::GROUP_METADATA_TABLE_NAME);
100 std::vector<TableViewColumnInfo>* colInfo =
101 groupMetadataTable_.getMockupViewP()->getColumnsInfoP();
104 TableViewColumnInfo::TYPE_UID,
107 TableViewColumnInfo::DATATYPE_NUMBER,
113 TableViewColumnInfo::DATATYPE_STRING,
117 TableViewColumnInfo::TYPE_COMMENT,
118 TableViewColumnInfo::COL_NAME_COMMENT,
119 "COMMENT_DESCRIPTION",
120 TableViewColumnInfo::DATATYPE_STRING,
124 TableViewColumnInfo::TYPE_AUTHOR,
127 TableViewColumnInfo::DATATYPE_STRING,
132 "GROUP_CREATION_TIME",
133 TableViewColumnInfo::DATATYPE_TIME,
136 auto tmpVersion = groupMetadataTable_.createTemporaryView();
137 groupMetadataTable_.setActiveView(tmpVersion);
139 groupMetadataTable_.getViewP()->addRow();
142 if(doInitializeFromFhicl)
145 initializeFromFhicl(__ENV__(
"CONFIGURATION_INIT_FCL"));
149 init(0 , initForWriteAccess);
154 ConfigurationManager::ConfigurationManager(
const std::string& username)
157 __COUT_INFO__ <<
"Private constructor for write access called." << __E__;
158 username_ = username;
162 ConfigurationManager::~ConfigurationManager() { destroy(); }
168 void ConfigurationManager::init(std::string* accumulatedErrors,
169 bool initForWriteAccess )
181 __COUTV__(username_);
183 restoreActiveTableGroups(
184 accumulatedErrors ?
true :
false ,
187 (username_ == ConfigurationManager::READONLY_USER)
188 ? (!initForWriteAccess)
193 catch(std::runtime_error& e)
195 if(accumulatedErrors)
196 *accumulatedErrors += e.what();
208 void ConfigurationManager::restoreActiveTableGroups(
210 const std::string& pathToActiveGroupsFile,
211 bool onlyLoadIfBackboneOrContext )
213 destroyTableGroup(
"",
true);
216 pathToActiveGroupsFile ==
"" ? ACTIVE_GROUPS_FILENAME : pathToActiveGroupsFile;
217 FILE* fp = fopen(fn.c_str(),
"r");
219 __COUT__ <<
"ACTIVE_GROUPS_FILENAME = " << fn << __E__;
220 __COUT__ <<
"ARTDAQ_DATABASE_URI = " << std::string(__ENV__(
"ARTDAQ_DATABASE_URI"))
225 __COUT_WARN__ <<
"No active groups file found at " << fn << __E__;
234 std::string groupName;
235 std::string errorStr =
"";
240 while(fgets(tmp, 500, fp))
245 sscanf(tmp,
"%d", &numberCheck);
249 <<
"Out of sync with active groups file lines, attempting to resync."
256 sscanf(tmp,
"%s", strVal);
257 for(
unsigned int j = 0; j < strlen(strVal); ++j)
258 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') ||
259 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
260 (strVal[j] >=
'0' && strVal[j] <=
'9')))
263 __COUT_INFO__ <<
"Illegal character found in group name '" << strVal
264 <<
"', so skipping! Check active groups file: " << fn
276 sscanf(tmp,
"%s", strVal);
278 for(
unsigned int j = 0; j < strlen(strVal); ++j)
279 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
283 if(groupName.size() > 3)
285 <<
"Skipping active group with illegal character in group key '"
286 << strVal <<
".' Check active groups file: " << fn << __E__;
297 TableGroupKey::getFullGroupString(groupName,
TableGroupKey(strVal));
301 __COUT__ <<
"illegal group according to TableGroupKey::getFullGroupString... "
302 "Check active groups file: "
326 onlyLoadIfBackboneOrContext
329 catch(std::runtime_error& e)
331 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
332 << groupName <<
"(" << strVal
333 <<
")' specified active by active groups file: " << fn << __E__;
334 ss << e.what() << __E__;
336 errorStr += ss.str();
340 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
341 << groupName <<
"(" << strVal
342 <<
")' specified active by active groups file: " << fn << __E__;
344 errorStr += ss.str();
350 if(throwErrors && errorStr !=
"")
352 __COUT_INFO__ <<
"\n" << ss.str();
355 else if(errorStr !=
"")
356 __COUT_INFO__ <<
"\n" << ss.str();
365 void ConfigurationManager::destroyTableGroup(
const std::string& theGroup,
369 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
370 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
371 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
372 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
374 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
376 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
377 __COUT_ERR__ << ss.str();
381 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
385 __COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
387 __COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
389 __COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
391 __COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
394 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
395 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
398 contextFindIt = contextMemberNames_.find(it->first);
399 backboneFindIt = backboneMemberNames_.find(it->first);
400 iterateFindIt = iterateMemberNames_.find(it->first);
402 ((isContext && contextFindIt != contextMemberNames_.end()) ||
403 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
404 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
405 (!isContext && !isBackbone && contextFindIt == contextMemberNames_.end() &&
406 backboneFindIt == backboneMemberNames_.end() &&
407 iterateFindIt == iterateMemberNames_.end())))
415 it->second->deactivate();
421 nameToTableMap_.erase(it++);
430 theConfigurationTableGroup_ =
"";
431 if(theConfigurationTableGroupKey_ != 0)
433 __COUT__ <<
"Destroying Configuration Key: "
434 << *theConfigurationTableGroupKey_ << __E__;
435 theConfigurationTableGroupKey_.reset();
442 theBackboneTableGroup_ =
"";
443 if(theBackboneTableGroupKey_ != 0)
445 __COUT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_
447 theBackboneTableGroupKey_.reset();
452 theIterateTableGroup_ =
"";
453 if(theIterateTableGroupKey_ != 0)
455 __COUT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_ << __E__;
456 theIterateTableGroupKey_.reset();
461 theContextTableGroup_ =
"";
462 if(theContextTableGroupKey_ != 0)
464 __COUT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_ << __E__;
465 theContextTableGroupKey_.reset();
471 void ConfigurationManager::destroy(
void)
486 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
488 return groupTypeId == CONTEXT_TYPE
489 ? ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT
490 : (groupTypeId == BACKBONE_TYPE
491 ? ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE
492 : (groupTypeId == ITERATE_TYPE
493 ? ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE
494 : ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
504 int ConfigurationManager::getTypeOfGroup(
505 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
507 bool isContext =
true;
508 bool isBackbone =
true;
509 bool isIterate =
true;
511 bool inContext =
false;
512 bool inBackbone =
false;
513 bool inIterate =
false;
514 unsigned int matchCount = 0;
516 for(
auto& memberPair : memberMap)
521 for(
auto& contextMemberString : contextMemberNames_)
522 if(memberPair.first == contextMemberString)
534 __SS__ <<
"This group is an incomplete match to a Context group.\n";
535 __COUT_ERR__ <<
"\n" << ss.str();
536 ss <<
"\nTo be a Context group, the members must exactly match "
537 <<
"the following members:\n";
539 for(
const auto& memberName : contextMemberNames_)
540 ss << ++i <<
". " << memberName <<
"\n";
541 ss <<
"\nThe members are as follows::\n";
543 for(
const auto& memberPairTmp : memberMap)
544 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
551 for(
auto& backboneMemberString : backboneMemberNames_)
552 if(memberPair.first == backboneMemberString)
564 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
565 __COUT_ERR__ <<
"\n" << ss.str();
566 ss <<
"\nTo be a Backbone group, the members must exactly match "
567 <<
"the following members:\n";
569 for(
auto& memberName : backboneMemberNames_)
570 ss << ++i <<
". " << memberName <<
"\n";
571 ss <<
"\nThe members are as follows::\n";
573 for(
const auto& memberPairTmp : memberMap)
574 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
582 for(
auto& iterateMemberString : iterateMemberNames_)
583 if(memberPair.first == iterateMemberString)
595 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
596 __COUT_ERR__ <<
"\n" << ss.str();
597 ss <<
"\nTo be a Iterate group, the members must exactly match "
598 <<
"the following members:\n";
600 for(
auto& memberName : iterateMemberNames_)
601 ss << ++i <<
". " << memberName <<
"\n";
602 ss <<
"\nThe members are as follows::\n";
604 for(
const auto& memberPairTmp : memberMap)
605 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
612 if(isContext && matchCount != contextMemberNames_.size())
614 __SS__ <<
"This group is an incomplete match to a Context group: "
615 <<
" Size=" << matchCount <<
" but should be "
616 << contextMemberNames_.size() << __E__;
617 __COUT_ERR__ <<
"\n" << ss.str();
618 ss <<
"\nThe members currently are...\n";
620 for(
auto& memberPair : memberMap)
621 ss << ++i <<
". " << memberPair.first <<
"\n";
622 ss <<
"\nThe expected Context members are...\n";
624 for(
auto& memberName : contextMemberNames_)
625 ss << ++i <<
". " << memberName <<
"\n";
630 if(isBackbone && matchCount != backboneMemberNames_.size())
632 __SS__ <<
"This group is an incomplete match to a Backbone group: "
633 <<
" Size=" << matchCount <<
" but should be "
634 << backboneMemberNames_.size() << __E__;
635 __COUT_ERR__ <<
"\n" << ss.str();
636 ss <<
"\nThe members currently are...\n";
638 for(
auto& memberPair : memberMap)
639 ss << ++i <<
". " << memberPair.first <<
"\n";
640 ss <<
"\nThe expected Backbone members are...\n";
642 for(
auto& memberName : backboneMemberNames_)
643 ss << ++i <<
". " << memberName <<
"\n";
648 if(isIterate && matchCount != iterateMemberNames_.size())
650 __SS__ <<
"This group is an incomplete match to a Iterate group: "
651 <<
" Size=" << matchCount <<
" but should be "
652 << iterateMemberNames_.size() << __E__;
653 __COUT_ERR__ <<
"\n" << ss.str();
654 ss <<
"\nThe members currently are...\n";
656 for(
auto& memberPair : memberMap)
657 ss << ++i <<
". " << memberPair.first <<
"\n";
658 ss <<
"\nThe expected Iterate members are...\n";
660 for(
auto& memberName : iterateMemberNames_)
661 ss << ++i <<
". " << memberName <<
"\n";
666 return isContext ? CONTEXT_TYPE
667 : (isBackbone ? BACKBONE_TYPE
668 : (isIterate ? ITERATE_TYPE : CONFIGURATION_TYPE));
674 const std::string& ConfigurationManager::getTypeNameOfGroup(
675 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
677 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
686 #define OUT out << tabStr << commentStr
687 #define PUSHTAB tabStr += "\t"
688 #define POPTAB tabStr.resize(tabStr.size() - 1)
689 #define PUSHCOMMENT commentStr += "# "
690 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
692 void ConfigurationManager::dumpMacroMakerModeFhicl()
694 std::string filepath =
695 __ENV__(
"USER_DATA") + std::string(
"/") +
"MacroMakerModeConfigurations";
696 mkdir(filepath.c_str(), 0755);
697 filepath +=
"/MacroMakerModeFhiclDump.fcl";
698 __COUT__ <<
"dumpMacroMakerModeFhicl: " << filepath << __E__;
704 std::string tabStr =
"";
705 std::string commentStr =
"";
707 out.open(filepath, std::fstream::out | std::fstream::trunc);
710 __SS__ <<
"Failed to open MacroMaker mode fcl file for configuration dump: "
711 << filepath << __E__;
717 std::vector<std::pair<std::string, ConfigurationTree>> fes =
718 getNode(
"FEInterfaceTable").getChildren();
723 if(!fe.second.getNode(
"Status").getValue<
bool>())
728 OUT << fe.first <<
": {" << __E__;
733 OUT <<
"FEInterfacePluginName"
735 <<
"\"" << fe.second.getNode(
"FEInterfacePluginName").getValueAsString()
738 recursiveTreeToFhicl(
739 fe.second.getNode(
"LinkToFETypeTable"), out, tabStr, commentStr);
742 OUT <<
"} //end " << fe.first << __E__ << __E__;
748 __COUT_ERR__ <<
"Failed to complete MacroMaker mode fcl "
749 "file configuration dump due to error."
768 std::string& tabStr ,
769 std::string& commentStr ,
774 __COUT__ << __COUT_HDR_P__ <<
"Depth limit reached. Ending recursion." << __E__;
778 __COUT__ << __COUT_HDR_P__ <<
"Adding tree record '" << node.getValueAsString()
779 <<
"' fields..." << __E__;
781 if(depth == (
unsigned int)-1)
785 if(node.isLinkNode())
787 if(node.isDisconnected())
789 __COUT__ << node.getFieldName() <<
" field is a disconnected link." << __E__;
793 OUT << node.getFieldName() <<
"_"
794 << node.getValueAsString(
true ) <<
" \t{" << __E__;
798 if(node.isGroupLinkNode())
801 std::vector<std::pair<std::string, ConfigurationTree>> children =
803 for(
auto& child : children)
804 recursiveTreeToFhicl(child.second, out, tabStr, commentStr, depth - 1);
813 OUT << node.getValueAsString() <<
": \t{" << __E__;
817 std::vector<std::pair<std::string, ConfigurationTree>> fields =
821 for(
unsigned int i = 0; i < fields.size() - 3; ++i)
823 __COUT__ << fields[i].first << __E__;
825 if(fields[i].second.isLinkNode())
827 recursiveTreeToFhicl(
828 fields[i].second, out, tabStr, commentStr, depth - 1);
833 OUT << fields[i].second.getFieldName() <<
": \t";
834 if(fields[i].second.isValueNumberDataType())
835 OUT << fields[i].second.getValueAsString() << __E__;
837 OUT <<
"\"" << fields[i].second.getValueAsString() <<
"\"" << __E__;
843 OUT <<
"} //end " << node.getValueAsString() <<
" record" << __E__;
846 if(node.isLinkNode())
849 OUT <<
"} //end " << node.getValueAsString(
true )
850 <<
" link record" << __E__;
858 void ConfigurationManager::dumpActiveConfiguration(
const std::string& filePath,
859 const std::string& dumpType)
861 time_t rawtime = time(0);
862 __COUT__ <<
"filePath = " << filePath << __E__;
863 __COUT__ <<
"dumpType = " << dumpType << __E__;
866 fs.open(filePath, std::fstream::out | std::fstream::trunc);
877 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath
878 <<
" could not be opened!" << __E__;
879 __COUT_ERR__ << ss.str();
885 (*out) <<
"#################################" << __E__;
886 (*out) <<
"This is an ots configuration dump.\n\n" << __E__;
887 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t"
888 << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
889 (*out) <<
"\nOriginal location of dump: \t" << filePath << __E__;
890 (*out) <<
"Type of dump: \t" << dumpType << __E__;
891 (*out) <<
"Linux time for dump: \t" << rawtime << __E__;
894 struct tm* timeinfo = localtime(&rawtime);
896 strftime(buffer, 100,
"%c %Z", timeinfo);
897 (*out) <<
"Display time for dump: \t" << buffer << __E__;
908 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
909 cfgMgr->getActiveTableGroups();
911 (*out) <<
"\n\n************************" << __E__;
912 (*out) <<
"Active Groups:" << __E__;
913 for(
auto& group : activeGroups)
915 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
916 << group.second.second <<
")" << __E__;
922 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
924 (*out) <<
"\n\n************************" << __E__;
925 (*out) <<
"Active Tables:" << __E__;
926 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
929 for(
auto& table : activeTables)
931 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
937 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
938 cfgMgr->getActiveTableGroups();
939 (*out) <<
"\n\n************************" << __E__;
940 (*out) <<
"Active Group Members:" << __E__;
942 for(
auto& group : activeGroups)
944 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
945 << group.second.second <<
")" << __E__;
947 if(group.second.first ==
"")
950 <<
"Empty group name. Assuming no active group." << __E__;
955 std::map<std::string , std::string > groupAliases;
956 std::string groupComment;
957 std::string groupAuthor;
958 std::string groupCreateTime;
959 time_t groupCreateTime_t;
961 cfgMgr->loadTableGroup(group.second.first,
974 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
975 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
977 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
978 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t) << __E__;
979 (*out) <<
"\t\tGroup Aliases: \t" << StringMacros::mapToString(groupAliases)
982 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
983 tableCount += memberMap.size();
986 for(
auto& member : memberMap)
988 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v" << member.second
992 (*out) <<
"\nActive Group Members total table count = " << tableCount << __E__;
997 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
999 (*out) <<
"\n\n************************" << __E__;
1000 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
1003 for(
auto& table : activeTables)
1005 (*out) <<
"\n\n=============================================================="
1008 (*out) <<
"=================================================================="
1011 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
1013 cfgMgr->nameToTableMap_.find(table.first)->second->print(*out);
1017 if(dumpType ==
"GroupKeys")
1019 localDumpActiveGroups(
this, out);
1021 else if(dumpType ==
"TableVersions")
1023 localDumpActiveTables(
this, out);
1025 else if(dumpType ==
"GroupKeysAndTableVersions")
1027 localDumpActiveGroups(
this, out);
1028 localDumpActiveTables(
this, out);
1030 else if(dumpType ==
"All")
1032 localDumpActiveGroups(
this, out);
1033 localDumpActiveGroupMembers(
this, out);
1034 localDumpActiveTables(
this, out);
1035 localDumpActiveTableContents(
this, out);
1040 <<
"Invalid dump type '" << dumpType
1041 <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
1049 <<
"GroupsKeysAndTableVersions"
1054 "\n\nPlease change the State Machine configuration to a valid dump type."
1069 void ConfigurationManager::loadMemberMap(
1070 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap,
1071 std::string* accumulateWarnings )
1076 for(
auto& memberPair : memberMap)
1088 tmpConfigBasePtr = 0;
1089 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1090 tmpConfigBasePtr = nameToTableMap_[memberPair.first];
1092 std::string getError =
"";
1095 theInterface_->get(tmpConfigBasePtr,
1104 catch(
const std::runtime_error& e)
1106 __SS__ <<
"Failed to load member table '" << memberPair.first
1107 <<
"' - here is the error: \n\n"
1108 << e.what() << __E__;
1110 ss <<
"\nIf the table '" << memberPair.first
1111 <<
"' should not exist, then please remove it from the group. If it "
1112 "should exist, then it "
1113 <<
"seems to have a problem; use the Table Editor to fix the table "
1115 "edit the table content to match the table definition."
1119 if(accumulateWarnings)
1120 getError = ss.str();
1126 __SS__ <<
"Failed to load member table '" << memberPair.first
1127 <<
"' due to unknown error!" << __E__;
1129 ss <<
"\nIf the table '" << memberPair.first
1130 <<
"' should not exist, then please remove it from the group. If it "
1131 "should exist, then it "
1132 <<
"seems to have a problem; use the Table Editor to fix the table "
1134 "edit the table content to match the table definition."
1138 if(accumulateWarnings)
1139 getError = ss.str();
1145 if(!tmpConfigBasePtr)
1147 __SS__ <<
"Null pointer returned for table '" << memberPair.first
1148 <<
".' Was the table info deleted?" << __E__;
1149 __COUT_ERR__ << ss.str();
1151 nameToTableMap_.erase(memberPair.first);
1152 if(accumulateWarnings)
1154 *accumulateWarnings += ss.str();
1161 nameToTableMap_[memberPair.first] = tmpConfigBasePtr;
1162 if(nameToTableMap_[memberPair.first]->getViewP())
1167 if(accumulateWarnings && getError !=
"")
1169 __SS__ <<
"Error caught during '" << memberPair.first
1170 <<
"' table retrieval: \n"
1171 << getError << __E__;
1172 __COUT_ERR__ << ss.str();
1173 *accumulateWarnings += ss.str();
1178 __SS__ << nameToTableMap_[memberPair.first]->getTableName()
1179 <<
": View version not activated properly!";
1201 void ConfigurationManager::loadTableGroup(
1202 const std::string& groupName,
1205 std::map<std::string /*table name*/, TableVersion>* groupMembers,
1207 std::string* accumulatedTreeErrors,
1208 std::string* groupComment,
1209 std::string* groupAuthor,
1210 std::string* groupCreateTime,
1211 bool doNotLoadMember ,
1212 std::string* groupTypeString,
1213 std::map<std::string /*name*/, std::string /*alias*/>* groupAliases,
1214 bool onlyLoadIfBackboneOrContext )
try
1218 *groupComment =
"NO COMMENT FOUND";
1220 *groupAuthor =
"NO AUTHOR FOUND";
1222 *groupCreateTime =
"0";
1224 *groupTypeString =
"UNKNOWN";
1255 theInterface_->getTableGroupMembers(
1256 TableGroupKey::getFullGroupString(groupName, groupKey),
1258 std::map<std::string , std::string > aliasMap;
1261 progressBar->step();
1264 auto metaTablePair = memberMap.find(groupMetadataTable_.getTableName());
1265 if(metaTablePair != memberMap.end())
1269 memberMap.erase(metaTablePair);
1272 while(groupMetadataTable_.getView().getNumberOfRows())
1273 groupMetadataTable_.getViewP()->deleteRow(0);
1278 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
1280 catch(
const std::runtime_error& e)
1282 __COUT_WARN__ <<
"Ignoring metadata error: " << e.what() << __E__;
1286 __COUT_WARN__ <<
"Ignoring unknown metadata error. " << __E__;
1290 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
1293 *groupMembers = memberMap;
1295 groupMetadataTable_.print();
1296 __SS__ <<
"Ignoring that groupMetadataTable_ has wrong number of rows! Must "
1297 "be 1. Going with anonymous defaults."
1299 __COUT_ERR__ <<
"\n" << ss.str();
1302 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
1303 groupMetadataTable_.getViewP()->deleteRow(0);
1304 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
1305 groupMetadataTable_.getViewP()->addRow();
1308 *groupComment =
"NO COMMENT FOUND";
1310 *groupAuthor =
"NO AUTHOR FOUND";
1312 *groupCreateTime =
"0";
1317 groupType = getTypeOfGroup(memberMap);
1318 *groupTypeString = convertGroupTypeIdToName(groupType);
1326 StringMacros::getMapFromString(groupMetadataTable_.getView().getValueAsString(
1327 0, ConfigurationManager::METADATA_COL_ALIASES),
1330 *groupAliases = aliasMap;
1332 *groupComment = groupMetadataTable_.getView().getValueAsString(
1333 0, ConfigurationManager::METADATA_COL_COMMENT);
1335 *groupAuthor = groupMetadataTable_.getView().getValueAsString(
1336 0, ConfigurationManager::METADATA_COL_AUTHOR);
1338 *groupCreateTime = groupMetadataTable_.getView().getValueAsString(
1339 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
1343 std::map<std::string , std::map<std::string ,
TableVersion>>
1347 __COUTV__(StringMacros::mapToString(aliasMap));
1348 versionAliases = ConfigurationManager::getVersionAliases();
1349 __COUTV__(StringMacros::mapToString(versionAliases));
1353 for(
auto& aliasPair : aliasMap)
1356 if(memberMap.find(aliasPair.first) != memberMap.end())
1358 __COUT__ <<
"Group member '" << aliasPair.first
1359 <<
"' was found in group member map!" << __E__;
1360 __COUT__ <<
"Looking for alias '" << aliasPair.second
1361 <<
"' in active version aliases..." << __E__;
1363 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
1364 versionAliases[aliasPair.first].find(aliasPair.second) ==
1365 versionAliases[aliasPair.first].end())
1367 __SS__ <<
"Group '" << groupName <<
"(" << groupKey
1368 <<
")' requires table version alias '" << aliasPair.first
1369 <<
":" << aliasPair.second
1370 <<
",' which was not found in the active Backbone!"
1375 memberMap[aliasPair.first] =
1376 versionAliases[aliasPair.first][aliasPair.second];
1377 __COUT__ <<
"Version alias translated to " << aliasPair.first
1385 *groupMembers = memberMap;
1388 progressBar->step();
1397 groupType = getTypeOfGroup(memberMap);
1398 *groupTypeString = convertGroupTypeIdToName(groupType);
1417 if(!groupTypeString)
1418 groupType = getTypeOfGroup(memberMap);
1420 if(onlyLoadIfBackboneOrContext &&
1421 groupType != ConfigurationManager::CONTEXT_TYPE &&
1422 groupType != ConfigurationManager::BACKBONE_TYPE)
1424 __COUT_WARN__ <<
"Not loading group because it is not of type Context or "
1425 "Backbone (it is type '"
1426 << convertGroupTypeIdToName(groupType) <<
"')." << __E__;
1431 __COUT__ <<
"------------------------------------- init start \t [for all "
1433 << convertGroupTypeIdToName(groupType) <<
" group '" << groupName
1434 <<
"(" << groupKey <<
")"
1439 std::string groupToDeactivate =
1440 groupType == ConfigurationManager::CONTEXT_TYPE
1441 ? theContextTableGroup_
1442 : (groupType == ConfigurationManager::BACKBONE_TYPE
1443 ? theBackboneTableGroup_
1444 : (groupType == ConfigurationManager::ITERATE_TYPE
1445 ? theIterateTableGroup_
1446 : theConfigurationTableGroup_));
1449 if(groupToDeactivate !=
"")
1453 destroyTableGroup(groupToDeactivate,
true);
1474 progressBar->step();
1478 loadMemberMap(memberMap, accumulatedTreeErrors);
1483 progressBar->step();
1485 if(accumulatedTreeErrors)
1489 getChildren(&memberMap, accumulatedTreeErrors);
1490 if(*accumulatedTreeErrors !=
"")
1492 __COUT_ERR__ <<
"Errors detected while loading Table Group: " << groupName
1493 <<
"(" << groupKey <<
"). Aborting."
1495 << *accumulatedTreeErrors << __E__;
1501 progressBar->step();
1506 for(
auto& memberPair : memberMap)
1509 if(ConfigurationInterface::isVersionTrackingEnabled() &&
1510 memberPair.second.isScratchVersion())
1512 __SS__ <<
"Error while activating member Table '"
1513 << nameToTableMap_[memberPair.first]->getTableName() <<
"-v"
1514 << memberPair.second <<
" for Table Group '" << groupName
1516 <<
")'. When version tracking is enabled, Scratch views"
1517 <<
" are not allowed! Please only use unique, persistent "
1518 "versions when version tracking is enabled."
1520 __COUT_ERR__ <<
"\n" << ss.str();
1524 if(accumulatedTreeErrors)
1526 __COUTV__(memberPair.first);
1527 __COUTV__(accumulatedTreeErrors);
1534 nameToTableMap_[memberPair.first]->init(
this);
1536 catch(std::runtime_error& e)
1538 __SS__ <<
"Error detected calling "
1539 << nameToTableMap_[memberPair.first]->getTableName()
1540 <<
".init()!\n\n " << e.what() << __E__;
1544 if(accumulatedTreeErrors)
1546 *accumulatedTreeErrors += ss.str();
1553 __SS__ <<
"Unknown Error detected calling "
1554 << nameToTableMap_[memberPair.first]->getTableName()
1555 <<
".init()!\n\n " << __E__;
1557 if(accumulatedTreeErrors)
1559 *accumulatedTreeErrors += ss.str();
1562 __COUT_WARN__ << ss.str();
1567 progressBar->step();
1576 if(groupType == ConfigurationManager::CONTEXT_TYPE)
1582 theContextTableGroup_ = groupName;
1583 theContextTableGroupKey_ =
1584 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1586 else if(groupType == ConfigurationManager::BACKBONE_TYPE)
1591 theBackboneTableGroup_ = groupName;
1592 theBackboneTableGroupKey_ =
1593 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1595 else if(groupType == ConfigurationManager::ITERATE_TYPE)
1601 theIterateTableGroup_ = groupName;
1602 theIterateTableGroupKey_ =
1603 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1610 theConfigurationTableGroup_ = groupName;
1611 theConfigurationTableGroupKey_ =
1612 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1617 progressBar->step();
1620 __COUT__ <<
"------------------------------------- init complete \t [for all "
1622 << convertGroupTypeIdToName(groupType) <<
" group '" << groupName
1623 <<
"(" << groupKey <<
")"
1629 lastFailedGroupLoad_[convertGroupTypeIdToName(groupType)] =
1630 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1636 catch(
const std::runtime_error& e)
1638 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
1639 << groupKey <<
")': \n"
1640 << e.what() << __E__;
1641 __COUT_WARN__ << ss.str();
1642 if(accumulatedTreeErrors)
1643 *accumulatedTreeErrors += ss.str();
1649 __SS__ <<
"An unknown error occurred while loading table group '" << groupName
1650 <<
"(" << groupKey <<
")." << __E__;
1651 __COUT_WARN__ << ss.str();
1652 if(accumulatedTreeErrors)
1653 *accumulatedTreeErrors += ss.str();
1664 lastFailedGroupLoad_[ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN] =
1665 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1671 catch(
const std::runtime_error& e)
1673 __SS__ <<
"Error occurred while loading table group: " << e.what() << __E__;
1674 __COUT_WARN__ << ss.str();
1675 if(accumulatedTreeErrors)
1676 *accumulatedTreeErrors += ss.str();
1682 __SS__ <<
"An unknown error occurred while loading table group." << __E__;
1683 __COUT_WARN__ << ss.str();
1684 if(accumulatedTreeErrors)
1685 *accumulatedTreeErrors += ss.str();
1697 std::map<std::string, std::pair<std::string, TableGroupKey>>
1698 ConfigurationManager::getActiveTableGroups(
void)
const
1701 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
1703 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1704 std::pair<std::string, TableGroupKey>(
1705 theContextTableGroup_,
1706 theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
1707 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
1708 std::pair<std::string, TableGroupKey>(
1709 theBackboneTableGroup_,
1710 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
1711 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
1712 std::pair<std::string, TableGroupKey>(
1713 theIterateTableGroup_,
1714 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
1715 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1716 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_,
1717 theConfigurationTableGroupKey_
1718 ? *theConfigurationTableGroupKey_
1724 const std::string& ConfigurationManager::getActiveGroupName(
const std::string& type)
const
1726 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1727 return theConfigurationTableGroup_;
1728 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1729 return theContextTableGroup_;
1730 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1731 return theBackboneTableGroup_;
1732 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1733 return theIterateTableGroup_;
1735 __SS__ <<
"Invalid type requested '" << type <<
"'" << __E__;
1736 __COUT_ERR__ << ss.str();
1741 TableGroupKey ConfigurationManager::getActiveGroupKey(
const std::string& type)
const
1743 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1744 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_
1746 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1747 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
1748 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1749 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
1750 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1751 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
1753 __SS__ <<
"Invalid type requested '" << type <<
"'" << __E__;
1754 __COUT_ERR__ << ss.str();
1760 const std::string& contextUID,
const std::string& applicationUID)
const
1762 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1768 const std::string& contextUID,
const std::string& applicationUID)
const
1770 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1771 contextUID +
"/LinkToApplicationTable/" + applicationUID);
1776 const std::string& contextUID,
const std::string& applicationUID)
const
1778 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1779 contextUID +
"/LinkToApplicationTable/" + applicationUID +
1780 "/LinkToSupervisorTable");
1785 bool doNotThrowOnBrokenUIDLinks)
const
1790 if(nodeString.length() < 1)
1792 __SS__ << (
"Invalid empty node name") << __E__;
1793 __COUT_ERR__ << ss.str();
1798 unsigned int startingIndex = 0;
1799 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
1802 std::string nodeName = nodeString.substr(
1803 startingIndex, nodeString.find(
'/', startingIndex) - startingIndex);
1805 if(nodeName.length() < 1)
1815 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
1821 if(childPath.length() > 1)
1822 return configTree.getNode(childPath, doNotThrowOnBrokenUIDLinks);
1829 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree& node,
1830 const std::string& startPath)
const
1834 std::string path =
"/";
1844 std::vector<std::pair<std::string, ConfigurationTree>> ConfigurationManager::getChildren(
1845 std::map<std::string, TableVersion>* memberMap,
1846 std::string* accumulatedTreeErrors)
const
1848 std::vector<std::pair<std::string, ConfigurationTree>> retMap;
1853 if(!memberMap || memberMap->empty())
1855 for(
auto& configPair : nameToTableMap_)
1860 if(configPair.second->isActive())
1864 if(accumulatedTreeErrors)
1868 std::vector<std::pair<std::string, ConfigurationTree>>
1869 newNodeChildren = newNode.getChildren();
1870 for(
auto& newNodeChild : newNodeChildren)
1872 std::vector<std::pair<std::string, ConfigurationTree>>
1873 twoDeepChildren = newNodeChild.second.getChildren();
1875 for(
auto& twoDeepChild : twoDeepChildren)
1880 if(twoDeepChild.second.isLinkNode() &&
1881 twoDeepChild.second.isDisconnected() &&
1882 twoDeepChild.second.getDisconnectedTableName() !=
1883 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1884 *accumulatedTreeErrors +=
1885 "\n\nAt node '" + configPair.first +
1886 "' with entry UID '" + newNodeChild.first +
1887 "' there is a disconnected child node at link "
1889 twoDeepChild.first +
"'" +
1890 " that points to table named '" +
1891 twoDeepChild.second.getDisconnectedTableName() +
1896 catch(std::runtime_error& e)
1898 *accumulatedTreeErrors +=
1899 "\n\nAt node '" + configPair.first +
1900 "' error detected descending through children:\n" + e.what();
1905 std::pair<std::string, ConfigurationTree>(configPair.first, newNode));
1913 for(
auto& memberPair : *memberMap)
1915 auto mapIt = nameToTableMap_.find(memberPair.first);
1918 if(mapIt == nameToTableMap_.end())
1920 __SS__ <<
"Get Children with member map requires a child '"
1921 << memberPair.first <<
"' that is not present!" << __E__;
1924 if(!(*mapIt).second->isActive())
1926 __SS__ <<
"Get Children with member map requires a child '"
1927 << memberPair.first <<
"' that is not active!" << __E__;
1931 catch(
const std::runtime_error& e)
1933 if(accumulatedTreeErrors)
1935 *accumulatedTreeErrors += e.what();
1936 __COUT_ERR__ <<
"Skipping " << memberPair.first
1937 <<
" since the table "
1946 if(accumulatedTreeErrors)
1950 std::vector<std::pair<std::string, ConfigurationTree>>
1951 newNodeChildren = newNode.getChildren();
1952 for(
auto& newNodeChild : newNodeChildren)
1954 std::vector<std::pair<std::string, ConfigurationTree>>
1955 twoDeepChildren = newNodeChild.second.getChildren();
1957 for(
auto& twoDeepChild : twoDeepChildren)
1961 if(twoDeepChild.second.isLinkNode() &&
1962 twoDeepChild.second.isDisconnected() &&
1963 twoDeepChild.second.getDisconnectedTableName() !=
1964 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1966 *accumulatedTreeErrors +=
1967 "\n\nAt node '" + memberPair.first +
1968 "' with entry UID '" + newNodeChild.first +
1969 "' there is a disconnected child node at link column "
1971 twoDeepChild.first +
"'" +
1972 " that points to table named '" +
1973 twoDeepChild.second.getDisconnectedTableName() +
1980 for(
auto& searchMemberPair : *memberMap)
1981 if(searchMemberPair.first ==
1982 twoDeepChild.second.getDisconnectedTableName())
1990 <<
"Note: It may be safe to ignore this "
1991 <<
"error since the link's target table "
1992 << twoDeepChild.second.getDisconnectedTableName()
1993 <<
" is not a member of this group (and may not "
1995 <<
"loaded yet)" << __E__;
1996 *accumulatedTreeErrors += ss.str();
2002 catch(std::runtime_error& e)
2004 __SS__ <<
"At node '" << memberPair.first
2005 <<
"' error detected descending through children:\n"
2006 << e.what() << __E__;
2007 *accumulatedTreeErrors += ss.str();
2012 std::pair<std::string, ConfigurationTree>(memberPair.first, newNode));
2024 const TableBase* ConfigurationManager::getTableByName(
const std::string& tableName)
const
2026 std::map<std::string, TableBase*>::const_iterator it;
2027 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
2029 __SS__ <<
"\n\nCan not find configuration named '" << tableName
2030 <<
"'\n\n\n\nYou need to load the configuration before it can be used."
2031 <<
" It probably is missing from the member list of the Table "
2032 "Group that was loaded.\n"
2033 <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
2035 <<
"\n\t StartOTS.sh --wiz"
2039 ss << __E__ << StringMacros::stackTrace() << __E__;
2053 TableGroupKey ConfigurationManager::loadConfigurationBackbone()
2055 if(!theBackboneTableGroupKey_)
2057 __COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently."
2063 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
2065 return *theBackboneTableGroupKey_;
2081 std::pair<std::string, TableGroupKey> ConfigurationManager::getTableGroupFromAlias(
2082 std::string systemAlias,
ProgressBar* progressBar)
2092 progressBar->step();
2094 if(systemAlias.find(
"GROUP:") == 0)
2097 progressBar->step();
2099 unsigned int i = strlen(
"GROUP:");
2100 unsigned int j = systemAlias.find(
':', i);
2103 progressBar->step();
2105 return std::pair<std::string, TableGroupKey>(
2106 systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
2108 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
2111 loadConfigurationBackbone();
2114 progressBar->step();
2120 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getNode(systemAlias);
2123 progressBar->step();
2125 return std::pair<std::string, TableGroupKey>(
2126 entry.getNode(
"GroupName").getValueAsString(),
2127 TableGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
2136 progressBar->step();
2138 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
2142 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
2143 ConfigurationManager::getActiveGroupAliases(
void)
2145 restoreActiveTableGroups();
2149 std::map<std::string ,
2153 std::vector<std::pair<std::string, ConfigurationTree>> entries =
2154 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getChildren();
2155 for(
auto& entryPair : entries)
2157 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(
2158 entryPair.second.getNode(
"GroupName").getValueAsString(),
2159 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
2167 std::map<std::string ,
2169 ConfigurationManager::getVersionAliases(
void)
const
2173 std::map<std::string ,
2177 std::map<std::string, TableVersion> activeVersions = getActiveVersions();
2178 std::string versionAliasesTableName =
2179 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
2180 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
2182 __SS__ <<
"Active version of VersionAliases missing!"
2183 <<
"Make sure you have a valid active Backbone Group." << __E__;
2184 __COUT_WARN__ <<
"\n" << ss.str();
2188 __COUT__ <<
"activeVersions[\"" << versionAliasesTableName
2189 <<
"\"]=" << activeVersions[versionAliasesTableName] << __E__;
2191 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
2192 getNode(versionAliasesTableName).getChildren();
2197 std::string tableName, versionAlias;
2198 for(
auto& aliasNodePair : aliasNodePairs)
2200 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
2201 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
2203 if(retMap.find(tableName) != retMap.end() &&
2204 retMap[tableName].find(versionAlias) != retMap[tableName].end())
2209 retMap[tableName][versionAlias] =
2210 TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
2218 std::map<std::string, TableVersion> ConfigurationManager::getActiveVersions(
void)
const
2220 std::map<std::string, TableVersion> retMap;
2221 for(
auto& config : nameToTableMap_)
2226 if(config.second && config.second->isActive())
2230 retMap.insert(std::pair<std::string, TableVersion>(
2231 config.first, config.second->getViewVersion()));
2260 std::shared_ptr<TableGroupKey> ConfigurationManager::makeTheTableGroupKey(
2263 if(theConfigurationTableGroupKey_)
2265 if(*theConfigurationTableGroupKey_ != key)
2266 destroyTableGroup();
2268 return theConfigurationTableGroupKey_;
2270 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
2273 const std::set<std::string>& ConfigurationManager::getContextMemberNames()
2275 return ConfigurationManager::contextMemberNames_;
2278 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
2280 return ConfigurationManager::backboneMemberNames_;
2283 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
2285 return ConfigurationManager::iterateMemberNames_;
2289 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
2291 __COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
2296 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
2325 theInterface_->get(table,
2326 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
2332 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
2334 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2335 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2338 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2343 auto colMap = view->getColumnNamesMap();
2345 view->setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
2346 view->setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
2347 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2348 view->setValue(
"1", 0, colMap[
"Status"]);
2350 __COUT__ <<
"Done adding context record..." << __E__;
2360 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
2366 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
2368 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2369 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2372 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2377 auto colMap = view->getColumnNamesMap();
2379 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2380 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
2381 view->setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
2382 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
2383 view->setValue(
"1", 0, colMap[
"Status"]);
2385 __COUT__ <<
"Done adding application record..." << __E__;
2392 theInterface_->get(table,
2393 "FESupervisorTable",
2399 nameToTableMap_[
"FESupervisorTable"] = table;
2401 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2402 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2405 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2410 auto colMap = view->getColumnNamesMap();
2412 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
2413 view->setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
2415 "MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
2417 __COUT__ <<
"Done adding supervisor record..." << __E__;
2422 recursiveInitFromFhiclPSet(
"FEInterfaceTable" ,
2425 "MacroMakerFESupervisorInterfaces" ,
2429 for(
auto& table : nameToTableMap_)
2431 table.second->getViewP()->init();
2437 __COUT__ <<
"================================================" << __E__;
2438 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
2439 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
2441 auto sups = getNode(
"FESupervisorTable").getChildrenNames();
2442 __COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
2443 auto fes = getNode(
"FEInterfaceTable").getChildrenNames();
2444 __COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
2446 auto a = getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
2447 __COUTV__(a.getValueAsString());
2449 auto b = a.getNode(
"MacroMakerFEContext");
2450 __COUTV__(b.getValueAsString());
2452 auto c = b.getNode(
"LinkToApplicationTable");
2453 __COUTV__(c.getValueAsString());
2455 auto d = c.getNode(
"MacroMakerFESupervisor");
2456 __COUTV__(d.getValueAsString());
2458 auto e = d.getNode(
"LinkToSupervisorTable");
2459 __COUTV__(e.getValueAsString());
2461 auto f = e.getNode(
"LinkToFEInterfaceTable");
2462 __COUTV__(f.getValueAsString());
2464 auto z = f.getChildrenNames();
2465 __COUTV__(StringMacros::vectorToString(z));
2466 __COUTV__(z.size());
2467 auto y = f.getChildrenNames(
false ,
true );
2468 __COUTV__(StringMacros::vectorToString(y));
2469 __COUTV__(y.size());
2470 auto x = f.getChildrenNames(
true ,
true );
2471 __COUTV__(StringMacros::vectorToString(x));
2472 __COUTV__(x.size());
2474 auto g = f.getNode(
"dtc0");
2475 __COUTV__(g.getValueAsString());
2476 auto h = f.getNode(
"interface0");
2477 __COUTV__(h.getValueAsString());
2480 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
2482 "MacroMakerFEContext/LinkToApplicationTable/"
2483 "MacroMakerFESupervisor/LinkToSupervisorTable")
2484 .getNode(
"LinkToFEInterfaceTable")
2485 .getChildrenNames(
true ,
true );
2486 __COUTV__(fes.size());
2487 __COUTV__(StringMacros::vectorToString(fes));
2498 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
2499 const fhicl::ParameterSet& pset,
2500 const std::string& recordName,
2501 const std::string& groupName,
2502 const std::string& groupLinkIndex)
2504 __COUT__ << __COUT_HDR_P__ <<
"Adding table '" << tableName <<
"' record(s)..."
2511 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
2513 __COUT__ <<
"Table not found, so making '" << tableName <<
"'instance..."
2515 theInterface_->get(table,
2522 nameToTableMap_[tableName] = table;
2523 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2527 __COUT__ <<
"Existing table found, so using '" << tableName <<
"'instance..."
2529 table = nameToTableMap_[tableName];
2532 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2535 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2538 if(recordName !=
"")
2546 __COUTV__(recordName);
2549 unsigned int r = view->addRow();
2550 auto colMap = view->getColumnNamesMap();
2553 view->setValue(recordName, r, view->getColUID());
2556 view->setValue(
"1", r, view->getColStatus());
2560 __COUT__ <<
"No status column to set for '" << recordName <<
"'" << __E__;
2565 int groupIDCol = view->getColLinkGroupID(groupLinkIndex);
2566 __COUT__ <<
"Setting group ID for group link ID '" << groupLinkIndex
2567 <<
"' at column " << groupIDCol <<
" to '" << groupName <<
".'"
2570 view->setValue(groupName, r, groupIDCol);
2574 auto names = pset.get_names();
2575 for(
const auto& colName : names)
2577 if(!pset.is_key_to_atom(colName))
2580 auto colIt = colMap.find(colName);
2581 if(colIt == colMap.end())
2583 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName
2584 <<
"' in table '" << tableName <<
"' was not found in columns."
2585 <<
"\n\nHere are the existing column names:\n";
2587 for(
const auto& col : colMap)
2588 ss <<
"\n" << ++i <<
".\t" << col.first;
2592 const std::string value = pset.get<std::string>(colName);
2593 __COUT__ <<
"Setting '" << recordName <<
"' parameter at column "
2594 << colIt->second <<
", '" << colName <<
"'\t = " << value
2596 view->setValueAsString(value, r, colIt->second);
2600 for(
const auto& linkName : names)
2602 if(pset.is_key_to_atom(linkName))
2605 __COUTV__(linkName);
2608 unsigned int c = linkName.size() - 1;
2610 if(linkName[c] ==
'_')
2615 __SS__ <<
"Illegal link name '" << linkName
2616 <<
"' found. The format must be <Column name>_<Target table "
2617 "name>,.. for example '"
2618 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'"
2622 std::string colName = linkName.substr(0, c);
2625 auto colIt = colMap.find(colName);
2626 if(colIt == colMap.end())
2628 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName
2629 <<
"' in table '" << tableName <<
"' was not found in columns."
2630 <<
"\n\nHere are the existing column names:\n";
2632 for(
const auto& col : colMap)
2633 ss <<
"\n" << i <<
".\t" << col.first << __E__;
2638 std::pair<
unsigned int ,
unsigned int >
2641 view->getChildLink(colIt->second, isGroupLink, linkPair);
2647 std::string linkTableName = linkName.substr(c + 1);
2648 __COUTV__(linkTableName);
2650 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
2651 auto linkRecords = linkPset.get_pset_names();
2652 if(!isGroupLink && linkRecords.size() > 1)
2654 __SS__ <<
"A Unique Link can only point to one record. "
2655 <<
"The specified link '" << colName <<
"' of record '"
2656 << recordName <<
"' in table '" << tableName <<
"' has "
2657 << linkRecords.size() <<
" children records specified. "
2662 if(linkRecords.size() == 0)
2664 __COUT__ <<
"No child records, so leaving link disconnected."
2669 __COUT__ <<
"Setting Link at columns [" << linkPair.first <<
","
2670 << linkPair.second <<
"]" << __E__;
2671 view->setValue(linkTableName, r, linkPair.first);
2675 __COUT__ <<
"Setting up Unique link to " << linkRecords[0] << __E__;
2677 view->setValue(linkRecords[0], r, linkPair.second);
2679 recursiveInitFromFhiclPSet(
2681 linkPset.get<fhicl::ParameterSet>(
2690 std::string childLinkIndex =
2691 view->getColumnInfo(linkPair.first).getChildLinkIndex();
2692 std::string groupName = recordName +
"Group";
2694 view->setValue(groupName, r, linkPair.second);
2696 for(
const auto& groupRecord : linkRecords)
2698 __COUT__ <<
"Setting '" << childLinkIndex <<
"' Group link to '"
2699 << groupName <<
"' record '" << groupRecord <<
"'"
2702 recursiveInitFromFhiclPSet(
2704 linkPset.get<fhicl::ParameterSet>(
2714 else if(groupName !=
"")
2718 __COUTV__(groupName);
2719 auto psets = pset.get_pset_names();
2720 for(
const auto& ps : psets)
2723 recursiveInitFromFhiclPSet(
2725 pset.get<fhicl::ParameterSet>(ps) ,
2735 __SS__ <<
"Illegal recursive parameters!" << __E__;
2740 __COUT__ << __COUT_HDR_P__ <<
"Done adding table '" << tableName <<
"' record(s)..."
2746 bool ConfigurationManager::isOwnerFirstAppInContext()
2748 __COUT__ <<
"Checking if owner is first App in Context." << __E__;
2749 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
2752 __COUTV__(ownerContextUID_);
2753 __COUTV__(ownerAppUID_);
2755 auto contextChildren =
2756 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" + ownerContextUID_)
2757 .getChildrenNames();
2759 bool isFirstAppInContext =
2760 contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
2762 __COUTV__(isFirstAppInContext);
2764 return isFirstAppInContext;