1 #include "otsdaq-core/ConfigurationInterface/ConfigurationManager.h"
2 #include "artdaq/Application/LoadParameterSet.hh"
3 #include "otsdaq-core/ConfigurationInterface/ConfigurationInterface.h"
4 #include "otsdaq-core/ProgressBar/ProgressBar.h"
8 #include "otsdaq-core/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 ((__ENV__(
"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 "CommentDescription",
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)
191 catch(std::runtime_error& e)
193 if(accumulatedErrors)
194 *accumulatedErrors += e.what();
206 void ConfigurationManager::restoreActiveTableGroups(
208 const std::string& pathToActiveGroupsFile,
209 bool onlyLoadIfBackboneOrContext )
211 destroyTableGroup(
"",
true);
214 pathToActiveGroupsFile ==
"" ? ACTIVE_GROUPS_FILENAME : pathToActiveGroupsFile;
215 FILE* fp = fopen(fn.c_str(),
"r");
217 __COUT__ <<
"ACTIVE_GROUPS_FILENAME = " << fn << __E__;
218 __COUT__ <<
"ARTDAQ_DATABASE_URI = " << std::string(__ENV__(
"ARTDAQ_DATABASE_URI"))
223 __COUT_WARN__ <<
"No active groups file found at " << fn << __E__;
232 std::string groupName;
233 std::string errorStr =
"";
238 while(fgets(tmp, 500, fp))
243 sscanf(tmp,
"%s", strVal);
244 for(
unsigned int j = 0; j < strlen(strVal); ++j)
245 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') ||
246 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
247 (strVal[j] >=
'0' && strVal[j] <=
'9')))
250 __COUT_INFO__ <<
"Illegal character found, so skipping!" << __E__;
261 sscanf(tmp,
"%s", strVal);
263 for(
unsigned int j = 0; j < strlen(strVal); ++j)
264 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
268 if(groupName.size() > 3)
270 <<
"Skipping active group with illegal character in name."
282 TableGroupKey::getFullGroupString(groupName,
TableGroupKey(strVal));
286 __COUT__ <<
"illegal group according to TableGroupKey::getFullGroupString..."
310 onlyLoadIfBackboneOrContext
313 catch(std::runtime_error& e)
315 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
316 << groupName <<
"(" << strVal <<
")'" << __E__;
317 ss << e.what() << __E__;
319 errorStr += ss.str();
323 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
324 << groupName <<
"(" << strVal <<
")'" << __E__;
326 errorStr += ss.str();
332 if(throwErrors && errorStr !=
"")
334 __COUT_INFO__ <<
"\n" << ss.str();
337 else if(errorStr !=
"")
338 __COUT_INFO__ <<
"\n" << ss.str();
347 void ConfigurationManager::destroyTableGroup(
const std::string& theGroup,
351 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
352 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
353 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
354 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
356 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
358 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
359 __COUT_ERR__ << ss.str();
363 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
367 __COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
369 __COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
371 __COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
373 __COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
376 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
377 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
380 contextFindIt = contextMemberNames_.find(it->first);
381 backboneFindIt = backboneMemberNames_.find(it->first);
382 iterateFindIt = iterateMemberNames_.find(it->first);
384 ((isContext && contextFindIt != contextMemberNames_.end()) ||
385 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
386 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
387 (!isContext && !isBackbone && contextFindIt == contextMemberNames_.end() &&
388 backboneFindIt == backboneMemberNames_.end() &&
389 iterateFindIt == iterateMemberNames_.end())))
397 it->second->deactivate();
403 nameToTableMap_.erase(it++);
412 theConfigurationTableGroup_ =
"";
413 if(theConfigurationTableGroupKey_ != 0)
415 __COUT__ <<
"Destroying Configuration Key: "
416 << *theConfigurationTableGroupKey_ << __E__;
417 theConfigurationTableGroupKey_.reset();
424 theBackboneTableGroup_ =
"";
425 if(theBackboneTableGroupKey_ != 0)
427 __COUT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_
429 theBackboneTableGroupKey_.reset();
434 theIterateTableGroup_ =
"";
435 if(theIterateTableGroupKey_ != 0)
437 __COUT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_ << __E__;
438 theIterateTableGroupKey_.reset();
443 theContextTableGroup_ =
"";
444 if(theContextTableGroupKey_ != 0)
446 __COUT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_ << __E__;
447 theContextTableGroupKey_.reset();
453 void ConfigurationManager::destroy(
void)
468 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
470 return groupTypeId == CONTEXT_TYPE
471 ? ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT
472 : (groupTypeId == BACKBONE_TYPE
473 ? ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE
474 : (groupTypeId == ITERATE_TYPE
475 ? ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE
476 : ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
486 int ConfigurationManager::getTypeOfGroup(
487 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
489 bool isContext =
true;
490 bool isBackbone =
true;
491 bool isIterate =
true;
493 bool inContext =
false;
494 bool inBackbone =
false;
495 bool inIterate =
false;
496 unsigned int matchCount = 0;
498 for(
auto& memberPair : memberMap)
503 for(
auto& contextMemberString : contextMemberNames_)
504 if(memberPair.first == contextMemberString)
516 __SS__ <<
"This group is an incomplete match to a Context group.\n";
517 __COUT_ERR__ <<
"\n" << ss.str();
518 ss <<
"\nTo be a Context group, the members must exactly match "
519 <<
"the following members:\n";
521 for(
const auto& memberName : contextMemberNames_)
522 ss << ++i <<
". " << memberName <<
"\n";
523 ss <<
"\nThe members are as follows::\n";
525 for(
const auto& memberPairTmp : memberMap)
526 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
533 for(
auto& backboneMemberString : backboneMemberNames_)
534 if(memberPair.first == backboneMemberString)
546 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
547 __COUT_ERR__ <<
"\n" << ss.str();
548 ss <<
"\nTo be a Backbone group, the members must exactly match "
549 <<
"the following members:\n";
551 for(
auto& memberName : backboneMemberNames_)
552 ss << ++i <<
". " << memberName <<
"\n";
553 ss <<
"\nThe members are as follows::\n";
555 for(
const auto& memberPairTmp : memberMap)
556 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
564 for(
auto& iterateMemberString : iterateMemberNames_)
565 if(memberPair.first == iterateMemberString)
577 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
578 __COUT_ERR__ <<
"\n" << ss.str();
579 ss <<
"\nTo be a Iterate group, the members must exactly match "
580 <<
"the following members:\n";
582 for(
auto& memberName : iterateMemberNames_)
583 ss << ++i <<
". " << memberName <<
"\n";
584 ss <<
"\nThe members are as follows::\n";
586 for(
const auto& memberPairTmp : memberMap)
587 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
594 if(isContext && matchCount != contextMemberNames_.size())
596 __SS__ <<
"This group is an incomplete match to a Context group: "
597 <<
" Size=" << matchCount <<
" but should be "
598 << contextMemberNames_.size() << __E__;
599 __COUT_ERR__ <<
"\n" << ss.str();
600 ss <<
"\nThe members currently are...\n";
602 for(
auto& memberPair : memberMap)
603 ss << ++i <<
". " << memberPair.first <<
"\n";
604 ss <<
"\nThe expected Context members are...\n";
606 for(
auto& memberName : contextMemberNames_)
607 ss << ++i <<
". " << memberName <<
"\n";
612 if(isBackbone && matchCount != backboneMemberNames_.size())
614 __SS__ <<
"This group is an incomplete match to a Backbone group: "
615 <<
" Size=" << matchCount <<
" but should be "
616 << backboneMemberNames_.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 Backbone members are...\n";
624 for(
auto& memberName : backboneMemberNames_)
625 ss << ++i <<
". " << memberName <<
"\n";
630 if(isIterate && matchCount != iterateMemberNames_.size())
632 __SS__ <<
"This group is an incomplete match to a Iterate group: "
633 <<
" Size=" << matchCount <<
" but should be "
634 << iterateMemberNames_.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 Iterate members are...\n";
642 for(
auto& memberName : iterateMemberNames_)
643 ss << ++i <<
". " << memberName <<
"\n";
648 return isContext ? CONTEXT_TYPE
649 : (isBackbone ? BACKBONE_TYPE
650 : (isIterate ? ITERATE_TYPE : CONFIGURATION_TYPE));
656 const std::string& ConfigurationManager::getTypeNameOfGroup(
657 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
659 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
668 void ConfigurationManager::dumpActiveConfiguration(
const std::string& filePath,
669 const std::string& dumpType)
671 time_t rawtime = time(0);
672 __COUT__ <<
"filePath = " << filePath << __E__;
673 __COUT__ <<
"dumpType = " << dumpType << __E__;
676 fs.open(filePath, std::fstream::out | std::fstream::trunc);
687 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath
688 <<
" could not be opened!" << __E__;
689 __COUT_ERR__ << ss.str();
695 (*out) <<
"#################################" << __E__;
696 (*out) <<
"This is an ots configuration dump.\n\n" << __E__;
697 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t"
698 << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
699 (*out) <<
"\nOriginal location of dump: \t" << filePath << __E__;
700 (*out) <<
"Type of dump: \t" << dumpType << __E__;
701 (*out) <<
"Linux time for dump: \t" << rawtime << __E__;
704 struct tm* timeinfo = localtime(&rawtime);
706 strftime(buffer, 100,
"%c %Z", timeinfo);
707 (*out) <<
"Display time for dump: \t" << buffer << __E__;
718 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
719 cfgMgr->getActiveTableGroups();
721 (*out) <<
"\n\n************************" << __E__;
722 (*out) <<
"Active Groups:" << __E__;
723 for(
auto& group : activeGroups)
725 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
726 << group.second.second <<
")" << __E__;
732 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
734 (*out) <<
"\n\n************************" << __E__;
735 (*out) <<
"Active Tables:" << __E__;
736 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
739 for(
auto& table : activeTables)
741 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
747 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
748 cfgMgr->getActiveTableGroups();
749 (*out) <<
"\n\n************************" << __E__;
750 (*out) <<
"Active Group Members:" << __E__;
752 for(
auto& group : activeGroups)
754 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
755 << group.second.second <<
")" << __E__;
757 if(group.second.first ==
"")
760 <<
"Empty group name. Assuming no active group." << __E__;
765 std::map<std::string , std::string > groupAliases;
766 std::string groupComment;
767 std::string groupAuthor;
768 std::string groupCreateTime;
769 time_t groupCreateTime_t;
771 cfgMgr->loadTableGroup(group.second.first,
784 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
785 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
787 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
788 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t) << __E__;
789 (*out) <<
"\t\tGroup Aliases: \t" << StringMacros::mapToString(groupAliases)
792 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
793 tableCount += memberMap.size();
796 for(
auto& member : memberMap)
798 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v" << member.second
802 (*out) <<
"\nActive Group Members total table count = " << tableCount << __E__;
807 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
809 (*out) <<
"\n\n************************" << __E__;
810 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
813 for(
auto& table : activeTables)
815 (*out) <<
"\n\n=============================================================="
818 (*out) <<
"=================================================================="
821 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
823 cfgMgr->nameToTableMap_.find(table.first)->second->print(*out);
827 if(dumpType ==
"GroupKeys")
829 localDumpActiveGroups(
this, out);
831 else if(dumpType ==
"TableVersions")
833 localDumpActiveTables(
this, out);
835 else if(dumpType ==
"GroupKeysAndTableVersions")
837 localDumpActiveGroups(
this, out);
838 localDumpActiveTables(
this, out);
840 else if(dumpType ==
"All")
842 localDumpActiveGroups(
this, out);
843 localDumpActiveGroupMembers(
this, out);
844 localDumpActiveTables(
this, out);
845 localDumpActiveTableContents(
this, out);
850 <<
"Invalid dump type '" << dumpType
851 <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
859 <<
"GroupsKeysAndTableVersions"
864 "\n\nPlease change the State Machine configuration to a valid dump type."
877 void ConfigurationManager::loadMemberMap(
878 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
883 for(
auto& memberPair : memberMap)
894 tmpConfigBasePtr = 0;
895 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
896 tmpConfigBasePtr = nameToTableMap_[memberPair.first];
898 theInterface_->get(tmpConfigBasePtr,
907 nameToTableMap_[memberPair.first] = tmpConfigBasePtr;
908 if(nameToTableMap_[memberPair.first]->getViewP())
915 __SS__ << nameToTableMap_[memberPair.first]->getTableName()
916 <<
": View version not activated properly!";
938 void ConfigurationManager::loadTableGroup(
939 const std::string& groupName,
942 std::map<std::string, TableVersion>* groupMembers,
944 std::string* accumulatedTreeErrors,
945 std::string* groupComment,
946 std::string* groupAuthor,
947 std::string* groupCreateTime,
948 bool doNotLoadMember ,
949 std::string* groupTypeString,
950 std::map<std::string /*name*/, std::string /*alias*/>* groupAliases,
951 bool onlyLoadIfBackboneOrContext )
try
955 *groupComment =
"NO COMMENT FOUND";
957 *groupAuthor =
"NO AUTHOR FOUND";
959 *groupCreateTime =
"0";
961 *groupTypeString =
"UNKNOWN";
992 theInterface_->getTableGroupMembers(
993 TableGroupKey::getFullGroupString(groupName, groupKey),
995 std::map<std::string , std::string > aliasMap;
1001 auto metaTablePair = memberMap.find(groupMetadataTable_.getTableName());
1002 if(metaTablePair != memberMap.end())
1006 memberMap.erase(metaTablePair);
1009 while(groupMetadataTable_.getView().getNumberOfRows())
1010 groupMetadataTable_.getViewP()->deleteRow(0);
1015 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
1017 catch(
const std::runtime_error& e)
1019 __COUT_WARN__ <<
"Ignoring metadata error: " << e.what() << __E__;
1023 __COUT_WARN__ <<
"Ignoring unknown metadata error. " << __E__;
1027 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
1030 *groupMembers = memberMap;
1032 groupMetadataTable_.print();
1033 __SS__ <<
"Ignoring that groupMetadataTable_ has wrong number of rows! Must "
1034 "be 1. Going with anonymous defaults."
1036 __COUT_ERR__ <<
"\n" << ss.str();
1039 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
1040 groupMetadataTable_.getViewP()->deleteRow(0);
1041 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
1042 groupMetadataTable_.getViewP()->addRow();
1045 *groupComment =
"NO COMMENT FOUND";
1047 *groupAuthor =
"NO AUTHOR FOUND";
1049 *groupCreateTime =
"0";
1054 groupType = getTypeOfGroup(memberMap);
1055 *groupTypeString = convertGroupTypeIdToName(groupType);
1063 StringMacros::getMapFromString(groupMetadataTable_.getView().getValueAsString(
1064 0, ConfigurationManager::METADATA_COL_ALIASES),
1067 *groupAliases = aliasMap;
1069 *groupComment = groupMetadataTable_.getView().getValueAsString(
1070 0, ConfigurationManager::METADATA_COL_COMMENT);
1072 *groupAuthor = groupMetadataTable_.getView().getValueAsString(
1073 0, ConfigurationManager::METADATA_COL_AUTHOR);
1075 *groupCreateTime = groupMetadataTable_.getView().getValueAsString(
1076 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
1080 std::map<std::string , std::map<std::string ,
TableVersion>>
1084 __COUTV__(StringMacros::mapToString(aliasMap));
1085 versionAliases = ConfigurationManager::getVersionAliases();
1086 __COUTV__(StringMacros::mapToString(versionAliases));
1090 for(
auto& aliasPair : aliasMap)
1093 if(memberMap.find(aliasPair.first) != memberMap.end())
1095 __COUT__ <<
"Group member '" << aliasPair.first
1096 <<
"' was found in group member map!" << __E__;
1097 __COUT__ <<
"Looking for alias '" << aliasPair.second
1098 <<
"' in active version aliases..." << __E__;
1100 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
1101 versionAliases[aliasPair.first].find(aliasPair.second) ==
1102 versionAliases[aliasPair.first].end())
1104 __SS__ <<
"Group '" << groupName <<
"(" << groupKey
1105 <<
")' requires table version alias '" << aliasPair.first
1106 <<
":" << aliasPair.second
1107 <<
",' which was not found in the active Backbone!"
1112 memberMap[aliasPair.first] =
1113 versionAliases[aliasPair.first][aliasPair.second];
1114 __COUT__ <<
"Version alias translated to " << aliasPair.first
1122 *groupMembers = memberMap;
1125 progressBar->step();
1134 groupType = getTypeOfGroup(memberMap);
1135 *groupTypeString = convertGroupTypeIdToName(groupType);
1154 if(!groupTypeString)
1155 groupType = getTypeOfGroup(memberMap);
1157 if(onlyLoadIfBackboneOrContext &&
1158 groupType != ConfigurationManager::CONTEXT_TYPE &&
1159 groupType != ConfigurationManager::BACKBONE_TYPE)
1161 __COUT_WARN__ <<
"Not loading group because it is not of type Context or "
1162 "Backbone (it is type '"
1163 << convertGroupTypeIdToName(groupType) <<
"')." << __E__;
1168 __COUT__ <<
"------------------------------------- init start \t [for all "
1170 << convertGroupTypeIdToName(groupType) <<
" group '" << groupName
1171 <<
"(" << groupKey <<
")"
1176 std::string groupToDeactivate =
1177 groupType == ConfigurationManager::CONTEXT_TYPE
1178 ? theContextTableGroup_
1179 : (groupType == ConfigurationManager::BACKBONE_TYPE
1180 ? theBackboneTableGroup_
1181 : (groupType == ConfigurationManager::ITERATE_TYPE
1182 ? theIterateTableGroup_
1183 : theConfigurationTableGroup_));
1186 if(groupToDeactivate !=
"")
1190 destroyTableGroup(groupToDeactivate,
true);
1211 progressBar->step();
1215 loadMemberMap(memberMap);
1218 progressBar->step();
1220 if(accumulatedTreeErrors)
1224 getChildren(&memberMap, accumulatedTreeErrors);
1225 if(*accumulatedTreeErrors !=
"")
1227 __COUT_ERR__ <<
"Errors detected while loading Table Group: " << groupName
1228 <<
"(" << groupKey <<
"). Aborting."
1230 << *accumulatedTreeErrors << __E__;
1236 progressBar->step();
1241 for(
auto& memberPair : memberMap)
1244 if(ConfigurationInterface::isVersionTrackingEnabled() &&
1245 memberPair.second.isScratchVersion())
1247 __SS__ <<
"Error while activating member Table '"
1248 << nameToTableMap_[memberPair.first]->getTableName() <<
"-v"
1249 << memberPair.second <<
" for Table Group '" << groupName
1251 <<
")'. When version tracking is enabled, Scratch views"
1252 <<
" are not allowed! Please only use unique, persistent "
1253 "versions when version tracking is enabled."
1255 __COUT_ERR__ <<
"\n" << ss.str();
1264 nameToTableMap_[memberPair.first]->init(
this);
1266 catch(std::runtime_error& e)
1268 __SS__ <<
"Error detected calling "
1269 << nameToTableMap_[memberPair.first]->getTableName()
1270 <<
".init()!\n\n " << e.what() << __E__;
1274 if(accumulatedTreeErrors)
1276 *accumulatedTreeErrors += ss.str();
1283 __SS__ <<
"Unknown Error detected calling "
1284 << nameToTableMap_[memberPair.first]->getTableName()
1285 <<
".init()!\n\n " << __E__;
1287 if(accumulatedTreeErrors)
1289 *accumulatedTreeErrors += ss.str();
1292 __COUT_WARN__ << ss.str();
1297 progressBar->step();
1306 if(groupType == ConfigurationManager::CONTEXT_TYPE)
1312 theContextTableGroup_ = groupName;
1313 theContextTableGroupKey_ =
1314 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1316 else if(groupType == ConfigurationManager::BACKBONE_TYPE)
1321 theBackboneTableGroup_ = groupName;
1322 theBackboneTableGroupKey_ =
1323 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1325 else if(groupType == ConfigurationManager::ITERATE_TYPE)
1331 theIterateTableGroup_ = groupName;
1332 theIterateTableGroupKey_ =
1333 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1340 theConfigurationTableGroup_ = groupName;
1341 theConfigurationTableGroupKey_ =
1342 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1347 progressBar->step();
1350 __COUT__ <<
"------------------------------------- init complete \t [for all "
1352 << convertGroupTypeIdToName(groupType) <<
" group '" << groupName
1353 <<
"(" << groupKey <<
")"
1359 lastFailedGroupLoad_[convertGroupTypeIdToName(groupType)] =
1360 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1366 catch(
const std::runtime_error& e)
1368 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
1369 << groupKey <<
")': \n"
1370 << e.what() << __E__;
1371 __COUT_WARN__ << ss.str();
1372 if(accumulatedTreeErrors)
1373 *accumulatedTreeErrors += ss.str();
1379 __SS__ <<
"An unknown error occurred while loading table group '" << groupName
1380 <<
"(" << groupKey <<
")." << __E__;
1381 __COUT_WARN__ << ss.str();
1382 if(accumulatedTreeErrors)
1383 *accumulatedTreeErrors += ss.str();
1394 lastFailedGroupLoad_[ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN] =
1395 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1401 catch(
const std::runtime_error& e)
1403 __SS__ <<
"Error occurred while loading table group: " << e.what() << __E__;
1404 __COUT_WARN__ << ss.str();
1405 if(accumulatedTreeErrors)
1406 *accumulatedTreeErrors += ss.str();
1412 __SS__ <<
"An unknown error occurred while loading table group." << __E__;
1413 __COUT_WARN__ << ss.str();
1414 if(accumulatedTreeErrors)
1415 *accumulatedTreeErrors += ss.str();
1427 std::map<std::string, std::pair<std::string, TableGroupKey>>
1428 ConfigurationManager::getActiveTableGroups(
void)
const
1431 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
1433 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1434 std::pair<std::string, TableGroupKey>(
1435 theContextTableGroup_,
1436 theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
1437 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
1438 std::pair<std::string, TableGroupKey>(
1439 theBackboneTableGroup_,
1440 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
1441 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
1442 std::pair<std::string, TableGroupKey>(
1443 theIterateTableGroup_,
1444 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
1445 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1446 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_,
1447 theConfigurationTableGroupKey_
1448 ? *theConfigurationTableGroupKey_
1454 const std::string& ConfigurationManager::getActiveGroupName(
const std::string& type)
const
1456 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1457 return theConfigurationTableGroup_;
1458 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1459 return theContextTableGroup_;
1460 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1461 return theBackboneTableGroup_;
1462 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1463 return theIterateTableGroup_;
1465 __SS__ <<
"Invalid type requested '" << type <<
"'" << __E__;
1466 __COUT_ERR__ << ss.str();
1471 TableGroupKey ConfigurationManager::getActiveGroupKey(
const std::string& type)
const
1473 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1474 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_
1476 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1477 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
1478 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1479 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
1480 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1481 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
1483 __SS__ <<
"Invalid type requested '" << type <<
"'" << __E__;
1484 __COUT_ERR__ << ss.str();
1490 const std::string& contextUID,
const std::string& applicationUID)
const
1492 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1498 const std::string& contextUID,
const std::string& applicationUID)
const
1500 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1501 contextUID +
"/LinkToApplicationTable/" + applicationUID);
1506 const std::string& contextUID,
const std::string& applicationUID)
const
1508 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1509 contextUID +
"/LinkToApplicationTable/" + applicationUID +
1510 "/LinkToSupervisorTable");
1515 bool doNotThrowOnBrokenUIDLinks)
const
1520 if(nodeString.length() < 1)
1522 __SS__ << (
"Invalid empty node name") << __E__;
1523 __COUT_ERR__ << ss.str();
1528 unsigned int startingIndex = 0;
1529 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
1532 std::string nodeName = nodeString.substr(
1533 startingIndex, nodeString.find(
'/', startingIndex) - startingIndex);
1535 if(nodeName.length() < 1)
1545 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
1551 if(childPath.length() > 1)
1552 return configTree.getNode(childPath, doNotThrowOnBrokenUIDLinks);
1559 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree& node,
1560 const std::string& startPath)
const
1564 std::string path =
"/";
1574 std::vector<std::pair<std::string, ConfigurationTree>> ConfigurationManager::getChildren(
1575 std::map<std::string, TableVersion>* memberMap,
1576 std::string* accumulatedTreeErrors)
const
1578 std::vector<std::pair<std::string, ConfigurationTree>> retMap;
1583 if(!memberMap || memberMap->empty())
1585 for(
auto& configPair : nameToTableMap_)
1590 if(configPair.second->isActive())
1594 if(accumulatedTreeErrors)
1598 std::vector<std::pair<std::string, ConfigurationTree>>
1599 newNodeChildren = newNode.getChildren();
1600 for(
auto& newNodeChild : newNodeChildren)
1602 std::vector<std::pair<std::string, ConfigurationTree>>
1603 twoDeepChildren = newNodeChild.second.getChildren();
1605 for(
auto& twoDeepChild : twoDeepChildren)
1610 if(twoDeepChild.second.isLinkNode() &&
1611 twoDeepChild.second.isDisconnected() &&
1612 twoDeepChild.second.getDisconnectedTableName() !=
1613 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1614 *accumulatedTreeErrors +=
1615 "\n\nAt node '" + configPair.first +
1616 "' with entry UID '" + newNodeChild.first +
1617 "' there is a disconnected child node at link "
1619 twoDeepChild.first +
"'" +
1620 " that points to table named '" +
1621 twoDeepChild.second.getDisconnectedTableName() +
1626 catch(std::runtime_error& e)
1628 *accumulatedTreeErrors +=
1629 "\n\nAt node '" + configPair.first +
1630 "' error detected descending through children:\n" + e.what();
1635 std::pair<std::string, ConfigurationTree>(configPair.first, newNode));
1643 for(
auto& memberPair : *memberMap)
1645 auto mapIt = nameToTableMap_.find(memberPair.first);
1646 if(mapIt == nameToTableMap_.end())
1648 __SS__ <<
"Get Children with member map requires a child '"
1649 << memberPair.first <<
"' that is not present!" << __E__;
1652 if(!(*mapIt).second->isActive())
1654 __SS__ <<
"Get Children with member map requires a child '"
1655 << memberPair.first <<
"' that is not active!" << __E__;
1661 if(accumulatedTreeErrors)
1665 std::vector<std::pair<std::string, ConfigurationTree>>
1666 newNodeChildren = newNode.getChildren();
1667 for(
auto& newNodeChild : newNodeChildren)
1669 std::vector<std::pair<std::string, ConfigurationTree>>
1670 twoDeepChildren = newNodeChild.second.getChildren();
1672 for(
auto& twoDeepChild : twoDeepChildren)
1676 if(twoDeepChild.second.isLinkNode() &&
1677 twoDeepChild.second.isDisconnected() &&
1678 twoDeepChild.second.getDisconnectedTableName() !=
1679 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1681 *accumulatedTreeErrors +=
1682 "\n\nAt node '" + memberPair.first +
1683 "' with entry UID '" + newNodeChild.first +
1684 "' there is a disconnected child node at link column "
1686 twoDeepChild.first +
"'" +
1687 " that points to table named '" +
1688 twoDeepChild.second.getDisconnectedTableName() +
1695 for(
auto& searchMemberPair : *memberMap)
1696 if(searchMemberPair.first ==
1697 twoDeepChild.second.getDisconnectedTableName())
1705 <<
"Note: It may be safe to ignore this "
1706 <<
"error since the link's target table "
1707 << twoDeepChild.second.getDisconnectedTableName()
1708 <<
" is not a member of this group (and may not "
1710 <<
"loaded yet)" << __E__;
1711 *accumulatedTreeErrors += ss.str();
1717 catch(std::runtime_error& e)
1719 __SS__ <<
"At node '" << memberPair.first
1720 <<
"' error detected descending through children:\n"
1721 << e.what() << __E__;
1722 *accumulatedTreeErrors += ss.str();
1727 std::pair<std::string, ConfigurationTree>(memberPair.first, newNode));
1739 const TableBase* ConfigurationManager::getTableByName(
const std::string& tableName)
const
1741 std::map<std::string, TableBase*>::const_iterator it;
1742 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
1744 __SS__ <<
"\n\nCan not find configuration named '" << tableName
1745 <<
"'\n\n\n\nYou need to load the configuration before it can be used."
1746 <<
" It probably is missing from the member list of the Table "
1747 "Group that was loaded.\n"
1748 <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
1750 <<
"\n\t StartOTS.sh --wiz"
1754 ss << __E__ << StringMacros::stackTrace() << __E__;
1768 TableGroupKey ConfigurationManager::loadConfigurationBackbone()
1770 if(!theBackboneTableGroupKey_)
1772 __COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently."
1778 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
1780 return *theBackboneTableGroupKey_;
1796 std::pair<std::string, TableGroupKey> ConfigurationManager::getTableGroupFromAlias(
1797 std::string systemAlias,
ProgressBar* progressBar)
1807 progressBar->step();
1809 if(systemAlias.find(
"GROUP:") == 0)
1812 progressBar->step();
1814 unsigned int i = strlen(
"GROUP:");
1815 unsigned int j = systemAlias.find(
':', i);
1818 progressBar->step();
1820 return std::pair<std::string, TableGroupKey>(
1821 systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
1823 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
1826 loadConfigurationBackbone();
1829 progressBar->step();
1835 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getNode(systemAlias);
1838 progressBar->step();
1840 return std::pair<std::string, TableGroupKey>(
1841 entry.getNode(
"GroupName").getValueAsString(),
1842 TableGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1851 progressBar->step();
1853 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
1857 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
1858 ConfigurationManager::getActiveGroupAliases(
void)
1860 restoreActiveTableGroups();
1864 std::map<std::string ,
1868 std::vector<std::pair<std::string, ConfigurationTree>> entries =
1869 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getChildren();
1870 for(
auto& entryPair : entries)
1872 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(
1873 entryPair.second.getNode(
"GroupName").getValueAsString(),
1874 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
1882 std::map<std::string ,
1884 ConfigurationManager::getVersionAliases(
void)
const
1888 std::map<std::string ,
1892 std::map<std::string, TableVersion> activeVersions = getActiveVersions();
1893 std::string versionAliasesTableName =
1894 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
1895 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
1897 __SS__ <<
"Active version of VersionAliases missing!"
1898 <<
"Make sure you have a valid active Backbone Group." << __E__;
1899 __COUT_WARN__ <<
"\n" << ss.str();
1903 __COUT__ <<
"activeVersions[\"" << versionAliasesTableName
1904 <<
"\"]=" << activeVersions[versionAliasesTableName] << __E__;
1906 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
1907 getNode(versionAliasesTableName).getChildren();
1912 std::string tableName, versionAlias;
1913 for(
auto& aliasNodePair : aliasNodePairs)
1915 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
1916 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
1918 if(retMap.find(tableName) != retMap.end() &&
1919 retMap[tableName].find(versionAlias) != retMap[tableName].end())
1924 retMap[tableName][versionAlias] =
1925 TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
1933 std::map<std::string, TableVersion> ConfigurationManager::getActiveVersions(
void)
const
1935 std::map<std::string, TableVersion> retMap;
1936 for(
auto& config : nameToTableMap_)
1941 if(config.second && config.second->isActive())
1945 retMap.insert(std::pair<std::string, TableVersion>(
1946 config.first, config.second->getViewVersion()));
1975 std::shared_ptr<TableGroupKey> ConfigurationManager::makeTheTableGroupKey(
1978 if(theConfigurationTableGroupKey_)
1980 if(*theConfigurationTableGroupKey_ != key)
1981 destroyTableGroup();
1983 return theConfigurationTableGroupKey_;
1985 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
1989 std::string ConfigurationManager::encodeURIComponent(
const std::string& sourceStr)
1991 std::string retStr =
"";
1993 for(
const auto& c : sourceStr)
1994 if((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') || (c >=
'0' && c <=
'9'))
1998 sprintf(encodeStr,
"%%%2.2X", c);
1999 retStr += encodeStr;
2005 const std::set<std::string>& ConfigurationManager::getContextMemberNames()
2007 return ConfigurationManager::contextMemberNames_;
2010 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
2012 return ConfigurationManager::backboneMemberNames_;
2015 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
2017 return ConfigurationManager::iterateMemberNames_;
2021 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
2023 __COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
2028 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
2057 theInterface_->get(table,
2058 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
2064 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
2066 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2067 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2070 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2075 auto colMap = view->getColumnNamesMap();
2077 view->setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
2078 view->setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
2079 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2080 view->setValue(
"1", 0, colMap[
"Status"]);
2082 __COUT__ <<
"Done adding context record..." << __E__;
2092 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
2098 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
2100 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2101 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2104 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2109 auto colMap = view->getColumnNamesMap();
2111 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2112 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
2113 view->setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
2114 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
2115 view->setValue(
"1", 0, colMap[
"Status"]);
2117 __COUT__ <<
"Done adding application record..." << __E__;
2124 theInterface_->get(table,
2125 "FESupervisorTable",
2131 nameToTableMap_[
"FESupervisorTable"] = table;
2133 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2134 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2137 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2142 auto colMap = view->getColumnNamesMap();
2144 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
2145 view->setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
2147 "MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
2149 __COUT__ <<
"Done adding supervisor record..." << __E__;
2154 recursiveInitFromFhiclPSet(
"FEInterfaceTable" ,
2157 "MacroMakerFESupervisorInterfaces" ,
2161 for(
auto& table : nameToTableMap_)
2163 table.second->getViewP()->init();
2169 __COUT__ <<
"================================================" << __E__;
2170 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
2171 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
2173 auto sups = getNode(
"FESupervisorTable").getChildrenNames();
2174 __COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
2175 auto fes = getNode(
"FEInterfaceTable").getChildrenNames();
2176 __COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
2178 auto a = getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
2179 __COUTV__(a.getValueAsString());
2181 auto b = a.getNode(
"MacroMakerFEContext");
2182 __COUTV__(b.getValueAsString());
2184 auto c = b.getNode(
"LinkToApplicationTable");
2185 __COUTV__(c.getValueAsString());
2187 auto d = c.getNode(
"MacroMakerFESupervisor");
2188 __COUTV__(d.getValueAsString());
2190 auto e = d.getNode(
"LinkToSupervisorTable");
2191 __COUTV__(e.getValueAsString());
2193 auto f = e.getNode(
"LinkToFEInterfaceTable");
2194 __COUTV__(f.getValueAsString());
2196 auto z = f.getChildrenNames();
2197 __COUTV__(StringMacros::vectorToString(z));
2198 __COUTV__(z.size());
2199 auto y = f.getChildrenNames(
false ,
true );
2200 __COUTV__(StringMacros::vectorToString(y));
2201 __COUTV__(y.size());
2202 auto x = f.getChildrenNames(
true ,
true );
2203 __COUTV__(StringMacros::vectorToString(x));
2204 __COUTV__(x.size());
2206 auto g = f.getNode(
"dtc0");
2207 __COUTV__(g.getValueAsString());
2208 auto h = f.getNode(
"interface0");
2209 __COUTV__(h.getValueAsString());
2212 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
2214 "MacroMakerFEContext/LinkToApplicationTable/"
2215 "MacroMakerFESupervisor/LinkToSupervisorTable")
2216 .getNode(
"LinkToFEInterfaceTable")
2217 .getChildrenNames(
true ,
true );
2218 __COUTV__(fes.size());
2219 __COUTV__(StringMacros::vectorToString(fes));
2230 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
2231 const fhicl::ParameterSet& pset,
2232 const std::string& recordName,
2233 const std::string& groupName,
2234 const std::string& groupLinkIndex)
2236 __COUT__ << __COUT_HDR_P__ <<
"Adding table '" << tableName <<
"' record(s)..."
2243 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
2245 __COUT__ <<
"Table not found, so making '" << tableName <<
"'instance..."
2247 theInterface_->get(table,
2254 nameToTableMap_[tableName] = table;
2255 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2259 __COUT__ <<
"Existing table found, so using '" << tableName <<
"'instance..."
2261 table = nameToTableMap_[tableName];
2264 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2267 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2270 if(recordName !=
"")
2278 __COUTV__(recordName);
2281 unsigned int r = view->addRow();
2282 auto colMap = view->getColumnNamesMap();
2285 view->setValue(recordName, r, view->getColUID());
2288 view->setValue(
"1", r, view->getColStatus());
2292 __COUT__ <<
"No status column to set for '" << recordName <<
"'" << __E__;
2297 int groupIDCol = view->getColLinkGroupID(groupLinkIndex);
2298 __COUT__ <<
"Setting group ID for group link ID '" << groupLinkIndex
2299 <<
"' at column " << groupIDCol <<
" to '" << groupName <<
".'"
2302 view->setValue(groupName, r, groupIDCol);
2306 auto names = pset.get_names();
2307 for(
const auto& colName : names)
2309 if(!pset.is_key_to_atom(colName))
2312 auto colIt = colMap.find(colName);
2313 if(colIt == colMap.end())
2315 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName
2316 <<
"' in table '" << tableName <<
"' was not found in columns."
2317 <<
"\n\nHere are the existing column names:\n";
2319 for(
const auto& col : colMap)
2320 ss <<
"\n" << ++i <<
".\t" << col.first;
2324 const std::string value = pset.get<std::string>(colName);
2325 __COUT__ <<
"Setting '" << recordName <<
"' parameter at column "
2326 << colIt->second <<
", '" << colName <<
"'\t = " << value
2328 view->setValueAsString(value, r, colIt->second);
2332 for(
const auto& linkName : names)
2334 if(pset.is_key_to_atom(linkName))
2337 __COUTV__(linkName);
2340 unsigned int c = linkName.size() - 1;
2342 if(linkName[c] ==
'_')
2347 __SS__ <<
"Illegal link name '" << linkName
2348 <<
"' found. The format must be <Column name>_<Target table "
2349 "name>,.. for example '"
2350 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'"
2354 std::string colName = linkName.substr(0, c);
2357 auto colIt = colMap.find(colName);
2358 if(colIt == colMap.end())
2360 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName
2361 <<
"' in table '" << tableName <<
"' was not found in columns."
2362 <<
"\n\nHere are the existing column names:\n";
2364 for(
const auto& col : colMap)
2365 ss <<
"\n" << i <<
".\t" << col.first << __E__;
2370 std::pair<
unsigned int ,
unsigned int >
2373 view->getChildLink(colIt->second, isGroupLink, linkPair);
2379 std::string linkTableName = linkName.substr(c + 1);
2380 __COUTV__(linkTableName);
2382 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
2383 auto linkRecords = linkPset.get_pset_names();
2384 if(!isGroupLink && linkRecords.size() > 1)
2386 __SS__ <<
"A Unique Link can only point to one record. "
2387 <<
"The specified link '" << colName <<
"' of record '"
2388 << recordName <<
"' in table '" << tableName <<
"' has "
2389 << linkRecords.size() <<
" children records specified. "
2394 if(linkRecords.size() == 0)
2396 __COUT__ <<
"No child records, so leaving link disconnected."
2401 __COUT__ <<
"Setting Link at columns [" << linkPair.first <<
","
2402 << linkPair.second <<
"]" << __E__;
2403 view->setValue(linkTableName, r, linkPair.first);
2407 __COUT__ <<
"Setting up Unique link to " << linkRecords[0] << __E__;
2409 view->setValue(linkRecords[0], r, linkPair.second);
2411 recursiveInitFromFhiclPSet(
2413 linkPset.get<fhicl::ParameterSet>(
2422 std::string childLinkIndex =
2423 view->getColumnInfo(linkPair.first).getChildLinkIndex();
2424 std::string groupName = recordName +
"Group";
2426 view->setValue(groupName, r, linkPair.second);
2428 for(
const auto& groupRecord : linkRecords)
2430 __COUT__ <<
"Setting '" << childLinkIndex <<
"' Group link to '"
2431 << groupName <<
"' record '" << groupRecord <<
"'"
2434 recursiveInitFromFhiclPSet(
2436 linkPset.get<fhicl::ParameterSet>(
2446 else if(groupName !=
"")
2450 __COUTV__(groupName);
2451 auto psets = pset.get_pset_names();
2452 for(
const auto& ps : psets)
2455 recursiveInitFromFhiclPSet(
2457 pset.get<fhicl::ParameterSet>(ps) ,
2467 __SS__ <<
"Illegal recursive parameters!" << __E__;
2472 __COUT__ << __COUT_HDR_P__ <<
"Done adding table '" << tableName <<
"' record(s)..."
2478 bool ConfigurationManager::isOwnerFirstAppInContext()
2480 __COUT__ <<
"Checking if owner is first App in Context." << __E__;
2481 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
2484 __COUTV__(ownerContextUID_);
2485 __COUTV__(ownerAppUID_);
2487 auto contextChildren =
2488 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" + ownerContextUID_)
2489 .getChildrenNames();
2491 bool isFirstAppInContext =
2492 contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
2494 __COUTV__(isFirstAppInContext);
2496 return isFirstAppInContext;