1 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
2 #include "artdaq/Application/LoadParameterSet.hh"
3 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
4 #include "otsdaq/ProgressBar/ProgressBar.h"
5 #include "otsdaq/TablePlugins/XDAQContextTable/XDAQContextTable.h"
11 #include "otsdaq/TableCore/TableGroupKey.h"
12 #include "otsdaq/TablePlugins/DesktopIconTable.h"
17 #define __MF_SUBJECT__ "ConfigurationManager"
24 const std::string ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH = ((getenv(
"SERVICE_DATA_PATH") == NULL)
25 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
26 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
29 const std::string ConfigurationManager::LAST_ACTIVATED_CONFIG_GROUP_FILE =
"CFGLastActivatedConfigGroup.hist";
30 const std::string ConfigurationManager::LAST_ACTIVATED_CONTEXT_GROUP_FILE =
"CFGLastActivatedContextGroup.hist";
31 const std::string ConfigurationManager::LAST_ACTIVATED_BACKBONE_GROUP_FILE =
"CFGLastActivatedBackboneGroup.hist";
32 const std::string ConfigurationManager::LAST_ACTIVATED_ITERATE_GROUP_FILE =
"CFGLastActivatedIterateGroup.hist";
34 const std::string ConfigurationManager::ACTIVATED_CONFIGS_FILE =
"CFGActivatedConfigGroups.hist";
35 const std::string ConfigurationManager::ACTIVATED_CONTEXTS_FILE =
"CFGActivatedContextGroups.hist";
36 const std::string ConfigurationManager::ACTIVATED_BACKBONES_FILE =
"CFGActivatedBackboneGroups.hist";
37 const std::string ConfigurationManager::ACTIVATED_ITERATES_FILE =
"CFGActivatedIterateGroups.hist";
39 const std::string ConfigurationManager::LAST_ATTEMPTED_CONFIGURE_CONFIG_ALIAS_FILE =
"CFGAttemptedConfigureConfigAlias.hist";
40 const std::string ConfigurationManager::LAST_ATTEMPTED_CONFIGURE_CONFIG_GROUP_FILE =
"CFGAttemptedConfigureConfigGroup.hist";
42 const std::string ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIG_ALIASES_FILE =
"CFGAttemptedConfigureConfigAliases.hist";
43 const std::string ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIGS_FILE =
"CFGAttemptedConfigureConfigGroups.hist";
45 const std::string ConfigurationManager::LAST_CONFIGURED_CONFIG_ALIAS_FILE =
"CFGLastConfiguredConfigAlias.hist";
46 const std::string ConfigurationManager::LAST_CONFIGURED_CONFIG_GROUP_FILE =
"CFGLastConfiguredConfigGroup.hist";
47 const std::string ConfigurationManager::LAST_CONFIGURED_CONTEXT_GROUP_FILE =
"CFGLastConfiguredContextGroup.hist";
48 const std::string ConfigurationManager::LAST_CONFIGURED_BACKBONE_GROUP_FILE =
"CFGLastConfiguredBackboneGroup.hist";
49 const std::string ConfigurationManager::LAST_CONFIGURED_ITERATE_GROUP_FILE =
"CFGLastConfiguredIterateGroup.hist";
51 const std::string ConfigurationManager::CONFIGURED_CONFIG_ALIASES_FILE =
"CFGConfiguredConfigAliases.hist";
52 const std::string ConfigurationManager::CONFIGURED_CONFIGS_FILE =
"CFGConfiguredConfigGroups.hist";
53 const std::string ConfigurationManager::CONFIGURED_CONTEXTS_FILE =
"CFGConfiguredContextGroups.hist";
54 const std::string ConfigurationManager::CONFIGURED_BACKBONES_FILE =
"CFGConfiguredBackboneGroups.hist";
55 const std::string ConfigurationManager::CONFIGURED_ITERATES_FILE =
"CFGConfiguredIterateGroups.hist";
57 const std::string ConfigurationManager::LAST_STARTED_CONFIG_ALIAS_FILE =
"CFGLastStartedConfigAlias.hist";
58 const std::string ConfigurationManager::LAST_STARTED_CONFIG_GROUP_FILE =
"CFGLastStartedConfigGroup.hist";
59 const std::string ConfigurationManager::LAST_STARTED_CONTEXT_GROUP_FILE =
"CFGLastStartedContextGroup.hist";
60 const std::string ConfigurationManager::LAST_STARTED_BACKBONE_GROUP_FILE =
"CFGLastStartedBackboneGroup.hist";
61 const std::string ConfigurationManager::LAST_STARTED_ITERATE_GROUP_FILE =
"CFGLastStartedIterateGroup.hist";
63 const std::string ConfigurationManager::STARTED_CONFIG_ALIASES_FILE =
"CFGStartedConfigAliases.hist";
64 const std::string ConfigurationManager::STARTED_CONFIGS_FILE =
"CFGStartedConfigGroups.hist";
65 const std::string ConfigurationManager::STARTED_CONTEXTS_FILE =
"CFGStartedContextGroups.hist";
66 const std::string ConfigurationManager::STARTED_BACKBONES_FILE =
"CFGStartedBackboneGroups.hist";
67 const std::string ConfigurationManager::STARTED_ITERATES_FILE =
"CFGStartedIterateGroups.hist";
69 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_CONFIG_ALIASES_FILE =
"CFGConfiguredOrStartedConfigAliases.hist";
70 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_CONFIGS_FILE =
"CFGConfiguredOrStartedConfigGroups.hist";
71 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_CONTEXTS_FILE =
"CFGConfiguredOrStartedContextGroups.hist";
72 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_BACKBONES_FILE =
"CFGConfiguredOrStartedBackboneGroups.hist";
73 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_ITERATES_FILE =
"CFGConfiguredOrStartedIterateGroups.hist";
76 const std::string ConfigurationManager::READONLY_USER =
"READONLY_USER";
78 const std::string ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME =
"XDAQContextTable";
79 const std::string ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME =
"XDAQApplicationTable";
80 const std::string ConfigurationManager::XDAQ_APP_PROPERTY_TABLE_NAME =
"XDAQApplicationPropertyTable";
81 const std::string ConfigurationManager::GROUP_ALIASES_TABLE_NAME =
"GroupAliasesTable";
82 const std::string ConfigurationManager::VERSION_ALIASES_TABLE_NAME =
"VersionAliasesTable";
83 const std::string ConfigurationManager::ARTDAQ_TOP_TABLE_NAME =
"ARTDAQSupervisorTable";
84 const std::string ConfigurationManager::DESKTOP_ICON_TABLE_NAME =
"DesktopIconTable";
88 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
89 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
90 "/ActiveTableGroups.cfg";
92 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
93 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
94 const std::string ConfigurationManager::SUBSYSTEM_COMMON_VERSION_ALIAS =
"SubsystemCommon";
95 const std::string ConfigurationManager::SUBSYSTEM_COMMON_OVERRIDE_VERSION_ALIAS =
"SubsystemCommonOverride";
98 const std::string ConfigurationManager::GROUP_TYPE_NAME_CONTEXT =
"Context";
99 const std::string ConfigurationManager::GROUP_TYPE_NAME_BACKBONE =
"Backbone";
100 const std::string ConfigurationManager::GROUP_TYPE_NAME_ITERATE =
"Iterate";
101 const std::string ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION =
"Configuration";
102 const std::string ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN =
"UNKNOWN";
104 const std::string ConfigurationManager::UNKNOWN_INFO =
"UNKNOWN";
105 const std::string ConfigurationManager::UNKNOWN_TIME =
"0";
107 const uint8_t ConfigurationManager::METADATA_COL_ALIASES = 1;
108 const uint8_t ConfigurationManager::METADATA_COL_COMMENT = 2;
109 const uint8_t ConfigurationManager::METADATA_COL_AUTHOR = 3;
110 const uint8_t ConfigurationManager::METADATA_COL_TIMESTAMP = 4;
112 const std::string ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE =
"SubsystemUserDataPathsTable";
115 const std::set<std::string> ConfigurationManager::fixedContextMemberNames_ = {
116 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
117 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
118 "XDAQApplicationPropertyTable",
119 ConfigurationManager::DESKTOP_ICON_TABLE_NAME,
120 "MessageFacilityTable",
121 "GatewaySupervisorTable",
123 "DesktopWindowParameterTable",
124 "SlowControlsDashboardSupervisorTable"
126 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = {
127 ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
128 ConfigurationManager::VERSION_ALIASES_TABLE_NAME
130 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = {
132 "IterationPlanTable",
133 "IterationTargetTable",
134 "IterationCommandBeginLabelTable",
135 "IterationCommandChooseFSMTable",
136 "IterationCommandConfigureAliasTable",
137 "IterationCommandConfigureGroupTable",
138 "IterationCommandExecuteFEMacroTable",
139 "IterationCommandExecuteMacroTable",
140 "IterationCommandMacroDimensionalLoopTable",
141 "IterationCommandMacroDimensionalLoopParameterTable",
142 "IterationCommandModifyGroupTable",
143 "IterationCommandRepeatLabelTable",
144 "IterationCommandRunTable"
151 bool doInitializeFromFhicl ,
152 bool forceNotFirstInContext )
153 : startClockTime_(std::chrono::steady_clock::now())
154 , deltaClockTime_(std::chrono::steady_clock::now())
155 , forceNotFirstInContext_(forceNotFirstInContext)
159 , theConfigurationTableGroupKey_(0)
160 , theContextTableGroupKey_(0)
161 , theBackboneTableGroupKey_(0)
162 , theConfigurationTableGroup_(
"")
163 , theContextTableGroup_(
"")
164 , theBackboneTableGroup_(
"")
165 , groupMetadataTable_(true ,
TableBase::GROUP_METADATA_TABLE_NAME)
167 __GEN_COUTTV__(runTimeSeconds());
168 theInterface_ = ConfigurationInterface::getInstance(
169 ConfigurationInterface::CONFIGURATION_MODE::
172 __GEN_COUTTV__(runTimeSeconds());
244 if(doInitializeFromFhicl)
247 initializeFromFhicl(__ENV__(
"CONFIGURATION_INIT_FCL"));
252 __GEN_COUTTV__(runTimeSeconds());
253 if(!initForWriteAccess)
254 init(0 , initForWriteAccess);
255 __GEN_COUTTV__(runTimeSeconds());
263 __GEN_COUT__ <<
"Private constructor for write access called." << __E__;
265 mfSubject_ = username;
266 username_ = username;
270 ConfigurationManager::~ConfigurationManager() { destroy(); }
279 bool initForWriteAccess ,
280 std::string* accumulatedWarnings )
292 __GEN_COUTTV__(username_);
297 ConfigurationManager::LoadGroupType onlyLoadIfBackboneOrContext =
298 ConfigurationManager::LoadGroupType::ALL_TYPES;
299 if(username_ == ConfigurationManager::READONLY_USER && !initForWriteAccess)
300 onlyLoadIfBackboneOrContext =
301 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_OR_CONTEXT_TYPES;
306 onlyLoadIfBackboneOrContext,
307 accumulatedWarnings);
310 catch(std::runtime_error& e)
312 __GEN_COUT_ERR__ <<
"Error caught in init(): " << e.what();
313 if(accumulatedErrors)
314 *accumulatedErrors += e.what();
331 const std::string& pathToActiveGroupsFile ,
332 ConfigurationManager::LoadGroupType
333 onlyLoadIfBackboneOrContext ,
334 std::string* accumulatedWarnings )
340 FILE* fp = fopen(fn.c_str(),
"r");
342 __GEN_COUTT__ <<
"ACTIVE_GROUPS_FILENAME = " << fn << __E__;
343 __GEN_COUTS__(10) <<
"ARTDAQ_DATABASE_URI = "
344 << std::string(__ENV__(
"ARTDAQ_DATABASE_URI")) << __E__;
348 __GEN_COUT_WARN__ <<
"No active groups file found at " << fn << __E__;
352 __GEN_COUTVS__(10, throwErrors);
357 std::string groupName;
358 std::string errorStr =
"";
363 while(fgets(tmp, 500, fp))
368 sscanf(tmp,
"%d", &numberCheck);
372 <<
"Out of sync with active groups file lines, attempting to resync."
379 sscanf(tmp,
"%s", strVal);
380 for(
unsigned int j = 0; j < strlen(strVal); ++j)
381 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') ||
382 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
383 (strVal[j] >=
'0' && strVal[j] <=
'9')))
386 if(strlen(strVal) == 0)
387 __GEN_COUT__ <<
"Empty group name found, so skipping! Check active "
392 <<
"Illegal character found in group name '" << strVal
393 <<
"', so skipping! Check active groups file: " << fn << __E__;
404 sscanf(tmp,
"%s", strVal);
406 for(
unsigned int j = 0; j < strlen(strVal); ++j)
407 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
411 if(groupName.size() > 3)
413 <<
"Skipping active group with illegal character in group key '"
414 << strVal <<
".' Check active groups file: " << fn << __E__;
420 if(groupName.size() <= 3)
433 <<
"illegal group according to TableGroupKey::getFullGroupString... "
434 "Check active groups file: "
445 std::string groupAccumulatedErrors =
"";
447 if(accumulatedWarnings)
448 __GEN_COUT__ <<
"Ignoring warnings while loading and activating group '"
449 << groupName <<
"(" << strVal <<
")'" << __E__;
457 (accumulatedWarnings ? &groupAccumulatedErrors
465 onlyLoadIfBackboneOrContext
468 if(accumulatedWarnings)
469 *accumulatedWarnings += groupAccumulatedErrors;
471 catch(std::runtime_error& e)
473 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
474 << groupName <<
"(" << strVal
475 <<
")' specified active by active groups file: " << fn << __E__;
476 ss << e.what() << __E__;
478 errorStr += ss.str();
482 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
483 << groupName <<
"(" << strVal
484 <<
")' specified active by active groups file: " << fn << __E__;
489 catch(
const std::exception& e)
491 ss <<
"Exception message: " << e.what();
496 errorStr += ss.str();
502 if(throwErrors && errorStr !=
"")
504 __SS__ <<
"\n" << errorStr;
507 else if(errorStr !=
"")
508 __GEN_COUT_WARN__ <<
"\n" << errorStr;
521 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
522 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
523 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
524 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
526 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
528 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
529 __GEN_COUT_ERR__ << ss.str();
533 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
537 __GEN_COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
539 __GEN_COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
541 __GEN_COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
543 __GEN_COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
546 getActiveContextMemberNames();
548 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
549 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
552 contextFindIt = contextMemberNames_.find(it->first);
553 backboneFindIt = backboneMemberNames_.find(it->first);
554 iterateFindIt = iterateMemberNames_.find(it->first);
556 __GEN_COUTT__ <<
"Considering table: " << it->first <<
" contextFindIt:"
557 << (contextFindIt != contextMemberNames_.end() ?
"Y" :
"N")
558 <<
" backboneFindIt:"
559 << (backboneFindIt != backboneMemberNames_.end() ?
"Y" :
"N")
561 << (iterateFindIt != iterateMemberNames_.end() ?
"Y" :
"N")
571 CONTEXT_SUBSYSTEM_OPTIONAL_TABLE) ||
572 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
573 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
575 contextFindIt == contextMemberNames_.end() &&
576 it->first != ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE &&
577 backboneFindIt == backboneMemberNames_.end() &&
578 iterateFindIt == iterateMemberNames_.end())))
580 __GEN_COUTT__ <<
"\t" << dbgHeader <<
".. " << it->first
581 << (it->second->isActive()
582 ?
"_v" + it->second->getViewVersion().str()
588 it->second->deactivate();
594 nameToTableMap_.erase(it++);
603 theConfigurationTableGroup_ =
"";
604 if(theConfigurationTableGroupKey_ != 0)
606 __GEN_COUTT__ <<
"Destroying Configuration Key: "
607 << *theConfigurationTableGroupKey_ << __E__;
608 theConfigurationTableGroupKey_.reset();
613 theBackboneTableGroup_ =
"";
614 if(theBackboneTableGroupKey_ != 0)
616 __GEN_COUTT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_
618 theBackboneTableGroupKey_.reset();
623 theIterateTableGroup_ =
"";
624 if(theIterateTableGroupKey_ != 0)
626 __GEN_COUTT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_
628 theIterateTableGroupKey_.reset();
633 theContextTableGroup_ =
"";
634 if(theContextTableGroupKey_ != 0)
636 __GEN_COUTT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_
638 theContextTableGroupKey_.reset();
653 const ConfigurationManager::GroupType& groupTypeId)
655 return groupTypeId == ConfigurationManager::GroupType::CONTEXT_TYPE
656 ? ConfigurationManager::GROUP_TYPE_NAME_CONTEXT
657 : (groupTypeId == ConfigurationManager::GroupType::BACKBONE_TYPE
658 ? ConfigurationManager::GROUP_TYPE_NAME_BACKBONE
659 : (groupTypeId == ConfigurationManager::GroupType::ITERATE_TYPE
660 ? ConfigurationManager::GROUP_TYPE_NAME_ITERATE
661 : (groupTypeId == ConfigurationManager::GroupType::
663 ? ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION
664 : ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN)));
675 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
677 bool isContext =
true;
678 bool isBackbone =
true;
679 bool isIterate =
true;
681 bool inContext =
false;
682 bool inBackbone =
false;
683 bool inIterate =
false;
684 unsigned int matchCount = 0;
686 for(
auto& memberPair : memberMap)
691 if(memberPair.first == CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
697 for(
auto& contextMemberString : fixedContextMemberNames_)
698 if(memberPair.first == contextMemberString)
710 __SS__ <<
"This group is an incomplete match to a Context group.\n";
711 ss <<
"\nTo be a Context group, the members must exactly match "
712 <<
"the following members (w/ or wo/ the optional table "
713 << CONTEXT_SUBSYSTEM_OPTIONAL_TABLE <<
"):\n";
715 for(
const auto& memberName : fixedContextMemberNames_)
716 ss << ++i <<
". " << memberName <<
"\n";
717 ss <<
"\nThe members are as follows::\n";
719 for(
const auto& memberPairTmp : memberMap)
720 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
727 for(
auto& backboneMemberString : backboneMemberNames_)
728 if(memberPair.first == backboneMemberString)
740 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
741 ss <<
"\nTo be a Backbone group, the members must exactly match "
742 <<
"the following members:\n";
744 for(
auto& memberName : backboneMemberNames_)
745 ss << ++i <<
". " << memberName <<
"\n";
746 ss <<
"\nThe members are as follows::\n";
748 for(
const auto& memberPairTmp : memberMap)
749 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
757 for(
auto& iterateMemberString : iterateMemberNames_)
758 if(memberPair.first == iterateMemberString)
770 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
771 ss <<
"\nTo be a Iterate group, the members must exactly match "
772 <<
"the following members:\n";
774 for(
auto& memberName : iterateMemberNames_)
775 ss << ++i <<
". " << memberName <<
"\n";
776 ss <<
"\nThe members are as follows::\n";
778 for(
const auto& memberPairTmp : memberMap)
779 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
786 if((isContext || inContext) && matchCount != fixedContextMemberNames_.size())
788 __SS__ <<
"This group is an incomplete match to a Context group: "
789 <<
" Size=" << matchCount <<
" but should be "
790 << fixedContextMemberNames_.size() << __E__;
791 ss <<
"\nThe members currently are...\n";
793 for(
auto& memberPair : memberMap)
794 ss << ++i <<
". " << memberPair.first <<
"\n";
795 ss <<
"\nThe expected Context members are...\n";
797 for(
auto& memberName : fixedContextMemberNames_)
798 ss << ++i <<
". " << memberName <<
"\n";
799 ss <<
"optional. (" << CONTEXT_SUBSYSTEM_OPTIONAL_TABLE <<
")\n";
804 if((isBackbone || inBackbone) && matchCount != backboneMemberNames_.size())
806 __SS__ <<
"This group is an incomplete match to a Backbone group: "
807 <<
" Size=" << matchCount <<
" but should be "
808 << backboneMemberNames_.size() << __E__;
809 ss <<
"\nThe members currently are...\n";
811 for(
auto& memberPair : memberMap)
812 ss << ++i <<
". " << memberPair.first <<
"\n";
813 ss <<
"\nThe expected Backbone members are...\n";
815 for(
auto& memberName : backboneMemberNames_)
816 ss << ++i <<
". " << memberName <<
"\n";
821 if((isIterate || inIterate) && matchCount != iterateMemberNames_.size())
823 __SS__ <<
"This group is an incomplete match to a Iterate group: "
824 <<
" Size=" << matchCount <<
" but should be "
825 << iterateMemberNames_.size() << __E__;
826 ss <<
"\nThe members currently are...\n";
828 for(
auto& memberPair : memberMap)
829 ss << ++i <<
". " << memberPair.first <<
"\n";
830 ss <<
"\nThe expected Iterate members are...\n";
832 for(
auto& memberName : iterateMemberNames_)
833 ss << ++i <<
". " << memberName <<
"\n";
839 ? ConfigurationManager::GroupType::CONTEXT_TYPE
841 ? ConfigurationManager::GroupType::BACKBONE_TYPE
843 ? ConfigurationManager::GroupType::ITERATE_TYPE
844 : ConfigurationManager::GroupType::CONFIGURATION_TYPE));
851 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
862 #define OUT out << tabStr << commentStr
863 #define PUSHTAB tabStr += "\t"
864 #define POPTAB tabStr.resize(tabStr.size() - 1)
865 #define PUSHCOMMENT commentStr += "# "
866 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
868 void ConfigurationManager::dumpMacroMakerModeFhicl()
870 if(nameToTableMap_.find(
"FEInterfaceTable") == nameToTableMap_.end())
872 __COUT__ <<
"Skipping dumpMacroMakerModeFhicl() since FEInterface table is not "
878 std::string filepath =
879 __ENV__(
"USER_DATA") + std::string(
"/") +
"MacroMakerModeConfigurations";
880 mkdir(filepath.c_str(), 0755);
881 filepath +=
"/MacroMakerModeFhiclDump.fcl";
882 __GEN_COUT__ <<
"dumpMacroMakerModeFhicl: " << filepath << __E__;
888 std::string tabStr =
"";
889 std::string commentStr =
"";
891 out.open(filepath, std::fstream::out | std::fstream::trunc);
894 __SS__ <<
"Failed to open MacroMaker mode fcl file for configuration dump: "
895 << filepath << __E__;
901 std::vector<std::pair<std::string, ConfigurationTree>> fes =
907 if(!fe.second.status())
912 OUT << fe.first <<
": {" << __E__;
917 OUT <<
"FEInterfacePluginName"
919 <<
"\"" << fe.second.getNode(
"FEInterfacePluginName").getValueAsString()
922 recursiveTreeToFhicl(
923 fe.second.getNode(
"LinkToFETypeTable"), out, tabStr, commentStr);
926 OUT <<
"} //end " << fe.first << __E__ << __E__;
932 __SS__ <<
"Failed to complete MacroMaker mode fcl "
933 "file configuration dump due to error."
939 catch(
const std::runtime_error& e)
941 ss <<
"Exception message: " << e.what();
943 catch(
const std::exception& e)
945 ss <<
"Exception message: " << e.what();
947 __GEN_COUT_ERR__ << ss.str();
965 std::string& tabStr ,
966 std::string& commentStr ,
971 __COUT__ << __COUT_HDR_P__ <<
"Depth limit reached. Ending recursion." << __E__;
977 if(depth == (
unsigned int)-1)
997 std::vector<std::pair<std::string, ConfigurationTree>> children =
999 for(
auto& child : children)
1000 recursiveTreeToFhicl(child.second, out, tabStr, commentStr, depth - 1);
1004 <<
" group link record" << __E__;
1016 std::vector<std::pair<std::string, ConfigurationTree>> fields =
1020 for(
unsigned int i = 0; i < fields.size() - 3; ++i)
1024 if(fields[i].second.isLinkNode())
1026 recursiveTreeToFhicl(
1027 fields[i].second, out, tabStr, commentStr, depth - 1);
1032 OUT << fields[i].second.getFieldName() <<
": \t";
1033 if(fields[i].second.isValueNumberDataType())
1034 OUT << fields[i].second.getValueAsString() << __E__;
1036 OUT <<
"\"" << fields[i].second.getValueAsString() <<
"\"" << __E__;
1049 <<
" link record" << __E__;
1058 const std::string& filePath,
1059 const std::string& dumpType,
1060 const std::string& configurationAlias,
1061 const std::string& subsystemCommonList,
1062 const std::string& subsystemCommonOverrideList,
1063 const std::string& logEntry,
1064 const std::string& activeUsers,
1065 const std::string& activeStateMachine,
1066 std::ostream& altOut )
1068 time_t rawtime = time(0);
1069 __GEN_COUT__ <<
"filePath = " << filePath << __E__;
1070 __GEN_COUT__ <<
"dumpType = " << dumpType << __E__;
1074 fs.open(filePath, std::fstream::out | std::fstream::trunc);
1085 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath
1086 <<
" could not be opened!" << __E__;
1087 __GEN_COUT_ERR__ << ss.str();
1093 if(dumpType ==
"JSON All")
1096 (*out) <<
"\t\"ARTDAQ_DATABASE_URI\": \"" << __ENV__(
"ARTDAQ_DATABASE_URI")
1100 (*out) <<
"\t\"HOSTNAME\": \"" << __ENV__(
"HOSTNAME") <<
"\"," << __E__;
1101 (*out) <<
"\t\"HOSTNAME filepath\": \"" << filePath <<
"\"," << __E__;
1102 (*out) <<
"\t\"Active State Machine\": \"" << activeStateMachine <<
"\","
1105 (*out) <<
"\t\"active_users\": \t[";
1106 if(activeUsers.size())
1108 std::istringstream iss(activeUsers);
1111 while(std::getline(iss, user,
','))
1115 (*out) <<
"\n\t\t\"" << user <<
"\"";
1119 (*out) <<
"\n\t]," << __E__;
1120 (*out) <<
"\t\"dump_type\": \t\t\"" << dumpType <<
"\"," << __E__;
1121 (*out) <<
"\t\"dump_time\": \t\t\"" << rawtime <<
"\"," << __E__;
1122 (*out) <<
"\t\"dump_time_formatted\": \t\t\""
1127 (*out) <<
"#################################" << __E__;
1128 (*out) <<
"This is an ots system configuration dump.\n" << __E__;
1129 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI: "
1130 << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
1132 (*out) <<
"Original location of dump: " << __ENV__(
"HOSTNAME")
1133 <<
":" << filePath << __E__;
1134 (*out) <<
"\nActive ots users: \t"
1135 << (activeUsers.size() ? activeUsers :
"no active users") << __E__;
1136 (*out) <<
"Type of dump: \t\t" << dumpType << __E__;
1137 (*out) <<
"Time of dump: \t\t" << rawtime;
1142 std::pair<std::string, ots::TableGroupKey> configurationTableGroup =
1145 if(dumpType !=
"JSON All")
1147 (*out) <<
"Configuration Alias: \t\t\t" << configurationAlias <<
"\n";
1148 (*out) <<
"Configuration Alias translation: \t" << configurationTableGroup.first
1149 <<
"(" << configurationTableGroup.second <<
")\n\n";
1152 (*out) <<
"User Log Entry (" << logEntry.size() <<
" chars):\n"
1153 << logEntry << __E__;
1165 std::string subsystemCommonList,
1166 std::string subsystemCommonOverrideList,
1167 bool jsonify =
false,
1168 std::string configurationAlias =
"") {
1169 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
1174 if(!subsystemCommonList.empty())
1175 (*out) <<
"\n\t\"subsystem_common_table_list\": \"" << subsystemCommonList
1177 if(!subsystemCommonOverrideList.empty())
1178 (*out) <<
"\n\t\"subsystem_common_override_table_list\": \""
1179 << subsystemCommonOverrideList <<
"\",\n"
1181 (*out) <<
"\n\t\"groups\": {\n";
1185 (*out) <<
"Subsystem Common Table List: " << subsystemCommonList << __E__;
1186 (*out) <<
"Subsystem Common Override Table List: "
1187 << subsystemCommonOverrideList << __E__;
1188 (*out) <<
"\n\n************************" << __E__;
1189 (*out) <<
"Active Groups: " << __E__;
1192 std::map<std::string, std::pair<std::string, TableGroupKey>>::iterator it;
1194 for(it = activeGroups.begin(); it != activeGroups.end(); ++it)
1198 (*out) <<
"\t\t\"" << it->first <<
"_group_name\": \"" << it->second.first
1200 (*out) <<
"\t\t\"" << it->first <<
"_group_key\": \"" << it->second.second
1202 if(it->first ==
"Configuration")
1206 <<
"Configuration_alias\": \"" << configurationAlias <<
"\"";
1208 (*out) << (std::next(it) == activeGroups.end() ?
"" :
",") <<
"\n";
1212 (*out) <<
"\t" << it->first <<
" := " << it->second.first <<
" ("
1213 << it->second.second <<
")" << __E__;
1224 bool jsonify =
false) {
1229 (*out) <<
"\t\"tables\": { " << __E__;
1233 (*out) <<
"\n\n************************" << __E__;
1234 (*out) <<
"Active Tables:" << __E__;
1235 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
1239 std::map<std::string, TableVersion>::iterator it;
1240 for(it = activeTables.begin(); it != activeTables.end(); ++it)
1245 <<
"active_table_name"
1246 <<
"\": \"" << it->first <<
"\",\n";
1248 <<
"active_table_version"
1249 <<
"\": \"" << it->second <<
"\"";
1250 (*out) << (std::next(it) == activeTables.end() ?
"" :
",") <<
"\n";
1254 (*out) <<
"\t" << ++i <<
". " << it->first <<
"-v" << it->second << __E__;
1265 bool jsonify =
false) {
1266 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
1271 (*out) <<
"\t\"group_members\": { " << __E__;
1275 (*out) <<
"\n\n************************" << __E__;
1276 (*out) <<
"Active Group Members:" << __E__;
1280 std::map<std::string, std::pair<std::string, TableGroupKey>>::iterator it;
1281 for(it = activeGroups.begin(); it != activeGroups.end(); ++it)
1285 (*out) <<
"\t" << it->first <<
" := " << it->second.first <<
" ("
1286 << it->second.second <<
")" << __E__;
1289 if(it->second.first ==
"")
1294 <<
"Empty group name. Assuming no active group." << __E__;
1301 (*out) <<
"\t\t\"" << it->first <<
"\" : {" << __E__;
1302 (*out) <<
"\t\t\t\"Name\": \t\"" << it->second.first <<
"\""
1303 << (std::next(it) == activeGroups.end() ?
"" :
",") << __E__;
1307 std::map<std::string , std::string > groupAliases;
1308 std::string groupComment;
1309 std::string groupAuthor;
1310 std::string groupCreateTime;
1311 time_t groupCreateTime_t;
1328 (*out) <<
"\t\t\t\"key\": \t\"" << it->second.second <<
"\"," << __E__;
1329 (*out) <<
"\t\t\t\"comment\": \t\"" << groupComment <<
"\"," << __E__;
1330 (*out) <<
"\t\t\t\"author\": \t\"" << groupAuthor <<
"\"," << __E__;
1332 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
1333 std::string timeCreated = ctime(&groupCreateTime_t);
1334 (*out) <<
"\t\t\t\"create_time\": \t\""
1335 << timeCreated.erase(timeCreated.find(
'\n', 0), 1) <<
"\","
1337 (*out) <<
"\t\t\t\"group_aliases\": \t\""
1340 (*out) <<
"\t\t\t\"table_count\": \t\"" << memberMap.size() <<
"\","
1342 tableCount += memberMap.size();
1344 (*out) <<
"\t\t\t\"tables\": {" << __E__;
1348 for(iterMap = memberMap.begin(); iterMap != memberMap.end(); ++iterMap)
1350 (*out) <<
"\t\t\t\t\"" << iterMap->first <<
"\": \""
1351 << iterMap->second <<
"\""
1352 << (std::next(iterMap) == memberMap.end() ?
"" :
",") << __E__;
1354 (*out) <<
"\t\t\t}" << __E__;
1355 (*out) <<
"\t\t}," << __E__;
1359 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
1360 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
1362 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
1363 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t)
1365 (*out) <<
"\t\tGroup Aliases: \t"
1368 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
1369 tableCount += memberMap.size();
1372 for(
auto& member : memberMap)
1374 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v"
1375 << member.second << __E__;
1382 (*out) <<
"\t\"total_table_count\": \"" << tableCount <<
"\"" << __E__;
1387 (*out) <<
"\nActive Group Members total table count = " << tableCount
1395 bool jsonify =
false) {
1400 (*out) <<
"\t\"tables\": {" << __E__;
1404 (*out) <<
"\n\n************************" << __E__;
1405 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
1410 std::map<std::string, TableVersion>::iterator it;
1411 for(it = activeTables.begin(); it != activeTables.end(); ++it)
1415 __COUTT__ <<
"localDumpActiveTableContents table: " << it->first << __E__;
1416 auto table = cfgMgr->nameToTableMap_.find(it->first)->second->getViewP();
1417 (*out) <<
"\t\t\"" << it->first <<
"-v" << it->second <<
"\": ";
1418 table->printJSON(*out);
1419 (*out) << (std::next(it) == activeTables.end() ?
"" :
",") << __E__;
1423 (*out) <<
"\n\n=========================================================="
1427 (*out) <<
"=============================================================="
1431 (*out) <<
"\t" << ++i <<
". " << it->first <<
"-v" << it->second << __E__;
1433 cfgMgr->nameToTableMap_.find(it->first)->second->print(*out);
1439 (*out) <<
"\t}" << __E__;
1445 std::ostream* out) {
1448 __COUT__ <<
"Active Table size: " << activeTables.size() << __E__;
1449 (*out) <<
"\t\"custom\": {" << __E__;
1451 std::string activeTableStructure =
"";
1452 std::map<std::string, TableVersion>::iterator it;
1453 size_t tableStructureFoundCount = 0;
1454 for(it = activeTables.begin(); it != activeTables.end(); ++it)
1458 __COUTT__ <<
"Trying to retrieve " << it->first <<
"-v" << it->second
1459 <<
" Structure" << __E__;
1460 activeTableStructure =
1461 cfgMgr->nameToTableMap_.find(it->first)->second->getStructureAsJSON(
1463 if(activeTableStructure !=
"")
1465 __COUTT__ <<
"Found Structure for Active Table: " << it->first <<
"-v"
1466 << it->second << __E__;
1468 (*out) << (tableStructureFoundCount++ ?
"," :
"") << __E__;
1470 (*out) <<
"\t\"" << it->first <<
"\": " << __E__;
1471 (*out) << activeTableStructure << __E__;
1474 catch(
const std::exception& e)
1476 __COUTT__ <<
"Error caught in localDumpActiveTableStructureStatus(): "
1478 __COUTT__ <<
"Structure Status may not be implemented." << __E__;
1482 __COUT__ <<
"Found " << tableStructureFoundCount <<
" Active Table Structures."
1485 (*out) <<
"\t}" << __E__;
1489 auto localDumpSoftwareVersions = [](std::ostream* out,
bool jsonFormat =
false) {
1490 __COUT__ <<
"localDumpSoftwareVersions()" << __E__;
1491 std::vector<std::string> entries;
1494 std::map<std::string, std::string> spackPackages;
1495 std::map<std::string, std::string> checkedOutRepos;
1496 std::string environment;
1500 std::istringstream iss(spackOut);
1502 while(std::getline(iss, line))
1508 if(line.find(
"==> In environment") != std::string::npos)
1510 size_t start = line.find(
"environment ") + 12;
1511 environment = line.substr(start);
1513 else if(line[0] !=
'[' && line[0] !=
'-' &&
1514 line.find(
"root specs") == std::string::npos)
1517 size_t atPos = line.find(
'@');
1518 if(atPos != std::string::npos)
1520 std::string pkgName = line.substr(0, atPos);
1522 if(pkgName.find(
'[') != std::string::npos)
1523 pkgName = pkgName.substr(pkgName.find(
']') + 2);
1524 std::string version = line.substr(atPos + 1);
1525 spackPackages[pkgName] = version;
1527 else if(line.find(
'[') == std::string::npos && !line.empty() &&
1531 std::string pkgName = line;
1532 if(pkgName.find(
'[') != std::string::npos)
1533 pkgName = pkgName.substr(pkgName.find(
']') + 2);
1534 spackPackages[pkgName] =
"";
1543 struct dirent* entry;
1547 std::string src = __ENV__(
"OTS_SOURCE");
1548 if(!(pDIR = opendir((src).c_str())))
1550 __SS__ <<
"Path '" << src <<
"' could not be opened!" << __E__;
1553 while((entry = readdir(pDIR)))
1555 name = std::string(entry->d_name);
1556 type = int(entry->d_type);
1558 __COUTS__(2) << type <<
" " << name <<
"\n" << std::endl;
1559 if(name[0] !=
'.' &&
1569 if(type == 0 || type == 10)
1572 DIR* pTmpDIR = opendir((src +
"/" + name).c_str());
1579 __COUTS__(2) <<
"Unable to open path as directory: "
1580 << (src +
"/" + name) << __E__;
1590 __COUTS__(2) <<
"Directory: " << type <<
" " << name << __E__;
1592 (
"cd " + src +
"/" + name +
"; git describe --tags").c_str());
1596 if(describe.back() ==
'\n')
1597 describe.pop_back();
1598 checkedOutRepos[name] = describe;
1608 (*out) <<
"\t\"software_versions\": {" << __E__;
1611 (*out) <<
"\t\t\"spack\": {" << __E__;
1613 for(
const auto& pkg : spackPackages)
1616 (*out) <<
"," << __E__;
1622 (*out) << __E__ <<
"\t\t}," << __E__;
1625 (*out) <<
"\t\t\"checked_out\": {" << __E__;
1627 for(
const auto& repo : checkedOutRepos)
1630 (*out) <<
"," << __E__;
1636 (*out) << __E__ <<
"\t\t}," << __E__;
1639 (*out) <<
"\t\t\"environment\": \""
1643 (*out) <<
"\t}" << __E__;
1647 (*out) <<
"\n\n\"Software Versions\": {" << __E__;
1648 (*out) <<
" \"spack\": " << spackPackages.size() <<
" packages," << __E__;
1649 (*out) <<
" \"checked_out\": " << checkedOutRepos.size() <<
" repositories,"
1651 (*out) <<
" \"environment\": \"" << environment <<
"\"" << __E__;
1652 (*out) <<
"}" << __E__;
1656 if(dumpType ==
"Group Keys")
1658 localDumpActiveGroups(
1659 this, out, subsystemCommonList, subsystemCommonOverrideList);
1661 else if(dumpType ==
"Table Versions")
1663 localDumpActiveTables(
this, out);
1665 else if(dumpType ==
"Group Keys and Table Versions")
1667 localDumpActiveGroups(
1668 this, out, subsystemCommonList, subsystemCommonOverrideList);
1669 localDumpActiveTables(
this, out);
1671 else if(dumpType ==
"All")
1673 localDumpActiveGroups(
1674 this, out, subsystemCommonList, subsystemCommonOverrideList);
1675 localDumpActiveGroupMembers(
this, out);
1676 localDumpActiveTables(
this, out);
1677 localDumpActiveTableContents(
this, out);
1678 localDumpSoftwareVersions(out);
1680 else if(dumpType ==
"JSON All")
1682 localDumpActiveGroups(
this,
1684 subsystemCommonList,
1685 subsystemCommonOverrideList,
1687 configurationAlias);
1689 localDumpActiveGroupMembers(
this, out,
true);
1693 localDumpActiveTableContents(
this, out,
true);
1694 (*out) <<
",\n" << __E__;
1695 localDumpActiveTableStructureStatus(
this, out);
1696 (*out) <<
",\n" << __E__;
1697 localDumpSoftwareVersions(out,
true);
1703 <<
"Invalid dump type '" << dumpType
1704 <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
1712 <<
"Group Keys and Table Versions"
1719 "\n\nPlease change the State Machine configuration to a valid dump type."
1736 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap,
1737 std::string* accumulatedWarnings )
1739 __GEN_COUTTV__(runTimeSeconds());
1744 bool usingCache =
false;
1745 if(memberMap.size() > 10 && nameToTableMap_.size() &&
1746 nameToTableMap_.find(memberMap.begin()->first) != nameToTableMap_.end() &&
1747 nameToTableMap_.at(memberMap.begin()->first)->isStored(memberMap.begin()->second))
1752 __GEN_COUTT__ <<
"Using cache!" << __E__;
1756 const int numOfThreads =
1758 if(memberMap.size() <= 2 || usingCache ||
1763 for(
auto& memberPair : memberMap)
1775 tmpTableBasePtr =
nullptr;
1776 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1777 tmpTableBasePtr = nameToTableMap_.at(memberPair.first);
1779 std::string getError =
"";
1782 theInterface_->get(tmpTableBasePtr,
1791 catch(
const std::runtime_error& e)
1793 __SS__ <<
"Failed to load member table '" << memberPair.first <<
"-v"
1794 << memberPair.second <<
"' - here is the error: \n\n"
1795 << e.what() << __E__;
1797 ss <<
"\nIf the table '" << memberPair.first
1798 <<
"' should not exist, then please remove it from the group. If it "
1799 "should exist, then it "
1800 <<
"seems to have a problem; use the Table Editor to fix the table "
1802 "edit the table content to match the table definition."
1806 if(accumulatedWarnings)
1807 getError = ss.str();
1813 __SS__ <<
"Failed to load member table '" << memberPair.first <<
" -v"
1814 << memberPair.second <<
"' due to unknown error!" << __E__;
1819 catch(
const std::exception& e)
1821 ss <<
"Exception message: " << e.what();
1827 ss <<
"\nIf the table '" << memberPair.first
1828 <<
"' should not exist, then please remove it from the group. If it "
1829 "should exist, then it "
1830 <<
"seems to have a problem; use the Table Editor to fix the table "
1832 "edit the table content to match the table definition."
1836 if(accumulatedWarnings)
1837 getError = ss.str();
1843 if(!tmpTableBasePtr)
1845 __SS__ <<
"Null pointer returned for table '" << memberPair.first <<
" -v"
1846 << memberPair.second <<
".' Was the table info deleted?" << __E__;
1847 __GEN_COUT_ERR__ << ss.str();
1849 nameToTableMap_.erase(memberPair.first);
1850 if(accumulatedWarnings)
1852 *accumulatedWarnings += ss.str();
1859 nameToTableMap_[memberPair.first] = tmpTableBasePtr;
1860 if(nameToTableMap_[memberPair.first]->getViewP())
1865 if(accumulatedWarnings && getError !=
"")
1867 __SS__ <<
"Error caught during '" << memberPair.first <<
" -v"
1868 << memberPair.second <<
"' table retrieval: \n"
1869 << getError << __E__;
1870 __GEN_COUT_ERR__ << ss.str();
1871 *accumulatedWarnings += ss.str();
1876 __SS__ << nameToTableMap_[memberPair.first]->getTableName() <<
" -v"
1877 << memberPair.second <<
": View version not activated properly!";
1884 __GEN_COUTT__ <<
" PROCESSOR_COUNT " <<
PROCESSOR_COUNT <<
" ==> " << numOfThreads
1885 <<
" threads for loading member map of size " << memberMap.size()
1888 int threadsLaunched = 0;
1889 int foundThreadIndex = 0;
1890 std::string threadErrors;
1891 std::mutex threadMutex;
1892 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
1893 for(
int i = 0; i < numOfThreads; ++i)
1894 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
1895 std::vector<TableBase*> tmpTableBasePtrs;
1896 for(
int i = 0; i < numOfThreads; ++i)
1897 tmpTableBasePtrs.push_back(
nullptr);
1899 for(
auto& memberPair : memberMap)
1901 if(threadsLaunched >= numOfThreads)
1904 foundThreadIndex = -1;
1905 while(foundThreadIndex == -1)
1907 for(
int i = 0; i < numOfThreads; ++i)
1908 if(*(threadDone[i]))
1910 foundThreadIndex = i;
1913 if(foundThreadIndex == -1)
1915 __GEN_COUTT__ <<
"Waiting for available thread..." << __E__;
1919 threadsLaunched = numOfThreads - 1;
1921 __GEN_COUTT__ <<
"Starting filling thread... " << foundThreadIndex <<
" for "
1922 << memberPair.first <<
" -v" << memberPair.second << __E__;
1923 *(threadDone[foundThreadIndex]) =
false;
1931 tmpTableBasePtrs[foundThreadIndex] =
nullptr;
1932 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1933 tmpTableBasePtrs[foundThreadIndex] = nameToTableMap_.at(memberPair.first);
1937 std::map<std::string, ots::TableBase*>* theNameToTableMap,
1939 std::string theTableName,
1941 std::string* theThreadErrors,
1942 std::mutex* theThreadMutex,
1943 std::shared_ptr<std::atomic<bool>> theThreadDone) {
1944 ConfigurationManager::fillTableThread(theInterface,
1955 tmpTableBasePtrs[foundThreadIndex],
1960 threadDone[foundThreadIndex])
1970 foundThreadIndex = -1;
1971 for(
int i = 0; i < numOfThreads; ++i)
1972 if(!*(threadDone[i]))
1974 foundThreadIndex = i;
1977 if(foundThreadIndex != -1)
1979 __GEN_COUT_TYPE__(TLVL_DEBUG + 2)
1980 << __COUT_HDR__ <<
"Waiting for thread to finish... "
1981 << foundThreadIndex << __E__;
1984 }
while(foundThreadIndex != -1);
1985 __GEN_COUTT__ <<
"All threads done." << __E__;
1987 if(threadErrors !=
"")
1989 __SS__ <<
"Error identified in threads during loading of member map: \n"
1990 << threadErrors << __E__;
1991 __GEN_COUTT__ <<
"\n" << ss.str() << __E__;
1992 if(accumulatedWarnings)
1993 *accumulatedWarnings += ss.str();
1999 __GEN_COUTT__ <<
"loadMemberMap end runTimeSeconds()=" << runTimeSeconds() << __E__;
2025 const std::string& groupName,
2028 std::map<std::string /*table name*/, TableVersion>*
2031 std::string* accumulatedWarnings ,
2032 std::string* groupComment ,
2033 std::string* groupAuthor ,
2034 std::string* groupCreateTime ,
2035 bool doNotLoadMembers ,
2036 std::string* groupTypeString ,
2037 std::map<std::string /*name*/, std::string /*alias*/>*
2039 ConfigurationManager::LoadGroupType
2041 bool ignoreVersionTracking ,
2042 std::map<std::string /* tableName */, TableVersion> mergInTables ,
2043 std::map<std::string /* tableName */, TableVersion> overrideTables )
2047 *groupComment = ConfigurationManager::UNKNOWN_INFO;
2049 *groupAuthor = ConfigurationManager::UNKNOWN_INFO;
2051 *groupCreateTime = ConfigurationManager::UNKNOWN_TIME;
2053 *groupTypeString = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
2055 __GEN_COUTT__ <<
"No group type requested." << __E__;
2082 __GEN_COUTT__ <<
"Loading Table Group: " << groupName <<
"(" << groupKey <<
")"
2083 <<
" accumulatedWarnings=" << (accumulatedWarnings ? 1 : 0) << __E__;
2095 progressBar->
step();
2098 auto metaTablePair = memberMap.find(TableBase::GROUP_METADATA_TABLE_NAME);
2099 if(metaTablePair != memberMap.end())
2102 if(groupAliases || groupComment || groupAuthor || groupCreateTime)
2104 std::lock_guard<std::mutex> lock(metaDataTableMutex_);
2107 while(groupMetadataTable_.getView().getNumberOfRows())
2108 groupMetadataTable_.getViewP()->
deleteRow(0);
2113 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
2115 catch(
const std::runtime_error& e)
2118 <<
"Failed to load " << groupMetadataTable_.
getTableName() <<
"-v"
2119 << metaTablePair->second <<
". Metadata error: " << e.what()
2125 <<
"Failed to load " << groupMetadataTable_.
getTableName() <<
"-v"
2126 << metaTablePair->second <<
". Ignoring unknown metadata error. "
2131 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
2133 groupMetadataTable_.
print();
2134 __GEN_COUT_ERR__ <<
"Ignoring that groupMetadataTable_ has wrong "
2135 "number of rows for '"
2136 << groupName <<
"(" << groupKey
2138 "be 1. Going with anonymous defaults."
2142 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
2143 groupMetadataTable_.getViewP()->
deleteRow(0);
2144 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
2145 groupMetadataTable_.getViewP()->
addRow();
2154 0, ConfigurationManager::METADATA_COL_ALIASES),
2158 0, ConfigurationManager::METADATA_COL_COMMENT);
2161 0, ConfigurationManager::METADATA_COL_AUTHOR);
2164 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
2168 memberMap.erase(metaTablePair);
2173 __GEN_COUTT__ <<
"Ignoring that groupMetadataTable_ is missing for group '"
2174 << groupName <<
"(" << groupKey
2175 <<
"). Going with anonymous defaults." << __E__;
2186 std::map<std::string, std::string>& aliasMap = *groupAliases;
2187 std::map<std::string , std::map<std::string ,
TableVersion>>
2197 for(
auto& aliasPair : aliasMap)
2200 if(memberMap.find(aliasPair.first) != memberMap.end())
2202 __GEN_COUT__ <<
"Group member '" << aliasPair.first
2203 <<
"' was found in group member map!" << __E__;
2204 __GEN_COUT__ <<
"Looking for alias '" << aliasPair.second
2205 <<
"' in active version aliases..." << __E__;
2207 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
2208 versionAliases[aliasPair.first].find(aliasPair.second) ==
2209 versionAliases[aliasPair.first].end())
2211 __SS__ <<
"Group '" << groupName <<
"(" << groupKey
2212 <<
")' requires table version alias '" << aliasPair.first
2213 <<
":" << aliasPair.second
2214 <<
",' which was not found in the active Backbone!"
2219 memberMap[aliasPair.first] =
2220 versionAliases[aliasPair.first][aliasPair.second];
2221 __GEN_COUT__ <<
"Version alias translated to " << aliasPair.first
2228 *groupMembers = memberMap;
2231 progressBar->
step();
2233 ConfigurationManager::GroupType groupType =
2234 ConfigurationManager::GroupType::CONFIGURATION_TYPE;
2243 __GEN_COUTT__ <<
"No group type requested." << __E__;
2245 if(doNotLoadMembers)
2249 if(!groupTypeString)
2252 if(groupTypeToLoad ==
2253 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_OR_CONTEXT_TYPES &&
2254 groupType != ConfigurationManager::GroupType::CONTEXT_TYPE &&
2255 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
2257 __GEN_COUT__ <<
"Not loading group because it is not of type Context or "
2258 "Backbone (it is type '"
2262 else if(groupTypeToLoad ==
2263 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_TYPE &&
2264 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
2266 __GEN_COUT__ <<
"Not loading group because it is not of type "
2267 "Backbone (it is type '"
2275 <<
"------------------------------------- init start \t [for all "
2283 std::string groupToDeactivate =
2284 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2285 ? theContextTableGroup_
2286 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
2287 ? theBackboneTableGroup_
2289 ConfigurationManager::GroupType::ITERATE_TYPE
2290 ? theIterateTableGroup_
2291 : theConfigurationTableGroup_));
2294 if(groupToDeactivate !=
"")
2296 __GEN_COUTT__ <<
"groupToDeactivate '" << groupToDeactivate
2305 __GEN_COUTT__ <<
"no group to deactivate of type "
2312 progressBar->
step();
2317 progressBar->
step();
2319 __GEN_COUTT__ <<
"loadMemberMap() completed." << __E__;
2321 if(accumulatedWarnings)
2323 __GEN_COUTT__ <<
"Checking chosen group for tree errors... here are the "
2324 "current warnings: "
2325 << *accumulatedWarnings << __E__;
2328 if(*accumulatedWarnings !=
"")
2331 <<
"Errors detected while loading Table Group: " << groupName
2332 <<
"(" << groupKey <<
"). Ignoring the following errors: "
2334 << *accumulatedWarnings << __E__;
2336 __GEN_COUTT__ <<
"After checking children warnings: "
2337 << *accumulatedWarnings << __E__;
2341 progressBar->
step();
2343 __GEN_COUTT__ <<
"Tree view check complete." << __E__;
2351 if(overrideTables.size())
2353 __GEN_COUT__ <<
"Overriding tables: "
2356 std::map<std::pair<std::string ,
2360 std::map<std::pair<std::string ,
2361 std::pair<std::string ,
2364 groupidConversionMap;
2366 for(
const auto& mergeInPair : overrideTables)
2368 if(memberMap.find(mergeInPair.first) == memberMap.end())
2370 __GEN_COUT__ <<
"Skipping override of table '"
2371 << mergeInPair.first <<
"-v"
2372 << mergeInPair.second
2373 <<
"' which is not in group " << groupName <<
"("
2374 << groupKey <<
")." << __E__;
2377 __GEN_COUT__ <<
"Overriding group member table '"
2378 << mergeInPair.first <<
"' v"
2379 << memberMap.at(mergeInPair.first)
2380 <<
" with version v" << mergeInPair.second << __E__;
2382 std::stringstream mergeReport;
2384 nameToTableMap_.at(mergeInPair.first)
2388 memberMap.at(mergeInPair.first))
2395 TableBase::MergeApproach::REPLACE,
2397 groupidConversionMap,
2403 __GEN_COUTV__(newVersion);
2404 nameToTableMap_.at(mergeInPair.first)->setActiveView(newVersion);
2405 nameToTableMap_.at(mergeInPair.first)
2407 ->setComment(nameToTableMap_.at(mergeInPair.first)
2410 "\n" + mergeReport.str());
2411 __GEN_COUT__ <<
"Overriding table '" << mergeInPair.first
2412 <<
"' resulting version v" << newVersion << __E__;
2413 __GEN_COUTV__(mergeReport.str());
2419 if(mergInTables.size())
2421 __GEN_COUT__ <<
"Merging-in tables: "
2424 std::map<std::pair<std::string ,
2428 std::map<std::pair<std::string ,
2429 std::pair<std::string ,
2432 groupidConversionMap;
2434 for(
const auto& mergeInPair : mergInTables)
2436 if(memberMap.find(mergeInPair.first) == memberMap.end())
2438 __GEN_COUT__ <<
"Skipping merging-in of table '"
2439 << mergeInPair.first <<
"-v"
2440 << mergeInPair.second
2441 <<
"' which is not in group " << groupName <<
"("
2442 << groupKey <<
")." << __E__;
2446 __GEN_COUT__ <<
"Merging-in group member table '"
2447 << mergeInPair.first <<
"' v"
2448 << memberMap.at(mergeInPair.first)
2449 <<
" with version v" << mergeInPair.second << __E__;
2451 std::stringstream mergeReport;
2453 nameToTableMap_.at(mergeInPair.first)
2457 memberMap.at(mergeInPair.first))
2464 TableBase::MergeApproach::SKIP,
2466 groupidConversionMap,
2472 __GEN_COUTV__(newVersion);
2473 nameToTableMap_.at(mergeInPair.first)->setActiveView(newVersion);
2474 nameToTableMap_.at(mergeInPair.first)
2476 ->setComment(nameToTableMap_.at(mergeInPair.first)
2479 "\n" + mergeReport.str());
2480 __GEN_COUT__ <<
"Merging-in table '" << mergeInPair.first
2481 <<
"' resulting version v" << newVersion << __E__;
2482 __GEN_COUTV__(mergeReport.str());
2489 progressBar->
step();
2494 <<
" threads for initializing tables for Table Group '"
2495 << groupName <<
"(" << groupKey <<
")'." << __E__;
2496 if(groupType != ConfigurationManager::GroupType::CONFIGURATION_TYPE ||
2499 for(
auto& memberPair : memberMap)
2502 if(!ignoreVersionTracking &&
2503 ConfigurationInterface::isVersionTrackingEnabled() &&
2504 memberPair.second.isScratchVersion())
2507 <<
"Error while activating member Table '"
2508 << nameToTableMap_[memberPair.first]->getTableName()
2509 <<
"-v" << memberPair.second <<
" for Table Group '"
2510 << groupName <<
"(" << groupKey
2511 <<
")'. When version tracking is enabled, Scratch views"
2512 <<
" are not allowed! Please only use unique, persistent "
2513 "versions when version tracking is enabled."
2522 nameToTableMap_.at(memberPair.first)->init(
this);
2524 catch(std::runtime_error& e)
2526 __SS__ <<
"Error detected calling " << memberPair.first
2527 <<
".init()!\n\n " << e.what() << __E__;
2529 if(accumulatedWarnings)
2531 *accumulatedWarnings += ss.str();
2541 __SS__ <<
"Unknown Error detected calling "
2542 << memberPair.first <<
".init()!\n\n " << __E__;
2547 catch(
const std::exception& e)
2549 ss <<
"Exception message: " << e.what();
2556 if(accumulatedWarnings)
2558 *accumulatedWarnings += ss.str();
2561 __GEN_COUT_WARN__ << ss.str();
2567 int threadsLaunched = 0;
2568 int foundThreadIndex = 0;
2569 std::string threadErrors;
2570 std::mutex threadMutex;
2571 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
2572 for(
int i = 0; i < numOfThreads; ++i)
2573 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
2575 if(!ignoreVersionTracking &&
2576 ConfigurationInterface::isVersionTrackingEnabled())
2577 for(
auto& memberPair : memberMap)
2580 if(memberPair.second.isScratchVersion())
2583 <<
"Error while activating member Table '"
2584 << nameToTableMap_[memberPair.first]->getTableName()
2585 <<
"-v" << memberPair.second <<
" for Table Group '"
2586 << groupName <<
"(" << groupKey
2587 <<
")'. When version tracking is enabled, Scratch "
2589 <<
" are not allowed! Please only use unique, "
2591 "versions when version tracking is enabled."
2597 for(
auto& memberPair : memberMap)
2599 if(threadsLaunched >= numOfThreads)
2602 foundThreadIndex = -1;
2603 while(foundThreadIndex == -1)
2605 for(
int i = 0; i < numOfThreads; ++i)
2606 if(*(threadDone[i]))
2608 foundThreadIndex = i;
2611 if(foundThreadIndex == -1)
2613 __GEN_COUTT__ <<
"Waiting for available thread..."
2618 threadsLaunched = numOfThreads - 1;
2620 __GEN_COUTT__ <<
"Starting init table thread... "
2621 << foundThreadIndex <<
" for " << memberPair.first
2623 *(threadDone[foundThreadIndex]) =
false;
2628 std::string* theThreadErrors,
2629 std::mutex* theThreadMutex,
2630 std::shared_ptr<std::atomic<bool>> theThreadDone) {
2631 ConfigurationManager::initTableThread(cfgMgr,
2638 nameToTableMap_.at(memberPair.first),
2641 threadDone[foundThreadIndex])
2651 foundThreadIndex = -1;
2652 for(
int i = 0; i < numOfThreads; ++i)
2653 if(!*(threadDone[i]))
2655 foundThreadIndex = i;
2658 if(foundThreadIndex != -1)
2660 __GEN_COUTT__ <<
"Waiting for thread to finish... "
2661 << foundThreadIndex << __E__;
2664 }
while(foundThreadIndex != -1);
2665 __GEN_COUTT__ <<
"All threads done." << __E__;
2667 if(threadErrors !=
"")
2669 __SS__ <<
"Error identified in threads during init of table "
2671 << threadErrors << __E__;
2672 __GEN_COUTT__ <<
"\n" << ss.str() << __E__;
2673 if(accumulatedWarnings)
2674 *accumulatedWarnings += ss.str();
2684 progressBar->
step();
2693 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
2699 theContextTableGroup_ = groupName;
2700 theContextTableGroupKey_ =
2701 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2703 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
2708 theBackboneTableGroup_ = groupName;
2709 theBackboneTableGroupKey_ =
2710 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2712 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
2718 theIterateTableGroup_ = groupName;
2719 theIterateTableGroupKey_ =
2720 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2727 theConfigurationTableGroup_ = groupName;
2728 theConfigurationTableGroupKey_ =
2729 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2734 progressBar->
step();
2738 <<
"------------------------------------- init complete \t [for all "
2748 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2754 catch(
const std::runtime_error& e)
2756 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
2757 << groupKey <<
")': \n"
2758 << e.what() << __E__;
2760 if(accumulatedWarnings)
2761 *accumulatedWarnings += ss.str();
2767 __SS__ <<
"An unknown error occurred while loading table group '"
2768 << groupName <<
"(" << groupKey <<
")." << __E__;
2773 catch(
const std::exception& e)
2775 ss <<
"Exception message: " << e.what();
2780 if(accumulatedWarnings)
2781 *accumulatedWarnings += ss.str();
2787 __GEN_COUTT__ <<
"loadTableGroup() complete for Table Group '" << groupName <<
"("
2788 << groupKey <<
")'." << __E__;
2790 std::make_pair(std::make_pair(groupName,
TableGroupKey(groupKey)), memberMap);
2795 __GEN_COUTT__ <<
"loadTableGroup() failed." << __E__;
2798 lastFailedGroupLoad_[ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN] =
2799 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2805 catch(
const std::runtime_error& e)
2807 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
2808 << groupKey <<
")': \n"
2809 << e.what() << __E__;
2811 if(accumulatedWarnings)
2812 *accumulatedWarnings += ss.str();
2818 __SS__ <<
"An unknown error occurred while loading table group '" << groupName
2819 <<
"(" << groupKey <<
")." << __E__;
2824 catch(
const std::exception& e)
2826 ss <<
"Exception message: " << e.what();
2833 if(accumulatedWarnings)
2834 *accumulatedWarnings += ss.str();
2846 const std::map<std::string, TableVersion>& memberMap,
2847 const std::string& groupName ,
2850 bool ignoreVersionTracking )
2855 ConfigurationManager::GroupType groupType =
getTypeOfGroup(memberMap);
2859 __GEN_COUT__ <<
"------------------------------------- cacheCopy init start "
2861 "plug-ins in member map"
2866 std::string groupToDeactivate =
2867 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2868 ? theContextTableGroup_
2869 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
2870 ? theBackboneTableGroup_
2871 : (groupType == ConfigurationManager::GroupType::ITERATE_TYPE
2872 ? theIterateTableGroup_
2873 : theConfigurationTableGroup_));
2876 if(groupToDeactivate !=
"")
2893 for(
auto& memberPair : memberMap)
2895 __GEN_COUTT__ <<
"Copying " << memberPair.first <<
"-v" << memberPair.second
2899 if(nameToTableMap_.find(memberPair.first) == nameToTableMap_.end())
2902 theInterface_->get(table,
2909 nameToTableMap_[memberPair.first] = table;
2911 nameToTableMap_.at(memberPair.first)
2913 ->getView(memberPair.second),
2916 ->getView(memberPair.second)
2924 __GEN_COUTT__ <<
"Done with member copy loop." << __E__;
2930 std::string accumulatedWarnings;
2933 << numOfThreads <<
" threads for initializing tables." << __E__;
2934 if(groupType != ConfigurationManager::GroupType::CONFIGURATION_TYPE ||
2937 for(
auto& memberPair : memberMap)
2940 if(!ignoreVersionTracking &&
2941 ConfigurationInterface::isVersionTrackingEnabled() &&
2942 memberPair.second.isScratchVersion())
2944 __SS__ <<
"Error while activating member Table '"
2945 << nameToTableMap_[memberPair.first]->getTableName()
2946 <<
"-v" << memberPair.second
2947 <<
" for member map. When version tracking is enabled, "
2949 <<
" are not allowed! Please only use unique, persistent "
2950 "versions when version tracking is enabled."
2959 nameToTableMap_.at(memberPair.first)->init(
this);
2961 catch(std::runtime_error& e)
2963 __SS__ <<
"Error detected calling " << memberPair.first
2964 <<
".init()!\n\n " << e.what() << __E__;
2965 accumulatedWarnings += ss.str();
2969 __SS__ <<
"Unknown Error detected calling " << memberPair.first
2970 <<
".init()!\n\n " << __E__;
2975 catch(
const std::exception& e)
2977 ss <<
"Exception message: " << e.what();
2982 accumulatedWarnings += ss.str();
2988 int threadsLaunched = 0;
2989 int foundThreadIndex = 0;
2990 std::mutex threadMutex;
2991 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
2992 for(
int i = 0; i < numOfThreads; ++i)
2993 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
2995 if(!ignoreVersionTracking &&
2996 ConfigurationInterface::isVersionTrackingEnabled())
2997 for(
auto& memberPair : memberMap)
3000 if(memberPair.second.isScratchVersion())
3003 <<
"Error while activating member Table '"
3004 << nameToTableMap_[memberPair.first]->getTableName()
3005 <<
"-v" << memberPair.second
3006 <<
" for member map. When version tracking is enabled, "
3008 <<
" are not allowed! Please only use unique, persistent "
3009 "versions when version tracking is enabled."
3015 for(
auto& memberPair : memberMap)
3017 if(threadsLaunched >= numOfThreads)
3020 foundThreadIndex = -1;
3021 while(foundThreadIndex == -1)
3023 for(
int i = 0; i < numOfThreads; ++i)
3024 if(*(threadDone[i]))
3026 foundThreadIndex = i;
3029 if(foundThreadIndex == -1)
3031 __GEN_COUTT__ <<
"Waiting for available thread..."
3036 threadsLaunched = numOfThreads - 1;
3038 __GEN_COUTT__ <<
"Starting init table thread... " << foundThreadIndex
3039 <<
" for " << memberPair.first << __E__;
3040 *(threadDone[foundThreadIndex]) =
false;
3045 std::string* theAccumulatedWarnings,
3046 std::mutex* theThreadMutex,
3047 std::shared_ptr<std::atomic<bool>> theThreadDone) {
3048 ConfigurationManager::initTableThread(cfgMgr,
3050 theAccumulatedWarnings,
3055 nameToTableMap_.at(memberPair.first),
3056 &accumulatedWarnings,
3058 threadDone[foundThreadIndex])
3068 foundThreadIndex = -1;
3069 for(
int i = 0; i < numOfThreads; ++i)
3070 if(!*(threadDone[i]))
3072 foundThreadIndex = i;
3075 if(foundThreadIndex != -1)
3077 __GEN_COUTT__ <<
"Waiting for thread to finish... "
3078 << foundThreadIndex << __E__;
3081 }
while(foundThreadIndex != -1);
3085 if(accumulatedWarnings !=
"")
3087 __GEN_COUT__ <<
"Activating the member map after copying cache had the "
3088 "following warnings: "
3089 << accumulatedWarnings << __E__;
3100 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
3106 theContextTableGroup_ = groupName;
3107 theContextTableGroupKey_ =
3108 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3110 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
3115 theBackboneTableGroup_ = groupName;
3116 theBackboneTableGroupKey_ =
3117 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3119 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
3125 theIterateTableGroup_ = groupName;
3126 theIterateTableGroupKey_ =
3127 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3134 theConfigurationTableGroup_ = groupName;
3135 theConfigurationTableGroupKey_ =
3136 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3141 __GEN_COUT__ <<
"------------------------------------- cacheCopy init "
3142 "complete \t [for all "
3143 "plug-ins in member map"
3146 __GEN_COUTT__ <<
"Completed cache copy." << __E__;
3149 make_pair(make_pair(groupName,
TableGroupKey(groupKey)), memberMap);
3153 __GEN_COUT__ <<
"Unknown failure in cache copy." << __E__;
3156 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
3163 ConfigurationManager::getGroupOfLoadedTable(
const std::string& tableName)
const
3165 for(
const auto& loadedGroup : lastGroupLoad_)
3166 if(loadedGroup.second.second.find(tableName) != loadedGroup.second.second.end())
3167 return loadedGroup.second.first;
3168 return std::make_pair(
"",
TableGroupKey(TableGroupKey::INVALID));
3175 std::string* threadErrors,
3176 std::mutex* threadMutex,
3177 std::shared_ptr<std::atomic<bool>> threadDone)
3180 __COUTT__ <<
"Thread init of " << table->
getTableName() <<
"-v"
3181 << table->
getViewVersion() <<
" threadErrors=" << (threadErrors ? 1 : 0)
3189 table->init(cfgMgr);
3191 catch(std::runtime_error& e)
3193 __SS__ <<
"Error detected calling " << table->
getTableName() <<
".init()!\n\n "
3194 << e.what() << __E__;
3198 std::lock_guard<std::mutex> lock(*threadMutex);
3199 *threadErrors += ss.str();
3209 __SS__ <<
"Unknown Error detected calling " << table->
getTableName()
3210 <<
".init()!\n\n " << __E__;
3215 catch(
const std::exception& e)
3217 ss <<
"Exception message: " << e.what();
3227 std::lock_guard<std::mutex> lock(*threadMutex);
3228 *threadErrors += ss.str();
3234 *(threadDone) =
true;
3238 __SS__ <<
"Error occurred initializing table '" << table->
getTableName() <<
"-v"
3244 catch(
const std::runtime_error& e)
3246 ss <<
" Run-time Exception message: " << e.what();
3248 catch(
const std::exception& e)
3250 ss <<
" Exception message: " << e.what();
3252 __COUT_WARN__ << ss.str() << __E__;
3256 std::lock_guard<std::mutex> lock(*threadMutex);
3257 *threadErrors += ss.str();
3260 *(threadDone) =
true;
3265 void ConfigurationManager::fillTableThread(
3267 std::map<std::string, ots::TableBase*>* nameToTableMap,
3269 std::string tableName,
3271 std::string* threadErrors,
3272 std::mutex* threadMutex,
3273 std::shared_ptr<std::atomic<bool>> threadDone)
3276 __COUTT__ <<
"Thread fill of " << tableName <<
"-v" << version << __E__;
3286 std::string getError =
"";
3291 theInterface->get(table,
3300 catch(
const std::runtime_error& e)
3302 __SS__ <<
"Failed to load member table '" << tableName <<
"-v" << version
3303 <<
"' - here is the error: \n\n"
3304 << e.what() << __E__;
3306 ss <<
"\nIf the table '" << tableName
3307 <<
"' should not exist, then please remove it from the group. If it "
3308 "should exist, then it "
3309 <<
"seems to have a problem; use the Table Editor to fix the table "
3311 "edit the table content to match the table definition."
3316 getError = ss.str();
3322 __SS__ <<
"Failed to load member table '" << tableName <<
"-v" << version
3323 <<
"' due to unknown error!" << __E__;
3328 catch(
const std::exception& e)
3330 ss <<
"Exception message: " << e.what();
3335 ss <<
"\nIf the table '" << tableName
3336 <<
"' should not exist, then please remove it from the group. If it "
3337 "should exist, then it "
3338 <<
"seems to have a problem; use the Table Editor to fix the table "
3340 "edit the table content to match the table definition."
3345 getError = ss.str();
3351 __COUTV__(getError);
3353 __COUT_TYPE__(TLVL_TRACE + 1)
3354 << __COUT_HDR__ <<
"Checking ptr.. " << (table ?
"GOOD" :
"BAD") << __E__;
3357 __SS__ <<
"Null pointer returned for table '" << tableName
3358 <<
".' Was the table info deleted?" << __E__;
3359 __COUT_ERR__ << ss.str();
3361 std::lock_guard<std::mutex> lock(*threadMutex);
3362 nameToTableMap->erase(tableName);
3366 *threadErrors += ss.str();
3367 *(threadDone) =
true;
3375 std::lock_guard<std::mutex> lock(*threadMutex);
3376 (*nameToTableMap)[tableName] = table;
3379 if(nameToTableMap->at(tableName)->getViewP())
3381 __COUT_TYPE__(TLVL_TRACE + 1)
3383 <<
"Activated version: " << nameToTableMap->at(tableName)->getViewVersion()
3386 if(threadErrors && getError !=
"")
3388 __SS__ <<
"Error caught during '" << tableName <<
"' table retrieval: \n"
3389 << getError << __E__;
3390 __COUT_ERR__ << ss.str();
3391 std::lock_guard<std::mutex> lock(*threadMutex);
3392 *threadErrors += ss.str();
3397 __SS__ << tableName <<
": View version not activated properly!";
3401 __COUTT__ <<
"end Thread fill of " << tableName <<
"-v" << version << __E__;
3402 *(threadDone) =
true;
3404 catch(
const std::runtime_error& e)
3406 __SS__ <<
"Error occurred filling table '" << tableName <<
"-v" << version
3407 <<
"': " << e.what() << __E__;
3408 __COUT_ERR__ << ss.str();
3412 std::lock_guard<std::mutex> lock(*threadMutex);
3413 *threadErrors += ss.str();
3416 *(threadDone) =
true;
3420 __SS__ <<
"Unknwon error occurred filling table '" << tableName <<
"-v" << version
3426 catch(
const std::exception& e)
3428 ss <<
"Exception message: " << e.what();
3433 __COUT_ERR__ << ss.str();
3437 std::lock_guard<std::mutex> lock(*threadMutex);
3438 *threadErrors += ss.str();
3441 *(threadDone) =
true;
3450 const std::string& tableName,
3452 bool looseColumnMatching ,
3453 std::string* accumulatedErrors ,
3456 auto it = nameToTableMap_.find(tableName);
3457 if(it == nameToTableMap_.end())
3459 __SS__ <<
"\nCan not find table named '" << tableName
3460 <<
"'\n\n\n\nYou need to load the table before it can be used."
3461 <<
"It probably is missing from the member list of the Table "
3462 "Group that was loaded?\n\n\n\n\n"
3470 table->setActiveView(version);
3474 std::stringstream jsonSs;
3475 table->getViewP()->printJSON(jsonSs);
3476 table->getViewP()->doGetSourceRawData(
true);
3482 theInterface_->get(table,
3489 looseColumnMatching,
3502 std::map<std::string, std::pair<std::string, TableGroupKey>>
3506 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
3508 retMap[ConfigurationManager::GROUP_TYPE_NAME_CONTEXT] =
3509 std::pair<std::string, TableGroupKey>(
3510 theContextTableGroup_,
3511 theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
3512 retMap[ConfigurationManager::GROUP_TYPE_NAME_BACKBONE] =
3513 std::pair<std::string, TableGroupKey>(
3514 theBackboneTableGroup_,
3515 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
3516 retMap[ConfigurationManager::GROUP_TYPE_NAME_ITERATE] =
3517 std::pair<std::string, TableGroupKey>(
3518 theIterateTableGroup_,
3519 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
3520 retMap[ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION] =
3521 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_,
3522 theConfigurationTableGroupKey_
3523 ? *theConfigurationTableGroupKey_
3529 const std::string& ConfigurationManager::getActiveGroupName(
3530 const ConfigurationManager::GroupType& type)
const
3532 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
3533 return theConfigurationTableGroup_;
3534 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
3535 return theContextTableGroup_;
3536 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
3537 return theBackboneTableGroup_;
3538 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
3539 return theIterateTableGroup_;
3541 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
3547 const ConfigurationManager::GroupType& type)
const
3549 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
3550 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_
3552 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
3553 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
3554 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
3555 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
3556 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
3557 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
3559 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
3565 const std::string& contextUID,
const std::string& )
const
3573 const std::string& contextUID,
const std::string& applicationUID)
const
3576 contextUID +
"/LinkToApplicationTable/" + applicationUID);
3581 const std::string& contextUID,
const std::string& applicationUID)
const
3584 contextUID +
"/LinkToApplicationTable/" + applicationUID +
3585 "/LinkToSupervisorTable");
3592 auto contextChildren =
3595 for(
const auto& contextChild : contextChildren)
3597 auto appChildren = contextChild.second.getNode(
"LinkToApplicationTable")
3599 for(
const auto& appChild : appChildren)
3601 if(appChild.second.getNode(
"Class").getValue() ==
3602 "ots::GatewaySupervisor")
3603 return appChild.second;
3606 __SS__ <<
"No Gateway Supervisor node found!" << __E__;
3612 bool doNotThrowOnBrokenUIDLinks)
const
3617 if(nodeString.length() < 1)
3619 __SS__ << (
"Invalid empty node name") << __E__;
3624 size_t startingIndex = 0;
3625 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
3627 size_t endingIndex = nodeString.find(
'/', startingIndex);
3628 if(endingIndex == std::string::npos)
3629 endingIndex = nodeString.length();
3631 std::string nodeName = nodeString.substr(startingIndex, endingIndex - startingIndex);
3633 if(nodeName.length() < 1)
3643 std::string childPath =
3644 (endingIndex >= nodeString.length() ?
"" : nodeString.substr(endingIndex));
3650 if(childPath.length() > 1)
3651 return configTree.
getNode(childPath, doNotThrowOnBrokenUIDLinks);
3657 std::map<std::string, ConfigurationTree> ConfigurationManager::getNodes(
3658 const std::string& nodeString)
const
3670 std::string path =
"/";
3681 std::map<std::string, TableVersion>* memberMap,
3682 std::string* accumulatedTreeErrors)
const
3684 std::vector<std::pair<std::string, ConfigurationTree>> retVector;
3689 bool filtering = memberMap && memberMap->size();
3692 for(
auto& tablePair : nameToTableMap_)
3697 if(memberMap->find(tablePair.first) == memberMap->end())
3703 if(!tablePair.second->isActive())
3705 __SS__ <<
"Get Children with member map requires a child '"
3706 << tablePair.first <<
"' that is not active!" << __E__;
3710 catch(
const std::runtime_error& e)
3712 if(accumulatedTreeErrors)
3714 *accumulatedTreeErrors += e.what();
3715 __GEN_COUT_ERR__ <<
"Skipping " << tablePair.first
3716 <<
" since the table "
3725 if(!tablePair.second->isActive())
3729 if(accumulatedTreeErrors)
3733 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren =
3735 for(
auto& newNodeChild : newNodeChildren)
3737 if(newNodeChild.second.getTableName() ==
3738 ConfigurationManager::DESKTOP_ICON_TABLE_NAME &&
3739 !newNodeChild.second.isEnabled())
3742 std::vector<std::pair<std::string, ConfigurationTree>>
3743 twoDeepChildren = newNodeChild.second.getChildren();
3745 for(
auto& twoDeepChild : twoDeepChildren)
3750 if(twoDeepChild.second.isLinkNode() &&
3751 twoDeepChild.second.isDisconnected() &&
3752 twoDeepChild.second.getDisconnectedTableName() !=
3753 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
3755 __SS__ <<
"At node '" + tablePair.first +
3756 "' with entry UID '" + newNodeChild.first +
3757 "' there is a disconnected child node at link "
3759 twoDeepChild.first +
"'" +
3760 " that points to table named '" +
3761 twoDeepChild.second.getDisconnectedTableName() +
3763 *accumulatedTreeErrors += ss.str();
3768 catch(std::runtime_error& e)
3770 __SS__ <<
"At node '" + tablePair.first +
3771 "' error detected descending through children:\n" +
3773 *accumulatedTreeErrors += ss.str();
3777 retVector.push_back(
3778 std::pair<std::string, ConfigurationTree>(tablePair.first, newNode));
3792 std::string* accumulatedTreeErrors)
const
3799 bool filtering = memberMap && memberMap->size();
3802 for(
auto& tablePair : nameToTableMap_)
3807 if(memberMap->find(tablePair.first) == memberMap->end())
3813 if(!tablePair.second->isActive())
3815 __SS__ <<
"Get Children with member map requires a child '"
3816 << tablePair.first <<
"' that is not active!" << __E__;
3820 catch(
const std::runtime_error& e)
3822 if(accumulatedTreeErrors)
3824 *accumulatedTreeErrors += e.what();
3825 __GEN_COUT_ERR__ <<
"Skipping " << tablePair.first
3826 <<
" since the table "
3835 if(!tablePair.second->isActive())
3839 if(accumulatedTreeErrors)
3843 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren =
3845 for(
auto& newNodeChild : newNodeChildren)
3847 if(newNodeChild.second.getTableName() ==
3848 ConfigurationManager::DESKTOP_ICON_TABLE_NAME &&
3849 !newNodeChild.second.isEnabled())
3852 std::vector<std::pair<std::string, ConfigurationTree>>
3853 twoDeepChildren = newNodeChild.second.getChildren();
3855 for(
auto& twoDeepChild : twoDeepChildren)
3860 if(twoDeepChild.second.isLinkNode() &&
3861 twoDeepChild.second.isDisconnected() &&
3862 twoDeepChild.second.getDisconnectedTableName() !=
3863 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
3865 __SS__ <<
"At node '" + tablePair.first +
3866 "' with entry UID '" + newNodeChild.first +
3867 "' there is a disconnected child node at link "
3869 twoDeepChild.first +
"'" +
3870 " that points to table named '" +
3871 twoDeepChild.second.getDisconnectedTableName() +
3873 *accumulatedTreeErrors += ss.str();
3878 catch(std::runtime_error& e)
3880 __SS__ <<
"At node '" + tablePair.first +
3881 "' error detected descending through children:\n" +
3883 *accumulatedTreeErrors += ss.str();
3888 std::pair<std::string, ConfigurationTree>(tablePair.first, newNode));
3901 std::map<std::string, TableBase*>::const_iterator it;
3902 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
3904 __SS__ <<
"Cannot find table named '" << tableName
3905 <<
"' - you need to load the table before it can be used.";
3907 if(nameToTableMap_.size() == 0)
3908 ss <<
"\n\nAll tables are missing. Your configuration database connection "
3909 "may have been interrupted. Did an ssh tunnel disconnect?"
3913 if(tableName == XDAQ_CONTEXT_TABLE_NAME)
3914 ss <<
"\n\nThe XDAQ Context Table is essential to the operation of ots. "
3915 "Without it, ots can not determine which applications are running "
3916 "on which hosts. Make sure that you have loaded a valid "
3917 "Configuration Context group that contains the XDAQ Context "
3921 ss <<
" It is likely missing from the member list of the Table "
3922 "Group that was loaded."
3925 ss <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
3936 TLOG_DEBUG(55) <<
"Table " << tableName <<
" is at "
3937 <<
static_cast<void*
>(it->second);
3947 if(!theBackboneTableGroupKey_)
3949 __GEN_COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently."
3955 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
3957 return *theBackboneTableGroupKey_;
3974 std::string systemAlias,
ProgressBar* progressBar)
3984 progressBar->
step();
3986 if(systemAlias.find(
"GROUP:") == 0)
3989 progressBar->
step();
3991 unsigned int i = strlen(
"GROUP:");
3992 unsigned int j = systemAlias.find(
':', i);
3995 progressBar->
step();
3997 return std::pair<std::string, TableGroupKey>(
3998 systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
4000 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
4006 progressBar->
step();
4012 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).
getNode(systemAlias);
4015 progressBar->
step();
4017 return std::pair<std::string, TableGroupKey>(
4028 progressBar->
step();
4030 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
4036 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
4042 ConfigurationManager::LoadGroupType::
4043 ONLY_BACKBONE_TYPE);
4046 std::map<std::string ,
4050 std::vector<std::pair<std::string, ConfigurationTree>> entries =
4052 for(
auto& entryPair : entries)
4054 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(
4055 entryPair.second.getNode(
"GroupName").getValueAsString(),
4056 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
4072 for(
auto& tableAliasMap : tableAliasMap)
4073 for(
auto& tableAliasPair : tableAliasMap.second)
4074 if(tableAliasPair.first == tableAliasNeedle)
4075 retSet.insert(std::pair<std::string ,
4077 tableAliasMap.first, tableAliasPair.second));
4085 std::map<std::string ,
4091 std::map<std::string ,
4096 std::string versionAliasesTableName =
4097 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
4098 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
4100 __SS__ <<
"Active version of VersionAliases missing!"
4101 <<
" Make sure you have a valid active Backbone Group." << __E__;
4102 __GEN_COUT_WARN__ <<
"\n" << ss.str();
4108 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
4114 std::string tableName, versionAlias;
4115 for(
auto& aliasNodePair : aliasNodePairs)
4117 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
4118 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
4120 if(retMap.find(tableName) != retMap.end() &&
4121 retMap[tableName].find(versionAlias) != retMap[tableName].end())
4126 retMap[tableName][versionAlias] =
4127 TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
4137 std::map<std::string, TableVersion> retMap;
4138 for(
auto& table : nameToTableMap_)
4140 __GEN_COUTS__(2) << table.first << __E__;
4143 if(table.second && table.second->
isActive())
4145 __GEN_COUTS__(2) << table.first <<
"_v" << table.second->
getViewVersion()
4147 retMap.insert(std::pair<std::string, TableVersion>(
4181 if(theConfigurationTableGroupKey_)
4183 if(*theConfigurationTableGroupKey_ != key)
4186 return theConfigurationTableGroupKey_;
4188 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
4192 const std::set<std::string>& ConfigurationManager::getActiveContextMemberNames()
4195 contextMemberNames_ = ConfigurationManager::fixedContextMemberNames_;
4198 nameToTableMap_.find(ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE);
4199 if(it == nameToTableMap_.end())
4200 return contextMemberNames_;
4202 if(!it->second->isActive())
4204 contextMemberNames_.emplace(
4205 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE);
4207 return contextMemberNames_;
4211 const std::set<std::string>& ConfigurationManager::getFixedContextMemberNames()
4213 return ConfigurationManager::fixedContextMemberNames_;
4217 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
4219 return ConfigurationManager::backboneMemberNames_;
4223 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
4225 return ConfigurationManager::iterateMemberNames_;
4229 const std::set<std::string>& ConfigurationManager::getConfigurationMemberNames(
void)
4231 configurationMemberNames_.clear();
4235 for(
auto& tablePair : activeTables)
4238 ConfigurationManager::fixedContextMemberNames_.find(tablePair.first) ==
4239 ConfigurationManager::fixedContextMemberNames_.end() &&
4240 tablePair.first != ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE &&
4243 ConfigurationManager::backboneMemberNames_.find(tablePair.first) ==
4244 ConfigurationManager::backboneMemberNames_.end() &&
4247 ConfigurationManager::iterateMemberNames_.find(tablePair.first) ==
4248 ConfigurationManager::iterateMemberNames_.end())
4251 configurationMemberNames_.emplace(tablePair.first);
4254 return configurationMemberNames_;
4258 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
4260 __GEN_COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
4265 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
4267 if(pset.get_names().size() == 0)
4269 __GEN_SS__ <<
"Empty fcl configuration parameter set found! File: " << fhiclPath
4301 theInterface_->get(table,
4302 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
4308 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
4311 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4314 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4319 auto colMap = view->getColumnNamesMap();
4321 view->
setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
4322 view->
setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
4323 view->
setValue(
"MacroMakerFEContextApps", 0, colMap[
"LinkToApplicationGroupID"]);
4324 view->
setValue(
"1", 0, colMap[TableViewColumnInfo::COL_NAME_STATUS]);
4326 __GEN_COUT__ <<
"Done adding context record..." << __E__;
4336 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
4342 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
4345 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4348 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4353 auto colMap = view->getColumnNamesMap();
4355 view->
setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
4356 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
4357 view->
setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
4358 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
4359 view->
setValue(
"1", 0, colMap[TableViewColumnInfo::COL_NAME_STATUS]);
4360 view->
setValue(__ENV__(
"FE_SUPERVISOR_ID"), 0, colMap[
"Id"]);
4362 __GEN_COUT__ <<
"Done adding application record..." << __E__;
4369 theInterface_->get(table,
4370 "FESupervisorTable",
4376 nameToTableMap_[
"FESupervisorTable"] = table;
4379 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4382 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4387 auto colMap = view->getColumnNamesMap();
4389 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
4390 view->
setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
4392 "MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
4394 __GEN_COUT__ <<
"Done adding supervisor record..." << __E__;
4399 recursiveInitFromFhiclPSet(
"FEInterfaceTable" ,
4402 "MacroMakerFESupervisorInterfaces" ,
4406 for(
auto& table : nameToTableMap_)
4408 table.second->getViewP()->
init();
4414 __GEN_COUT__ <<
"================================================" << __E__;
4415 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
4416 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
4419 __GEN_COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
4421 __GEN_COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
4423 auto a =
getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
4424 __GEN_COUTV__(a.getValueAsString());
4426 auto b = a.getNode(
"MacroMakerFEContext");
4427 __GEN_COUTV__(b.getValueAsString());
4429 auto c = b.getNode(
"LinkToApplicationTable");
4430 __GEN_COUTV__(c.getValueAsString());
4432 auto d = c.getNode(
"MacroMakerFESupervisor");
4433 __GEN_COUTV__(d.getValueAsString());
4435 auto e = d.getNode(
"LinkToSupervisorTable");
4436 __GEN_COUTV__(e.getValueAsString());
4438 auto f = e.getNode(
"LinkToFEInterfaceTable");
4439 __GEN_COUTV__(f.getValueAsString());
4441 auto z = f.getChildrenNames();
4443 __GEN_COUTV__(z.size());
4444 auto y = f.getChildrenNames(
false ,
true );
4446 __GEN_COUTV__(y.size());
4447 auto x = f.getChildrenNames(
true ,
true );
4449 __GEN_COUTV__(x.size());
4451 auto g = f.getNode(
"dtc0");
4452 __GEN_COUTV__(g.getValueAsString());
4453 auto h = f.getNode(
"interface0");
4454 __GEN_COUTV__(h.getValueAsString());
4457 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
4459 "MacroMakerFEContext/LinkToApplicationTable/"
4460 "MacroMakerFESupervisor/LinkToSupervisorTable")
4461 .
getNode(
"LinkToFEInterfaceTable")
4463 __GEN_COUTV__(fes.size());
4475 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
4476 const fhicl::ParameterSet& pset,
4477 const std::string& recordName,
4478 const std::string& groupName,
4479 const std::string& groupLinkIndex)
4481 __GEN_COUT__ << __COUT_HDR_P__ <<
"Adding table '" << tableName <<
"' record(s)..."
4488 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
4490 __GEN_COUT__ <<
"Table not found, so making '" << tableName <<
"' instance..."
4492 theInterface_->get(table,
4499 nameToTableMap_[tableName] = table;
4504 __GEN_COUT__ <<
"Existing table found, so using '" << tableName
4505 <<
"'instance..." << __E__;
4506 table = nameToTableMap_[tableName];
4509 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4512 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4515 if(recordName !=
"")
4523 __GEN_COUTV__(recordName);
4526 unsigned int r = view->
addRow();
4527 auto colMap = view->getColumnNamesMap();
4537 __GEN_COUT__ <<
"No status column to set for '" << recordName <<
"'"
4543 __GEN_COUT__ <<
"Setting group ID for group link index '"
4544 << groupLinkIndex <<
"'" << __E__;
4547 __GEN_COUT__ <<
"Setting group ID for group link index '"
4548 << groupLinkIndex <<
"' at column " << groupIDCol <<
" to '"
4549 << groupName <<
".'" << __E__;
4551 view->
setValue(groupName, r, groupIDCol);
4555 auto names = pset.get_names();
4556 for(
const auto& colName : names)
4558 if(!pset.is_key_to_atom(colName))
4561 auto colIt = colMap.find(colName);
4562 if(colIt == colMap.end())
4564 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName
4565 <<
"' in table '" << tableName <<
"' was not found in columns."
4566 <<
"\n\nHere are the existing column names:\n";
4568 for(
const auto& col : colMap)
4569 ss <<
"\n" << ++i <<
".\t" << col.first;
4574 if(view->getColumnInfo(colIt->second).
isGroupID())
4577 const std::string value = pset.get<std::string>(colName);
4578 __GEN_COUT__ <<
"Setting '" << recordName <<
"' parameter at column "
4579 << colIt->second <<
", '" << colName <<
"'\t = " << value
4585 for(
const auto& linkName : names)
4587 if(pset.is_key_to_atom(linkName))
4590 __GEN_COUTV__(linkName);
4593 unsigned int c = linkName.size() - 1;
4595 if(linkName[c] ==
'_')
4600 __SS__ <<
"Illegal link name '" << linkName
4601 <<
"' found. The format must be <Column name>_<Target table "
4602 "name>,.. for example '"
4603 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'"
4607 std::string colName = linkName.substr(0, c);
4608 __GEN_COUTV__(colName);
4610 auto colIt = colMap.find(colName);
4611 if(colIt == colMap.end())
4613 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName
4614 <<
"' in table '" << tableName <<
"' was not found in columns."
4615 <<
"\n\nHere are the existing column names:\n";
4617 for(
const auto& col : colMap)
4618 ss <<
"\n" << i <<
".\t" << col.first << __E__;
4623 std::pair<
unsigned int ,
unsigned int >
4626 view->
getChildLink(colIt->second, isGroupLink, linkPair);
4632 std::string linkTableName = linkName.substr(c + 1);
4633 __GEN_COUTV__(linkTableName);
4635 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
4636 auto linkRecords = linkPset.get_pset_names();
4637 if(!isGroupLink && linkRecords.size() > 1)
4639 __SS__ <<
"A Unique Link can only point to one record. "
4640 <<
"The specified link '" << colName <<
"' of record '"
4641 << recordName <<
"' in table '" << tableName <<
"' has "
4642 << linkRecords.size() <<
" children records specified. "
4647 if(linkRecords.size() == 0)
4649 __GEN_COUT__ <<
"No child records, so leaving link disconnected."
4654 __GEN_COUT__ <<
"Setting Link at columns [" << linkPair.first <<
","
4655 << linkPair.second <<
"]" << __E__;
4656 view->
setValue(linkTableName, r, linkPair.first);
4660 __GEN_COUT__ <<
"Setting up Unique link to " << linkRecords[0]
4663 view->
setValue(linkRecords[0], r, linkPair.second);
4665 recursiveInitFromFhiclPSet(
4667 linkPset.get<fhicl::ParameterSet>(
4674 std::string childLinkIndex =
4676 std::string groupName = recordName +
"Group";
4678 view->
setValue(groupName, r, linkPair.second);
4680 for(
const auto& groupRecord : linkRecords)
4682 __GEN_COUT__ <<
"Setting '" << childLinkIndex
4683 <<
"' Group link to '" << groupName <<
"' record '"
4684 << groupRecord <<
"'" << __E__;
4686 recursiveInitFromFhiclPSet(
4688 linkPset.get<fhicl::ParameterSet>(
4698 else if(groupName !=
"")
4702 __GEN_COUTV__(groupName);
4703 auto psets = pset.get_pset_names();
4704 for(
const auto& ps : psets)
4707 recursiveInitFromFhiclPSet(
4709 pset.get<fhicl::ParameterSet>(ps) ,
4717 __SS__ <<
"Illegal recursive parameters!" << __E__;
4720 __GEN_COUT__ << __COUT_HDR_P__ <<
"Done adding table '" << tableName
4721 <<
"' record(s)..." << __E__;
4733 __GEN_COUTS__(11) <<
"Checking if owner '" << ownerContextUID_ <<
"/" << ownerAppUID_
4734 <<
"' is first App in Context:\n"
4737 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
4739 __GEN_COUTTV__(!forceNotFirstInContext_);
4740 return !forceNotFirstInContext_;
4743 __GEN_COUTVS__(10, ownerContextUID_);
4744 __GEN_COUTVS__(10, ownerAppUID_);
4748 auto contextChildren =
4749 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" +
4750 ownerContextUID_ +
"/LinkToApplicationTable")
4753 if(contextChildren.size() == 0)
4756 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" +
4757 ownerContextUID_ +
"/LinkToApplicationTable")
4764 bool isFirstAppInContext =
4765 contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
4767 __GEN_COUTVS__(10, isFirstAppInContext);
4769 return isFirstAppInContext;
4773 __GEN_COUTS__(10) <<
"Exception caught looking for XDAQ Context '"
4774 << ownerContextUID_ <<
"' in tree, so defaulting to 'yes'."
4784 const std::string& otherSubsystemUID,
4785 std::string* userDataPathPtr ,
4786 std::string* hostnamePtr ,
4787 std::string* usernamePtr ,
4788 std::string* fullNamePtr )
4790 __GEN_COUTTV__(otherSubsystemUID);
4793 getNode(ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
4795 std::string userPath = node.
getNode(
"SubsystemUserDataPath").
getValue();
4802 if(!splitPath.size() || splitPath.size() > 2)
4804 __GEN_SS__ <<
"Illegal user data path specified for subsystem '"
4805 << otherSubsystemUID <<
"': " << userPath << __E__;
4808 std::string userDataPath = splitPath[splitPath.size() - 1];
4811 for(
unsigned int i = 0; i < userDataPath.length(); ++i)
4812 if(!((userDataPath[i] >=
'a' && userDataPath[i] <=
'z') ||
4813 (userDataPath[i] >=
'A' && userDataPath[i] <=
'Z') ||
4814 (userDataPath[i] >=
'0' && userDataPath[i] <=
'9') ||
4815 userDataPath[i] ==
'-' || userDataPath[i] ==
'_' || userDataPath[i] ==
'/'))
4817 __GEN_SS__ <<
"Illegal user data path specified (no special characters "
4818 "allowed) for subsystem '"
4819 << otherSubsystemUID <<
"': " << userPath << __E__;
4824 *userDataPathPtr = userDataPath;
4826 std::string username, hostname;
4827 if(splitPath.size() == 2)
4830 std::vector<std::string> userHostSplit =
4832 __GEN_COUTTV__(userHostSplit.size());
4833 if(userHostSplit.size() == 1)
4834 hostname = userHostSplit[0];
4835 else if(userHostSplit.size() == 2)
4837 username = userHostSplit[0];
4838 hostname = userHostSplit[1];
4842 __GEN_SS__ <<
"Illegal remote username/host specified for subsystem '"
4843 << otherSubsystemUID <<
"': " << userPath << __E__;
4847 for(
unsigned int i = 0; userHostSplit.size() == 2 && i < username.length(); ++i)
4848 if(!((username[i] >=
'a' && username[i] <=
'z') ||
4849 (username[i] >=
'A' && username[i] <=
'Z') ||
4850 (username[i] >=
'0' && username[i] <=
'9') || username[i] ==
'-' ||
4851 username[i] ==
'_'))
4853 __GEN_SS__ <<
"Illegal remote username specified for subsystem '"
4854 << otherSubsystemUID <<
"': " << userPath << __E__;
4857 unsigned int ii = 0;
4858 for(
unsigned int i = 0; i < hostname.length(); ++i)
4859 if(!((hostname[i] >=
'a' && hostname[i] <=
'z') ||
4860 (hostname[i] >=
'A' && hostname[i] <=
'Z') ||
4861 (hostname[i] >=
'0' && hostname[i] <=
'9') || hostname[i] ==
'-' ||
4862 hostname[i] ==
'_'))
4864 if(hostname[i] ==
'.' && i > ii + 1)
4871 __GEN_SS__ <<
"Illegal remote hostname '" << hostname
4872 <<
"' specified for subsystem '" << otherSubsystemUID
4873 <<
"': " << userPath << __E__;
4878 else if(splitPath.size() == 1)
4880 __GEN_COUT__ <<
"Local user date path identified." << __E__;
4884 __GEN_SS__ <<
"Illegal user data path specified for subsystem '"
4885 << otherSubsystemUID <<
"': " << userPath << __E__;
4890 *hostnamePtr = hostname;
4892 *usernamePtr = username;
4897 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
4898 ConfigurationManager::getOtherSubsystemActiveTableGroups(
4899 const std::string& otherSubsystemUID,
4900 std::string* userDataPathPtr ,
4901 std::string* hostnamePtr ,
4902 std::string* usernamePtr )
4904 std::map<std::string ,
4908 __GEN_COUTTV__(otherSubsystemUID);
4910 std::string userDataPath;
4911 std::string username, hostname;
4915 __GEN_COUTTV__(userDataPath);
4916 __GEN_COUTTV__(username);
4917 __GEN_COUTTV__(hostname);
4920 *userDataPathPtr = userDataPath;
4922 *hostnamePtr = hostname;
4924 *usernamePtr = username;
4927 std::string filename = userDataPath +
"/ServiceData/ActiveTableGroups.cfg";
4929 std::string cmdResult;
4933 std::string tmpSubsystemFilename =
4935 __GEN_COUTTV__(tmpSubsystemFilename);
4939 (
"rm " + tmpSubsystemFilename +
" 2>/dev/null; scp " + username +
"@" +
4940 hostname +
":" + filename +
" " + tmpSubsystemFilename +
" 2>&1; cat " +
4941 tmpSubsystemFilename +
" 2>&1")
4946 (
"rm " + tmpSubsystemFilename +
" 2>/dev/null; scp " + hostname +
":" +
4947 filename +
" " + tmpSubsystemFilename +
" 2>&1; cat " +
4948 tmpSubsystemFilename +
" 2>&1")
4953 __GEN_COUT__ <<
"Local user date path identified." << __E__;
4957 __GEN_COUTTV__(cmdResult);
4958 if(cmdResult.find(
"Permission denied") != std::string::npos)
4961 <<
"\n\nPermission denied accessing user data path specified for subsystem '"
4962 << otherSubsystemUID <<
"': ";
4964 ss << username <<
"@";
4966 ss << hostname <<
":";
4967 ss << userDataPath << __E__;
4972 cmdResult, {
'\n'} , {
' ',
'\t'} );
4974 __GEN_COUTTV__(subsystemActiveGroupMap.size());
4978 for(
unsigned int i = 0; i + 1 < subsystemActiveGroupMap.size(); i += 2)
4980 if(subsystemActiveGroupMap[i] ==
"" || subsystemActiveGroupMap[i + 1] ==
"-1")
4983 __GEN_COUTT__ <<
"Loading type of subsystem '" << otherSubsystemUID <<
"' group "
4984 << subsystemActiveGroupMap[i] <<
"("
4985 << subsystemActiveGroupMap[i + 1] <<
")" << __E__;
5001 catch(
const std::runtime_error& e)
5003 __GEN_COUTT__ <<
"Ignoring error loading subsystem '" << otherSubsystemUID
5004 <<
"' group " << subsystemActiveGroupMap[i] <<
"("
5005 << subsystemActiveGroupMap[i + 1] <<
"): " << __E__ << e.what()
5007 groupType = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
5009 retMap[groupType] = std::make_pair(subsystemActiveGroupMap[i],
5019 std::set<std::string >
5022 std::set<std::string> retSet;
5024 __GEN_COUTTV__(otherSubsystemUID);
5026 std::map<std::string ,
5028 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
5033 auto it = retMap.find(
5035 if(it == retMap.end())
5038 <<
"No active Backbone group found in the active groups of remote subsystem '"
5039 << otherSubsystemUID <<
"!'" << __E__;
5042 auto it2 = retMap.find(
5044 if(it2 == retMap.end())
5047 <<
"No active Context group found in the active groups of remote subsystem '"
5048 << otherSubsystemUID <<
"!'" << __E__;
5052 std::string accumulatedWarnings;
5061 &accumulatedWarnings
5063 __GEN_COUTTV__(accumulatedWarnings);
5066 std::vector<std::pair<std::string, ConfigurationTree>> entries =
5069 for(
auto& entry : entries)
5071 if(entry.first.find(
"Context") == std::string::npos &&
5072 entry.first.find(
"Iterat") == std::string::npos)
5073 retSet.emplace(entry.first);
5081 std::set<std::string >
5083 const std::string& otherSubsystemUID,
const std::string& otherSubsystemFsmName)
5085 std::set<std::string> retSet;
5087 std::map<std::string ,
5089 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
5092 auto it = retMap.find(
5094 if(it == retMap.end())
5097 <<
"No active Backbone group found in the active groups of remote subsystem '"
5098 << otherSubsystemUID <<
"!'" << __E__;
5101 auto it2 = retMap.find(
5103 if(it2 == retMap.end())
5106 <<
"No active Context group found in the active groups of remote subsystem '"
5107 << otherSubsystemUID <<
"!'" << __E__;
5111 std::string accumulatedWarnings;
5120 &accumulatedWarnings
5127 &accumulatedWarnings
5129 __GEN_COUTTV__(accumulatedWarnings);
5132 std::vector<std::pair<std::string, ConfigurationTree>> entries =
5137 std::string stateMachineAliasFilter =
"*";
5142 otherGatewayNode.
getNode(
"LinkToStateMachineTable")
5143 .
getNode(otherSubsystemFsmName +
"/SystemAliasFilter");
5145 stateMachineAliasFilter = fsmFilterNode.
getValue<std::string>();
5147 __GEN_COUT_INFO__ <<
"FSM has no SystemAliasFilter value." << __E__;
5149 catch(std::runtime_error& e)
5151 __COUT__ <<
"Ignoring unsetup SystemAliasFilter value: " << e.what() << __E__;
5155 __COUT__ <<
"Ignoring unsetup SystemAliasFilter value." << __E__;
5158 __COUT__ <<
"Applying alias filter for other user_data path FSM '"
5159 << otherSubsystemFsmName
5160 <<
"' and stateMachineAliasFilter = " << stateMachineAliasFilter << __E__;
5167 stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
5168 std::vector<std::string> filterArr;
5175 while((f = stateMachineAliasFilter.find(
'*', i)) != std::string::npos)
5177 tmp = stateMachineAliasFilter.substr(i, f - i);
5179 filterArr.push_back(tmp);
5180 __COUTS__(20) << filterArr[filterArr.size() - 1] <<
" " << i <<
" of "
5181 << stateMachineAliasFilter.size() << __E__;
5183 if(i <= stateMachineAliasFilter.size())
5185 tmp = stateMachineAliasFilter.substr(i);
5186 filterArr.push_back(tmp);
5187 __COUTS__(20) << filterArr[filterArr.size() - 1] <<
" last." << __E__;
5192 for(
auto& aliasMapPair : entries)
5194 __COUTS__(20) <<
"aliasMapPair.first: " << aliasMapPair.first << __E__;
5198 if(filterArr.size() == 1)
5200 if(filterArr[0] !=
"" && filterArr[0] !=
"*" &&
5201 aliasMapPair.first != filterArr[0])
5202 filterMatch =
false;
5207 for(f = 0; f < filterArr.size(); ++f)
5209 if(!filterArr[f].size())
5214 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
5216 filterMatch =
false;
5220 else if(f == filterArr.size() - 1)
5222 if(aliasMapPair.first.rfind(filterArr[f]) !=
5223 aliasMapPair.first.size() - filterArr[f].size())
5225 filterMatch =
false;
5229 else if((i = aliasMapPair.first.find(filterArr[f])) ==
5232 filterMatch =
false;
5239 filterMatch = !filterMatch;
5241 __COUTS__(20) <<
"filterMatch=" << filterMatch << __E__;
5246 retSet.emplace(aliasMapPair.first);
5258 const std::string& otherSubsystemUID,
5259 const std::string& configAlias,
5260 std::pair<std::string, TableGroupKey>& groupTranslation,
5261 std::string& groupComment,
5262 std::string& groupAuthor,
5263 std::string& groupCreationTime)
5265 __GEN_COUTV__(otherSubsystemUID);
5267 std::map<std::string ,
5269 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
5272 auto it = retMap.find(
5274 if(it == retMap.end())
5277 <<
"No active Backbone group found in the active groups of remote subsystem '"
5278 << otherSubsystemUID <<
"!'" << __E__;
5281 auto it2 = retMap.find(
5283 if(it2 == retMap.end())
5286 <<
"No active Context group found in the active groups of remote subsystem '"
5287 << otherSubsystemUID <<
"!'" << __E__;
5291 std::string accumulatedWarnings;
5300 &accumulatedWarnings
5302 __GEN_COUTTV__(accumulatedWarnings);
5309 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).
getNode(configAlias);
5311 groupTranslation = std::pair<std::string, TableGroupKey>(
5314 __COUT__ <<
"Found " << configAlias <<
" translates to " << groupTranslation.first
5315 <<
"(" << groupTranslation.second <<
")" << __E__;
5321 groupTranslation.second,
5325 &accumulatedWarnings,
5333 __COUT_WARN__ <<
"Failed to load group metadata." << __E__;
5335 __COUT__ <<
"Found " << configAlias <<
" author: " << groupAuthor
5336 <<
", createTime: " << groupCreationTime <<
", comment: " << groupComment
5341 __GEN_SS__ <<
"Did not find the Configuration Alias '" << configAlias
5342 <<
"' in the active Backbone group of remote subsystem '"
5343 << otherSubsystemUID <<
"!'" << __E__;
5351 TableBase* ConfigurationManager::getDesktopIconTable(
void)
5353 if(nameToTableMap_.find(DESKTOP_ICON_TABLE_NAME) == nameToTableMap_.end())
5355 __SS__ <<
"Desktop icon table not found!" << __E__;
5360 return nameToTableMap_.at(DESKTOP_ICON_TABLE_NAME);
5364 void ConfigurationManager::saveGroupNameAndKey(
5365 const std::pair<std::string /*group name*/, TableGroupKey>& theGroup,
5366 const std::string& fileName,
5368 const std::string& associatedUser )
5370 std::string fullPath =
5371 ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/" + fileName;
5372 __COUTT__ <<
"Saving group " << theGroup.first <<
"(" << theGroup.second <<
") to "
5373 << (appendMode ?
"history " :
"") <<
"file: " << fullPath << __E__;
5375 std::ofstream groupFile;
5379 const size_t MAX_RECORDS = 200;
5381 while(records.size() >= MAX_RECORDS)
5382 records.erase(records.begin());
5384 groupFile.open(fullPath.c_str());
5385 for(
const auto& record : records)
5387 groupFile << record.at(
"groupName") <<
"\n"
5388 << record.at(
"groupKey") <<
"\n"
5389 << record.at(
"time") <<
" , " << record.at(
"user") <<
"\n";
5393 groupFile.open(fullPath.c_str());
5394 if(!groupFile.is_open())
5396 __SS__ <<
"Error. Can't open file to save group activity: " << fullPath << __E__;
5399 std::stringstream outss;
5400 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n";
5402 if(associatedUser !=
"")
5403 outss <<
" , " << associatedUser;
5405 groupFile << outss.str().c_str();
5417 std::string& returnedTimeString)
5419 std::string fullPath =
5420 ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/" + fileName;
5422 FILE* groupFile = fopen(fullPath.c_str(),
"r");
5425 __COUT__ <<
"Can't open file: " << fullPath
5426 <<
". Returning empty groupName and key -1" << __E__;
5435 fgets(line, 500, groupFile);
5436 if(strlen(line) && line[strlen(line) - 1] ==
'\n')
5437 line[strlen(line) - 1] =
'\0';
5438 theGroup.first = line;
5440 fgets(line, 500, groupFile);
5442 sscanf(line,
"%d", &key);
5443 theGroup.second = key;
5445 fgets(line, 500, groupFile);
5447 sscanf(line,
"%ld", ×tamp);
5454 __COUTS__(2) <<
"theGroup.first=" << theGroup.first
5455 <<
" theGroup.second=" << theGroup.second << __E__;
5463 std::map<std::string , std::string >>
5465 const std::string& groupType,
5468 __COUTTV__(groupAction);
5469 __COUTTV__(groupType);
5471 std::string fullPath = ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/";
5473 if(groupAction ==
"Activated")
5475 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5476 fullPath += ConfigurationManager::ACTIVATED_BACKBONES_FILE;
5477 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5478 fullPath += ConfigurationManager::ACTIVATED_CONTEXTS_FILE;
5479 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5480 fullPath += ConfigurationManager::ACTIVATED_CONFIGS_FILE;
5481 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5482 fullPath += ConfigurationManager::ACTIVATED_ITERATES_FILE;
5484 else if(groupAction ==
"Attempted Configure")
5486 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5487 fullPath += ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIGS_FILE;
5488 else if(groupType ==
"Config Alias")
5489 fullPath += ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIG_ALIASES_FILE;
5491 else if(groupAction ==
"Configured")
5493 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5494 fullPath += ConfigurationManager::CONFIGURED_BACKBONES_FILE;
5495 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5496 fullPath += ConfigurationManager::CONFIGURED_CONTEXTS_FILE;
5497 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5498 fullPath += ConfigurationManager::CONFIGURED_CONFIGS_FILE;
5499 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5500 fullPath += ConfigurationManager::CONFIGURED_ITERATES_FILE;
5501 else if(groupType ==
"Config Alias")
5502 fullPath += ConfigurationManager::CONFIGURED_CONFIG_ALIASES_FILE;
5504 else if(groupAction ==
"Started")
5506 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5507 fullPath += ConfigurationManager::STARTED_BACKBONES_FILE;
5508 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5509 fullPath += ConfigurationManager::STARTED_CONTEXTS_FILE;
5510 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5511 fullPath += ConfigurationManager::STARTED_CONFIGS_FILE;
5512 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5513 fullPath += ConfigurationManager::STARTED_ITERATES_FILE;
5514 else if(groupType ==
"Config Alias")
5515 fullPath += ConfigurationManager::STARTED_CONFIG_ALIASES_FILE;
5517 else if(groupAction ==
"Configured or Started")
5519 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5520 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_BACKBONES_FILE;
5521 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5522 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_CONTEXTS_FILE;
5523 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5524 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_CONFIGS_FILE;
5525 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5526 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_ITERATES_FILE;
5527 else if(groupType ==
"Config Alias")
5528 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_CONFIG_ALIASES_FILE;
5531 if(fullPath == ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/")
5533 __SS__ <<
"Illegal attempted group history request combination of groupAction: "
5534 << groupAction <<
", and groupType: " << groupType << __E__;
5543 std::map<std::string , std::string >>
5548 std::map<std::string , std::string >>
5551 __COUTTV__(fullPath);
5552 FILE* groupFile = fopen(fullPath.c_str(),
"r");
5555 __COUT_WARN__ <<
"Can't open group history file (assuming no history yet): "
5556 << fullPath << __E__;
5558 __COUTTV__(retVec.size());
5565 std::string returnedTimeString, associatedUser;
5568 while(fgets(line, 500, groupFile))
5570 if(strlen(line) && line[strlen(line) - 1] ==
'\n')
5571 line[strlen(line) - 1] =
'\0';
5572 theGroup.first = line;
5574 fgets(line, 500, groupFile);
5576 sscanf(line,
"%d", &key);
5577 theGroup.second = key;
5579 fgets(line, 500, groupFile);
5582 sscanf(line,
"%ld , %s", ×tamp, user);
5587 __COUTS__(20) <<
"Read group from history file: " << theGroup.first <<
"("
5588 << theGroup.second <<
"), timestamp=" << timestamp
5589 <<
", user=" << user << __E__;
5591 retVec.push_back({{
"groupName", theGroup.first},
5592 {
"groupKey", theGroup.second.toString()},
5595 : std::to_string(timestamp)},
5601 __COUTTV__(retVec.size());
5611 __COUTT__ <<
"Initializing prerequisites for artdaq!" << __E__;
5614 for(
auto& tablePair : activeTables)
5616 __COUTVS__(2, tablePair.first);
5619 nameToTableMap_.at(tablePair.first)->initPrereqsForARTDAQ(
this);
5621 catch(
const std::runtime_error& e)
5623 __COUTVS__(2, e.what());
5624 if(std::string(e.what()).find(
5625 "initPrereqsForARTDAQ() is not implemented for this table") ==
5632 __COUTT__ <<
"Done initializing prerequisites for artdaq!" << __E__;
5636 __SS__ <<
"Error caught while initializing prerequisites for artdaq!";
5641 catch(
const std::runtime_error& e)
5643 ss <<
" Here was the error: " << e.what() << __E__;
virtual std::map< std::string, TableVersion > getTableGroupMembers(std::string const &, bool=false) const
returns the set of table groups that contain the specified table name and version
std::map< std::string, std::map< std::string, TableVersion > > getVersionAliases(void) const
TableBase * getVersionedTableByName(const std::string &tableName, TableVersion version, bool looseColumnMatching=false, std::string *accumulatedErrors=0, bool getRawData=false)
static const unsigned int PROCESSOR_COUNT
Static members.
static const std::string & convertGroupTypeToName(const ConfigurationManager::GroupType &groupTypeId)
bool isOwnerFirstAppInContext(void)
void restoreActiveTableGroups(bool throwErrors=false, const std::string &pathToActiveGroupsFile="", ConfigurationManager::LoadGroupType onlyLoadIfBackboneOrContext=ConfigurationManager::LoadGroupType::ALL_TYPES, std::string *accumulatedWarnings=0)
std::map< std::string, std::pair< std::string, TableGroupKey > > getActiveTableGroups(void) const
std::set< std::string > getOtherSubsystemConfigAliases(const std::string &otherSubsystemUID)
Ignore any System Aliases with "Context" or "Iterat" in the name.
void dumpActiveConfiguration(const std::string &filePath, const std::string &dumpType, const std::string &configurationAlias, const std::string &subsystemCommonList, const std::string &subsystemCommonOverrideList, const std::string &logEntry, const std::string &activeUsers, const std::string &activeStateMachine, std::ostream &altOut=std::cout)
void loadMemberMap(const std::map< std::string, TableVersion > &memberMap, std::string *accumulateWarnings=0)
std::map< std::string, TableVersion > getActiveVersions(void) const
getActiveVersions
std::shared_ptr< TableGroupKey > makeTheTableGroupKey(TableGroupKey key)
Setters/Modifiers.
void copyTableGroupFromCache(const ConfigurationManager &cacheConfigMgr, const std::map< std::string, TableVersion > &groupMembers, const std::string &configGroupName="", const TableGroupKey &tableGroupKey=TableGroupKey(TableGroupKey::INVALID), bool doActivate=false, bool ignoreVersionTracking=false)
void getOtherSubsystemInstanceInfo(const std::string &otherSubsystemUID, std::string *userDataPathPtr=nullptr, std::string *hostnamePtr=nullptr, std::string *usernamePtr=nullptr, std::string *fullNamePtr=nullptr)
ConfigurationManager(bool initForWriteAccess=false, bool initializeFromFhicl=false, bool forceNotFirstInContext=false)
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
"root/parent/parent/"
void loadTableGroup(const std::string &tableGroupName, const TableGroupKey &tableGroupKey, bool doActivate=false, std::map< std::string, TableVersion > *groupMembers=0, ProgressBar *progressBar=0, std::string *accumulateWarnings=0, std::string *groupComment=0, std::string *groupAuthor=0, std::string *groupCreateTime=0, bool doNotLoadMember=false, std::string *groupTypeString=0, std::map< std::string, std::string > *groupAliases=0, ConfigurationManager::LoadGroupType groupTypeToLoad=ConfigurationManager::LoadGroupType::ALL_TYPES, bool ignoreVersionTracking=false, std::map< std::string, TableVersion > mergeInTables={}, std::map< std::string, TableVersion > overrideTables={})
void init(std::string *accumulatedErrors=0, bool initForWriteAccess=false, std::string *accumulatedWarnings=0)
std::string getFirstPathToNode(const ConfigurationTree &node, const std::string &startPath="/") const
getFirstPathToNode
static ConfigurationManager::GroupType getTypeOfGroup(const std::map< std::string, TableVersion > &memberMap)
static const std::string & getTypeNameOfGroup(const std::map< std::string, TableVersion > &memberMap)
void destroyTableGroup(const std::string &theGroup="", bool onlyDeactivate=false)
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, TableVersion > *memberMap=0, std::string *accumulatedTreeErrors=0) const
std::map< std::string, ConfigurationTree > getChildrenMap(std::map< std::string, TableVersion > *memberMap=0, std::string *accumulatedTreeErrors=0) const
std::pair< std::string, TableGroupKey > getTableGroupFromAlias(std::string systemAlias, ProgressBar *progressBar=0)
Getters.
static std::vector< std::map< std::string, std::string > > loadGroupHistory(const std::string &groupAction, const std::string &groupType, bool formatTime=false)
loadGroupHistory static
void getOtherSubsystemConfigAliasInfo(const std::string &otherSubsystemUID, const std::string &configAlias, std::pair< std::string, TableGroupKey > &groupTranslation, std::string &groupComment, std::string &groupAuthor, std::string &groupCreationTime)
returns configAlias translation group info by reference
ConfigurationTree getGatewaySupervisorNode(void) const
There can only be one active Gateway Superivsor app, so find it.
static const std::string ACTIVE_GROUPS_FILENAME
added env check for otsdaq_flatten_active_to_version to function
std::set< std::string > getOtherSubsystemFilteredConfigAliases(const std::string &otherSubsystemUID, const std::string &otherSubsystemFsmName)
Ignore any System Aliases with "Context" or "Iterat" in the name.
TableGroupKey loadConfigurationBackbone(void)
const TableBase * getTableByName(const std::string &configurationName) const
static std::pair< std::string, TableGroupKey > loadGroupNameAndKey(const std::string &fileName, std::string &returnedTimeString)
std::map< std::string, std::pair< std::string, TableGroupKey > > getActiveGroupAliases(void)
void initPrereqsForARTDAQ(void)
loadGroupHistory
bool isDisconnected(void) const
std::vector< std::string > getChildrenNames(bool byPriority=false, bool onlyStatusTrue=false) const
ConfigurationTree getNode(const std::string &nodeName, bool doNotThrowOnBrokenUIDLinks=false) const
navigating between nodes
std::map< std::string, ConfigurationTree > getChildrenMap(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool onlyStatusTrue=false) const
const std::string & getValueAsString(bool returnLinkTableValue=false) const
void getValue(T &value) const
std::vector< std::pair< std::string, ConfigurationTree > > getChildren(std::map< std::string, std::string > filterMap=std::map< std::string, std::string >(), bool byPriority=false, bool onlyStatusTrue=false) const
bool isLinkNode(void) const
const std::string & getFieldName(void) const
alias for getValueName
bool isGroupLinkNode(void) const
bool isDefaultValue(void) const
boolean info
const std::string & getTableName(void) const
Getters.
void setupMockupView(TableVersion version)
bool isActive(void)
isActive
const TableVersion & getViewVersion(void) const
always the active one
void print(std::ostream &out=std::cout) const
always prints active view
static std::string getFullGroupString(const std::string &groupName, const TableGroupKey &key, const std::string &preKey="_v", const std::string &postKey="")
bool isTemporaryVersion(void) const
std::string getChildLinkIndex(void) const
getChildLinkIndex
bool isGroupID(void) const
void setValueAsString(const std::string &value, unsigned int row, unsigned int col)
unsigned int getColStatus(void) const
unsigned int getLinkGroupIDColumn(const std::string &childLinkIndex) const
bool getChildLink(const unsigned int &col, bool &isGroup, std::pair< unsigned int, unsigned int > &linkPair) const
std::string getValueAsString(unsigned int row, unsigned int col, bool convertEnvironmentVariables=true) const
int fillFromJSON(const std::string &json)
unsigned int getColUID(void) const
void setValue(const T &value, unsigned int row, unsigned int col)
< in included .icc source
unsigned int addRow(const std::string &author="", unsigned char incrementUniqueData=false, const std::string &baseNameAutoUID="", unsigned int rowToAdd=(unsigned int) -1, std::string childLinkIndex="", std::string groupId="")
defines used also by OtsConfigurationWizardSupervisor
static std::string getTimestampString(const std::string &linuxTimeInSeconds)
static void getVectorFromString(const std::string &inputString, std::vector< std::string > &listToReturn, const std::set< char > &delimiter={',', '|', '&'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'}, std::vector< char > *listOfDelimiters=0, bool decodeURIComponents=false)
static std::string exec(const char *cmd)
static std::string setToString(const std::set< T > &setToReturn, const std::string &delimeter=", ")
setToString ~
static std::string vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
vectorToString ~
static std::string escapeJSONStringEntities(const std::string &str)
static std::string mapToString(const std::map< std::string, T > &mapToReturn, const std::string &primaryDelimeter=", ", const std::string &secondaryDelimeter=": ")
static void getMapFromString(const std::string &inputString, std::map< S, T > &mapToReturn, const std::set< char > &pairPairDelimiter={',', '|', '&'}, const std::set< char > &nameValueDelimiter={'=', ':'}, const std::set< char > &whitespace={' ', '\t', '\n', '\r'})
getMapFromString ~
static std::string stackTrace(void)