1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "artdaq/Application/LoadParameterSet.hh"
3 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
4 #include "otsdaq/ProgressBar/ProgressBar.h"
8 #include "otsdaq/TableCore/TableGroupKey.h"
9 #include "otsdaq/TablePlugins/DesktopIconTable.h"
14 #define __MF_SUBJECT__ "ConfigurationManager"
17 const std::string ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH = std::string(__ENV__(
"SERVICE_DATA_PATH")) +
"/RunControlData/";
18 const std::string ConfigurationManager::LAST_ACTIVATED_CONFIG_GROUP_FILE =
"CFGLastActivatedConfigGroup.hist";
19 const std::string ConfigurationManager::LAST_ACTIVATED_CONTEXT_GROUP_FILE =
"CFGLastActivatedContextGroup.hist";
20 const std::string ConfigurationManager::LAST_ACTIVATED_BACKBONE_GROUP_FILE =
"CFGLastActivatedBackboneGroup.hist";
21 const std::string ConfigurationManager::LAST_ACTIVATED_ITERATOR_GROUP_FILE =
"CFGLastActivatedIteratorGroup.hist";
24 const std::string ConfigurationManager::READONLY_USER =
"READONLY_USER";
26 const std::string ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME =
"XDAQContextTable";
27 const std::string ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME =
"XDAQApplicationTable";
28 const std::string ConfigurationManager::XDAQ_APP_PROPERTY_TABLE_NAME =
"XDAQApplicationPropertyTable";
29 const std::string ConfigurationManager::GROUP_ALIASES_TABLE_NAME =
"GroupAliasesTable";
30 const std::string ConfigurationManager::VERSION_ALIASES_TABLE_NAME =
"VersionAliasesTable";
31 const std::string ConfigurationManager::ARTDAQ_TOP_TABLE_NAME =
"ARTDAQSupervisorTable";
32 const std::string ConfigurationManager::DESKTOP_ICON_TABLE_NAME =
"DesktopIconTable";
35 const std::string ConfigurationManager::ACTIVE_GROUPS_FILENAME =
36 ((getenv(
"SERVICE_DATA_PATH") == NULL) ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData") : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
37 "/ActiveTableGroups.cfg";
38 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
39 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
41 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT =
"Context";
42 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE =
"Backbone";
43 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE =
"Iterate";
44 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION =
"Configuration";
45 const std::string ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN =
"Unknown";
47 const uint8_t ConfigurationManager::METADATA_COL_ALIASES = 1;
48 const uint8_t ConfigurationManager::METADATA_COL_COMMENT = 2;
49 const uint8_t ConfigurationManager::METADATA_COL_AUTHOR = 3;
50 const uint8_t ConfigurationManager::METADATA_COL_TIMESTAMP = 4;
52 const std::set<std::string> ConfigurationManager::contextMemberNames_ = {ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
53 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
54 "XDAQApplicationPropertyTable",
55 ConfigurationManager::DESKTOP_ICON_TABLE_NAME,
56 "MessageFacilityTable",
57 "GatewaySupervisorTable",
59 "DesktopWindowParameterTable",
60 "SlowControlsDashboardSupervisorTable"};
61 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = {ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
62 ConfigurationManager::VERSION_ALIASES_TABLE_NAME};
63 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = {
"IterateTable",
65 "IterationTargetTable",
66 "IterationCommandBeginLabelTable",
67 "IterationCommandChooseFSMTable",
68 "IterationCommandConfigureAliasTable",
69 "IterationCommandConfigureGroupTable",
70 "IterationCommandExecuteFEMacroTable",
71 "IterationCommandExecuteMacroTable",
72 "IterationCommandMacroDimensionalLoopTable",
73 "IterationCommandMacroDimensionalLoopParameterTable",
74 "IterationCommandModifyGroupTable",
75 "IterationCommandRepeatLabelTable",
76 "IterationCommandRunTable"};
80 ConfigurationManager::ConfigurationManager(
bool initForWriteAccess ,
bool doInitializeFromFhicl )
83 , theConfigurationTableGroupKey_(0)
84 , theContextTableGroupKey_(0)
85 , theBackboneTableGroupKey_(0)
86 , theConfigurationTableGroup_(
"")
87 , theContextTableGroup_(
"")
88 , theBackboneTableGroup_(
"")
91 theInterface_ = ConfigurationInterface::getInstance(
false);
105 groupMetadataTable_.setTableName(ConfigurationInterface::GROUP_METADATA_TABLE_NAME);
106 std::vector<TableViewColumnInfo>* colInfo = groupMetadataTable_.getMockupViewP()->getColumnsInfoP();
111 TableViewColumnInfo::DATATYPE_NUMBER,
114 colInfo->push_back(
TableViewColumnInfo(TableViewColumnInfo::TYPE_DATA,
"GroupAliases",
"GROUP_ALIASES", TableViewColumnInfo::DATATYPE_STRING,
"", 0));
116 TableViewColumnInfo::COL_NAME_COMMENT,
117 "COMMENT_DESCRIPTION",
118 TableViewColumnInfo::DATATYPE_STRING,
124 TableViewColumnInfo::DATATYPE_STRING,
128 TableViewColumnInfo(TableViewColumnInfo::TYPE_TIMESTAMP,
"GroupCreationTime",
"GROUP_CREATION_TIME", TableViewColumnInfo::DATATYPE_TIME,
"", 0));
129 auto tmpVersion = groupMetadataTable_.createTemporaryView();
130 groupMetadataTable_.setActiveView(tmpVersion);
132 groupMetadataTable_.getViewP()->addRow();
135 if(doInitializeFromFhicl)
138 initializeFromFhicl(__ENV__(
"CONFIGURATION_INIT_FCL"));
142 init(0 , initForWriteAccess);
147 ConfigurationManager::ConfigurationManager(
const std::string& username) :
ConfigurationManager(true )
149 __COUT_INFO__ <<
"Private constructor for write access called." << __E__;
150 username_ = username;
154 ConfigurationManager::~ConfigurationManager() { destroy(); }
162 void ConfigurationManager::init(std::string* accumulatedErrors ,
bool initForWriteAccess , std::string* accumulatedWarnings )
174 __COUTV__(username_);
176 restoreActiveTableGroups(accumulatedErrors ?
true :
false ,
181 (username_ == ConfigurationManager::READONLY_USER) ?
182 (!initForWriteAccess)
191 catch(std::runtime_error& e)
193 __COUT_ERR__ <<
"Error caught in init(): " << e.what();
194 if(accumulatedErrors)
195 *accumulatedErrors += e.what();
210 void ConfigurationManager::restoreActiveTableGroups(
bool throwErrors ,
211 const std::string& pathToActiveGroupsFile ,
212 bool onlyLoadIfBackboneOrContext ,
213 std::string* accumulatedWarnings )
215 destroyTableGroup(
"",
true);
217 std::string fn = pathToActiveGroupsFile ==
"" ? ACTIVE_GROUPS_FILENAME : pathToActiveGroupsFile;
218 FILE* fp = fopen(fn.c_str(),
"r");
220 __COUT__ <<
"ACTIVE_GROUPS_FILENAME = " << fn << __E__;
221 __COUT__ <<
"ARTDAQ_DATABASE_URI = " << std::string(__ENV__(
"ARTDAQ_DATABASE_URI")) << __E__;
225 __COUT_WARN__ <<
"No active groups file found at " << fn << __E__;
234 std::string groupName;
235 std::string errorStr =
"";
240 while(fgets(tmp, 500, fp))
245 sscanf(tmp,
"%d", &numberCheck);
248 __COUT__ <<
"Out of sync with active groups file lines, attempting to resync." << __E__;
254 sscanf(tmp,
"%s", strVal);
255 for(
unsigned int j = 0; j < strlen(strVal); ++j)
256 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') || (strVal[j] >=
'A' && strVal[j] <=
'Z') || (strVal[j] >=
'0' && strVal[j] <=
'9')))
259 __COUT_INFO__ <<
"Illegal character found in group name '" << strVal <<
"', so skipping! Check active groups file: " << fn << __E__;
270 sscanf(tmp,
"%s", strVal);
272 for(
unsigned int j = 0; j < strlen(strVal); ++j)
273 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
277 if(groupName.size() > 3)
278 __COUT_INFO__ <<
"Skipping active group with illegal character in group key '" << strVal <<
".' Check active groups file: " << fn << __E__;
289 TableGroupKey::getFullGroupString(groupName,
TableGroupKey(strVal));
293 __COUT__ <<
"illegal group according to TableGroupKey::getFullGroupString... "
294 "Check active groups file: "
305 std::string groupAccumulatedErrors =
"";
307 if(accumulatedWarnings)
308 __COUT__ <<
"Ignoring warnings while loading and activating group '" << groupName <<
"(" << strVal <<
")'" << __E__;
310 loadTableGroup(groupName,
315 (accumulatedWarnings ? &groupAccumulatedErrors : 0) ,
322 onlyLoadIfBackboneOrContext
325 if(accumulatedWarnings)
326 *accumulatedWarnings += groupAccumulatedErrors;
328 catch(std::runtime_error& e)
330 ss <<
"Failed to load group in ConfigurationManager::init() with name '" << groupName <<
"(" << strVal
331 <<
")' specified active by active groups file: " << fn << __E__;
332 ss << e.what() << __E__;
334 errorStr += ss.str();
338 ss <<
"Failed to load group in ConfigurationManager::init() with name '" << groupName <<
"(" << strVal
339 <<
")' specified active by active groups file: " << fn << __E__;
341 errorStr += ss.str();
347 if(throwErrors && errorStr !=
"")
349 __SS__ <<
"\n" << errorStr;
352 else if(errorStr !=
"")
353 __COUT_INFO__ <<
"\n" << errorStr;
362 void ConfigurationManager::destroyTableGroup(
const std::string& theGroup,
bool onlyDeactivate)
365 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
366 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
367 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
368 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
370 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
372 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
373 __COUT_ERR__ << ss.str();
377 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
381 __COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
383 __COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
385 __COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
387 __COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
390 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
391 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
394 contextFindIt = contextMemberNames_.find(it->first);
395 backboneFindIt = backboneMemberNames_.find(it->first);
396 iterateFindIt = iterateMemberNames_.find(it->first);
397 if(theGroup ==
"" || ((isContext && contextFindIt != contextMemberNames_.end()) || (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
398 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
399 (!isContext && !isBackbone && contextFindIt == contextMemberNames_.end() && backboneFindIt == backboneMemberNames_.end() &&
400 iterateFindIt == iterateMemberNames_.end())))
408 it->second->deactivate();
414 nameToTableMap_.erase(it++);
423 theConfigurationTableGroup_ =
"";
424 if(theConfigurationTableGroupKey_ != 0)
426 __COUT__ <<
"Destroying Configuration Key: " << *theConfigurationTableGroupKey_ << __E__;
427 theConfigurationTableGroupKey_.reset();
434 theBackboneTableGroup_ =
"";
435 if(theBackboneTableGroupKey_ != 0)
437 __COUT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_ << __E__;
438 theBackboneTableGroupKey_.reset();
443 theIterateTableGroup_ =
"";
444 if(theIterateTableGroupKey_ != 0)
446 __COUT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_ << __E__;
447 theIterateTableGroupKey_.reset();
452 theContextTableGroup_ =
"";
453 if(theContextTableGroupKey_ != 0)
455 __COUT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_ << __E__;
456 theContextTableGroupKey_.reset();
462 void ConfigurationManager::destroy(
void)
477 const std::string& ConfigurationManager::convertGroupTypeToName(
const ConfigurationManager::GroupType& groupTypeId)
479 return groupTypeId == ConfigurationManager::GroupType::CONTEXT_TYPE
480 ? ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT
481 : (groupTypeId == ConfigurationManager::GroupType::BACKBONE_TYPE
482 ? ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE
483 : (groupTypeId == ConfigurationManager::GroupType::ITERATE_TYPE ? ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE
484 : ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION));
494 ConfigurationManager::GroupType ConfigurationManager::getTypeOfGroup(
const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
496 bool isContext =
true;
497 bool isBackbone =
true;
498 bool isIterate =
true;
500 bool inContext =
false;
501 bool inBackbone =
false;
502 bool inIterate =
false;
503 unsigned int matchCount = 0;
505 for(
auto& memberPair : memberMap)
510 for(
auto& contextMemberString : contextMemberNames_)
511 if(memberPair.first == contextMemberString)
523 __SS__ <<
"This group is an incomplete match to a Context group.\n";
524 __COUT_ERR__ <<
"\n" << ss.str();
525 ss <<
"\nTo be a Context group, the members must exactly match "
526 <<
"the following members:\n";
528 for(
const auto& memberName : contextMemberNames_)
529 ss << ++i <<
". " << memberName <<
"\n";
530 ss <<
"\nThe members are as follows::\n";
532 for(
const auto& memberPairTmp : memberMap)
533 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
540 for(
auto& backboneMemberString : backboneMemberNames_)
541 if(memberPair.first == backboneMemberString)
553 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
554 __COUT_ERR__ <<
"\n" << ss.str();
555 ss <<
"\nTo be a Backbone group, the members must exactly match "
556 <<
"the following members:\n";
558 for(
auto& memberName : backboneMemberNames_)
559 ss << ++i <<
". " << memberName <<
"\n";
560 ss <<
"\nThe members are as follows::\n";
562 for(
const auto& memberPairTmp : memberMap)
563 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
571 for(
auto& iterateMemberString : iterateMemberNames_)
572 if(memberPair.first == iterateMemberString)
584 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
585 __COUT_ERR__ <<
"\n" << ss.str();
586 ss <<
"\nTo be a Iterate group, the members must exactly match "
587 <<
"the following members:\n";
589 for(
auto& memberName : iterateMemberNames_)
590 ss << ++i <<
". " << memberName <<
"\n";
591 ss <<
"\nThe members are as follows::\n";
593 for(
const auto& memberPairTmp : memberMap)
594 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
601 if(isContext && matchCount != contextMemberNames_.size())
603 __SS__ <<
"This group is an incomplete match to a Context group: "
604 <<
" Size=" << matchCount <<
" but should be " << contextMemberNames_.size() << __E__;
605 __COUT_ERR__ <<
"\n" << ss.str();
606 ss <<
"\nThe members currently are...\n";
608 for(
auto& memberPair : memberMap)
609 ss << ++i <<
". " << memberPair.first <<
"\n";
610 ss <<
"\nThe expected Context members are...\n";
612 for(
auto& memberName : contextMemberNames_)
613 ss << ++i <<
". " << memberName <<
"\n";
618 if(isBackbone && matchCount != backboneMemberNames_.size())
620 __SS__ <<
"This group is an incomplete match to a Backbone group: "
621 <<
" Size=" << matchCount <<
" but should be " << backboneMemberNames_.size() << __E__;
622 __COUT_ERR__ <<
"\n" << ss.str();
623 ss <<
"\nThe members currently are...\n";
625 for(
auto& memberPair : memberMap)
626 ss << ++i <<
". " << memberPair.first <<
"\n";
627 ss <<
"\nThe expected Backbone members are...\n";
629 for(
auto& memberName : backboneMemberNames_)
630 ss << ++i <<
". " << memberName <<
"\n";
635 if(isIterate && matchCount != iterateMemberNames_.size())
637 __SS__ <<
"This group is an incomplete match to a Iterate group: "
638 <<
" Size=" << matchCount <<
" but should be " << iterateMemberNames_.size() << __E__;
639 __COUT_ERR__ <<
"\n" << ss.str();
640 ss <<
"\nThe members currently are...\n";
642 for(
auto& memberPair : memberMap)
643 ss << ++i <<
". " << memberPair.first <<
"\n";
644 ss <<
"\nThe expected Iterate members are...\n";
646 for(
auto& memberName : iterateMemberNames_)
647 ss << ++i <<
". " << memberName <<
"\n";
652 return isContext ? ConfigurationManager::GroupType::CONTEXT_TYPE
653 : (isBackbone ? ConfigurationManager::GroupType::BACKBONE_TYPE
654 : (isIterate ? ConfigurationManager::GroupType::ITERATE_TYPE : ConfigurationManager::GroupType::CONFIGURATION_TYPE));
660 const std::string& ConfigurationManager::getTypeNameOfGroup(
const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
662 return convertGroupTypeToName(getTypeOfGroup(memberMap));
671 #define OUT out << tabStr << commentStr
672 #define PUSHTAB tabStr += "\t"
673 #define POPTAB tabStr.resize(tabStr.size() - 1)
674 #define PUSHCOMMENT commentStr += "# "
675 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
677 void ConfigurationManager::dumpMacroMakerModeFhicl()
679 std::string filepath = __ENV__(
"USER_DATA") + std::string(
"/") +
"MacroMakerModeConfigurations";
680 mkdir(filepath.c_str(), 0755);
681 filepath +=
"/MacroMakerModeFhiclDump.fcl";
682 __COUT__ <<
"dumpMacroMakerModeFhicl: " << filepath << __E__;
688 std::string tabStr =
"";
689 std::string commentStr =
"";
691 out.open(filepath, std::fstream::out | std::fstream::trunc);
694 __SS__ <<
"Failed to open MacroMaker mode fcl file for configuration dump: " << filepath << __E__;
700 std::vector<std::pair<std::string, ConfigurationTree>> fes = getNode(
"FEInterfaceTable").getChildren();
705 if(!fe.second.getNode(
"Status").getValue<
bool>())
710 OUT << fe.first <<
": {" << __E__;
715 OUT <<
"FEInterfacePluginName"
717 <<
"\"" << fe.second.getNode(
"FEInterfacePluginName").getValueAsString() <<
"\"" << __E__;
719 recursiveTreeToFhicl(fe.second.getNode(
"LinkToFETypeTable"), out, tabStr, commentStr);
722 OUT <<
"} //end " << fe.first << __E__ << __E__;
728 __COUT_ERR__ <<
"Failed to complete MacroMaker mode fcl "
729 "file configuration dump due to error."
748 std::string& tabStr ,
749 std::string& commentStr ,
754 __COUT__ << __COUT_HDR_P__ <<
"Depth limit reached. Ending recursion." << __E__;
758 __COUT__ << __COUT_HDR_P__ <<
"Adding tree record '" << node.getValueAsString() <<
"' fields..." << __E__;
760 if(depth == (
unsigned int)-1)
764 if(node.isLinkNode())
766 if(node.isDisconnected())
768 __COUT__ << node.getFieldName() <<
" field is a disconnected link." << __E__;
772 OUT << node.getFieldName() <<
"_" << node.getValueAsString(
true ) <<
" \t{" << __E__;
776 if(node.isGroupLinkNode())
779 std::vector<std::pair<std::string, ConfigurationTree>> children = node.getChildren();
780 for(
auto& child : children)
781 recursiveTreeToFhicl(child.second, out, tabStr, commentStr, depth - 1);
790 OUT << node.getValueAsString() <<
": \t{" << __E__;
794 std::vector<std::pair<std::string, ConfigurationTree>> fields = node.getChildren();
797 for(
unsigned int i = 0; i < fields.size() - 3; ++i)
799 __COUT__ << fields[i].first << __E__;
801 if(fields[i].second.isLinkNode())
803 recursiveTreeToFhicl(fields[i].second, out, tabStr, commentStr, depth - 1);
808 OUT << fields[i].second.getFieldName() <<
": \t";
809 if(fields[i].second.isValueNumberDataType())
810 OUT << fields[i].second.getValueAsString() << __E__;
812 OUT <<
"\"" << fields[i].second.getValueAsString() <<
"\"" << __E__;
818 OUT <<
"} //end " << node.getValueAsString() <<
" record" << __E__;
821 if(node.isLinkNode())
824 OUT <<
"} //end " << node.getValueAsString(
true ) <<
" link record" << __E__;
832 void ConfigurationManager::dumpActiveConfiguration(
const std::string& filePath,
const std::string& dumpType)
834 time_t rawtime = time(0);
835 __COUT__ <<
"filePath = " << filePath << __E__;
836 __COUT__ <<
"dumpType = " << dumpType << __E__;
839 fs.open(filePath, std::fstream::out | std::fstream::trunc);
850 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath <<
" could not be opened!" << __E__;
851 __COUT_ERR__ << ss.str();
857 (*out) <<
"#################################" << __E__;
858 (*out) <<
"This is an ots configuration dump.\n\n" << __E__;
859 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI = \t" << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
860 (*out) <<
"\nOriginal location of dump: \t" << filePath << __E__;
861 (*out) <<
"Type of dump: \t" << dumpType << __E__;
862 (*out) <<
"Linux time for dump: \t" << rawtime << __E__;
865 struct tm* timeinfo = localtime(&rawtime);
867 strftime(buffer, 100,
"%c %Z", timeinfo);
868 (*out) <<
"Display time for dump: \t" << buffer << __E__;
878 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups = cfgMgr->getActiveTableGroups();
880 (*out) <<
"\n\n************************" << __E__;
881 (*out) <<
"Active Groups:" << __E__;
882 for(
auto& group : activeGroups)
884 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" (" << group.second.second <<
")" << __E__;
889 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
891 (*out) <<
"\n\n************************" << __E__;
892 (*out) <<
"Active Tables:" << __E__;
893 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
896 for(
auto& table : activeTables)
898 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
903 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups = cfgMgr->getActiveTableGroups();
904 (*out) <<
"\n\n************************" << __E__;
905 (*out) <<
"Active Group Members:" << __E__;
907 for(
auto& group : activeGroups)
909 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" (" << group.second.second <<
")" << __E__;
911 if(group.second.first ==
"")
914 <<
"Empty group name. Assuming no active group." << __E__;
919 std::map<std::string , std::string > groupAliases;
920 std::string groupComment;
921 std::string groupAuthor;
922 std::string groupCreateTime;
923 time_t groupCreateTime_t;
925 cfgMgr->loadTableGroup(group.second.first,
938 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
939 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
941 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
942 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t) << __E__;
943 (*out) <<
"\t\tGroup Aliases: \t" << StringMacros::mapToString(groupAliases) << __E__;
945 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
946 tableCount += memberMap.size();
949 for(
auto& member : memberMap)
951 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v" << member.second << __E__;
954 (*out) <<
"\nActive Group Members total table count = " << tableCount << __E__;
958 std::map<std::string, TableVersion> activeTables = cfgMgr->getActiveVersions();
960 (*out) <<
"\n\n************************" << __E__;
961 (*out) <<
"Active Table Contents (table count = " << activeTables.size() <<
"):" << __E__;
963 for(
auto& table : activeTables)
965 (*out) <<
"\n\n=============================================================="
968 (*out) <<
"=================================================================="
971 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
973 cfgMgr->nameToTableMap_.find(table.first)->second->print(*out);
977 if(dumpType ==
"GroupKeys")
979 localDumpActiveGroups(
this, out);
981 else if(dumpType ==
"TableVersions")
983 localDumpActiveTables(
this, out);
985 else if(dumpType ==
"GroupKeysAndTableVersions")
987 localDumpActiveGroups(
this, out);
988 localDumpActiveTables(
this, out);
990 else if(dumpType ==
"All")
992 localDumpActiveGroups(
this, out);
993 localDumpActiveGroupMembers(
this, out);
994 localDumpActiveTables(
this, out);
995 localDumpActiveTableContents(
this, out);
999 __SS__ <<
"Invalid dump type '" << dumpType <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
1007 <<
"GroupsKeysAndTableVersions"
1012 "\n\nPlease change the State Machine configuration to a valid dump type." << __E__;
1026 void ConfigurationManager::loadMemberMap(
const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap, std::string* accumulateWarnings )
1031 for(
auto& memberPair : memberMap)
1043 tmpConfigBasePtr = 0;
1044 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1045 tmpConfigBasePtr = nameToTableMap_[memberPair.first];
1047 std::string getError =
"";
1050 theInterface_->get(tmpConfigBasePtr,
1059 catch(
const std::runtime_error& e)
1061 __SS__ <<
"Failed to load member table '" << memberPair.first <<
"' - here is the error: \n\n" << e.what() << __E__;
1063 ss <<
"\nIf the table '" << memberPair.first
1064 <<
"' should not exist, then please remove it from the group. If it "
1065 "should exist, then it "
1066 <<
"seems to have a problem; use the Table Editor to fix the table "
1068 "edit the table content to match the table definition."
1072 if(accumulateWarnings)
1073 getError = ss.str();
1079 __SS__ <<
"Failed to load member table '" << memberPair.first <<
"' due to unknown error!" << __E__;
1081 ss <<
"\nIf the table '" << memberPair.first
1082 <<
"' should not exist, then please remove it from the group. If it "
1083 "should exist, then it "
1084 <<
"seems to have a problem; use the Table Editor to fix the table "
1086 "edit the table content to match the table definition."
1090 if(accumulateWarnings)
1091 getError = ss.str();
1097 if(!tmpConfigBasePtr)
1099 __SS__ <<
"Null pointer returned for table '" << memberPair.first <<
".' Was the table info deleted?" << __E__;
1100 __COUT_ERR__ << ss.str();
1102 nameToTableMap_.erase(memberPair.first);
1103 if(accumulateWarnings)
1105 *accumulateWarnings += ss.str();
1112 nameToTableMap_[memberPair.first] = tmpConfigBasePtr;
1113 if(nameToTableMap_[memberPair.first]->getViewP())
1118 if(accumulateWarnings && getError !=
"")
1120 __SS__ <<
"Error caught during '" << memberPair.first <<
"' table retrieval: \n" << getError << __E__;
1121 __COUT_ERR__ << ss.str();
1122 *accumulateWarnings += ss.str();
1127 __SS__ << nameToTableMap_[memberPair.first]->getTableName() <<
": View version not activated properly!";
1149 void ConfigurationManager::loadTableGroup(
const std::string& groupName,
1152 std::map<std::string /*table name*/, TableVersion>* groupMembers,
1154 std::string* accumulatedWarnings,
1155 std::string* groupComment,
1156 std::string* groupAuthor,
1157 std::string* groupCreateTime,
1158 bool doNotLoadMember ,
1159 std::string* groupTypeString,
1160 std::map<std::string /*name*/, std::string /*alias*/>* groupAliases,
1161 bool onlyLoadIfBackboneOrContext )
try
1165 *groupComment =
"NO COMMENT FOUND";
1167 *groupAuthor =
"NO AUTHOR FOUND";
1169 *groupCreateTime =
"0";
1171 *groupTypeString =
"UNKNOWN";
1202 theInterface_->getTableGroupMembers(TableGroupKey::getFullGroupString(groupName, groupKey),
true );
1203 std::map<std::string , std::string > aliasMap;
1206 progressBar->step();
1209 auto metaTablePair = memberMap.find(groupMetadataTable_.getTableName());
1210 if(metaTablePair != memberMap.end())
1214 memberMap.erase(metaTablePair);
1217 while(groupMetadataTable_.getView().getNumberOfRows())
1218 groupMetadataTable_.getViewP()->deleteRow(0);
1223 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
1225 catch(
const std::runtime_error& e)
1227 __COUT_WARN__ <<
"Ignoring metadata error: " << e.what() << __E__;
1231 __COUT_WARN__ <<
"Ignoring unknown metadata error. " << __E__;
1235 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
1238 *groupMembers = memberMap;
1240 groupMetadataTable_.print();
1241 __SS__ <<
"Ignoring that groupMetadataTable_ has wrong number of rows! Must "
1242 "be 1. Going with anonymous defaults."
1244 __COUT_ERR__ <<
"\n" << ss.str();
1247 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
1248 groupMetadataTable_.getViewP()->deleteRow(0);
1249 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
1250 groupMetadataTable_.getViewP()->addRow();
1253 *groupComment =
"NO COMMENT FOUND";
1255 *groupAuthor =
"NO AUTHOR FOUND";
1257 *groupCreateTime =
"0";
1260 *groupTypeString = convertGroupTypeToName(getTypeOfGroup(memberMap));
1268 StringMacros::getMapFromString(groupMetadataTable_.getView().getValueAsString(0, ConfigurationManager::METADATA_COL_ALIASES), aliasMap);
1270 *groupAliases = aliasMap;
1272 *groupComment = groupMetadataTable_.getView().getValueAsString(0, ConfigurationManager::METADATA_COL_COMMENT);
1274 *groupAuthor = groupMetadataTable_.getView().getValueAsString(0, ConfigurationManager::METADATA_COL_AUTHOR);
1276 *groupCreateTime = groupMetadataTable_.getView().getValueAsString(0, ConfigurationManager::METADATA_COL_TIMESTAMP);
1280 std::map<std::string , std::map<std::string ,
TableVersion>> versionAliases;
1283 __COUTV__(StringMacros::mapToString(aliasMap));
1284 versionAliases = ConfigurationManager::getVersionAliases();
1285 __COUTV__(StringMacros::mapToString(versionAliases));
1289 for(
auto& aliasPair : aliasMap)
1292 if(memberMap.find(aliasPair.first) != memberMap.end())
1294 __COUT__ <<
"Group member '" << aliasPair.first <<
"' was found in group member map!" << __E__;
1295 __COUT__ <<
"Looking for alias '" << aliasPair.second <<
"' in active version aliases..." << __E__;
1297 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
1298 versionAliases[aliasPair.first].find(aliasPair.second) == versionAliases[aliasPair.first].end())
1300 __SS__ <<
"Group '" << groupName <<
"(" << groupKey <<
")' requires table version alias '" << aliasPair.first <<
":" << aliasPair.second
1301 <<
",' which was not found in the active Backbone!" << __E__;
1305 memberMap[aliasPair.first] = versionAliases[aliasPair.first][aliasPair.second];
1306 __COUT__ <<
"Version alias translated to " << aliasPair.first << __E__;
1313 *groupMembers = memberMap;
1316 progressBar->step();
1320 ConfigurationManager::GroupType groupType = ConfigurationManager::GroupType::CONFIGURATION_TYPE;
1325 groupType = getTypeOfGroup(memberMap);
1326 *groupTypeString = convertGroupTypeToName(groupType);
1345 if(!groupTypeString)
1346 groupType = getTypeOfGroup(memberMap);
1348 if(onlyLoadIfBackboneOrContext && groupType != ConfigurationManager::GroupType::CONTEXT_TYPE &&
1349 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
1351 __COUT_WARN__ <<
"Not loading group because it is not of type Context or "
1352 "Backbone (it is type '"
1353 << convertGroupTypeToName(groupType) <<
"')." << __E__;
1358 __COUT__ <<
"------------------------------------- init start \t [for all "
1360 << convertGroupTypeToName(groupType) <<
" group '" << groupName <<
"(" << groupKey <<
")"
1365 std::string groupToDeactivate =
1366 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
1367 ? theContextTableGroup_
1368 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
1369 ? theBackboneTableGroup_
1370 : (groupType == ConfigurationManager::GroupType::ITERATE_TYPE ? theIterateTableGroup_ : theConfigurationTableGroup_));
1373 if(groupToDeactivate !=
"")
1377 destroyTableGroup(groupToDeactivate,
true);
1398 progressBar->step();
1402 loadMemberMap(memberMap, accumulatedWarnings);
1407 progressBar->step();
1409 if(accumulatedWarnings)
1413 getChildren(&memberMap, accumulatedWarnings);
1414 if(*accumulatedWarnings !=
"")
1416 __COUT_ERR__ <<
"Errors detected while loading Table Group: " << groupName <<
"(" << groupKey <<
"). Ignoring the following errors: "
1418 << *accumulatedWarnings << __E__;
1423 progressBar->step();
1428 for(
auto& memberPair : memberMap)
1431 if(ConfigurationInterface::isVersionTrackingEnabled() && memberPair.second.isScratchVersion())
1433 __SS__ <<
"Error while activating member Table '" << nameToTableMap_[memberPair.first]->getTableName() <<
"-v" << memberPair.second
1434 <<
" for Table Group '" << groupName <<
"(" << groupKey <<
")'. When version tracking is enabled, Scratch views"
1435 <<
" are not allowed! Please only use unique, persistent "
1436 "versions when version tracking is enabled."
1445 nameToTableMap_.at(memberPair.first)->init(
this);
1447 catch(std::runtime_error& e)
1449 __SS__ <<
"Error detected calling " << memberPair.first <<
".init()!\n\n " << e.what() << __E__;
1451 if(accumulatedWarnings)
1453 *accumulatedWarnings += ss.str();
1457 ss << StringMacros::stackTrace();
1463 __SS__ <<
"Unknown Error detected calling " << memberPair.first <<
".init()!\n\n " << __E__;
1465 if(accumulatedWarnings)
1467 *accumulatedWarnings += ss.str();
1470 __COUT_WARN__ << ss.str();
1475 progressBar->step();
1484 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
1490 theContextTableGroup_ = groupName;
1491 theContextTableGroupKey_ = std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1493 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
1498 theBackboneTableGroup_ = groupName;
1499 theBackboneTableGroupKey_ = std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1501 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
1507 theIterateTableGroup_ = groupName;
1508 theIterateTableGroupKey_ = std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1515 theConfigurationTableGroup_ = groupName;
1516 theConfigurationTableGroupKey_ = std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
1521 progressBar->step();
1524 __COUT__ <<
"------------------------------------- init complete \t [for all "
1526 << convertGroupTypeToName(groupType) <<
" group '" << groupName <<
"(" << groupKey <<
")"
1532 lastFailedGroupLoad_[convertGroupTypeToName(groupType)] = std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1538 catch(
const std::runtime_error& e)
1540 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"(" << groupKey <<
")': \n" << e.what() << __E__;
1542 if(accumulatedWarnings)
1543 *accumulatedWarnings += ss.str();
1549 __SS__ <<
"An unknown error occurred while loading table group '" << groupName <<
"(" << groupKey <<
")." << __E__;
1551 if(accumulatedWarnings)
1552 *accumulatedWarnings += ss.str();
1563 lastFailedGroupLoad_[ConfigurationManager::ACTIVE_GROUP_NAME_UNKNOWN] = std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
1569 catch(
const std::runtime_error& e)
1571 __SS__ <<
"Error occurred while loading table group: " << e.what() << __E__;
1573 if(accumulatedWarnings)
1574 *accumulatedWarnings += ss.str();
1580 __SS__ <<
"An unknown error occurred while loading table group." << __E__;
1582 if(accumulatedWarnings)
1583 *accumulatedWarnings += ss.str();
1595 std::map<std::string, std::pair<std::string, TableGroupKey>> ConfigurationManager::getActiveTableGroups(
void)
const
1598 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
1600 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONTEXT] =
1601 std::pair<std::string, TableGroupKey>(theContextTableGroup_, theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
1602 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_BACKBONE] =
1603 std::pair<std::string, TableGroupKey>(theBackboneTableGroup_, theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
1604 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_ITERATE] =
1605 std::pair<std::string, TableGroupKey>(theIterateTableGroup_, theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
1606 retMap[ConfigurationManager::ACTIVE_GROUP_NAME_CONFIGURATION] =
1607 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_, theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_ :
TableGroupKey());
1612 const std::string& ConfigurationManager::getActiveGroupName(
const ConfigurationManager::GroupType& type)
const
1614 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
1615 return theConfigurationTableGroup_;
1616 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
1617 return theContextTableGroup_;
1618 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
1619 return theBackboneTableGroup_;
1620 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
1621 return theIterateTableGroup_;
1623 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
1628 TableGroupKey ConfigurationManager::getActiveGroupKey(
const ConfigurationManager::GroupType& type)
const
1630 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
1631 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_ :
TableGroupKey();
1632 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
1633 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
1634 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
1635 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
1636 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
1637 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
1639 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
1644 ConfigurationTree ConfigurationManager::getContextNode(
const std::string& contextUID,
const std::string& )
const
1646 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" + contextUID);
1650 ConfigurationTree ConfigurationManager::getSupervisorNode(
const std::string& contextUID,
const std::string& applicationUID)
const
1652 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" + contextUID +
"/LinkToApplicationTable/" + applicationUID);
1656 ConfigurationTree ConfigurationManager::getSupervisorTableNode(
const std::string& contextUID,
const std::string& applicationUID)
const
1658 return getNode(
"/" + getTableByName(XDAQ_CONTEXT_TABLE_NAME)->getTableName() +
"/" + contextUID +
"/LinkToApplicationTable/" + applicationUID +
1659 "/LinkToSupervisorTable");
1663 ConfigurationTree ConfigurationManager::getNode(
const std::string& nodeString,
bool doNotThrowOnBrokenUIDLinks)
const
1668 if(nodeString.length() < 1)
1670 __SS__ << (
"Invalid empty node name") << __E__;
1671 __COUT_ERR__ << ss.str();
1676 unsigned int startingIndex = 0;
1677 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
1680 std::string nodeName = nodeString.substr(startingIndex, nodeString.find(
'/', startingIndex) - startingIndex);
1682 if(nodeName.length() < 1)
1692 std::string childPath = nodeString.substr(nodeName.length() + startingIndex);
1698 if(childPath.length() > 1)
1699 return configTree.getNode(childPath, doNotThrowOnBrokenUIDLinks);
1706 std::string ConfigurationManager::getFirstPathToNode(
const ConfigurationTree& ,
const std::string& ) const
1710 std::string path =
"/";
1720 std::vector<std::pair<std::string, ConfigurationTree>> ConfigurationManager::getChildren(std::map<std::string, TableVersion>* memberMap,
1721 std::string* accumulatedTreeErrors)
const
1723 std::vector<std::pair<std::string, ConfigurationTree>> retMap;
1728 if(!memberMap || memberMap->empty())
1730 for(
auto& configPair : nameToTableMap_)
1735 if(configPair.second->isActive())
1739 if(accumulatedTreeErrors)
1743 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren = newNode.getChildren();
1744 for(
auto& newNodeChild : newNodeChildren)
1746 std::vector<std::pair<std::string, ConfigurationTree>> twoDeepChildren = newNodeChild.second.getChildren();
1748 for(
auto& twoDeepChild : twoDeepChildren)
1753 if(twoDeepChild.second.isLinkNode() && twoDeepChild.second.isDisconnected() &&
1754 twoDeepChild.second.getDisconnectedTableName() != TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1756 __SS__ <<
"At node '" + configPair.first +
"' with entry UID '" + newNodeChild.first +
1757 "' there is a disconnected child node at link "
1759 twoDeepChild.first +
"'" +
" that points to table named '" + twoDeepChild.second.getDisconnectedTableName() +
1761 *accumulatedTreeErrors += ss.str();
1766 catch(std::runtime_error& e)
1768 __SS__ <<
"At node '" + configPair.first +
"' error detected descending through children:\n" + e.what();
1769 *accumulatedTreeErrors += ss.str();
1773 retMap.push_back(std::pair<std::string, ConfigurationTree>(configPair.first, newNode));
1781 for(
auto& memberPair : *memberMap)
1783 auto mapIt = nameToTableMap_.find(memberPair.first);
1786 if(mapIt == nameToTableMap_.end())
1788 __SS__ <<
"Get Children with member map requires a child '" << memberPair.first <<
"' that is not present!" << __E__;
1791 if(!(*mapIt).second->isActive())
1793 __SS__ <<
"Get Children with member map requires a child '" << memberPair.first <<
"' that is not active!" << __E__;
1797 catch(
const std::runtime_error& e)
1799 if(accumulatedTreeErrors)
1801 *accumulatedTreeErrors += e.what();
1802 __COUT_ERR__ <<
"Skipping " << memberPair.first
1803 <<
" since the table "
1812 if(accumulatedTreeErrors)
1816 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren = newNode.getChildren();
1817 for(
auto& newNodeChild : newNodeChildren)
1819 std::vector<std::pair<std::string, ConfigurationTree>> twoDeepChildren = newNodeChild.second.getChildren();
1821 for(
auto& twoDeepChild : twoDeepChildren)
1825 if(twoDeepChild.second.isLinkNode() && twoDeepChild.second.isDisconnected() &&
1826 twoDeepChild.second.getDisconnectedTableName() != TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
1828 __SS__ <<
"At node '" + memberPair.first +
"' with entry UID '" + newNodeChild.first +
1829 "' there is a disconnected child node at link column "
1831 twoDeepChild.first +
"'" +
" that points to table named '" + twoDeepChild.second.getDisconnectedTableName() +
1833 *accumulatedTreeErrors += ss.str();
1839 for(
auto& searchMemberPair : *memberMap)
1840 if(searchMemberPair.first == twoDeepChild.second.getDisconnectedTableName())
1847 __SS__ <<
"Note: It may be safe to ignore this "
1848 <<
"error since the link's target table " << twoDeepChild.second.getDisconnectedTableName()
1849 <<
" is not a member of this group (and may not "
1851 <<
"loaded yet)" << __E__;
1852 *accumulatedTreeErrors += ss.str();
1858 catch(std::runtime_error& e)
1860 __SS__ <<
"At node '" << memberPair.first <<
"' error detected descending through children:\n" << e.what() << __E__;
1861 *accumulatedTreeErrors += ss.str();
1865 retMap.push_back(std::pair<std::string, ConfigurationTree>(memberPair.first, newNode));
1877 const TableBase* ConfigurationManager::getTableByName(
const std::string& tableName)
const
1879 std::map<std::string, TableBase*>::const_iterator it;
1880 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
1882 __SS__ <<
"Can not find table named '" << tableName <<
"' - you need to load the table before it can be used."
1883 <<
" It probably is missing from the member list of the Table "
1884 "Group that was loaded.\n"
1885 <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
1887 <<
"\n\t StartOTS.sh --wiz"
1891 ss << __E__ << StringMacros::stackTrace() << __E__;
1905 TableGroupKey ConfigurationManager::loadConfigurationBackbone()
1907 if(!theBackboneTableGroupKey_)
1909 __COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently." << __E__;
1914 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
1916 return *theBackboneTableGroupKey_;
1932 std::pair<std::string, TableGroupKey> ConfigurationManager::getTableGroupFromAlias(std::string systemAlias,
ProgressBar* progressBar)
1942 progressBar->step();
1944 if(systemAlias.find(
"GROUP:") == 0)
1947 progressBar->step();
1949 unsigned int i = strlen(
"GROUP:");
1950 unsigned int j = systemAlias.find(
':', i);
1953 progressBar->step();
1955 return std::pair<std::string, TableGroupKey>(systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
1957 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
1960 loadConfigurationBackbone();
1963 progressBar->step();
1968 ConfigurationTree entry = getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getNode(systemAlias);
1971 progressBar->step();
1973 return std::pair<std::string, TableGroupKey>(entry.getNode(
"GroupName").getValueAsString(),
1974 TableGroupKey(entry.getNode(
"GroupKey").getValueAsString()));
1983 progressBar->step();
1985 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
1989 std::map<std::string , std::pair<std::string ,
TableGroupKey>> ConfigurationManager::getActiveGroupAliases(
void)
1991 restoreActiveTableGroups();
1995 std::map<std::string , std::pair<std::string ,
TableGroupKey>> retMap;
1997 std::vector<std::pair<std::string, ConfigurationTree>> entries = getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).getChildren();
1998 for(
auto& entryPair : entries)
2000 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(entryPair.second.getNode(
"GroupName").getValueAsString(),
2001 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
2009 std::map<std::string , std::map<std::string ,
TableVersion >> ConfigurationManager::getVersionAliases(
2014 std::map<std::string , std::map<std::string ,
TableVersion >> retMap;
2016 std::map<std::string, TableVersion> activeVersions = getActiveVersions();
2017 std::string versionAliasesTableName = ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
2018 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
2020 __SS__ <<
"Active version of VersionAliases missing!"
2021 <<
"Make sure you have a valid active Backbone Group." << __E__;
2022 __COUT_WARN__ <<
"\n" << ss.str();
2028 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs = getNode(versionAliasesTableName).getChildren();
2033 std::string tableName, versionAlias;
2034 for(
auto& aliasNodePair : aliasNodePairs)
2036 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
2037 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
2039 if(retMap.find(tableName) != retMap.end() && retMap[tableName].find(versionAlias) != retMap[tableName].end())
2044 retMap[tableName][versionAlias] =
TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
2052 std::map<std::string, TableVersion> ConfigurationManager::getActiveVersions(
void)
const
2054 std::map<std::string, TableVersion> retMap;
2055 for(
auto& config : nameToTableMap_)
2060 if(config.second && config.second->isActive())
2064 retMap.insert(std::pair<std::string, TableVersion>(config.first, config.second->getViewVersion()));
2093 std::shared_ptr<TableGroupKey> ConfigurationManager::makeTheTableGroupKey(
TableGroupKey key)
2095 if(theConfigurationTableGroupKey_)
2097 if(*theConfigurationTableGroupKey_ != key)
2098 destroyTableGroup();
2100 return theConfigurationTableGroupKey_;
2102 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
2106 const std::set<std::string>& ConfigurationManager::getContextMemberNames() {
return ConfigurationManager::contextMemberNames_; }
2109 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
2111 return ConfigurationManager::backboneMemberNames_;
2115 const std::set<std::string>& ConfigurationManager::getIterateMemberNames() {
return ConfigurationManager::iterateMemberNames_; }
2117 const std::set<std::string>& ConfigurationManager::getConfigurationMemberNames(
void)
2119 configurationMemberNames_.clear();
2121 std::map<std::string, TableVersion> activeTables = getActiveVersions();
2123 for(
auto& tablePair : activeTables)
2124 if(ConfigurationManager::contextMemberNames_.find(tablePair.first) == ConfigurationManager::contextMemberNames_.end() &&
2125 ConfigurationManager::backboneMemberNames_.find(tablePair.first) == ConfigurationManager::backboneMemberNames_.end() &&
2126 ConfigurationManager::iterateMemberNames_.find(tablePair.first) == ConfigurationManager::iterateMemberNames_.end())
2127 configurationMemberNames_.emplace(tablePair.first);
2129 return configurationMemberNames_;
2133 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
2135 __COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
2140 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
2169 theInterface_->get(table,
2170 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
2176 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
2178 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2179 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2182 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2187 auto colMap = view->getColumnNamesMap();
2189 view->setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
2190 view->setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
2191 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2192 view->setValue(
"1", 0, colMap[
"Status"]);
2194 __COUT__ <<
"Done adding context record..." << __E__;
2202 theInterface_->get(table,
2203 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
2209 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
2211 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2212 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2215 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2220 auto colMap = view->getColumnNamesMap();
2222 view->setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
2223 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
2224 view->setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
2225 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
2226 view->setValue(
"1", 0, colMap[
"Status"]);
2228 __COUT__ <<
"Done adding application record..." << __E__;
2235 theInterface_->get(table,
2236 "FESupervisorTable",
2242 nameToTableMap_[
"FESupervisorTable"] = table;
2244 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2245 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2248 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2253 auto colMap = view->getColumnNamesMap();
2255 view->setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
2256 view->setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
2257 view->setValue(
"MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
2259 __COUT__ <<
"Done adding supervisor record..." << __E__;
2264 recursiveInitFromFhiclPSet(
2265 "FEInterfaceTable" , pset ,
"" ,
"MacroMakerFESupervisorInterfaces" ,
"FE" );
2268 for(
auto& table : nameToTableMap_)
2270 table.second->getViewP()->init();
2276 __COUT__ <<
"================================================" << __E__;
2277 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
2278 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
2280 auto sups = getNode(
"FESupervisorTable").getChildrenNames();
2281 __COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
2282 auto fes = getNode(
"FEInterfaceTable").getChildrenNames();
2283 __COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
2285 auto a = getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
2286 __COUTV__(a.getValueAsString());
2288 auto b = a.getNode(
"MacroMakerFEContext");
2289 __COUTV__(b.getValueAsString());
2291 auto c = b.getNode(
"LinkToApplicationTable");
2292 __COUTV__(c.getValueAsString());
2294 auto d = c.getNode(
"MacroMakerFESupervisor");
2295 __COUTV__(d.getValueAsString());
2297 auto e = d.getNode(
"LinkToSupervisorTable");
2298 __COUTV__(e.getValueAsString());
2300 auto f = e.getNode(
"LinkToFEInterfaceTable");
2301 __COUTV__(f.getValueAsString());
2303 auto z = f.getChildrenNames();
2304 __COUTV__(StringMacros::vectorToString(z));
2305 __COUTV__(z.size());
2306 auto y = f.getChildrenNames(
false ,
true );
2307 __COUTV__(StringMacros::vectorToString(y));
2308 __COUTV__(y.size());
2309 auto x = f.getChildrenNames(
true ,
true );
2310 __COUTV__(StringMacros::vectorToString(x));
2311 __COUTV__(x.size());
2313 auto g = f.getNode(
"dtc0");
2314 __COUTV__(g.getValueAsString());
2315 auto h = f.getNode(
"interface0");
2316 __COUTV__(h.getValueAsString());
2318 auto fes = getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
2320 "MacroMakerFEContext/LinkToApplicationTable/"
2321 "MacroMakerFESupervisor/LinkToSupervisorTable")
2322 .getNode(
"LinkToFEInterfaceTable")
2323 .getChildrenNames(
true ,
true );
2324 __COUTV__(fes.size());
2325 __COUTV__(StringMacros::vectorToString(fes));
2336 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
2337 const fhicl::ParameterSet& pset,
2338 const std::string& recordName,
2339 const std::string& groupName,
2340 const std::string& groupLinkIndex)
2342 __COUT__ << __COUT_HDR_P__ <<
"Adding table '" << tableName <<
"' record(s)..." << __E__;
2348 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
2350 __COUT__ <<
"Table not found, so making '" << tableName <<
"'instance..." << __E__;
2351 theInterface_->get(table,
2358 nameToTableMap_[tableName] = table;
2359 table->setupMockupView(
TableVersion(TableVersion::DEFAULT));
2363 __COUT__ <<
"Existing table found, so using '" << tableName <<
"'instance..." << __E__;
2364 table = nameToTableMap_[tableName];
2367 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
2370 __COUT__ <<
"Activated version: " << view->getVersion() << __E__;
2373 if(recordName !=
"")
2381 __COUTV__(recordName);
2384 unsigned int r = view->addRow();
2385 auto colMap = view->getColumnNamesMap();
2388 view->setValue(recordName, r, view->getColUID());
2391 view->setValue(
"1", r, view->getColStatus());
2395 __COUT__ <<
"No status column to set for '" << recordName <<
"'" << __E__;
2400 int groupIDCol = view->getLinkGroupIDColumn(groupLinkIndex);
2401 __COUT__ <<
"Setting group ID for group link ID '" << groupLinkIndex <<
"' at column " << groupIDCol <<
" to '" << groupName <<
".'" << __E__;
2403 view->setValue(groupName, r, groupIDCol);
2407 auto names = pset.get_names();
2408 for(
const auto& colName : names)
2410 if(!pset.is_key_to_atom(colName))
2413 auto colIt = colMap.find(colName);
2414 if(colIt == colMap.end())
2416 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName <<
"' in table '" << tableName <<
"' was not found in columns."
2417 <<
"\n\nHere are the existing column names:\n";
2419 for(
const auto& col : colMap)
2420 ss <<
"\n" << ++i <<
".\t" << col.first;
2424 const std::string value = pset.get<std::string>(colName);
2425 __COUT__ <<
"Setting '" << recordName <<
"' parameter at column " << colIt->second <<
", '" << colName <<
"'\t = " << value << __E__;
2426 view->setValueAsString(value, r, colIt->second);
2430 for(
const auto& linkName : names)
2432 if(pset.is_key_to_atom(linkName))
2435 __COUTV__(linkName);
2438 unsigned int c = linkName.size() - 1;
2440 if(linkName[c] ==
'_')
2445 __SS__ <<
"Illegal link name '" << linkName
2446 <<
"' found. The format must be <Column name>_<Target table "
2447 "name>,.. for example '"
2448 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'" << __E__;
2451 std::string colName = linkName.substr(0, c);
2454 auto colIt = colMap.find(colName);
2455 if(colIt == colMap.end())
2457 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName <<
"' in table '" << tableName <<
"' was not found in columns."
2458 <<
"\n\nHere are the existing column names:\n";
2460 for(
const auto& col : colMap)
2461 ss <<
"\n" << i <<
".\t" << col.first << __E__;
2466 std::pair<
unsigned int ,
unsigned int > linkPair;
2468 view->getChildLink(colIt->second, isGroupLink, linkPair);
2474 std::string linkTableName = linkName.substr(c + 1);
2475 __COUTV__(linkTableName);
2477 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
2478 auto linkRecords = linkPset.get_pset_names();
2479 if(!isGroupLink && linkRecords.size() > 1)
2481 __SS__ <<
"A Unique Link can only point to one record. "
2482 <<
"The specified link '" << colName <<
"' of record '" << recordName <<
"' in table '" << tableName <<
"' has "
2483 << linkRecords.size() <<
" children records specified. " << __E__;
2487 if(linkRecords.size() == 0)
2489 __COUT__ <<
"No child records, so leaving link disconnected." << __E__;
2493 __COUT__ <<
"Setting Link at columns [" << linkPair.first <<
"," << linkPair.second <<
"]" << __E__;
2494 view->setValue(linkTableName, r, linkPair.first);
2498 __COUT__ <<
"Setting up Unique link to " << linkRecords[0] << __E__;
2500 view->setValue(linkRecords[0], r, linkPair.second);
2502 recursiveInitFromFhiclPSet(linkTableName ,
2503 linkPset.get<fhicl::ParameterSet>(linkRecords[0]) ,
2511 std::string childLinkIndex = view->getColumnInfo(linkPair.first).getChildLinkIndex();
2512 std::string groupName = recordName +
"Group";
2514 view->setValue(groupName, r, linkPair.second);
2516 for(
const auto& groupRecord : linkRecords)
2518 __COUT__ <<
"Setting '" << childLinkIndex <<
"' Group link to '" << groupName <<
"' record '" << groupRecord <<
"'" << __E__;
2520 recursiveInitFromFhiclPSet(linkTableName ,
2521 linkPset.get<fhicl::ParameterSet>(groupRecord) ,
2530 else if(groupName !=
"")
2534 __COUTV__(groupName);
2535 auto psets = pset.get_pset_names();
2536 for(
const auto& ps : psets)
2539 recursiveInitFromFhiclPSet(tableName ,
2540 pset.get<fhicl::ParameterSet>(ps) ,
2550 __SS__ <<
"Illegal recursive parameters!" << __E__;
2555 __COUT__ << __COUT_HDR_P__ <<
"Done adding table '" << tableName <<
"' record(s)..." << __E__;
2560 bool ConfigurationManager::isOwnerFirstAppInContext()
2563 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
2569 auto contextChildren = getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" + ownerContextUID_).getChildrenNames();
2571 bool isFirstAppInContext = contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
2575 return isFirstAppInContext;
2580 TableBase* ConfigurationManager::getDesktopIconTable(
void)
2582 if(nameToTableMap_.find(DESKTOP_ICON_TABLE_NAME) == nameToTableMap_.end())
2584 __SS__ <<
"Desktop icon table not found!" << __E__;
2585 ss << StringMacros::stackTrace() << __E__;
2589 return nameToTableMap_.at(DESKTOP_ICON_TABLE_NAME);
2593 void ConfigurationManager::saveGroupNameAndKey(
const std::pair<std::string /*group name*/, TableGroupKey>& theGroup,
const std::string& fileName)
2595 std::string fullPath = ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
2598 std::ofstream groupFile(fullPath.c_str());
2599 if(!groupFile.is_open())
2601 __SS__ <<
"Error. Can't open file to save group activity: " << fullPath << __E__;
2604 std::stringstream outss;
2605 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n" << time(0);
2606 groupFile << outss.str().c_str();
2616 std::pair<std::string ,
TableGroupKey> ConfigurationManager::loadGroupNameAndKey(
const std::string& fileName, std::string& returnedTimeString)
2618 std::string fullPath = ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
2621 FILE* groupFile = fopen(fullPath.c_str(),
"r");
2624 __COUT__ <<
"Can't open file: " << fullPath << __E__;
2626 __COUT__ <<
"Returning empty groupName and key -1" << __E__;
2628 return std::pair<std::string ,
TableGroupKey>(
"", TableGroupKey());
2635 fgets(line, 500, groupFile);
2636 if(strlen(line) && line[strlen(line)-1] ==
'\n')
2637 line[strlen(line)-1] =
'\0';
2638 theGroup.first = line;
2640 fgets(line, 500, groupFile);
2642 sscanf(line,
"%d", &key);
2643 theGroup.second = key;
2645 fgets(line, 500, groupFile);
2647 sscanf(line,
"%ld", ×tamp);
2651 returnedTimeString = StringMacros::getTimestampString(timestamp);
2654 __COUT__ <<
"theGroup.first= " << theGroup.first <<
" theGroup.second= " << theGroup.second << __E__;