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 ((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,
"%s", strVal);
246 for(
unsigned int j = 0; j < strlen(strVal); ++j)
247 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') ||
248 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
249 (strVal[j] >=
'0' && strVal[j] <=
'9')))
252 __COUT_INFO__ <<
"Illegal character found, so skipping!" << __E__;
263 sscanf(tmp,
"%s", strVal);
265 for(
unsigned int j = 0; j < strlen(strVal); ++j)
266 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
270 if(groupName.size() > 3)
272 <<
"Skipping active group with illegal character in name."
284 TableGroupKey::getFullGroupString(groupName,
TableGroupKey(strVal));
288 __COUT__ <<
"illegal group according to TableGroupKey::getFullGroupString..."
312 onlyLoadIfBackboneOrContext
315 catch(std::runtime_error& e)
317 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
318 << groupName <<
"(" << strVal <<
")'" << __E__;
319 ss << e.what() << __E__;
321 errorStr += ss.str();
325 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
326 << groupName <<
"(" << strVal <<
")'" << __E__;
328 errorStr += ss.str();
334 if(throwErrors && errorStr !=
"")
336 __COUT_INFO__ <<
"\n" << ss.str();
339 else if(errorStr !=
"")
340 __COUT_INFO__ <<
"\n" << ss.str();
349 void ConfigurationManager::destroyTableGroup(
const std::string& theGroup,
353 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
354 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
355 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
356 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
358 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
360 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
361 __COUT_ERR__ << ss.str();
365 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
369 __COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
371 __COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
373 __COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
375 __COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
378 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
379 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
382 contextFindIt = contextMemberNames_.find(it->first);
383 backboneFindIt = backboneMemberNames_.find(it->first);
384 iterateFindIt = iterateMemberNames_.find(it->first);
386 ((isContext && contextFindIt != contextMemberNames_.end()) ||
387 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
388 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
389 (!isContext && !isBackbone && contextFindIt == contextMemberNames_.end() &&
390 backboneFindIt == backboneMemberNames_.end() &&
391 iterateFindIt == iterateMemberNames_.end())))
399 it->second->deactivate();
405 nameToTableMap_.erase(it++);
414 theConfigurationTableGroup_ =
"";
415 if(theConfigurationTableGroupKey_ != 0)
417 __COUT__ <<
"Destroying Configuration Key: "
418 << *theConfigurationTableGroupKey_ << __E__;
419 theConfigurationTableGroupKey_.reset();
426 theBackboneTableGroup_ =
"";
427 if(theBackboneTableGroupKey_ != 0)
429 __COUT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_
431 theBackboneTableGroupKey_.reset();
436 theIterateTableGroup_ =
"";
437 if(theIterateTableGroupKey_ != 0)
439 __COUT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_ << __E__;
440 theIterateTableGroupKey_.reset();
445 theContextTableGroup_ =
"";
446 if(theContextTableGroupKey_ != 0)
448 __COUT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_ << __E__;
449 theContextTableGroupKey_.reset();
455 void ConfigurationManager::destroy(
void)
470 const std::string& ConfigurationManager::convertGroupTypeIdToName(
int groupTypeId)
472 return groupTypeId == CONTEXT_TYPE
473 ? ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT
474 : (groupTypeId == BACKBONE_TYPE
475 ? ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE
476 : (groupTypeId == ITERATE_TYPE
477 ? ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE
478 : ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
488 int ConfigurationManager::getTypeOfGroup(
489 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
491 bool isContext =
true;
492 bool isBackbone =
true;
493 bool isIterate =
true;
495 bool inContext =
false;
496 bool inBackbone =
false;
497 bool inIterate =
false;
498 unsigned int matchCount = 0;
500 for(
auto& memberPair : memberMap)
505 for(
auto& contextMemberString : contextMemberNames_)
506 if(memberPair.first == contextMemberString)
518 __SS__ <<
"This group is an incomplete match to a Context group.\n";
519 __COUT_ERR__ <<
"\n" << ss.str();
520 ss <<
"\nTo be a Context group, the members must exactly match "
521 <<
"the following members:\n";
523 for(
const auto& memberName : contextMemberNames_)
524 ss << ++i <<
". " << memberName <<
"\n";
525 ss <<
"\nThe members are as follows::\n";
527 for(
const auto& memberPairTmp : memberMap)
528 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
535 for(
auto& backboneMemberString : backboneMemberNames_)
536 if(memberPair.first == backboneMemberString)
548 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
549 __COUT_ERR__ <<
"\n" << ss.str();
550 ss <<
"\nTo be a Backbone group, the members must exactly match "
551 <<
"the following members:\n";
553 for(
auto& memberName : backboneMemberNames_)
554 ss << ++i <<
". " << memberName <<
"\n";
555 ss <<
"\nThe members are as follows::\n";
557 for(
const auto& memberPairTmp : memberMap)
558 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
566 for(
auto& iterateMemberString : iterateMemberNames_)
567 if(memberPair.first == iterateMemberString)
579 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
580 __COUT_ERR__ <<
"\n" << ss.str();
581 ss <<
"\nTo be a Iterate group, the members must exactly match "
582 <<
"the following members:\n";
584 for(
auto& memberName : iterateMemberNames_)
585 ss << ++i <<
". " << memberName <<
"\n";
586 ss <<
"\nThe members are as follows::\n";
588 for(
const auto& memberPairTmp : memberMap)
589 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
596 if(isContext && matchCount != contextMemberNames_.size())
598 __SS__ <<
"This group is an incomplete match to a Context group: "
599 <<
" Size=" << matchCount <<
" but should be "
600 << contextMemberNames_.size() << __E__;
601 __COUT_ERR__ <<
"\n" << ss.str();
602 ss <<
"\nThe members currently are...\n";
604 for(
auto& memberPair : memberMap)
605 ss << ++i <<
". " << memberPair.first <<
"\n";
606 ss <<
"\nThe expected Context members are...\n";
608 for(
auto& memberName : contextMemberNames_)
609 ss << ++i <<
". " << memberName <<
"\n";
614 if(isBackbone && matchCount != backboneMemberNames_.size())
616 __SS__ <<
"This group is an incomplete match to a Backbone group: "
617 <<
" Size=" << matchCount <<
" but should be "
618 << backboneMemberNames_.size() << __E__;
619 __COUT_ERR__ <<
"\n" << ss.str();
620 ss <<
"\nThe members currently are...\n";
622 for(
auto& memberPair : memberMap)
623 ss << ++i <<
". " << memberPair.first <<
"\n";
624 ss <<
"\nThe expected Backbone members are...\n";
626 for(
auto& memberName : backboneMemberNames_)
627 ss << ++i <<
". " << memberName <<
"\n";
632 if(isIterate && matchCount != iterateMemberNames_.size())
634 __SS__ <<
"This group is an incomplete match to a Iterate group: "
635 <<
" Size=" << matchCount <<
" but should be "
636 << iterateMemberNames_.size() << __E__;
637 __COUT_ERR__ <<
"\n" << ss.str();
638 ss <<
"\nThe members currently are...\n";
640 for(
auto& memberPair : memberMap)
641 ss << ++i <<
". " << memberPair.first <<
"\n";
642 ss <<
"\nThe expected Iterate members are...\n";
644 for(
auto& memberName : iterateMemberNames_)
645 ss << ++i <<
". " << memberName <<
"\n";
650 return isContext ? CONTEXT_TYPE
651 : (isBackbone ? BACKBONE_TYPE
652 : (isIterate ? ITERATE_TYPE : CONFIGURATION_TYPE));
658 const std::string& ConfigurationManager::getTypeNameOfGroup(
659 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
661 return convertGroupTypeIdToName(getTypeOfGroup(memberMap));
670 void ConfigurationManager::dumpActiveConfiguration(
const std::string& filePath,
671 const std::string& dumpType)
673 time_t rawtime = time(0);
674 __COUT__ <<
"filePath = " << filePath << __E__;
675 __COUT__ <<
"dumpType = " << dumpType << __E__;
678 fs.open(filePath, std::fstream::out | std::fstream::trunc);
689 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath
690 <<
" could not be opened!" << __E__;
691 __COUT_ERR__ << ss.str();
697 (*out) <<
"#################################" << __E__;
698 (*out) <<
"This is an ots configuration dump.\n\n" << __E__;
699 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t"
700 << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
701 (*out) <<
"\nOriginal location of dump: \t" << filePath << __E__;
702 (*out) <<
"Type of dump: \t" << dumpType << __E__;
703 (*out) <<
"Linux time for dump: \t" << rawtime << __E__;
706 struct tm* timeinfo = localtime(&rawtime);
708 strftime(buffer, 100,
"%c %Z", timeinfo);
709 (*out) <<
"Display time for dump: \t" << buffer << __E__;
720 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
721 cfgMgr->getActiveTableGroups();
723 (*out) <<
"\n\n************************" << __E__;
724 (*out) <<
"Active Groups:" << __E__;
725 for(
auto& group : activeGroups)
727 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
728 << group.second.second <<
")" << __E__;
734 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
736 (*out) <<
"\n\n************************" << __E__;
737 (*out) <<
"Active Tables:" << __E__;
738 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
741 for(
auto& table : activeTables)
743 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
749 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
750 cfgMgr->getActiveTableGroups();
751 (*out) <<
"\n\n************************" << __E__;
752 (*out) <<
"Active Group Members:" << __E__;
754 for(
auto& group : activeGroups)
756 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
757 << group.second.second <<
")" << __E__;
759 if(group.second.first ==
"")
762 <<
"Empty group name. Assuming no active group." << __E__;
767 std::map<std::string , std::string > groupAliases;
768 std::string groupComment;
769 std::string groupAuthor;
770 std::string groupCreateTime;
771 time_t groupCreateTime_t;
773 cfgMgr->loadTableGroup(group.second.first,
786 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
787 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
789 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
790 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t) << __E__;
791 (*out) <<
"\t\tGroup Aliases: \t" << StringMacros::mapToString(groupAliases)
794 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
795 tableCount += memberMap.size();
798 for(
auto& member : memberMap)
800 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v" << member.second
804 (*out) <<
"\nActive Group Members total table count = " << tableCount << __E__;
809 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
811 (*out) <<
"\n\n************************" << __E__;
812 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
815 for(
auto& table : activeTables)
817 (*out) <<
"\n\n=============================================================="
820 (*out) <<
"=================================================================="
823 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
825 cfgMgr->nameToTableMap_.find(table.first)->second->print(*out);
829 if(dumpType ==
"GroupKeys")
831 localDumpActiveGroups(
this, out);
833 else if(dumpType ==
"TableVersions")
835 localDumpActiveTables(
this, out);
837 else if(dumpType ==
"GroupKeysAndTableVersions")
839 localDumpActiveGroups(
this, out);
840 localDumpActiveTables(
this, out);
842 else if(dumpType ==
"All")
844 localDumpActiveGroups(
this, out);
845 localDumpActiveGroupMembers(
this, out);
846 localDumpActiveTables(
this, out);
847 localDumpActiveTableContents(
this, out);
852 <<
"Invalid dump type '" << dumpType
853 <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
861 <<
"GroupsKeysAndTableVersions"
866 "\n\nPlease change the State Machine configuration to a valid dump type."
879 void ConfigurationManager::loadMemberMap(
880 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap,
881 std::string* accumulateWarnings )
886 for(
auto& memberPair : memberMap)
897 tmpConfigBasePtr = 0;
898 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
899 tmpConfigBasePtr = nameToTableMap_[memberPair.first];
901 std::string getError =
"";
904 theInterface_->get(tmpConfigBasePtr,
913 catch(
const std::runtime_error& e)
915 __SS__ <<
"Failed to load member table '" << memberPair.first
916 <<
"' - here is the error: \n\n"
917 << e.what() << __E__;
919 ss <<
"\nIf the table '" << memberPair.first
920 <<
"' should not exist, then please remove it from the group. If it "
921 "should exist, then it "
922 <<
"seems to be missing; use the Table Editor to create it, or copy it "
923 "from another source."
927 if(accumulateWarnings)
934 __SS__ <<
"Failed to load member table '" << memberPair.first
935 <<
"' due to unknown error!" << __E__;
937 ss <<
"\nIf the table '" << memberPair.first
938 <<
"' should not exist, then please remove it from the group. If it "
939 "should exist, then it "
940 <<
"seems to be missing; use the Table Editor to create it, or copy it "
941 "from another source."
945 if(accumulateWarnings)
951 if(!tmpConfigBasePtr)
953 __SS__ <<
"Null pointer returned for table '" << memberPair.first
954 <<
".' Was the table info deleted?" << __E__;
955 __COUT_ERR__ << ss.str();
957 nameToTableMap_.erase(memberPair.first);
958 if(accumulateWarnings)
960 *accumulateWarnings += ss.str();
967 nameToTableMap_[memberPair.first] = tmpConfigBasePtr;
968 if(nameToTableMap_[memberPair.first]->getViewP())
973 if(accumulateWarnings && getError !=
"")
975 __SS__ <<
"Error caught during '" << memberPair.first
976 <<
"' table retrieval: \n"
977 << getError << __E__;
978 __COUT_ERR__ << ss.str();
979 *accumulateWarnings += ss.str();
984 __SS__ << nameToTableMap_[memberPair.first]->getTableName()
985 <<
": View version not activated properly!";
1007 void ConfigurationManager::loadTableGroup(
1008 const std::string& groupName,
1011 std::map<std::string, TableVersion>* groupMembers,
1013 std::string* accumulatedTreeErrors,
1014 std::string* groupComment,
1015 std::string* groupAuthor,
1016 std::string* groupCreateTime,
1017 bool doNotLoadMember ,
1018 std::string* groupTypeString,
1019 std::map<std::string /*name*/, std::string /*alias*/>* groupAliases,
1020 bool onlyLoadIfBackboneOrContext )
try
1024 *groupComment =
"NO COMMENT FOUND";
1026 *groupAuthor =
"NO AUTHOR FOUND";
1028 *groupCreateTime =
"0";
1030 *groupTypeString =
"UNKNOWN";
1061 theInterface_->getTableGroupMembers(
1062 TableGroupKey::getFullGroupString(groupName, groupKey),
1064 std::map<std::string , std::string > aliasMap;
1067 progressBar->step();
1070 auto metaTablePair = memberMap.find(groupMetadataTable_.getTableName());
1071 if(metaTablePair != memberMap.end())
1075 memberMap.erase(metaTablePair);
1078 while(groupMetadataTable_.getView().getNumberOfRows())
1079 groupMetadataTable_.getViewP()->deleteRow(0);
1084 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
1086 catch(
const std::runtime_error& e)
1088 __COUT_WARN__ <<
"Ignoring metadata error: " << e.what() << __E__;
1092 __COUT_WARN__ <<
"Ignoring unknown metadata error. " << __E__;
1096 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
1099 *groupMembers = memberMap;
1101 groupMetadataTable_.print();
1102 __SS__ <<
"Ignoring that groupMetadataTable_ has wrong number of rows! Must "
1103 "be 1. Going with anonymous defaults."
1105 __COUT_ERR__ <<
"\n" << ss.str();
1108 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
1109 groupMetadataTable_.getViewP()->deleteRow(0);
1110 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
1111 groupMetadataTable_.getViewP()->addRow();
1114 *groupComment =
"NO COMMENT FOUND";
1116 *groupAuthor =
"NO AUTHOR FOUND";
1118 *groupCreateTime =
"0";
1123 groupType = getTypeOfGroup(memberMap);
1124 *groupTypeString = convertGroupTypeIdToName(groupType);
1132 StringMacros::getMapFromString(groupMetadataTable_.getView().getValueAsString(
1133 0, ConfigurationManager::METADATA_COL_ALIASES),
1136 *groupAliases = aliasMap;
1138 *groupComment = groupMetadataTable_.getView().getValueAsString(
1139 0, ConfigurationManager::METADATA_COL_COMMENT);
1141 *groupAuthor = groupMetadataTable_.getView().getValueAsString(
1142 0, ConfigurationManager::METADATA_COL_AUTHOR);
1144 *groupCreateTime = groupMetadataTable_.getView().getValueAsString(
1145 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
1149 std::map<std::string , std::map<std::string ,
TableVersion>>
1153 __COUTV__(StringMacros::mapToString(aliasMap));
1154 versionAliases = ConfigurationManager::getVersionAliases();
1155 __COUTV__(StringMacros::mapToString(versionAliases));
1159 for(
auto& aliasPair : aliasMap)
1162 if(memberMap.find(aliasPair.first) != memberMap.end())
1164 __COUT__ <<
"Group member '" << aliasPair.first
1165 <<
"' was found in group member map!" << __E__;
1166 __COUT__ <<
"Looking for alias '" << aliasPair.second
1167 <<
"' in active version aliases..." << __E__;
1169 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
1170 versionAliases[aliasPair.first].find(aliasPair.second) ==
1171 versionAliases[aliasPair.first].end())
1173 __SS__ <<
"Group '" << groupName <<
"(" << groupKey
1174 <<
")' requires table version alias '" << aliasPair.first
1175 <<
":" << aliasPair.second
1176 <<
",' which was not found in the active Backbone!"
1181 memberMap[aliasPair.first] =
1182 versionAliases[aliasPair.first][aliasPair.second];
1183 __COUT__ <<
"Version alias translated to " << aliasPair.first
1191 *groupMembers = memberMap;
1194 progressBar->step();
1203 groupType = getTypeOfGroup(memberMap);
1204 *groupTypeString = convertGroupTypeIdToName(groupType);
1223 if(!groupTypeString)
1224 groupType = getTypeOfGroup(memberMap);
1226 if(onlyLoadIfBackboneOrContext &&
1227 groupType != ConfigurationManager::CONTEXT_TYPE &&
1228 groupType != ConfigurationManager::BACKBONE_TYPE)
1230 __COUT_WARN__ <<
"Not loading group because it is not of type Context or "
1231 "Backbone (it is type '"
1232 << convertGroupTypeIdToName(groupType) <<
"')." << __E__;
1237 __COUT__ <<
"------------------------------------- init start \t [for all "
1239 << convertGroupTypeIdToName(groupType) <<
" group '" << groupName
1240 <<
"(" << groupKey <<
")"
1245 std::string groupToDeactivate =
1246 groupType == ConfigurationManager::CONTEXT_TYPE
1247 ? theContextTableGroup_
1248 : (groupType == ConfigurationManager::BACKBONE_TYPE
1249 ? theBackboneTableGroup_
1250 : (groupType == ConfigurationManager::ITERATE_TYPE
1251 ? theIterateTableGroup_
1252 : theConfigurationTableGroup_));
1255 if(groupToDeactivate !=
"")
1259 destroyTableGroup(groupToDeactivate,
true);
1280 progressBar->step();
1284 loadMemberMap(memberMap, accumulatedTreeErrors);
1289 progressBar->step();
1291 if(accumulatedTreeErrors)
1295 getChildren(&memberMap, accumulatedTreeErrors);
1296 if(*accumulatedTreeErrors !=
"")
1298 __COUT_ERR__ <<
"Errors detected while loading Table Group: " << groupName
1299 <<
"(" << groupKey <<
"). Aborting."
1301 << *accumulatedTreeErrors << __E__;
1307 progressBar->step();
1312 for(
auto& memberPair : memberMap)
1315 if(ConfigurationInterface::isVersionTrackingEnabled() &&
1316 memberPair.second.isScratchVersion())
1318 __SS__ <<
"Error while activating member Table '"
1319 << nameToTableMap_[memberPair.first]->getTableName() <<
"-v"
1320 << memberPair.second <<
" for Table Group '" << groupName
1322 <<
")'. When version tracking is enabled, Scratch views"
1323 <<
" are not allowed! Please only use unique, persistent "
1324 "versions when version tracking is enabled."
1326 __COUT_ERR__ <<
"\n" << ss.str();
1336 nameToTableMap_[memberPair.first]->init(
this);
1338 catch(std::runtime_error& e)
1340 __SS__ <<
"Error detected calling "
1341 << nameToTableMap_[memberPair.first]->getTableName()
1342 <<
".init()!\n\n " << e.what() << __E__;
1346 if(accumulatedTreeErrors)
1348 *accumulatedTreeErrors += ss.str();
1355 __SS__ <<
"Unknown Error detected calling "
1356 << nameToTableMap_[memberPair.first]->getTableName()
1357 <<
".init()!\n\n " << __E__;
1359 if(accumulatedTreeErrors)
1361 *accumulatedTreeErrors += ss.str();
1364 __COUT_WARN__ << ss.str();
1369 progressBar->step();
1378 if(groupType == ConfigurationManager::CONTEXT_TYPE)
1384 theContextTableGroup_ = groupName;
1385 theContextTableGroupKey_ =
1386 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1388 else if(groupType == ConfigurationManager::BACKBONE_TYPE)
1393 theBackboneTableGroup_ = groupName;
1394 theBackboneTableGroupKey_ =
1395 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1397 else if(groupType == ConfigurationManager::ITERATE_TYPE)
1403 theIterateTableGroup_ = groupName;
1404 theIterateTableGroupKey_ =
1405 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1412 theConfigurationTableGroup_ = groupName;
1413 theConfigurationTableGroupKey_ =
1414 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1419 progressBar->step();
1422 __COUT__ <<
"------------------------------------- init complete \t [for all "
1424 << convertGroupTypeIdToName(groupType) <<
" group '" << groupName
1425 <<
"(" << groupKey <<
")"
1431 lastFailedGroupLoad_[convertGroupTypeIdToName(groupType)] =
1432 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1438 catch(
const std::runtime_error& e)
1440 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
1441 << groupKey <<
")': \n"
1442 << e.what() << __E__;
1443 __COUT_WARN__ << ss.str();
1444 if(accumulatedTreeErrors)
1445 *accumulatedTreeErrors += ss.str();
1451 __SS__ <<
"An unknown error occurred while loading table group '" << groupName
1452 <<
"(" << groupKey <<
")." << __E__;
1453 __COUT_WARN__ << ss.str();
1454 if(accumulatedTreeErrors)
1455 *accumulatedTreeErrors += ss.str();
1466 lastFailedGroupLoad_[ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN] =
1467 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1473 catch(
const std::runtime_error& e)
1475 __SS__ <<
"Error occurred while loading table group: " << e.what() << __E__;
1476 __COUT_WARN__ << ss.str();
1477 if(accumulatedTreeErrors)
1478 *accumulatedTreeErrors += ss.str();
1484 __SS__ <<
"An unknown error occurred while loading table group." << __E__;
1485 __COUT_WARN__ << ss.str();
1486 if(accumulatedTreeErrors)
1487 *accumulatedTreeErrors += ss.str();
1499 std::map<std::string, std::pair<std::string, TableGroupKey>>
1500 ConfigurationManager::getActiveTableGroups(
void)
const
1503 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
1505 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1506 std::pair<std::string, TableGroupKey>(
1507 theContextTableGroup_,
1508 theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
1509 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
1510 std::pair<std::string, TableGroupKey>(
1511 theBackboneTableGroup_,
1512 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
1513 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
1514 std::pair<std::string, TableGroupKey>(
1515 theIterateTableGroup_,
1516 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
1517 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1518 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_,
1519 theConfigurationTableGroupKey_
1520 ? *theConfigurationTableGroupKey_
1526 const std::string& ConfigurationManager::getActiveGroupName(
const std::string& type)
const
1528 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1529 return theConfigurationTableGroup_;
1530 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1531 return theContextTableGroup_;
1532 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1533 return theBackboneTableGroup_;
1534 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1535 return theIterateTableGroup_;
1537 __SS__ <<
"Invalid type requested '" << type <<
"'" << __E__;
1538 __COUT_ERR__ << ss.str();
1543 TableGroupKey ConfigurationManager::getActiveGroupKey(
const std::string& type)
const
1545 if(type ==
"" || type == ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION)
1546 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_
1548 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT)
1549 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
1550 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE)
1551 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
1552 if(type == ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE)
1553 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
1555 __SS__ <<
"Invalid type requested '" << type <<
"'" << __E__;
1556 __COUT_ERR__ << ss.str();
1562 const std::string& contextUID,
const std::string& applicationUID)
const
1564 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1570 const std::string& contextUID,
const std::string& applicationUID)
const
1572 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1573 contextUID +
"/LinkToApplicationTable/" + applicationUID);
1578 const std::string& contextUID,
const std::string& applicationUID)
const
1580 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" +
1581 contextUID +
"/LinkToApplicationTable/" + applicationUID +
1582 "/LinkToSupervisorTable");
1587 bool doNotThrowOnBrokenUIDLinks)
const
1592 if(nodeString.length() < 1)
1594 __SS__ << (
"Invalid empty node name") << __E__;
1595 __COUT_ERR__ << ss.str();
1600 unsigned int startingIndex = 0;
1601 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
1604 std::string nodeName = nodeString.substr(
1605 startingIndex, nodeString.find(
'/', startingIndex) - startingIndex);
1607 if(nodeName.length() < 1)
1617 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
1623 if(childPath.length() > 1)
1624 return configTree.getNode(childPath, doNotThrowOnBrokenUIDLinks);
1631 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree& node,
1632 const std::string& startPath)
const
1636 std::string path =
"/";
1646 std::vector<std::pair<std::string, ConfigurationTree>> ConfigurationManager::getChildren(
1647 std::map<std::string, TableVersion>* memberMap,
1648 std::string* accumulatedTreeErrors)
const
1650 std::vector<std::pair<std::string, ConfigurationTree>> retMap;
1655 if(!memberMap || memberMap->empty())
1657 for(
auto& configPair : nameToTableMap_)
1662 if(configPair.second->isActive())
1666 if(accumulatedTreeErrors)
1670 std::vector<std::pair<std::string, ConfigurationTree>>
1671 newNodeChildren = newNode.getChildren();
1672 for(
auto& newNodeChild : newNodeChildren)
1674 std::vector<std::pair<std::string, ConfigurationTree>>
1675 twoDeepChildren = newNodeChild.second.getChildren();
1677 for(
auto& twoDeepChild : twoDeepChildren)
1682 if(twoDeepChild.second.isLinkNode() &&
1683 twoDeepChild.second.isDisconnected() &&
1684 twoDeepChild.second.getDisconnectedTableName() !=
1685 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1686 *accumulatedTreeErrors +=
1687 "\n\nAt node '" + configPair.first +
1688 "' with entry UID '" + newNodeChild.first +
1689 "' there is a disconnected child node at link "
1691 twoDeepChild.first +
"'" +
1692 " that points to table named '" +
1693 twoDeepChild.second.getDisconnectedTableName() +
1698 catch(std::runtime_error& e)
1700 *accumulatedTreeErrors +=
1701 "\n\nAt node '" + configPair.first +
1702 "' error detected descending through children:\n" + e.what();
1707 std::pair<std::string, ConfigurationTree>(configPair.first, newNode));
1715 for(
auto& memberPair : *memberMap)
1717 auto mapIt = nameToTableMap_.find(memberPair.first);
1718 if(mapIt == nameToTableMap_.end())
1720 __SS__ <<
"Get Children with member map requires a child '"
1721 << memberPair.first <<
"' that is not present!" << __E__;
1724 if(!(*mapIt).second->isActive())
1726 __SS__ <<
"Get Children with member map requires a child '"
1727 << memberPair.first <<
"' that is not active!" << __E__;
1733 if(accumulatedTreeErrors)
1737 std::vector<std::pair<std::string, ConfigurationTree>>
1738 newNodeChildren = newNode.getChildren();
1739 for(
auto& newNodeChild : newNodeChildren)
1741 std::vector<std::pair<std::string, ConfigurationTree>>
1742 twoDeepChildren = newNodeChild.second.getChildren();
1744 for(
auto& twoDeepChild : twoDeepChildren)
1748 if(twoDeepChild.second.isLinkNode() &&
1749 twoDeepChild.second.isDisconnected() &&
1750 twoDeepChild.second.getDisconnectedTableName() !=
1751 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1753 *accumulatedTreeErrors +=
1754 "\n\nAt node '" + memberPair.first +
1755 "' with entry UID '" + newNodeChild.first +
1756 "' there is a disconnected child node at link column "
1758 twoDeepChild.first +
"'" +
1759 " that points to table named '" +
1760 twoDeepChild.second.getDisconnectedTableName() +
1767 for(
auto& searchMemberPair : *memberMap)
1768 if(searchMemberPair.first ==
1769 twoDeepChild.second.getDisconnectedTableName())
1777 <<
"Note: It may be safe to ignore this "
1778 <<
"error since the link's target table "
1779 << twoDeepChild.second.getDisconnectedTableName()
1780 <<
" is not a member of this group (and may not "
1782 <<
"loaded yet)" << __E__;
1783 *accumulatedTreeErrors += ss.str();
1789 catch(std::runtime_error& e)
1791 __SS__ <<
"At node '" << memberPair.first
1792 <<
"' error detected descending through children:\n"
1793 << e.what() << __E__;
1794 *accumulatedTreeErrors += ss.str();
1799 std::pair<std::string, ConfigurationTree>(memberPair.first, newNode));
1811 const TableBase* ConfigurationManager::getTableByName(
const std::string& tableName)
const
1813 std::map<std::string, TableBase*>::const_iterator it;
1814 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
1816 __SS__ <<
"\n\nCan not find configuration named '" << tableName
1817 <<
"'\n\n\n\nYou need to load the configuration before it can be used."
1818 <<
" It probably is missing from the member list of the Table "
1819 "Group that was loaded.\n"
1820 <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
1822 <<
"\n\t StartOTS.sh --wiz"
1826 ss << __E__ << StringMacros::stackTrace() << __E__;
1840 TableGroupKey ConfigurationManager::loadConfigurationBackbone()
1842 if(!theBackboneTableGroupKey_)
1844 __COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently."
1850 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
1852 return *theBackboneTableGroupKey_;
1868 std::pair<std::string, TableGroupKey> ConfigurationManager::getTableGroupFromAlias(
1869 std::string systemAlias,
ProgressBar* progressBar)
1879 progressBar->step();
1881 if(systemAlias.find(
"GROUP:") == 0)
1884 progressBar->step();
1886 unsigned int i = strlen(
"GROUP:");
1887 unsigned int j = systemAlias.find(
':', i);
1890 progressBar->step();
1892 return std::pair<std::string, TableGroupKey>(
1893 systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
1895 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
1898 loadConfigurationBackbone();
1901 progressBar->step();
1907 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getNode(systemAlias);
1910 progressBar->step();
1912 return std::pair<std::string, TableGroupKey>(
1913 entry.getNode(
"GroupName").getValueAsString(),
1914 TableGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1923 progressBar->step();
1925 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
1929 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
1930 ConfigurationManager::getActiveGroupAliases(
void)
1932 restoreActiveTableGroups();
1936 std::map<std::string ,
1940 std::vector<std::pair<std::string, ConfigurationTree>> entries =
1941 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getChildren();
1942 for(
auto& entryPair : entries)
1944 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(
1945 entryPair.second.getNode(
"GroupName").getValueAsString(),
1946 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
1954 std::map<std::string ,
1956 ConfigurationManager::getVersionAliases(
void)
const
1960 std::map<std::string ,
1964 std::map<std::string, TableVersion> activeVersions = getActiveVersions();
1965 std::string versionAliasesTableName =
1966 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
1967 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
1969 __SS__ <<
"Active version of VersionAliases missing!"
1970 <<
"Make sure you have a valid active Backbone Group." << __E__;
1971 __COUT_WARN__ <<
"\n" << ss.str();
1975 __COUT__ <<
"activeVersions[\"" << versionAliasesTableName
1976 <<
"\"]=" << activeVersions[versionAliasesTableName] << __E__;
1978 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
1979 getNode(versionAliasesTableName).getChildren();
1984 std::string tableName, versionAlias;
1985 for(
auto& aliasNodePair : aliasNodePairs)
1987 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
1988 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
1990 if(retMap.find(tableName) != retMap.end() &&
1991 retMap[tableName].find(versionAlias) != retMap[tableName].end())
1996 retMap[tableName][versionAlias] =
1997 TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
2005 std::map<std::string, TableVersion> ConfigurationManager::getActiveVersions(
void)
const
2007 std::map<std::string, TableVersion> retMap;
2008 for(
auto& config : nameToTableMap_)
2013 if(config.second && config.second->isActive())
2017 retMap.insert(std::pair<std::string, TableVersion>(
2018 config.first, config.second->getViewVersion()));
2047 std::shared_ptr<TableGroupKey> ConfigurationManager::makeTheTableGroupKey(
2050 if(theConfigurationTableGroupKey_)
2052 if(*theConfigurationTableGroupKey_ != key)
2053 destroyTableGroup();
2055 return theConfigurationTableGroupKey_;
2057 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
2061 std::string ConfigurationManager::encodeURIComponent(
const std::string& sourceStr)
2063 std::string retStr =
"";
2065 for(
const auto& c : sourceStr)
2066 if((c >=
'a' && c <=
'z') || (c >=
'A' && c <=
'Z') || (c >=
'0' && c <=
'9'))
2070 sprintf(encodeStr,
"%%%2.2X", c);
2071 retStr += encodeStr;
2077 const std::set<std::string>& ConfigurationManager::getContextMemberNames()
2079 return ConfigurationManager::contextMemberNames_;
2082 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
2084 return ConfigurationManager::backboneMemberNames_;
2087 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
2089 return ConfigurationManager::iterateMemberNames_;
2093 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
2095 __COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
2100 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
2129 theInterface_->get(table,
2130 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
2136 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
2138 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2139 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2142 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2147 auto colMap = view->getColumnNamesMap();
2149 view->setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
2150 view->setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
2151 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2152 view->setValue(
"1", 0, colMap[
"Status"]);
2154 __COUT__ <<
"Done adding context record..." << __E__;
2164 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
2170 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
2172 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2173 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2176 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2181 auto colMap = view->getColumnNamesMap();
2183 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2184 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
2185 view->setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
2186 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
2187 view->setValue(
"1", 0, colMap[
"Status"]);
2189 __COUT__ <<
"Done adding application record..." << __E__;
2196 theInterface_->get(table,
2197 "FESupervisorTable",
2203 nameToTableMap_[
"FESupervisorTable"] = table;
2205 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2206 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2209 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2214 auto colMap = view->getColumnNamesMap();
2216 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
2217 view->setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
2219 "MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
2221 __COUT__ <<
"Done adding supervisor record..." << __E__;
2226 recursiveInitFromFhiclPSet(
"FEInterfaceTable" ,
2229 "MacroMakerFESupervisorInterfaces" ,
2233 for(
auto& table : nameToTableMap_)
2235 table.second->getViewP()->init();
2241 __COUT__ <<
"================================================" << __E__;
2242 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
2243 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
2245 auto sups = getNode(
"FESupervisorTable").getChildrenNames();
2246 __COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
2247 auto fes = getNode(
"FEInterfaceTable").getChildrenNames();
2248 __COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
2250 auto a = getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
2251 __COUTV__(a.getValueAsString());
2253 auto b = a.getNode(
"MacroMakerFEContext");
2254 __COUTV__(b.getValueAsString());
2256 auto c = b.getNode(
"LinkToApplicationTable");
2257 __COUTV__(c.getValueAsString());
2259 auto d = c.getNode(
"MacroMakerFESupervisor");
2260 __COUTV__(d.getValueAsString());
2262 auto e = d.getNode(
"LinkToSupervisorTable");
2263 __COUTV__(e.getValueAsString());
2265 auto f = e.getNode(
"LinkToFEInterfaceTable");
2266 __COUTV__(f.getValueAsString());
2268 auto z = f.getChildrenNames();
2269 __COUTV__(StringMacros::vectorToString(z));
2270 __COUTV__(z.size());
2271 auto y = f.getChildrenNames(
false ,
true );
2272 __COUTV__(StringMacros::vectorToString(y));
2273 __COUTV__(y.size());
2274 auto x = f.getChildrenNames(
true ,
true );
2275 __COUTV__(StringMacros::vectorToString(x));
2276 __COUTV__(x.size());
2278 auto g = f.getNode(
"dtc0");
2279 __COUTV__(g.getValueAsString());
2280 auto h = f.getNode(
"interface0");
2281 __COUTV__(h.getValueAsString());
2284 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
2286 "MacroMakerFEContext/LinkToApplicationTable/"
2287 "MacroMakerFESupervisor/LinkToSupervisorTable")
2288 .getNode(
"LinkToFEInterfaceTable")
2289 .getChildrenNames(
true ,
true );
2290 __COUTV__(fes.size());
2291 __COUTV__(StringMacros::vectorToString(fes));
2302 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
2303 const fhicl::ParameterSet& pset,
2304 const std::string& recordName,
2305 const std::string& groupName,
2306 const std::string& groupLinkIndex)
2308 __COUT__ << __COUT_HDR_P__ <<
"Adding table '" << tableName <<
"' record(s)..."
2315 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
2317 __COUT__ <<
"Table not found, so making '" << tableName <<
"'instance..."
2319 theInterface_->get(table,
2326 nameToTableMap_[tableName] = table;
2327 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2331 __COUT__ <<
"Existing table found, so using '" << tableName <<
"'instance..."
2333 table = nameToTableMap_[tableName];
2336 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2339 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2342 if(recordName !=
"")
2350 __COUTV__(recordName);
2353 unsigned int r = view->addRow();
2354 auto colMap = view->getColumnNamesMap();
2357 view->setValue(recordName, r, view->getColUID());
2360 view->setValue(
"1", r, view->getColStatus());
2364 __COUT__ <<
"No status column to set for '" << recordName <<
"'" << __E__;
2369 int groupIDCol = view->getColLinkGroupID(groupLinkIndex);
2370 __COUT__ <<
"Setting group ID for group link ID '" << groupLinkIndex
2371 <<
"' at column " << groupIDCol <<
" to '" << groupName <<
".'"
2374 view->setValue(groupName, r, groupIDCol);
2378 auto names = pset.get_names();
2379 for(
const auto& colName : names)
2381 if(!pset.is_key_to_atom(colName))
2384 auto colIt = colMap.find(colName);
2385 if(colIt == colMap.end())
2387 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName
2388 <<
"' in table '" << tableName <<
"' was not found in columns."
2389 <<
"\n\nHere are the existing column names:\n";
2391 for(
const auto& col : colMap)
2392 ss <<
"\n" << ++i <<
".\t" << col.first;
2396 const std::string value = pset.get<std::string>(colName);
2397 __COUT__ <<
"Setting '" << recordName <<
"' parameter at column "
2398 << colIt->second <<
", '" << colName <<
"'\t = " << value
2400 view->setValueAsString(value, r, colIt->second);
2404 for(
const auto& linkName : names)
2406 if(pset.is_key_to_atom(linkName))
2409 __COUTV__(linkName);
2412 unsigned int c = linkName.size() - 1;
2414 if(linkName[c] ==
'_')
2419 __SS__ <<
"Illegal link name '" << linkName
2420 <<
"' found. The format must be <Column name>_<Target table "
2421 "name>,.. for example '"
2422 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'"
2426 std::string colName = linkName.substr(0, c);
2429 auto colIt = colMap.find(colName);
2430 if(colIt == colMap.end())
2432 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName
2433 <<
"' in table '" << tableName <<
"' was not found in columns."
2434 <<
"\n\nHere are the existing column names:\n";
2436 for(
const auto& col : colMap)
2437 ss <<
"\n" << i <<
".\t" << col.first << __E__;
2442 std::pair<
unsigned int ,
unsigned int >
2445 view->getChildLink(colIt->second, isGroupLink, linkPair);
2451 std::string linkTableName = linkName.substr(c + 1);
2452 __COUTV__(linkTableName);
2454 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
2455 auto linkRecords = linkPset.get_pset_names();
2456 if(!isGroupLink && linkRecords.size() > 1)
2458 __SS__ <<
"A Unique Link can only point to one record. "
2459 <<
"The specified link '" << colName <<
"' of record '"
2460 << recordName <<
"' in table '" << tableName <<
"' has "
2461 << linkRecords.size() <<
" children records specified. "
2466 if(linkRecords.size() == 0)
2468 __COUT__ <<
"No child records, so leaving link disconnected."
2473 __COUT__ <<
"Setting Link at columns [" << linkPair.first <<
","
2474 << linkPair.second <<
"]" << __E__;
2475 view->setValue(linkTableName, r, linkPair.first);
2479 __COUT__ <<
"Setting up Unique link to " << linkRecords[0] << __E__;
2481 view->setValue(linkRecords[0], r, linkPair.second);
2483 recursiveInitFromFhiclPSet(
2485 linkPset.get<fhicl::ParameterSet>(
2494 std::string childLinkIndex =
2495 view->getColumnInfo(linkPair.first).getChildLinkIndex();
2496 std::string groupName = recordName +
"Group";
2498 view->setValue(groupName, r, linkPair.second);
2500 for(
const auto& groupRecord : linkRecords)
2502 __COUT__ <<
"Setting '" << childLinkIndex <<
"' Group link to '"
2503 << groupName <<
"' record '" << groupRecord <<
"'"
2506 recursiveInitFromFhiclPSet(
2508 linkPset.get<fhicl::ParameterSet>(
2518 else if(groupName !=
"")
2522 __COUTV__(groupName);
2523 auto psets = pset.get_pset_names();
2524 for(
const auto& ps : psets)
2527 recursiveInitFromFhiclPSet(
2529 pset.get<fhicl::ParameterSet>(ps) ,
2539 __SS__ <<
"Illegal recursive parameters!" << __E__;
2544 __COUT__ << __COUT_HDR_P__ <<
"Done adding table '" << tableName <<
"' record(s)..."
2550 bool ConfigurationManager::isOwnerFirstAppInContext()
2552 __COUT__ <<
"Checking if owner is first App in Context." << __E__;
2553 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
2556 __COUTV__(ownerContextUID_);
2557 __COUTV__(ownerAppUID_);
2559 auto contextChildren =
2560 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" + ownerContextUID_)
2561 .getChildrenNames();
2563 bool isFirstAppInContext =
2564 contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
2566 __COUTV__(isFirstAppInContext);
2568 return isFirstAppInContext;