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"
21 const std::string ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH = ((getenv(
"SERVICE_DATA_PATH") == NULL)
22 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
23 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
26 const std::string ConfigurationManager::LAST_ACTIVATED_CONFIG_GROUP_FILE =
"CFGLastActivatedConfigGroup.hist";
27 const std::string ConfigurationManager::LAST_ACTIVATED_CONTEXT_GROUP_FILE =
"CFGLastActivatedContextGroup.hist";
28 const std::string ConfigurationManager::LAST_ACTIVATED_BACKBONE_GROUP_FILE =
"CFGLastActivatedBackboneGroup.hist";
29 const std::string ConfigurationManager::LAST_ACTIVATED_ITERATE_GROUP_FILE =
"CFGLastActivatedIterateGroup.hist";
31 const std::string ConfigurationManager::ACTIVATED_CONFIGS_FILE =
"CFGActivatedConfigGroups.hist";
32 const std::string ConfigurationManager::ACTIVATED_CONTEXTS_FILE =
"CFGActivatedContextGroups.hist";
33 const std::string ConfigurationManager::ACTIVATED_BACKBONES_FILE =
"CFGActivatedBackboneGroups.hist";
34 const std::string ConfigurationManager::ACTIVATED_ITERATES_FILE =
"CFGActivatedIterateGroups.hist";
36 const std::string ConfigurationManager::LAST_ATTEMPTED_CONFIGURE_CONFIG_ALIAS_FILE =
"CFGAttemptedConfigureConfigAlias.hist";
37 const std::string ConfigurationManager::LAST_ATTEMPTED_CONFIGURE_CONFIG_GROUP_FILE =
"CFGAttemptedConfigureConfigGroup.hist";
39 const std::string ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIG_ALIASES_FILE =
"CFGAttemptedConfigureConfigAliases.hist";
40 const std::string ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIGS_FILE =
"CFGAttemptedConfigureConfigGroups.hist";
42 const std::string ConfigurationManager::LAST_CONFIGURED_CONFIG_ALIAS_FILE =
"CFGLastConfiguredConfigAlias.hist";
43 const std::string ConfigurationManager::LAST_CONFIGURED_CONFIG_GROUP_FILE =
"CFGLastConfiguredConfigGroup.hist";
44 const std::string ConfigurationManager::LAST_CONFIGURED_CONTEXT_GROUP_FILE =
"CFGLastConfiguredContextGroup.hist";
45 const std::string ConfigurationManager::LAST_CONFIGURED_BACKBONE_GROUP_FILE =
"CFGLastConfiguredBackboneGroup.hist";
46 const std::string ConfigurationManager::LAST_CONFIGURED_ITERATE_GROUP_FILE =
"CFGLastConfiguredIterateGroup.hist";
48 const std::string ConfigurationManager::CONFIGURED_CONFIG_ALIASES_FILE =
"CFGConfiguredConfigAliases.hist";
49 const std::string ConfigurationManager::CONFIGURED_CONFIGS_FILE =
"CFGConfiguredConfigGroups.hist";
50 const std::string ConfigurationManager::CONFIGURED_CONTEXTS_FILE =
"CFGConfiguredContextGroups.hist";
51 const std::string ConfigurationManager::CONFIGURED_BACKBONES_FILE =
"CFGConfiguredBackboneGroups.hist";
52 const std::string ConfigurationManager::CONFIGURED_ITERATES_FILE =
"CFGConfiguredIterateGroups.hist";
54 const std::string ConfigurationManager::LAST_STARTED_CONFIG_ALIAS_FILE =
"CFGLastStartedConfigAlias.hist";
55 const std::string ConfigurationManager::LAST_STARTED_CONFIG_GROUP_FILE =
"CFGLastStartedConfigGroup.hist";
56 const std::string ConfigurationManager::LAST_STARTED_CONTEXT_GROUP_FILE =
"CFGLastStartedContextGroup.hist";
57 const std::string ConfigurationManager::LAST_STARTED_BACKBONE_GROUP_FILE =
"CFGLastStartedBackboneGroup.hist";
58 const std::string ConfigurationManager::LAST_STARTED_ITERATE_GROUP_FILE =
"CFGLastStartedIterateGroup.hist";
60 const std::string ConfigurationManager::STARTED_CONFIG_ALIASES_FILE =
"CFGStartedConfigAliases.hist";
61 const std::string ConfigurationManager::STARTED_CONFIGS_FILE =
"CFGStartedConfigGroups.hist";
62 const std::string ConfigurationManager::STARTED_CONTEXTS_FILE =
"CFGStartedContextGroups.hist";
63 const std::string ConfigurationManager::STARTED_BACKBONES_FILE =
"CFGStartedBackboneGroups.hist";
64 const std::string ConfigurationManager::STARTED_ITERATES_FILE =
"CFGStartedIterateGroups.hist";
66 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_CONFIG_ALIASES_FILE =
"CFGConfiguredOrStartedConfigAliases.hist";
67 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_CONFIGS_FILE =
"CFGConfiguredOrStartedConfigGroups.hist";
68 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_CONTEXTS_FILE =
"CFGConfiguredOrStartedContextGroups.hist";
69 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_BACKBONES_FILE =
"CFGConfiguredOrStartedBackboneGroups.hist";
70 const std::string ConfigurationManager::CONFIGURED_OR_STARTED_ITERATES_FILE =
"CFGConfiguredOrStartedIterateGroups.hist";
75 const std::string ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME =
"XDAQContextTable";
76 const std::string ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME =
"XDAQApplicationTable";
77 const std::string ConfigurationManager::XDAQ_APP_PROPERTY_TABLE_NAME =
"XDAQApplicationPropertyTable";
78 const std::string ConfigurationManager::GROUP_ALIASES_TABLE_NAME =
"GroupAliasesTable";
79 const std::string ConfigurationManager::VERSION_ALIASES_TABLE_NAME =
"VersionAliasesTable";
80 const std::string ConfigurationManager::ARTDAQ_TOP_TABLE_NAME =
"ARTDAQSupervisorTable";
81 const std::string ConfigurationManager::DESKTOP_ICON_TABLE_NAME =
"DesktopIconTable";
85 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
86 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
87 "/ActiveTableGroups.cfg";
89 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
90 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
91 const std::string ConfigurationManager::SUBSYSTEM_COMMON_VERSION_ALIAS =
"SubsystemCommon";
92 const std::string ConfigurationManager::SUBSYSTEM_COMMON_OVERRIDE_VERSION_ALIAS =
"SubsystemCommonOverride";
93 const std::string ConfigurationManager::SUBSYSTEM_COMMON_CONTEXT_VERSION_ALIAS =
"SubsystemCommonContext";
94 const std::string ConfigurationManager::SUBSYSTEM_COMMON_CONTEXT_OVERRIDE_VERSION_ALIAS =
"SubsystemCommonContextOverride";
97 const std::string ConfigurationManager::GROUP_TYPE_NAME_CONTEXT =
"Context";
98 const std::string ConfigurationManager::GROUP_TYPE_NAME_BACKBONE =
"Backbone";
99 const std::string ConfigurationManager::GROUP_TYPE_NAME_ITERATE =
"Iterate";
100 const std::string ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION =
"Configuration";
101 const std::string ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN =
"UNKNOWN";
103 const std::string ConfigurationManager::UNKNOWN_INFO =
"UNKNOWN";
104 const std::string ConfigurationManager::UNKNOWN_TIME =
"0";
106 const uint8_t ConfigurationManager::METADATA_COL_ALIASES = 1;
107 const uint8_t ConfigurationManager::METADATA_COL_COMMENT = 2;
108 const uint8_t ConfigurationManager::METADATA_COL_AUTHOR = 3;
109 const uint8_t ConfigurationManager::METADATA_COL_TIMESTAMP = 4;
111 const std::string ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE =
"SubsystemUserDataPathsTable";
114 const std::set<std::string> ConfigurationManager::fixedContextMemberNames_ = {
115 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
116 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
117 "XDAQApplicationPropertyTable",
118 ConfigurationManager::DESKTOP_ICON_TABLE_NAME,
119 "MessageFacilityTable",
120 "GatewaySupervisorTable",
122 "DesktopWindowParameterTable",
123 "SlowControlsDashboardSupervisorTable"
125 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = {
126 ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
127 ConfigurationManager::VERSION_ALIASES_TABLE_NAME
129 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = {
131 "IterationPlanTable",
132 "IterationTargetTable",
133 "IterationCommandBeginLabelTable",
134 "IterationCommandChooseFSMTable",
135 "IterationCommandConfigureAliasTable",
136 "IterationCommandConfigureGroupTable",
137 "IterationCommandExecuteFEMacroTable",
138 "IterationCommandExecuteMacroTable",
139 "IterationCommandMacroDimensionalLoopTable",
140 "IterationCommandMacroDimensionalLoopParameterTable",
141 "IterationCommandModifyGroupTable",
142 "IterationCommandRepeatLabelTable",
143 "IterationCommandRunTable"
150 bool doInitializeFromFhicl ,
151 bool forceNotFirstInContext )
152 : startClockTime_(std::chrono::steady_clock::now())
153 , deltaClockTime_(std::chrono::steady_clock::now())
154 , forceNotFirstInContext_(forceNotFirstInContext)
158 , theConfigurationTableGroupKey_(0)
159 , theContextTableGroupKey_(0)
160 , theBackboneTableGroupKey_(0)
161 , theConfigurationTableGroup_(
"")
162 , theContextTableGroup_(
"")
163 , theBackboneTableGroup_(
"")
164 , groupMetadataTable_(true ,
TableBase::GROUP_METADATA_TABLE_NAME)
166 __GEN_COUTTV__(runTimeSeconds());
167 theInterface_ = ConfigurationInterface::getInstance(
168 ConfigurationInterface::CONFIGURATION_MODE::
171 __GEN_COUTTV__(runTimeSeconds());
243 if(doInitializeFromFhicl)
246 initializeFromFhicl(__ENV__(
"CONFIGURATION_INIT_FCL"));
251 __GEN_COUTTV__(runTimeSeconds());
252 if(!initForWriteAccess)
253 init(0 , initForWriteAccess);
254 __GEN_COUTTV__(runTimeSeconds());
262 __GEN_COUT__ <<
"Private constructor for write access called." << __E__;
264 mfSubject_ = username;
265 username_ = username;
269 ConfigurationManager::~ConfigurationManager() { destroy(); }
278 bool initForWriteAccess ,
279 std::string* accumulatedWarnings )
291 __GEN_COUTTV__(username_);
296 ConfigurationManager::LoadGroupType onlyLoadIfBackboneOrContext =
297 ConfigurationManager::LoadGroupType::ALL_TYPES;
299 onlyLoadIfBackboneOrContext =
300 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_OR_CONTEXT_TYPES;
305 onlyLoadIfBackboneOrContext,
306 accumulatedWarnings);
309 catch(std::runtime_error& e)
311 __GEN_COUT_ERR__ <<
"Error caught in init(): " << e.what();
312 if(accumulatedErrors)
313 *accumulatedErrors += e.what();
330 const std::string& pathToActiveGroupsFile ,
331 ConfigurationManager::LoadGroupType
332 onlyLoadIfBackboneOrContext ,
333 std::string* accumulatedWarnings )
339 FILE* fp = fopen(fn.c_str(),
"r");
341 __GEN_COUTT__ <<
"ACTIVE_GROUPS_FILENAME = " << fn << __E__;
342 __GEN_COUTS__(10) <<
"ARTDAQ_DATABASE_URI = "
343 << std::string(__ENV__(
"ARTDAQ_DATABASE_URI")) << __E__;
347 __GEN_COUT_WARN__ <<
"No active groups file found at " << fn << __E__;
351 __GEN_COUTVS__(10, throwErrors);
356 std::string groupName;
357 std::string errorStr =
"";
362 while(fgets(tmp, 500, fp))
367 sscanf(tmp,
"%d", &numberCheck);
371 <<
"Out of sync with active groups file lines, attempting to resync."
378 sscanf(tmp,
"%s", strVal);
379 for(
unsigned int j = 0; j < strlen(strVal); ++j)
380 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') ||
381 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
382 (strVal[j] >=
'0' && strVal[j] <=
'9')))
385 if(strlen(strVal) == 0)
386 __GEN_COUT__ <<
"Empty group name found, so skipping! Check active "
391 <<
"Illegal character found in group name '" << strVal
392 <<
"', so skipping! Check active groups file: " << fn << __E__;
403 sscanf(tmp,
"%s", strVal);
405 for(
unsigned int j = 0; j < strlen(strVal); ++j)
406 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
410 if(groupName.size() > 3)
412 <<
"Skipping active group with illegal character in group key '"
413 << strVal <<
".' Check active groups file: " << fn << __E__;
419 if(groupName.size() <= 3)
432 <<
"illegal group according to TableGroupKey::getFullGroupString... "
433 "Check active groups file: "
444 std::string groupAccumulatedErrors =
"";
446 if(accumulatedWarnings)
447 __GEN_COUT__ <<
"Ignoring warnings while loading and activating group '"
448 << groupName <<
"(" << strVal <<
")'" << __E__;
456 (accumulatedWarnings ? &groupAccumulatedErrors
464 onlyLoadIfBackboneOrContext
467 if(accumulatedWarnings)
468 *accumulatedWarnings += groupAccumulatedErrors;
470 catch(std::runtime_error& e)
472 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
473 << groupName <<
"(" << strVal
474 <<
")' specified active by active groups file: " << fn << __E__;
475 ss << e.what() << __E__;
477 errorStr += ss.str();
481 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
482 << groupName <<
"(" << strVal
483 <<
")' specified active by active groups file: " << fn << __E__;
488 catch(
const std::exception& e)
490 ss <<
"Exception message: " << e.what();
495 errorStr += ss.str();
501 if(throwErrors && errorStr !=
"")
503 __SS__ <<
"\n" << errorStr;
506 else if(errorStr !=
"")
507 __GEN_COUT_WARN__ <<
"\n" << errorStr;
520 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
521 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
522 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
523 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
525 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
527 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
528 __GEN_COUT_ERR__ << ss.str();
532 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
536 __GEN_COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
538 __GEN_COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
540 __GEN_COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
542 __GEN_COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
545 getActiveContextMemberNames();
547 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
548 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
551 contextFindIt = contextMemberNames_.find(it->first);
552 backboneFindIt = backboneMemberNames_.find(it->first);
553 iterateFindIt = iterateMemberNames_.find(it->first);
555 __GEN_COUTT__ <<
"Considering table: " << it->first <<
" contextFindIt:"
556 << (contextFindIt != contextMemberNames_.end() ?
"Y" :
"N")
557 <<
" backboneFindIt:"
558 << (backboneFindIt != backboneMemberNames_.end() ?
"Y" :
"N")
560 << (iterateFindIt != iterateMemberNames_.end() ?
"Y" :
"N")
570 CONTEXT_SUBSYSTEM_OPTIONAL_TABLE) ||
571 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
572 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
574 contextFindIt == contextMemberNames_.end() &&
575 it->first != ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE &&
576 backboneFindIt == backboneMemberNames_.end() &&
577 iterateFindIt == iterateMemberNames_.end())))
579 __GEN_COUTT__ <<
"\t" << dbgHeader <<
".. " << it->first
580 << (it->second->isActive()
581 ?
"_v" + it->second->getViewVersion().str()
587 it->second->deactivate();
593 nameToTableMap_.erase(it++);
602 theConfigurationTableGroup_ =
"";
603 if(theConfigurationTableGroupKey_ != 0)
605 __GEN_COUTT__ <<
"Destroying Configuration Key: "
606 << *theConfigurationTableGroupKey_ << __E__;
607 theConfigurationTableGroupKey_.reset();
612 theBackboneTableGroup_ =
"";
613 if(theBackboneTableGroupKey_ != 0)
615 __GEN_COUTT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_
617 theBackboneTableGroupKey_.reset();
622 theIterateTableGroup_ =
"";
623 if(theIterateTableGroupKey_ != 0)
625 __GEN_COUTT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_
627 theIterateTableGroupKey_.reset();
632 theContextTableGroup_ =
"";
633 if(theContextTableGroupKey_ != 0)
635 __GEN_COUTT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_
637 theContextTableGroupKey_.reset();
652 const ConfigurationManager::GroupType& groupTypeId)
654 return groupTypeId == ConfigurationManager::GroupType::CONTEXT_TYPE
655 ? ConfigurationManager::GROUP_TYPE_NAME_CONTEXT
656 : (groupTypeId == ConfigurationManager::GroupType::BACKBONE_TYPE
657 ? ConfigurationManager::GROUP_TYPE_NAME_BACKBONE
658 : (groupTypeId == ConfigurationManager::GroupType::ITERATE_TYPE
659 ? ConfigurationManager::GROUP_TYPE_NAME_ITERATE
660 : (groupTypeId == ConfigurationManager::GroupType::
662 ? ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION
663 : ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN)));
674 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
676 bool isContext =
true;
677 bool isBackbone =
true;
678 bool isIterate =
true;
680 bool inContext =
false;
681 bool inBackbone =
false;
682 bool inIterate =
false;
683 unsigned int matchCount = 0;
685 for(
auto& memberPair : memberMap)
690 if(memberPair.first == CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
696 for(
auto& contextMemberString : fixedContextMemberNames_)
697 if(memberPair.first == contextMemberString)
709 __SS__ <<
"This group is an incomplete match to a Context group.\n";
710 ss <<
"\nTo be a Context group, the members must exactly match "
711 <<
"the following members (w/ or wo/ the optional table "
712 << CONTEXT_SUBSYSTEM_OPTIONAL_TABLE <<
"):\n";
714 for(
const auto& memberName : fixedContextMemberNames_)
715 ss << ++i <<
". " << memberName <<
"\n";
716 ss <<
"\nThe members are as follows::\n";
718 for(
const auto& memberPairTmp : memberMap)
719 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
726 for(
auto& backboneMemberString : backboneMemberNames_)
727 if(memberPair.first == backboneMemberString)
739 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
740 ss <<
"\nTo be a Backbone group, the members must exactly match "
741 <<
"the following members:\n";
743 for(
auto& memberName : backboneMemberNames_)
744 ss << ++i <<
". " << memberName <<
"\n";
745 ss <<
"\nThe members are as follows::\n";
747 for(
const auto& memberPairTmp : memberMap)
748 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
756 for(
auto& iterateMemberString : iterateMemberNames_)
757 if(memberPair.first == iterateMemberString)
769 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
770 ss <<
"\nTo be a Iterate group, the members must exactly match "
771 <<
"the following members:\n";
773 for(
auto& memberName : iterateMemberNames_)
774 ss << ++i <<
". " << memberName <<
"\n";
775 ss <<
"\nThe members are as follows::\n";
777 for(
const auto& memberPairTmp : memberMap)
778 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
785 if((isContext || inContext) && matchCount != fixedContextMemberNames_.size())
787 __SS__ <<
"This group is an incomplete match to a Context group: "
788 <<
" Size=" << matchCount <<
" but should be "
789 << fixedContextMemberNames_.size() << __E__;
790 ss <<
"\nThe members currently are...\n";
792 for(
auto& memberPair : memberMap)
793 ss << ++i <<
". " << memberPair.first <<
"\n";
794 ss <<
"\nThe expected Context members are...\n";
796 for(
auto& memberName : fixedContextMemberNames_)
797 ss << ++i <<
". " << memberName <<
"\n";
798 ss <<
"optional. (" << CONTEXT_SUBSYSTEM_OPTIONAL_TABLE <<
")\n";
803 if((isBackbone || inBackbone) && matchCount != backboneMemberNames_.size())
805 __SS__ <<
"This group is an incomplete match to a Backbone group: "
806 <<
" Size=" << matchCount <<
" but should be "
807 << backboneMemberNames_.size() << __E__;
808 ss <<
"\nThe members currently are...\n";
810 for(
auto& memberPair : memberMap)
811 ss << ++i <<
". " << memberPair.first <<
"\n";
812 ss <<
"\nThe expected Backbone members are...\n";
814 for(
auto& memberName : backboneMemberNames_)
815 ss << ++i <<
". " << memberName <<
"\n";
820 if((isIterate || inIterate) && matchCount != iterateMemberNames_.size())
822 __SS__ <<
"This group is an incomplete match to a Iterate group: "
823 <<
" Size=" << matchCount <<
" but should be "
824 << iterateMemberNames_.size() << __E__;
825 ss <<
"\nThe members currently are...\n";
827 for(
auto& memberPair : memberMap)
828 ss << ++i <<
". " << memberPair.first <<
"\n";
829 ss <<
"\nThe expected Iterate members are...\n";
831 for(
auto& memberName : iterateMemberNames_)
832 ss << ++i <<
". " << memberName <<
"\n";
838 ? ConfigurationManager::GroupType::CONTEXT_TYPE
840 ? ConfigurationManager::GroupType::BACKBONE_TYPE
842 ? ConfigurationManager::GroupType::ITERATE_TYPE
843 : ConfigurationManager::GroupType::CONFIGURATION_TYPE));
850 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
861 #define OUT out << tabStr << commentStr
862 #define PUSHTAB tabStr += "\t"
863 #define POPTAB tabStr.resize(tabStr.size() - 1)
864 #define PUSHCOMMENT commentStr += "# "
865 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
867 void ConfigurationManager::dumpMacroMakerModeFhicl()
869 if(nameToTableMap_.find(
"FEInterfaceTable") == nameToTableMap_.end())
871 __COUT__ <<
"Skipping dumpMacroMakerModeFhicl() since FEInterface table is not "
877 std::string filepath =
878 __ENV__(
"USER_DATA") + std::string(
"/") +
"MacroMakerModeConfigurations";
879 mkdir(filepath.c_str(), 0755);
880 filepath +=
"/MacroMakerModeFhiclDump.fcl";
881 __GEN_COUT__ <<
"dumpMacroMakerModeFhicl: " << filepath << __E__;
887 std::string tabStr =
"";
888 std::string commentStr =
"";
890 out.open(filepath, std::fstream::out | std::fstream::trunc);
893 __SS__ <<
"Failed to open MacroMaker mode fcl file for configuration dump: "
894 << filepath << __E__;
900 std::vector<std::pair<std::string, ConfigurationTree>> fes =
906 if(!fe.second.status())
911 OUT << fe.first <<
": {" << __E__;
916 OUT <<
"FEInterfacePluginName"
918 <<
"\"" << fe.second.getNode(
"FEInterfacePluginName").getValueAsString()
921 recursiveTreeToFhicl(
922 fe.second.getNode(
"LinkToFETypeTable"), out, tabStr, commentStr);
925 OUT <<
"} //end " << fe.first << __E__ << __E__;
931 __SS__ <<
"Failed to complete MacroMaker mode fcl "
932 "file configuration dump due to error."
938 catch(
const std::runtime_error& e)
940 ss <<
"Exception message: " << e.what();
942 catch(
const std::exception& e)
944 ss <<
"Exception message: " << e.what();
946 __GEN_COUT_ERR__ << ss.str();
964 std::string& tabStr ,
965 std::string& commentStr ,
970 __COUT__ << __COUT_HDR_P__ <<
"Depth limit reached. Ending recursion." << __E__;
976 if(depth == (
unsigned int)-1)
996 std::vector<std::pair<std::string, ConfigurationTree>> children =
998 for(
auto& child : children)
999 recursiveTreeToFhicl(child.second, out, tabStr, commentStr, depth - 1);
1003 <<
" group link record" << __E__;
1015 std::vector<std::pair<std::string, ConfigurationTree>> fields =
1019 for(
unsigned int i = 0; i < fields.size() - 3; ++i)
1023 if(fields[i].second.isLinkNode())
1025 recursiveTreeToFhicl(
1026 fields[i].second, out, tabStr, commentStr, depth - 1);
1031 OUT << fields[i].second.getFieldName() <<
": \t";
1032 if(fields[i].second.isValueNumberDataType())
1033 OUT << fields[i].second.getValueAsString() << __E__;
1035 OUT <<
"\"" << fields[i].second.getValueAsString() <<
"\"" << __E__;
1048 <<
" link record" << __E__;
1057 const std::string& filePath,
1058 const std::string& dumpType,
1059 const std::string& configurationAlias,
1060 const std::string& subsystemCommonList,
1061 const std::string& subsystemCommonOverrideList,
1062 const std::string& logEntry,
1063 const std::string& activeUsers,
1064 const std::string& activeStateMachine,
1065 std::ostream& altOut )
1067 time_t rawtime = time(0);
1068 __GEN_COUT__ <<
"filePath = " << filePath << __E__;
1069 __GEN_COUT__ <<
"dumpType = " << dumpType << __E__;
1073 fs.open(filePath, std::fstream::out | std::fstream::trunc);
1084 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath
1085 <<
" could not be opened!" << __E__;
1086 __GEN_COUT_ERR__ << ss.str();
1092 if(dumpType ==
"JSON All")
1095 (*out) <<
"\t\"ARTDAQ_DATABASE_URI\": \"" << __ENV__(
"ARTDAQ_DATABASE_URI")
1099 (*out) <<
"\t\"HOSTNAME\": \"" << __ENV__(
"HOSTNAME") <<
"\"," << __E__;
1100 (*out) <<
"\t\"HOSTNAME filepath\": \"" << filePath <<
"\"," << __E__;
1101 (*out) <<
"\t\"Active State Machine\": \"" << activeStateMachine <<
"\","
1104 (*out) <<
"\t\"active_users\": \t[";
1105 if(activeUsers.size())
1107 std::istringstream iss(activeUsers);
1110 while(std::getline(iss, user,
','))
1114 (*out) <<
"\n\t\t\"" << user <<
"\"";
1118 (*out) <<
"\n\t]," << __E__;
1119 (*out) <<
"\t\"dump_type\": \t\t\"" << dumpType <<
"\"," << __E__;
1120 (*out) <<
"\t\"dump_time\": \t\t\"" << rawtime <<
"\"," << __E__;
1121 (*out) <<
"\t\"dump_time_formatted\": \t\t\""
1126 (*out) <<
"#################################" << __E__;
1127 (*out) <<
"This is an ots system configuration dump.\n" << __E__;
1128 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI: "
1129 << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
1131 (*out) <<
"Original location of dump: " << __ENV__(
"HOSTNAME")
1132 <<
":" << filePath << __E__;
1133 (*out) <<
"\nActive ots users: \t"
1134 << (activeUsers.size() ? activeUsers :
"no active users") << __E__;
1135 (*out) <<
"Type of dump: \t\t" << dumpType << __E__;
1136 (*out) <<
"Time of dump: \t\t" << rawtime;
1141 std::pair<std::string, ots::TableGroupKey> configurationTableGroup =
1144 if(dumpType !=
"JSON All")
1146 (*out) <<
"Configuration Alias: \t\t\t" << configurationAlias <<
"\n";
1147 (*out) <<
"Configuration Alias translation: \t" << configurationTableGroup.first
1148 <<
"(" << configurationTableGroup.second <<
")\n\n";
1151 (*out) <<
"User Log Entry (" << logEntry.size() <<
" chars):\n"
1152 << logEntry << __E__;
1164 std::string subsystemCommonList,
1165 std::string subsystemCommonOverrideList,
1166 bool jsonify =
false,
1167 std::string configurationAlias =
"") {
1168 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
1173 if(!subsystemCommonList.empty())
1174 (*out) <<
"\n\t\"subsystem_common_table_list\": \"" << subsystemCommonList
1176 if(!subsystemCommonOverrideList.empty())
1177 (*out) <<
"\n\t\"subsystem_common_override_table_list\": \""
1178 << subsystemCommonOverrideList <<
"\",\n"
1180 (*out) <<
"\n\t\"groups\": {\n";
1184 (*out) <<
"Subsystem Common Table List: " << subsystemCommonList << __E__;
1185 (*out) <<
"Subsystem Common Override Table List: "
1186 << subsystemCommonOverrideList << __E__;
1187 (*out) <<
"\n\n************************" << __E__;
1188 (*out) <<
"Active Groups: " << __E__;
1191 std::map<std::string, std::pair<std::string, TableGroupKey>>::iterator it;
1193 for(it = activeGroups.begin(); it != activeGroups.end(); ++it)
1197 (*out) <<
"\t\t\"" << it->first <<
"_group_name\": \"" << it->second.first
1199 (*out) <<
"\t\t\"" << it->first <<
"_group_key\": \"" << it->second.second
1201 if(it->first ==
"Configuration")
1205 <<
"Configuration_alias\": \"" << configurationAlias <<
"\"";
1207 (*out) << (std::next(it) == activeGroups.end() ?
"" :
",") <<
"\n";
1211 (*out) <<
"\t" << it->first <<
" := " << it->second.first <<
" ("
1212 << it->second.second <<
")" << __E__;
1223 bool jsonify =
false) {
1228 (*out) <<
"\t\"tables\": { " << __E__;
1232 (*out) <<
"\n\n************************" << __E__;
1233 (*out) <<
"Active Tables:" << __E__;
1234 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
1238 std::map<std::string, TableVersion>::iterator it;
1239 for(it = activeTables.begin(); it != activeTables.end(); ++it)
1244 <<
"active_table_name"
1245 <<
"\": \"" << it->first <<
"\",\n";
1247 <<
"active_table_version"
1248 <<
"\": \"" << it->second <<
"\"";
1249 (*out) << (std::next(it) == activeTables.end() ?
"" :
",") <<
"\n";
1253 (*out) <<
"\t" << ++i <<
". " << it->first <<
"-v" << it->second << __E__;
1264 bool jsonify =
false) {
1265 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
1270 (*out) <<
"\t\"group_members\": { " << __E__;
1274 (*out) <<
"\n\n************************" << __E__;
1275 (*out) <<
"Active Group Members:" << __E__;
1279 std::map<std::string, std::pair<std::string, TableGroupKey>>::iterator it;
1280 for(it = activeGroups.begin(); it != activeGroups.end(); ++it)
1284 (*out) <<
"\t" << it->first <<
" := " << it->second.first <<
" ("
1285 << it->second.second <<
")" << __E__;
1288 if(it->second.first ==
"")
1293 <<
"Empty group name. Assuming no active group." << __E__;
1300 (*out) <<
"\t\t\"" << it->first <<
"\" : {" << __E__;
1301 (*out) <<
"\t\t\t\"Name\": \t\"" << it->second.first <<
"\""
1302 << (std::next(it) == activeGroups.end() ?
"" :
",") << __E__;
1306 std::map<std::string , std::string > groupAliases;
1307 std::string groupComment;
1308 std::string groupAuthor;
1309 std::string groupCreateTime;
1310 time_t groupCreateTime_t;
1327 (*out) <<
"\t\t\t\"key\": \t\"" << it->second.second <<
"\"," << __E__;
1328 (*out) <<
"\t\t\t\"comment\": \t\"" << groupComment <<
"\"," << __E__;
1329 (*out) <<
"\t\t\t\"author\": \t\"" << groupAuthor <<
"\"," << __E__;
1331 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
1332 std::string timeCreated = ctime(&groupCreateTime_t);
1333 (*out) <<
"\t\t\t\"create_time\": \t\""
1334 << timeCreated.erase(timeCreated.find(
'\n', 0), 1) <<
"\","
1336 (*out) <<
"\t\t\t\"group_aliases\": \t\""
1339 (*out) <<
"\t\t\t\"table_count\": \t\"" << memberMap.size() <<
"\","
1341 tableCount += memberMap.size();
1343 (*out) <<
"\t\t\t\"tables\": {" << __E__;
1347 for(iterMap = memberMap.begin(); iterMap != memberMap.end(); ++iterMap)
1349 (*out) <<
"\t\t\t\t\"" << iterMap->first <<
"\": \""
1350 << iterMap->second <<
"\""
1351 << (std::next(iterMap) == memberMap.end() ?
"" :
",") << __E__;
1353 (*out) <<
"\t\t\t}" << __E__;
1354 (*out) <<
"\t\t}," << __E__;
1358 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
1359 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
1361 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
1362 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t)
1364 (*out) <<
"\t\tGroup Aliases: \t"
1367 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
1368 tableCount += memberMap.size();
1371 for(
auto& member : memberMap)
1373 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v"
1374 << member.second << __E__;
1381 (*out) <<
"\t\"total_table_count\": \"" << tableCount <<
"\"" << __E__;
1386 (*out) <<
"\nActive Group Members total table count = " << tableCount
1394 bool jsonify =
false) {
1399 (*out) <<
"\t\"tables\": {" << __E__;
1403 (*out) <<
"\n\n************************" << __E__;
1404 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
1409 std::map<std::string, TableVersion>::iterator it;
1410 for(it = activeTables.begin(); it != activeTables.end(); ++it)
1414 __COUTT__ <<
"localDumpActiveTableContents table: " << it->first << __E__;
1415 auto table = cfgMgr->nameToTableMap_.find(it->first)->second->getViewP();
1416 (*out) <<
"\t\t\"" << it->first <<
"-v" << it->second <<
"\": ";
1417 table->printJSON(*out);
1418 (*out) << (std::next(it) == activeTables.end() ?
"" :
",") << __E__;
1422 (*out) <<
"\n\n=========================================================="
1426 (*out) <<
"=============================================================="
1430 (*out) <<
"\t" << ++i <<
". " << it->first <<
"-v" << it->second << __E__;
1432 cfgMgr->nameToTableMap_.find(it->first)->second->print(*out);
1438 (*out) <<
"\t}" << __E__;
1444 std::ostream* out) {
1447 __COUT__ <<
"Active Table size: " << activeTables.size() << __E__;
1448 (*out) <<
"\t\"custom\": {" << __E__;
1450 std::string activeTableStructure =
"";
1451 std::map<std::string, TableVersion>::iterator it;
1452 size_t tableStructureFoundCount = 0;
1453 for(it = activeTables.begin(); it != activeTables.end(); ++it)
1457 __COUTT__ <<
"Trying to retrieve " << it->first <<
"-v" << it->second
1458 <<
" Structure" << __E__;
1459 activeTableStructure =
1460 cfgMgr->nameToTableMap_.find(it->first)->second->getStructureAsJSON(
1462 if(activeTableStructure !=
"")
1464 __COUTT__ <<
"Found Structure for Active Table: " << it->first <<
"-v"
1465 << it->second << __E__;
1467 (*out) << (tableStructureFoundCount++ ?
"," :
"") << __E__;
1469 (*out) <<
"\t\"" << it->first <<
"\": " << __E__;
1470 (*out) << activeTableStructure << __E__;
1473 catch(
const std::exception& e)
1475 __COUTT__ <<
"Error caught in localDumpActiveTableStructureStatus(): "
1477 __COUTT__ <<
"Structure Status may not be implemented." << __E__;
1481 __COUT__ <<
"Found " << tableStructureFoundCount <<
" Active Table Structures."
1484 (*out) <<
"\t}" << __E__;
1488 auto localDumpSoftwareVersions = [](std::ostream* out,
bool jsonFormat =
false) {
1489 __COUT__ <<
"localDumpSoftwareVersions()" << __E__;
1490 std::vector<std::string> entries;
1493 std::map<std::string, std::string> spackPackages;
1494 std::map<std::string, std::string> checkedOutRepos;
1495 std::string environment;
1499 std::istringstream iss(spackOut);
1501 while(std::getline(iss, line))
1507 if(line.find(
"==> In environment") != std::string::npos)
1509 size_t start = line.find(
"environment ") + 12;
1510 environment = line.substr(start);
1512 else if(line[0] !=
'[' && line[0] !=
'-' &&
1513 line.find(
"root specs") == std::string::npos)
1516 size_t atPos = line.find(
'@');
1517 if(atPos != std::string::npos)
1519 std::string pkgName = line.substr(0, atPos);
1521 if(pkgName.find(
'[') != std::string::npos)
1522 pkgName = pkgName.substr(pkgName.find(
']') + 2);
1523 std::string version = line.substr(atPos + 1);
1524 spackPackages[pkgName] = version;
1526 else if(line.find(
'[') == std::string::npos && !line.empty() &&
1530 std::string pkgName = line;
1531 if(pkgName.find(
'[') != std::string::npos)
1532 pkgName = pkgName.substr(pkgName.find(
']') + 2);
1533 spackPackages[pkgName] =
"";
1542 struct dirent* entry;
1546 std::string src = __ENV__(
"OTS_SOURCE");
1547 if(!(pDIR = opendir((src).c_str())))
1549 __SS__ <<
"Path '" << src <<
"' could not be opened!" << __E__;
1552 while((entry = readdir(pDIR)))
1554 name = std::string(entry->d_name);
1555 type = int(entry->d_type);
1557 __COUTS__(2) << type <<
" " << name <<
"\n" << std::endl;
1558 if(name[0] !=
'.' &&
1568 if(type == 0 || type == 10)
1571 DIR* pTmpDIR = opendir((src +
"/" + name).c_str());
1578 __COUTS__(2) <<
"Unable to open path as directory: "
1579 << (src +
"/" + name) << __E__;
1589 __COUTS__(2) <<
"Directory: " << type <<
" " << name << __E__;
1591 (
"cd " + src +
"/" + name +
"; git describe --tags").c_str());
1595 if(describe.back() ==
'\n')
1596 describe.pop_back();
1597 checkedOutRepos[name] = describe;
1607 (*out) <<
"\t\"software_versions\": {" << __E__;
1610 (*out) <<
"\t\t\"spack\": {" << __E__;
1612 for(
const auto& pkg : spackPackages)
1615 (*out) <<
"," << __E__;
1621 (*out) << __E__ <<
"\t\t}," << __E__;
1624 (*out) <<
"\t\t\"checked_out\": {" << __E__;
1626 for(
const auto& repo : checkedOutRepos)
1629 (*out) <<
"," << __E__;
1635 (*out) << __E__ <<
"\t\t}," << __E__;
1638 (*out) <<
"\t\t\"environment\": \""
1642 (*out) <<
"\t}" << __E__;
1646 (*out) <<
"\n\n\"Software Versions\": {" << __E__;
1647 (*out) <<
" \"spack\": " << spackPackages.size() <<
" packages," << __E__;
1648 (*out) <<
" \"checked_out\": " << checkedOutRepos.size() <<
" repositories,"
1650 (*out) <<
" \"environment\": \"" << environment <<
"\"" << __E__;
1651 (*out) <<
"}" << __E__;
1655 if(dumpType ==
"Group Keys")
1657 localDumpActiveGroups(
1658 this, out, subsystemCommonList, subsystemCommonOverrideList);
1660 else if(dumpType ==
"Table Versions")
1662 localDumpActiveTables(
this, out);
1664 else if(dumpType ==
"Group Keys and Table Versions")
1666 localDumpActiveGroups(
1667 this, out, subsystemCommonList, subsystemCommonOverrideList);
1668 localDumpActiveTables(
this, out);
1670 else if(dumpType ==
"All")
1672 localDumpActiveGroups(
1673 this, out, subsystemCommonList, subsystemCommonOverrideList);
1674 localDumpActiveGroupMembers(
this, out);
1675 localDumpActiveTables(
this, out);
1676 localDumpActiveTableContents(
this, out);
1677 localDumpSoftwareVersions(out);
1679 else if(dumpType ==
"JSON All")
1681 localDumpActiveGroups(
this,
1683 subsystemCommonList,
1684 subsystemCommonOverrideList,
1686 configurationAlias);
1688 localDumpActiveGroupMembers(
this, out,
true);
1692 localDumpActiveTableContents(
this, out,
true);
1693 (*out) <<
",\n" << __E__;
1694 localDumpActiveTableStructureStatus(
this, out);
1695 (*out) <<
",\n" << __E__;
1696 localDumpSoftwareVersions(out,
true);
1702 <<
"Invalid dump type '" << dumpType
1703 <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
1711 <<
"Group Keys and Table Versions"
1718 "\n\nPlease change the State Machine configuration to a valid dump type."
1735 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap,
1736 std::string* accumulatedWarnings )
1738 __GEN_COUTTV__(runTimeSeconds());
1743 bool usingCache =
false;
1744 if(memberMap.size() > 10 && nameToTableMap_.size() &&
1745 nameToTableMap_.find(memberMap.begin()->first) != nameToTableMap_.end() &&
1746 nameToTableMap_.at(memberMap.begin()->first)->isStored(memberMap.begin()->second))
1751 __GEN_COUTT__ <<
"Using cache!" << __E__;
1755 const int numOfThreads = StringMacros::getConcurrencyCount() / 2 < memberMap.size()
1756 ? (StringMacros::getConcurrencyCount() / 2)
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__ <<
" getConcurrencyCount " << StringMacros::getConcurrencyCount()
1885 <<
" ==> " << numOfThreads
1886 <<
" threads for loading member map of size " << memberMap.size()
1889 int threadsLaunched = 0;
1890 int foundThreadIndex = 0;
1891 std::string threadErrors;
1892 std::mutex threadMutex;
1893 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
1894 for(
int i = 0; i < numOfThreads; ++i)
1895 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
1896 std::vector<TableBase*> tmpTableBasePtrs;
1897 for(
int i = 0; i < numOfThreads; ++i)
1898 tmpTableBasePtrs.push_back(
nullptr);
1900 for(
auto& memberPair : memberMap)
1902 if(threadsLaunched >= numOfThreads)
1905 foundThreadIndex = -1;
1906 while(foundThreadIndex == -1)
1908 for(
int i = 0; i < numOfThreads; ++i)
1909 if(*(threadDone[i]))
1911 foundThreadIndex = i;
1914 if(foundThreadIndex == -1)
1916 __GEN_COUTT__ <<
"Waiting for available thread..." << __E__;
1920 threadsLaunched = numOfThreads - 1;
1922 __GEN_COUTT__ <<
"Starting filling thread... " << foundThreadIndex <<
" for "
1923 << memberPair.first <<
" -v" << memberPair.second << __E__;
1924 *(threadDone[foundThreadIndex]) =
false;
1932 tmpTableBasePtrs[foundThreadIndex] =
nullptr;
1933 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1934 tmpTableBasePtrs[foundThreadIndex] = nameToTableMap_.at(memberPair.first);
1938 std::map<std::string, ots::TableBase*>* theNameToTableMap,
1940 std::string theTableName,
1942 std::string* theThreadErrors,
1943 std::mutex* theThreadMutex,
1944 std::shared_ptr<std::atomic<bool>> theThreadDone) {
1945 ConfigurationManager::fillTableThread(theInterface,
1956 tmpTableBasePtrs[foundThreadIndex],
1961 threadDone[foundThreadIndex])
1971 foundThreadIndex = -1;
1972 for(
int i = 0; i < numOfThreads; ++i)
1973 if(!*(threadDone[i]))
1975 foundThreadIndex = i;
1978 if(foundThreadIndex != -1)
1980 __GEN_COUT_TYPE__(TLVL_DEBUG + 2)
1981 << __COUT_HDR__ <<
"Waiting for thread to finish... "
1982 << foundThreadIndex << __E__;
1985 }
while(foundThreadIndex != -1);
1986 __GEN_COUTT__ <<
"All threads done." << __E__;
1988 if(threadErrors !=
"")
1990 __SS__ <<
"Error identified in threads during loading of member map: \n"
1991 << threadErrors << __E__;
1992 __GEN_COUTT__ <<
"\n" << ss.str() << __E__;
1993 if(accumulatedWarnings)
1994 *accumulatedWarnings += ss.str();
2000 __GEN_COUTT__ <<
"loadMemberMap end runTimeSeconds()=" << runTimeSeconds() << __E__;
2026 const std::string& groupName,
2029 std::map<std::string /*table name*/, TableVersion>*
2032 std::string* accumulatedWarnings ,
2033 std::string* groupComment ,
2034 std::string* groupAuthor ,
2035 std::string* groupCreateTime ,
2036 bool doNotLoadMembers ,
2037 std::string* groupTypeString ,
2038 std::map<std::string /*name*/, std::string /*alias*/>*
2040 ConfigurationManager::LoadGroupType
2042 bool ignoreVersionTracking ,
2043 std::map<std::string /* tableName */, TableVersion> mergInTables ,
2044 std::map<std::string /* tableName */, TableVersion> overrideTables )
2048 *groupComment = ConfigurationManager::UNKNOWN_INFO;
2050 *groupAuthor = ConfigurationManager::UNKNOWN_INFO;
2052 *groupCreateTime = ConfigurationManager::UNKNOWN_TIME;
2054 *groupTypeString = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
2056 __GEN_COUTT__ <<
"No group type requested." << __E__;
2083 __GEN_COUTT__ <<
"Loading Table Group: " << groupName <<
"(" << groupKey <<
")"
2084 <<
" accumulatedWarnings=" << (accumulatedWarnings ? 1 : 0) << __E__;
2096 progressBar->
step();
2099 auto metaTablePair = memberMap.find(TableBase::GROUP_METADATA_TABLE_NAME);
2100 if(metaTablePair != memberMap.end())
2103 if(groupAliases || groupComment || groupAuthor || groupCreateTime)
2105 std::lock_guard<std::mutex> lock(metaDataTableMutex_);
2108 while(groupMetadataTable_.getView().getNumberOfRows())
2109 groupMetadataTable_.getViewP()->
deleteRow(0);
2114 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
2116 catch(
const std::runtime_error& e)
2119 <<
"Failed to load " << groupMetadataTable_.
getTableName() <<
"-v"
2120 << metaTablePair->second <<
". Metadata error: " << e.what()
2126 <<
"Failed to load " << groupMetadataTable_.
getTableName() <<
"-v"
2127 << metaTablePair->second <<
". Ignoring unknown metadata error. "
2132 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
2134 groupMetadataTable_.
print();
2135 __GEN_COUT_ERR__ <<
"Ignoring that groupMetadataTable_ has wrong "
2136 "number of rows for '"
2137 << groupName <<
"(" << groupKey
2139 "be 1. Going with anonymous defaults."
2143 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
2144 groupMetadataTable_.getViewP()->
deleteRow(0);
2145 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
2146 groupMetadataTable_.getViewP()->
addRow();
2155 0, ConfigurationManager::METADATA_COL_ALIASES),
2159 0, ConfigurationManager::METADATA_COL_COMMENT);
2162 0, ConfigurationManager::METADATA_COL_AUTHOR);
2165 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
2169 memberMap.erase(metaTablePair);
2174 __GEN_COUTT__ <<
"Ignoring that groupMetadataTable_ is missing for group '"
2175 << groupName <<
"(" << groupKey
2176 <<
"). Going with anonymous defaults." << __E__;
2187 std::map<std::string, std::string>& aliasMap = *groupAliases;
2188 std::map<std::string , std::map<std::string ,
TableVersion>>
2198 for(
auto& aliasPair : aliasMap)
2201 if(memberMap.find(aliasPair.first) != memberMap.end())
2203 __GEN_COUT__ <<
"Group member '" << aliasPair.first
2204 <<
"' was found in group member map!" << __E__;
2205 __GEN_COUT__ <<
"Looking for alias '" << aliasPair.second
2206 <<
"' in active version aliases..." << __E__;
2208 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
2209 versionAliases[aliasPair.first].find(aliasPair.second) ==
2210 versionAliases[aliasPair.first].end())
2212 __SS__ <<
"Group '" << groupName <<
"(" << groupKey
2213 <<
")' requires table version alias '" << aliasPair.first
2214 <<
":" << aliasPair.second
2215 <<
",' which was not found in the active Backbone!"
2220 memberMap[aliasPair.first] =
2221 versionAliases[aliasPair.first][aliasPair.second];
2222 __GEN_COUT__ <<
"Version alias translated to " << aliasPair.first
2229 *groupMembers = memberMap;
2232 progressBar->
step();
2234 ConfigurationManager::GroupType groupType =
2235 ConfigurationManager::GroupType::CONFIGURATION_TYPE;
2244 __GEN_COUTT__ <<
"No group type requested." << __E__;
2246 if(doNotLoadMembers)
2250 if(!groupTypeString)
2253 if(groupTypeToLoad ==
2254 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_OR_CONTEXT_TYPES &&
2255 groupType != ConfigurationManager::GroupType::CONTEXT_TYPE &&
2256 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
2258 __GEN_COUT__ <<
"Not loading group because it is not of type Context or "
2259 "Backbone (it is type '"
2263 else if(groupTypeToLoad ==
2264 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_TYPE &&
2265 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
2267 __GEN_COUT__ <<
"Not loading group because it is not of type "
2268 "Backbone (it is type '"
2276 <<
"------------------------------------- init start \t [for all "
2284 std::string groupToDeactivate =
2285 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2286 ? theContextTableGroup_
2287 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
2288 ? theBackboneTableGroup_
2290 ConfigurationManager::GroupType::ITERATE_TYPE
2291 ? theIterateTableGroup_
2292 : theConfigurationTableGroup_));
2295 if(groupToDeactivate !=
"")
2297 __GEN_COUTT__ <<
"groupToDeactivate '" << groupToDeactivate
2306 __GEN_COUTT__ <<
"no group to deactivate of type "
2313 progressBar->
step();
2318 progressBar->
step();
2320 __GEN_COUTT__ <<
"loadMemberMap() completed." << __E__;
2322 if(accumulatedWarnings)
2324 __GEN_COUTT__ <<
"Checking chosen group for tree errors... here are the "
2325 "current warnings: "
2326 << *accumulatedWarnings << __E__;
2329 if(*accumulatedWarnings !=
"")
2332 <<
"Errors detected while loading Table Group: " << groupName
2333 <<
"(" << groupKey <<
"). Ignoring the following errors: "
2335 << *accumulatedWarnings << __E__;
2337 __GEN_COUTT__ <<
"After checking children warnings: "
2338 << *accumulatedWarnings << __E__;
2342 progressBar->
step();
2344 __GEN_COUTT__ <<
"Tree view check complete." << __E__;
2352 if(overrideTables.size())
2354 __GEN_COUT__ <<
"Overriding tables: "
2357 std::map<std::pair<std::string ,
2361 std::map<std::pair<std::string ,
2362 std::pair<std::string ,
2365 groupidConversionMap;
2367 for(
const auto& mergeInPair : overrideTables)
2369 if(memberMap.find(mergeInPair.first) == memberMap.end())
2371 __GEN_COUT__ <<
"Skipping override of table '"
2372 << mergeInPair.first <<
"-v"
2373 << mergeInPair.second
2374 <<
"' which is not in group " << groupName <<
"("
2375 << groupKey <<
")." << __E__;
2378 __GEN_COUT__ <<
"Overriding group member table '"
2379 << mergeInPair.first <<
"' v"
2380 << memberMap.at(mergeInPair.first)
2381 <<
" with version v" << mergeInPair.second << __E__;
2383 std::stringstream mergeReport;
2385 nameToTableMap_.at(mergeInPair.first)
2389 memberMap.at(mergeInPair.first))
2396 TableBase::MergeApproach::REPLACE,
2398 groupidConversionMap,
2404 __GEN_COUTV__(newVersion);
2405 nameToTableMap_.at(mergeInPair.first)->setActiveView(newVersion);
2406 nameToTableMap_.at(mergeInPair.first)
2408 ->setComment(nameToTableMap_.at(mergeInPair.first)
2411 "\n" + mergeReport.str());
2412 __GEN_COUT__ <<
"Overriding table '" << mergeInPair.first
2413 <<
"' resulting version v" << newVersion << __E__;
2414 __GEN_COUTV__(mergeReport.str());
2420 if(mergInTables.size())
2422 __GEN_COUT__ <<
"Merging-in tables: "
2425 std::map<std::pair<std::string ,
2429 std::map<std::pair<std::string ,
2430 std::pair<std::string ,
2433 groupidConversionMap;
2435 for(
const auto& mergeInPair : mergInTables)
2437 if(memberMap.find(mergeInPair.first) == memberMap.end())
2439 __GEN_COUT__ <<
"Skipping merging-in of table '"
2440 << mergeInPair.first <<
"-v"
2441 << mergeInPair.second
2442 <<
"' which is not in group " << groupName <<
"("
2443 << groupKey <<
")." << __E__;
2447 __GEN_COUT__ <<
"Merging-in group member table '"
2448 << mergeInPair.first <<
"' v"
2449 << memberMap.at(mergeInPair.first)
2450 <<
" with version v" << mergeInPair.second << __E__;
2452 std::stringstream mergeReport;
2454 nameToTableMap_.at(mergeInPair.first)
2458 memberMap.at(mergeInPair.first))
2465 TableBase::MergeApproach::SKIP,
2467 groupidConversionMap,
2473 __GEN_COUTV__(newVersion);
2474 nameToTableMap_.at(mergeInPair.first)->setActiveView(newVersion);
2475 nameToTableMap_.at(mergeInPair.first)
2477 ->setComment(nameToTableMap_.at(mergeInPair.first)
2480 "\n" + mergeReport.str());
2481 __GEN_COUT__ <<
"Merging-in table '" << mergeInPair.first
2482 <<
"' resulting version v" << newVersion << __E__;
2483 __GEN_COUTV__(mergeReport.str());
2490 progressBar->
step();
2492 const int numOfThreads = StringMacros::getConcurrencyCount() / 2;
2493 __GEN_COUTT__ <<
" getConcurrencyCount "
2494 << StringMacros::getConcurrencyCount() <<
" ==> "
2496 <<
" threads for initializing tables for Table Group '"
2497 << groupName <<
"(" << groupKey <<
")'." << __E__;
2498 if(groupType != ConfigurationManager::GroupType::CONFIGURATION_TYPE ||
2501 for(
auto& memberPair : memberMap)
2504 if(!ignoreVersionTracking &&
2505 ConfigurationInterface::isVersionTrackingEnabled() &&
2506 memberPair.second.isScratchVersion())
2509 <<
"Error while activating member Table '"
2510 << nameToTableMap_[memberPair.first]->getTableName()
2511 <<
"-v" << memberPair.second <<
" for Table Group '"
2512 << groupName <<
"(" << groupKey
2513 <<
")'. When version tracking is enabled, Scratch views"
2514 <<
" are not allowed! Please only use unique, persistent "
2515 "versions when version tracking is enabled."
2524 nameToTableMap_.at(memberPair.first)->init(
this);
2526 catch(std::runtime_error& e)
2528 __SS__ <<
"Error detected calling " << memberPair.first
2529 <<
".init()!\n\n " << e.what() << __E__;
2531 if(accumulatedWarnings)
2533 *accumulatedWarnings += ss.str();
2543 __SS__ <<
"Unknown Error detected calling "
2544 << memberPair.first <<
".init()!\n\n " << __E__;
2549 catch(
const std::exception& e)
2551 ss <<
"Exception message: " << e.what();
2558 if(accumulatedWarnings)
2560 *accumulatedWarnings += ss.str();
2563 __GEN_COUT_WARN__ << ss.str();
2569 int threadsLaunched = 0;
2570 int foundThreadIndex = 0;
2571 std::string threadErrors;
2572 std::mutex threadMutex;
2573 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
2574 for(
int i = 0; i < numOfThreads; ++i)
2575 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
2577 if(!ignoreVersionTracking &&
2578 ConfigurationInterface::isVersionTrackingEnabled())
2579 for(
auto& memberPair : memberMap)
2582 if(memberPair.second.isScratchVersion())
2585 <<
"Error while activating member Table '"
2586 << nameToTableMap_[memberPair.first]->getTableName()
2587 <<
"-v" << memberPair.second <<
" for Table Group '"
2588 << groupName <<
"(" << groupKey
2589 <<
")'. When version tracking is enabled, Scratch "
2591 <<
" are not allowed! Please only use unique, "
2593 "versions when version tracking is enabled."
2599 for(
auto& memberPair : memberMap)
2601 if(threadsLaunched >= numOfThreads)
2604 foundThreadIndex = -1;
2605 while(foundThreadIndex == -1)
2607 for(
int i = 0; i < numOfThreads; ++i)
2608 if(*(threadDone[i]))
2610 foundThreadIndex = i;
2613 if(foundThreadIndex == -1)
2615 __GEN_COUTT__ <<
"Waiting for available thread..."
2620 threadsLaunched = numOfThreads - 1;
2622 __GEN_COUTT__ <<
"Starting init table thread... "
2623 << foundThreadIndex <<
" for " << memberPair.first
2625 *(threadDone[foundThreadIndex]) =
false;
2630 std::string* theThreadErrors,
2631 std::mutex* theThreadMutex,
2632 std::shared_ptr<std::atomic<bool>> theThreadDone) {
2633 ConfigurationManager::initTableThread(cfgMgr,
2640 nameToTableMap_.at(memberPair.first),
2643 threadDone[foundThreadIndex])
2653 foundThreadIndex = -1;
2654 for(
int i = 0; i < numOfThreads; ++i)
2655 if(!*(threadDone[i]))
2657 foundThreadIndex = i;
2660 if(foundThreadIndex != -1)
2662 __GEN_COUTT__ <<
"Waiting for thread to finish... "
2663 << foundThreadIndex << __E__;
2666 }
while(foundThreadIndex != -1);
2667 __GEN_COUTT__ <<
"All threads done." << __E__;
2669 if(threadErrors !=
"")
2671 __SS__ <<
"Error identified in threads during init of table "
2673 << threadErrors << __E__;
2674 __GEN_COUTT__ <<
"\n" << ss.str() << __E__;
2675 if(accumulatedWarnings)
2676 *accumulatedWarnings += ss.str();
2686 progressBar->
step();
2695 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
2701 theContextTableGroup_ = groupName;
2702 theContextTableGroupKey_ =
2703 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2705 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
2710 theBackboneTableGroup_ = groupName;
2711 theBackboneTableGroupKey_ =
2712 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2714 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
2720 theIterateTableGroup_ = groupName;
2721 theIterateTableGroupKey_ =
2722 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2729 theConfigurationTableGroup_ = groupName;
2730 theConfigurationTableGroupKey_ =
2731 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2736 progressBar->
step();
2740 <<
"------------------------------------- init complete \t [for all "
2750 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2756 catch(
const std::runtime_error& e)
2758 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
2759 << groupKey <<
")': \n"
2760 << e.what() << __E__;
2762 if(accumulatedWarnings)
2763 *accumulatedWarnings += ss.str();
2769 __SS__ <<
"An unknown error occurred while loading table group '"
2770 << groupName <<
"(" << groupKey <<
")." << __E__;
2775 catch(
const std::exception& e)
2777 ss <<
"Exception message: " << e.what();
2782 if(accumulatedWarnings)
2783 *accumulatedWarnings += ss.str();
2789 __GEN_COUTT__ <<
"loadTableGroup() complete for Table Group '" << groupName <<
"("
2790 << groupKey <<
")'." << __E__;
2792 std::make_pair(std::make_pair(groupName,
TableGroupKey(groupKey)), memberMap);
2797 __GEN_COUTT__ <<
"loadTableGroup() failed." << __E__;
2800 lastFailedGroupLoad_[ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN] =
2801 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2807 catch(
const std::runtime_error& e)
2809 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
2810 << groupKey <<
")': \n"
2811 << e.what() << __E__;
2813 if(accumulatedWarnings)
2814 *accumulatedWarnings += ss.str();
2820 __SS__ <<
"An unknown error occurred while loading table group '" << groupName
2821 <<
"(" << groupKey <<
")." << __E__;
2826 catch(
const std::exception& e)
2828 ss <<
"Exception message: " << e.what();
2835 if(accumulatedWarnings)
2836 *accumulatedWarnings += ss.str();
2848 const std::map<std::string, TableVersion>& memberMap,
2849 const std::string& groupName ,
2852 bool ignoreVersionTracking )
2857 ConfigurationManager::GroupType groupType =
getTypeOfGroup(memberMap);
2861 __GEN_COUT__ <<
"------------------------------------- cacheCopy init start "
2863 "plug-ins in member map"
2868 std::string groupToDeactivate =
2869 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2870 ? theContextTableGroup_
2871 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
2872 ? theBackboneTableGroup_
2873 : (groupType == ConfigurationManager::GroupType::ITERATE_TYPE
2874 ? theIterateTableGroup_
2875 : theConfigurationTableGroup_));
2878 if(groupToDeactivate !=
"")
2895 for(
auto& memberPair : memberMap)
2897 __GEN_COUTT__ <<
"Copying " << memberPair.first <<
"-v" << memberPair.second
2901 if(nameToTableMap_.find(memberPair.first) == nameToTableMap_.end())
2904 theInterface_->get(table,
2911 nameToTableMap_[memberPair.first] = table;
2913 nameToTableMap_.at(memberPair.first)
2915 ->getView(memberPair.second),
2918 ->getView(memberPair.second)
2926 __GEN_COUTT__ <<
"Done with member copy loop." << __E__;
2932 std::string accumulatedWarnings;
2933 const int numOfThreads = StringMacros::getConcurrencyCount() / 2;
2934 __GEN_COUT__ <<
" getConcurrencyCount " << StringMacros::getConcurrencyCount()
2935 <<
" ==> " << numOfThreads <<
" threads for initializing tables."
2937 if(groupType != ConfigurationManager::GroupType::CONFIGURATION_TYPE ||
2940 for(
auto& memberPair : memberMap)
2943 if(!ignoreVersionTracking &&
2944 ConfigurationInterface::isVersionTrackingEnabled() &&
2945 memberPair.second.isScratchVersion())
2947 __SS__ <<
"Error while activating member Table '"
2948 << nameToTableMap_[memberPair.first]->getTableName()
2949 <<
"-v" << memberPair.second
2950 <<
" for member map. When version tracking is enabled, "
2952 <<
" are not allowed! Please only use unique, persistent "
2953 "versions when version tracking is enabled."
2962 nameToTableMap_.at(memberPair.first)->init(
this);
2964 catch(std::runtime_error& e)
2966 __SS__ <<
"Error detected calling " << memberPair.first
2967 <<
".init()!\n\n " << e.what() << __E__;
2968 accumulatedWarnings += ss.str();
2972 __SS__ <<
"Unknown Error detected calling " << memberPair.first
2973 <<
".init()!\n\n " << __E__;
2978 catch(
const std::exception& e)
2980 ss <<
"Exception message: " << e.what();
2985 accumulatedWarnings += ss.str();
2991 int threadsLaunched = 0;
2992 int foundThreadIndex = 0;
2993 std::mutex threadMutex;
2994 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
2995 for(
int i = 0; i < numOfThreads; ++i)
2996 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
2998 if(!ignoreVersionTracking &&
2999 ConfigurationInterface::isVersionTrackingEnabled())
3000 for(
auto& memberPair : memberMap)
3003 if(memberPair.second.isScratchVersion())
3006 <<
"Error while activating member Table '"
3007 << nameToTableMap_[memberPair.first]->getTableName()
3008 <<
"-v" << memberPair.second
3009 <<
" for member map. When version tracking is enabled, "
3011 <<
" are not allowed! Please only use unique, persistent "
3012 "versions when version tracking is enabled."
3018 for(
auto& memberPair : memberMap)
3020 if(threadsLaunched >= numOfThreads)
3023 foundThreadIndex = -1;
3024 while(foundThreadIndex == -1)
3026 for(
int i = 0; i < numOfThreads; ++i)
3027 if(*(threadDone[i]))
3029 foundThreadIndex = i;
3032 if(foundThreadIndex == -1)
3034 __GEN_COUTT__ <<
"Waiting for available thread..."
3039 threadsLaunched = numOfThreads - 1;
3041 __GEN_COUTT__ <<
"Starting init table thread... " << foundThreadIndex
3042 <<
" for " << memberPair.first << __E__;
3043 *(threadDone[foundThreadIndex]) =
false;
3048 std::string* theAccumulatedWarnings,
3049 std::mutex* theThreadMutex,
3050 std::shared_ptr<std::atomic<bool>> theThreadDone) {
3051 ConfigurationManager::initTableThread(cfgMgr,
3053 theAccumulatedWarnings,
3058 nameToTableMap_.at(memberPair.first),
3059 &accumulatedWarnings,
3061 threadDone[foundThreadIndex])
3071 foundThreadIndex = -1;
3072 for(
int i = 0; i < numOfThreads; ++i)
3073 if(!*(threadDone[i]))
3075 foundThreadIndex = i;
3078 if(foundThreadIndex != -1)
3080 __GEN_COUTT__ <<
"Waiting for thread to finish... "
3081 << foundThreadIndex << __E__;
3084 }
while(foundThreadIndex != -1);
3088 if(accumulatedWarnings !=
"")
3090 __GEN_COUT__ <<
"Activating the member map after copying cache had the "
3091 "following warnings: "
3092 << accumulatedWarnings << __E__;
3103 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
3109 theContextTableGroup_ = groupName;
3110 theContextTableGroupKey_ =
3111 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3113 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
3118 theBackboneTableGroup_ = groupName;
3119 theBackboneTableGroupKey_ =
3120 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3122 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
3128 theIterateTableGroup_ = groupName;
3129 theIterateTableGroupKey_ =
3130 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3137 theConfigurationTableGroup_ = groupName;
3138 theConfigurationTableGroupKey_ =
3139 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
3144 __GEN_COUT__ <<
"------------------------------------- cacheCopy init "
3145 "complete \t [for all "
3146 "plug-ins in member map"
3149 __GEN_COUTT__ <<
"Completed cache copy." << __E__;
3152 make_pair(make_pair(groupName,
TableGroupKey(groupKey)), memberMap);
3156 __GEN_COUT__ <<
"Unknown failure in cache copy." << __E__;
3159 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
3166 ConfigurationManager::getGroupOfLoadedTable(
const std::string& tableName)
const
3168 for(
const auto& loadedGroup : lastGroupLoad_)
3169 if(loadedGroup.second.second.find(tableName) != loadedGroup.second.second.end())
3170 return loadedGroup.second.first;
3171 return std::make_pair(
"",
TableGroupKey(TableGroupKey::INVALID));
3178 std::string* threadErrors,
3179 std::mutex* threadMutex,
3180 std::shared_ptr<std::atomic<bool>> threadDone)
3183 __COUTT__ <<
"Thread init of " << table->
getTableName() <<
"-v"
3184 << table->
getViewVersion() <<
" threadErrors=" << (threadErrors ? 1 : 0)
3192 table->init(cfgMgr);
3194 catch(std::runtime_error& e)
3196 __SS__ <<
"Error detected calling " << table->
getTableName() <<
".init()!\n\n "
3197 << e.what() << __E__;
3201 std::lock_guard<std::mutex> lock(*threadMutex);
3202 *threadErrors += ss.str();
3212 __SS__ <<
"Unknown Error detected calling " << table->
getTableName()
3213 <<
".init()!\n\n " << __E__;
3218 catch(
const std::exception& e)
3220 ss <<
"Exception message: " << e.what();
3230 std::lock_guard<std::mutex> lock(*threadMutex);
3231 *threadErrors += ss.str();
3237 *(threadDone) =
true;
3241 __SS__ <<
"Error occurred initializing table '" << table->
getTableName() <<
"-v"
3247 catch(
const std::runtime_error& e)
3249 ss <<
" Run-time Exception message: " << e.what();
3251 catch(
const std::exception& e)
3253 ss <<
" Exception message: " << e.what();
3255 __COUT_WARN__ << ss.str() << __E__;
3259 std::lock_guard<std::mutex> lock(*threadMutex);
3260 *threadErrors += ss.str();
3263 *(threadDone) =
true;
3268 void ConfigurationManager::fillTableThread(
3270 std::map<std::string, ots::TableBase*>* nameToTableMap,
3272 std::string tableName,
3274 std::string* threadErrors,
3275 std::mutex* threadMutex,
3276 std::shared_ptr<std::atomic<bool>> threadDone)
3279 __COUTT__ <<
"Thread fill of " << tableName <<
"-v" << version << __E__;
3289 std::string getError =
"";
3294 theInterface->get(table,
3303 catch(
const std::runtime_error& e)
3305 __SS__ <<
"Failed to load member table '" << tableName <<
"-v" << version
3306 <<
"' - here is the error: \n\n"
3307 << e.what() << __E__;
3309 ss <<
"\nIf the table '" << tableName
3310 <<
"' should not exist, then please remove it from the group. If it "
3311 "should exist, then it "
3312 <<
"seems to have a problem; use the Table Editor to fix the table "
3314 "edit the table content to match the table definition."
3319 getError = ss.str();
3325 __SS__ <<
"Failed to load member table '" << tableName <<
"-v" << version
3326 <<
"' due to unknown error!" << __E__;
3331 catch(
const std::exception& e)
3333 ss <<
"Exception message: " << e.what();
3338 ss <<
"\nIf the table '" << tableName
3339 <<
"' should not exist, then please remove it from the group. If it "
3340 "should exist, then it "
3341 <<
"seems to have a problem; use the Table Editor to fix the table "
3343 "edit the table content to match the table definition."
3348 getError = ss.str();
3354 __COUTV__(getError);
3356 __COUT_TYPE__(TLVL_TRACE + 1)
3357 << __COUT_HDR__ <<
"Checking ptr.. " << (table ?
"GOOD" :
"BAD") << __E__;
3360 __SS__ <<
"Null pointer returned for table '" << tableName
3361 <<
".' Was the table info deleted?" << __E__;
3362 __COUT_ERR__ << ss.str();
3364 std::lock_guard<std::mutex> lock(*threadMutex);
3365 nameToTableMap->erase(tableName);
3369 *threadErrors += ss.str();
3370 *(threadDone) =
true;
3378 std::lock_guard<std::mutex> lock(*threadMutex);
3379 (*nameToTableMap)[tableName] = table;
3382 if(nameToTableMap->at(tableName)->getViewP())
3384 __COUT_TYPE__(TLVL_TRACE + 1)
3386 <<
"Activated version: " << nameToTableMap->at(tableName)->getViewVersion()
3389 if(threadErrors && getError !=
"")
3391 __SS__ <<
"Error caught during '" << tableName <<
"' table retrieval: \n"
3392 << getError << __E__;
3393 __COUT_ERR__ << ss.str();
3394 std::lock_guard<std::mutex> lock(*threadMutex);
3395 *threadErrors += ss.str();
3400 __SS__ << tableName <<
": View version not activated properly!";
3404 __COUTT__ <<
"end Thread fill of " << tableName <<
"-v" << version << __E__;
3405 *(threadDone) =
true;
3407 catch(
const std::runtime_error& e)
3409 __SS__ <<
"Error occurred filling table '" << tableName <<
"-v" << version
3410 <<
"': " << e.what() << __E__;
3411 __COUT_ERR__ << ss.str();
3415 std::lock_guard<std::mutex> lock(*threadMutex);
3416 *threadErrors += ss.str();
3419 *(threadDone) =
true;
3423 __SS__ <<
"Unknwon error occurred filling table '" << tableName <<
"-v" << version
3429 catch(
const std::exception& e)
3431 ss <<
"Exception message: " << e.what();
3436 __COUT_ERR__ << ss.str();
3440 std::lock_guard<std::mutex> lock(*threadMutex);
3441 *threadErrors += ss.str();
3444 *(threadDone) =
true;
3453 const std::string& tableName,
3455 bool looseColumnMatching ,
3456 std::string* accumulatedErrors ,
3458 bool touchLastAccessTime )
3460 auto it = nameToTableMap_.find(tableName);
3461 if(it == nameToTableMap_.end())
3463 __SS__ <<
"\nCan not find table named '" << tableName
3464 <<
"'\n\n\n\nYou need to load the table before it can be used."
3465 <<
"It probably is missing from the member list of the Table "
3466 "Group that was loaded?\n\n\n\n\n"
3474 table->setActiveView(version);
3478 std::stringstream jsonSs;
3479 table->getViewP()->printJSON(jsonSs);
3480 table->getViewP()->doGetSourceRawData(
true);
3486 theInterface_->get(table,
3493 looseColumnMatching,
3496 touchLastAccessTime);
3507 std::map<std::string, std::pair<std::string, TableGroupKey>>
3511 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
3513 retMap[ConfigurationManager::GROUP_TYPE_NAME_CONTEXT] =
3514 std::pair<std::string, TableGroupKey>(
3515 theContextTableGroup_,
3516 theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
3517 retMap[ConfigurationManager::GROUP_TYPE_NAME_BACKBONE] =
3518 std::pair<std::string, TableGroupKey>(
3519 theBackboneTableGroup_,
3520 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
3521 retMap[ConfigurationManager::GROUP_TYPE_NAME_ITERATE] =
3522 std::pair<std::string, TableGroupKey>(
3523 theIterateTableGroup_,
3524 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
3525 retMap[ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION] =
3526 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_,
3527 theConfigurationTableGroupKey_
3528 ? *theConfigurationTableGroupKey_
3534 const std::string& ConfigurationManager::getActiveGroupName(
3535 const ConfigurationManager::GroupType& type)
const
3537 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
3538 return theConfigurationTableGroup_;
3539 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
3540 return theContextTableGroup_;
3541 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
3542 return theBackboneTableGroup_;
3543 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
3544 return theIterateTableGroup_;
3546 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
3552 const ConfigurationManager::GroupType& type)
const
3554 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
3555 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_
3557 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
3558 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
3559 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
3560 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
3561 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
3562 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
3564 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
3570 const std::string& contextUID,
const std::string& )
const
3578 const std::string& contextUID,
const std::string& applicationUID)
const
3581 contextUID +
"/LinkToApplicationTable/" + applicationUID);
3586 const std::string& contextUID,
const std::string& applicationUID)
const
3589 contextUID +
"/LinkToApplicationTable/" + applicationUID +
3590 "/LinkToSupervisorTable");
3597 auto contextChildren =
3600 for(
const auto& contextChild : contextChildren)
3602 auto appChildren = contextChild.second.getNode(
"LinkToApplicationTable")
3604 for(
const auto& appChild : appChildren)
3606 if(appChild.second.getNode(
"Class").getValue() ==
3607 "ots::GatewaySupervisor")
3608 return appChild.second;
3611 __SS__ <<
"No Gateway Supervisor node found!" << __E__;
3617 bool doNotThrowOnBrokenUIDLinks)
const
3622 if(nodeString.length() < 1)
3624 __SS__ << (
"Invalid empty node name") << __E__;
3629 size_t startingIndex = 0;
3630 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
3632 size_t endingIndex = nodeString.find(
'/', startingIndex);
3633 if(endingIndex == std::string::npos)
3634 endingIndex = nodeString.length();
3636 std::string nodeName = nodeString.substr(startingIndex, endingIndex - startingIndex);
3638 if(nodeName.length() < 1)
3648 std::string childPath =
3649 (endingIndex >= nodeString.length() ?
"" : nodeString.substr(endingIndex));
3655 if(childPath.length() > 1)
3656 return configTree.
getNode(childPath, doNotThrowOnBrokenUIDLinks);
3662 std::map<std::string, ConfigurationTree> ConfigurationManager::getNodes(
3663 const std::string& nodeString)
const
3675 std::string path =
"/";
3686 std::map<std::string, TableVersion>* memberMap,
3687 std::string* accumulatedTreeErrors)
const
3689 std::vector<std::pair<std::string, ConfigurationTree>> retVector;
3694 bool filtering = memberMap && memberMap->size();
3697 for(
auto& tablePair : nameToTableMap_)
3702 if(memberMap->find(tablePair.first) == memberMap->end())
3708 if(!tablePair.second->isActive())
3710 __SS__ <<
"Get Children with member map requires a child '"
3711 << tablePair.first <<
"' that is not active!" << __E__;
3715 catch(
const std::runtime_error& e)
3717 if(accumulatedTreeErrors)
3719 *accumulatedTreeErrors += e.what();
3720 __GEN_COUT_ERR__ <<
"Skipping " << tablePair.first
3721 <<
" since the table "
3730 if(!tablePair.second->isActive())
3734 if(accumulatedTreeErrors)
3738 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren =
3740 for(
auto& newNodeChild : newNodeChildren)
3742 if(newNodeChild.second.getTableName() ==
3743 ConfigurationManager::DESKTOP_ICON_TABLE_NAME &&
3744 !newNodeChild.second.isEnabled())
3747 std::vector<std::pair<std::string, ConfigurationTree>>
3748 twoDeepChildren = newNodeChild.second.getChildren();
3750 for(
auto& twoDeepChild : twoDeepChildren)
3755 if(twoDeepChild.second.isLinkNode() &&
3756 twoDeepChild.second.isDisconnected() &&
3757 twoDeepChild.second.getDisconnectedTableName() !=
3758 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
3760 __SS__ <<
"At node '" + tablePair.first +
3761 "' with entry UID '" + newNodeChild.first +
3762 "' there is a disconnected child node at link "
3764 twoDeepChild.first +
"'" +
3765 " that points to table named '" +
3766 twoDeepChild.second.getDisconnectedTableName() +
3768 *accumulatedTreeErrors += ss.str();
3773 catch(std::runtime_error& e)
3775 __SS__ <<
"At node '" + tablePair.first +
3776 "' error detected descending through children:\n" +
3778 *accumulatedTreeErrors += ss.str();
3782 retVector.push_back(
3783 std::pair<std::string, ConfigurationTree>(tablePair.first, newNode));
3797 std::string* accumulatedTreeErrors)
const
3804 bool filtering = memberMap && memberMap->size();
3807 for(
auto& tablePair : nameToTableMap_)
3812 if(memberMap->find(tablePair.first) == memberMap->end())
3818 if(!tablePair.second->isActive())
3820 __SS__ <<
"Get Children with member map requires a child '"
3821 << tablePair.first <<
"' that is not active!" << __E__;
3825 catch(
const std::runtime_error& e)
3827 if(accumulatedTreeErrors)
3829 *accumulatedTreeErrors += e.what();
3830 __GEN_COUT_ERR__ <<
"Skipping " << tablePair.first
3831 <<
" since the table "
3840 if(!tablePair.second->isActive())
3844 if(accumulatedTreeErrors)
3848 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren =
3850 for(
auto& newNodeChild : newNodeChildren)
3852 if(newNodeChild.second.getTableName() ==
3853 ConfigurationManager::DESKTOP_ICON_TABLE_NAME &&
3854 !newNodeChild.second.isEnabled())
3857 std::vector<std::pair<std::string, ConfigurationTree>>
3858 twoDeepChildren = newNodeChild.second.getChildren();
3860 for(
auto& twoDeepChild : twoDeepChildren)
3865 if(twoDeepChild.second.isLinkNode() &&
3866 twoDeepChild.second.isDisconnected() &&
3867 twoDeepChild.second.getDisconnectedTableName() !=
3868 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
3870 __SS__ <<
"At node '" + tablePair.first +
3871 "' with entry UID '" + newNodeChild.first +
3872 "' there is a disconnected child node at link "
3874 twoDeepChild.first +
"'" +
3875 " that points to table named '" +
3876 twoDeepChild.second.getDisconnectedTableName() +
3878 *accumulatedTreeErrors += ss.str();
3883 catch(std::runtime_error& e)
3885 __SS__ <<
"At node '" + tablePair.first +
3886 "' error detected descending through children:\n" +
3888 *accumulatedTreeErrors += ss.str();
3893 std::pair<std::string, ConfigurationTree>(tablePair.first, newNode));
3906 std::map<std::string, TableBase*>::const_iterator it;
3907 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
3909 __SS__ <<
"Cannot find table named '" << tableName
3910 <<
"' - you need to load the table before it can be used.";
3912 if(nameToTableMap_.size() == 0)
3913 ss <<
"\n\nAll tables are missing. Your configuration database connection "
3914 "may have been interrupted. Did an ssh tunnel disconnect?"
3918 if(tableName == XDAQ_CONTEXT_TABLE_NAME)
3919 ss <<
"\n\nThe XDAQ Context Table is essential to the operation of ots. "
3920 "Without it, ots can not determine which applications are running "
3921 "on which hosts. Make sure that you have loaded a valid "
3922 "Configuration Context group that contains the XDAQ Context "
3926 ss <<
" It is likely missing from the member list of the Table "
3927 "Group that was loaded."
3930 ss <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
3941 TLOG_DEBUG(55) <<
"Table " << tableName <<
" is at "
3942 <<
static_cast<void*
>(it->second);
3952 if(!theBackboneTableGroupKey_)
3954 __GEN_COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently."
3960 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
3962 return *theBackboneTableGroupKey_;
3979 std::string systemAlias,
ProgressBar* progressBar)
3989 progressBar->
step();
3991 if(systemAlias.find(
"GROUP:") == 0)
3994 progressBar->
step();
3996 unsigned int i = strlen(
"GROUP:");
3997 unsigned int j = systemAlias.find(
':', i);
4000 progressBar->
step();
4002 return std::pair<std::string, TableGroupKey>(
4003 systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
4005 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
4011 progressBar->
step();
4017 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).
getNode(systemAlias);
4020 progressBar->
step();
4022 return std::pair<std::string, TableGroupKey>(
4033 progressBar->
step();
4035 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
4041 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
4047 ConfigurationManager::LoadGroupType::
4048 ONLY_BACKBONE_TYPE);
4051 std::map<std::string ,
4055 std::vector<std::pair<std::string, ConfigurationTree>> entries =
4057 for(
auto& entryPair : entries)
4059 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(
4060 entryPair.second.getNode(
"GroupName").getValueAsString(),
4061 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
4077 for(
auto& tableAliasMap : tableAliasMap)
4078 for(
auto& tableAliasPair : tableAliasMap.second)
4079 if(tableAliasPair.first == tableAliasNeedle)
4080 retSet.insert(std::pair<std::string ,
4082 tableAliasMap.first, tableAliasPair.second));
4090 std::map<std::string ,
4096 std::map<std::string ,
4101 std::string versionAliasesTableName =
4102 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
4103 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
4105 __SS__ <<
"Active version of VersionAliases missing!"
4106 <<
" Make sure you have a valid active Backbone Group." << __E__;
4107 __GEN_COUT_WARN__ <<
"\n" << ss.str();
4113 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
4119 std::string tableName, versionAlias;
4120 for(
auto& aliasNodePair : aliasNodePairs)
4122 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
4123 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
4125 if(retMap.find(tableName) != retMap.end() &&
4126 retMap[tableName].find(versionAlias) != retMap[tableName].end())
4131 if(versionAlias == SUBSYSTEM_COMMON_CONTEXT_VERSION_ALIAS ||
4132 versionAlias == SUBSYSTEM_COMMON_CONTEXT_OVERRIDE_VERSION_ALIAS)
4134 if(fixedContextMemberNames_.find(tableName) == fixedContextMemberNames_.end())
4136 __SS__ <<
"Version alias '" << versionAlias <<
"' for table '"
4137 << tableName <<
"' is invalid! '" << versionAlias
4138 <<
"' aliases may only reference Context group tables. "
4139 <<
"Valid Context group tables are: "
4146 retMap[tableName][versionAlias] =
4147 TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
4160 const std::map<std::string /*tableName*/, TableVersion>& mergeInTables,
4161 const std::map<std::string /*tableName*/, TableVersion>& overrideTables)
4163 __GEN_COUT__ <<
"Applying Context Common Tables..." << __E__;
4165 if(overrideTables.size())
4167 __GEN_COUT__ <<
"Context overriding tables: "
4170 std::map<std::pair<std::string, std::string>, std::string> uidConversionMap;
4171 std::map<std::pair<std::string, std::pair<std::string, std::string>>, std::string>
4172 groupidConversionMap;
4174 for(
const auto& overridePair : overrideTables)
4176 if(nameToTableMap_.find(overridePair.first) == nameToTableMap_.end())
4178 __GEN_COUT__ <<
"Skipping context override of table '"
4179 << overridePair.first <<
"-v" << overridePair.second
4180 <<
"' which is not loaded." << __E__;
4185 nameToTableMap_.at(overridePair.first)->getView().getVersion();
4186 __GEN_COUT__ <<
"Context overriding table '" << overridePair.first <<
"' v"
4187 << activeVersion <<
" with version v" << overridePair.second
4190 std::stringstream mergeReport;
4192 nameToTableMap_.at(overridePair.first)
4199 "context-override-table",
4200 TableBase::MergeApproach::REPLACE,
4202 groupidConversionMap,
4208 nameToTableMap_.at(overridePair.first)->setActiveView(newVersion);
4209 __GEN_COUT__ <<
"Context override applied: '" << overridePair.first
4210 <<
"' resulting version v" << newVersion << __E__;
4214 if(mergeInTables.size())
4216 __GEN_COUT__ <<
"Context merging-in tables: "
4219 std::map<std::pair<std::string, std::string>, std::string> uidConversionMap;
4220 std::map<std::pair<std::string, std::pair<std::string, std::string>>, std::string>
4221 groupidConversionMap;
4223 for(
const auto& mergeInPair : mergeInTables)
4225 if(overrideTables.find(mergeInPair.first) != overrideTables.end())
4228 if(nameToTableMap_.find(mergeInPair.first) == nameToTableMap_.end())
4230 __GEN_COUT__ <<
"Skipping context merge-in of table '"
4231 << mergeInPair.first <<
"-v" << mergeInPair.second
4232 <<
"' which is not loaded." << __E__;
4237 nameToTableMap_.at(mergeInPair.first)->getView().getVersion();
4238 __GEN_COUT__ <<
"Context merging-in table '" << mergeInPair.first <<
"' v"
4239 << activeVersion <<
" with version v" << mergeInPair.second
4242 std::stringstream mergeReport;
4244 nameToTableMap_.at(mergeInPair.first)
4251 "context-merge-in-table",
4252 TableBase::MergeApproach::SKIP,
4254 groupidConversionMap,
4260 nameToTableMap_.at(mergeInPair.first)->setActiveView(newVersion);
4261 __GEN_COUT__ <<
"Context merge-in applied: '" << mergeInPair.first
4262 <<
"' resulting version v" << newVersion << __E__;
4266 __GEN_COUT__ <<
"Done applying Context Common Tables." << __E__;
4273 std::map<std::string, TableVersion> retMap;
4274 for(
auto& table : nameToTableMap_)
4276 __GEN_COUTS__(2) << table.first << __E__;
4279 if(table.second && table.second->
isActive())
4281 __GEN_COUTS__(2) << table.first <<
"_v" << table.second->
getViewVersion()
4283 retMap.insert(std::pair<std::string, TableVersion>(
4317 if(theConfigurationTableGroupKey_)
4319 if(*theConfigurationTableGroupKey_ != key)
4322 return theConfigurationTableGroupKey_;
4324 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
4328 const std::set<std::string>& ConfigurationManager::getActiveContextMemberNames()
4331 contextMemberNames_ = ConfigurationManager::fixedContextMemberNames_;
4334 nameToTableMap_.find(ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE);
4335 if(it == nameToTableMap_.end())
4336 return contextMemberNames_;
4338 if(!it->second->isActive())
4340 contextMemberNames_.emplace(
4341 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE);
4343 return contextMemberNames_;
4347 const std::set<std::string>& ConfigurationManager::getFixedContextMemberNames()
4349 return ConfigurationManager::fixedContextMemberNames_;
4353 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
4355 return ConfigurationManager::backboneMemberNames_;
4359 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
4361 return ConfigurationManager::iterateMemberNames_;
4365 const std::set<std::string>& ConfigurationManager::getConfigurationMemberNames(
void)
4367 configurationMemberNames_.clear();
4371 for(
auto& tablePair : activeTables)
4374 ConfigurationManager::fixedContextMemberNames_.find(tablePair.first) ==
4375 ConfigurationManager::fixedContextMemberNames_.end() &&
4376 tablePair.first != ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE &&
4379 ConfigurationManager::backboneMemberNames_.find(tablePair.first) ==
4380 ConfigurationManager::backboneMemberNames_.end() &&
4383 ConfigurationManager::iterateMemberNames_.find(tablePair.first) ==
4384 ConfigurationManager::iterateMemberNames_.end())
4387 configurationMemberNames_.emplace(tablePair.first);
4390 return configurationMemberNames_;
4394 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
4396 __GEN_COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
4401 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
4403 if(pset.get_names().size() == 0)
4405 __GEN_SS__ <<
"Empty fcl configuration parameter set found! File: " << fhiclPath
4437 theInterface_->get(table,
4438 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
4444 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
4447 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4450 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4454 auto colMap = view->getColumnNamesMap();
4456 view->
setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
4457 view->
setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
4458 view->
setValue(
"MacroMakerFEContextApps", 0, colMap[
"LinkToApplicationGroupID"]);
4459 view->
setValue(
"1", 0, colMap[TableViewColumnInfo::COL_NAME_STATUS]);
4461 __GEN_COUT__ <<
"Done adding context record..." << __E__;
4464 std::stringstream ss;
4466 __GEN_COUTT__ <<
"view->print()" << ss.str() << __E__;
4476 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
4482 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
4485 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4488 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4492 auto colMap = view->getColumnNamesMap();
4494 view->
setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
4495 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
4496 view->
setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
4497 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
4498 view->
setValue(
"1", 0, colMap[TableViewColumnInfo::COL_NAME_STATUS]);
4499 view->
setValue(__ENV__(
"FE_SUPERVISOR_ID"), 0, colMap[
"Id"]);
4501 __GEN_COUT__ <<
"Done adding application record..." << __E__;
4504 std::stringstream ss;
4506 __GEN_COUTT__ <<
"view->print()" << ss.str() << __E__;
4513 theInterface_->get(table,
4514 "FESupervisorTable",
4520 nameToTableMap_[
"FESupervisorTable"] = table;
4523 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4526 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
4530 auto colMap = view->getColumnNamesMap();
4532 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
4533 view->
setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
4535 "MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
4537 __GEN_COUT__ <<
"Done adding supervisor record..." << __E__;
4540 std::stringstream ss;
4542 __GEN_COUTT__ <<
"view->print()" << ss.str() << __E__;
4547 recursiveInitFromFhiclPSet(
"FEInterfaceTable" ,
4550 "MacroMakerFESupervisorInterfaces" ,
4554 for(
auto& table : nameToTableMap_)
4556 table.second->getViewP()->
init();
4562 __GEN_COUT__ <<
"================================================" << __E__;
4563 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
4564 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
4567 __GEN_COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
4569 __GEN_COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
4571 auto a =
getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
4572 __GEN_COUTV__(a.getValueAsString());
4574 auto b = a.getNode(
"MacroMakerFEContext");
4575 __GEN_COUTV__(b.getValueAsString());
4577 auto c = b.getNode(
"LinkToApplicationTable");
4578 __GEN_COUTV__(c.getValueAsString());
4580 auto d = c.getNode(
"MacroMakerFESupervisor");
4581 __GEN_COUTV__(d.getValueAsString());
4583 auto e = d.getNode(
"LinkToSupervisorTable");
4584 __GEN_COUTV__(e.getValueAsString());
4586 auto f = e.getNode(
"LinkToFEInterfaceTable");
4587 __GEN_COUTV__(f.getValueAsString());
4589 auto z = f.getChildrenNames();
4591 __GEN_COUTV__(z.size());
4592 auto y = f.getChildrenNames(
false ,
true );
4594 __GEN_COUTV__(y.size());
4595 auto x = f.getChildrenNames(
true ,
true );
4597 __GEN_COUTV__(x.size());
4599 auto g = f.getNode(
"dtc0");
4600 __GEN_COUTV__(g.getValueAsString());
4601 auto h = f.getNode(
"interface0");
4602 __GEN_COUTV__(h.getValueAsString());
4605 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
4607 "MacroMakerFEContext/LinkToApplicationTable/"
4608 "MacroMakerFESupervisor/LinkToSupervisorTable")
4609 .
getNode(
"LinkToFEInterfaceTable")
4611 __GEN_COUTV__(fes.size());
4623 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
4624 const fhicl::ParameterSet& pset,
4625 const std::string& recordName,
4626 const std::string& groupName,
4627 const std::string& groupLinkIndex)
4629 __GEN_COUTT__ <<
"recursiveInitFromFhiclPSet() "
4630 <<
"Adding table '" << tableName <<
"' record(s)..." << __E__;
4636 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
4638 __GEN_COUTT__ <<
"Table not found, so making '" << tableName
4639 <<
"' instance..." << __E__;
4640 theInterface_->get(table,
4647 nameToTableMap_[tableName] = table;
4652 __GEN_COUTT__ <<
"Existing table found, so using '" << tableName
4653 <<
"'instance..." << __E__;
4654 table = nameToTableMap_[tableName];
4657 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
4660 __GEN_COUTT__ <<
"Activated version: " << view->getVersion() << __E__;
4663 if(recordName !=
"")
4671 __GEN_COUTTV__(recordName);
4674 unsigned int r = view->
addRow();
4675 auto colMap = view->getColumnNamesMap();
4685 __GEN_COUTT__ <<
"No status column to set for '" << recordName <<
"'"
4691 __GEN_COUTT__ <<
"Setting group ID for group link index '"
4692 << groupLinkIndex <<
"'" << __E__;
4695 __GEN_COUTT__ <<
"Setting group ID for group link index '"
4696 << groupLinkIndex <<
"' at column " << groupIDCol <<
" to '"
4697 << groupName <<
".'" << __E__;
4699 view->
setValue(groupName, r, groupIDCol);
4703 auto names = pset.get_names();
4704 for(
const auto& colName : names)
4706 if(!pset.is_key_to_atom(colName))
4709 auto colIt = colMap.find(colName);
4710 if(colIt == colMap.end())
4712 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName
4713 <<
"' in table '" << tableName <<
"' was not found in columns."
4714 <<
"\n\nHere are the existing column names:\n";
4716 for(
const auto& col : colMap)
4717 ss <<
"\n" << ++i <<
".\t" << col.first;
4722 if(view->getColumnInfo(colIt->second).
isGroupID())
4725 const std::string value = pset.get<std::string>(colName);
4726 __GEN_COUTT__ <<
"Setting '" << recordName <<
"' parameter at column "
4727 << colIt->second <<
", '" << colName <<
"'\t = " << value
4733 for(
const auto& linkName : names)
4735 if(pset.is_key_to_atom(linkName))
4738 __GEN_COUTTV__(linkName);
4741 unsigned int c = linkName.size() - 1;
4743 if(linkName[c] ==
'_')
4748 __SS__ <<
"Illegal link name '" << linkName
4749 <<
"' found. The format must be <Column name>_<Target table "
4750 "name>,.. for example '"
4751 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'"
4755 std::string colName = linkName.substr(0, c);
4756 __GEN_COUTTV__(colName);
4758 auto colIt = colMap.find(colName);
4759 if(colIt == colMap.end())
4761 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName
4762 <<
"' in table '" << tableName <<
"' was not found in columns."
4763 <<
"\n\nHere are the existing column names:\n";
4765 for(
const auto& col : colMap)
4766 ss <<
"\n" << i <<
".\t" << col.first << __E__;
4771 std::pair<
unsigned int ,
unsigned int >
4774 view->
getChildLink(colIt->second, isGroupLink, linkPair);
4780 std::string linkTableName = linkName.substr(c + 1);
4781 __GEN_COUTTV__(linkTableName);
4783 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
4784 auto linkRecords = linkPset.get_pset_names();
4785 if(!isGroupLink && linkRecords.size() > 1)
4787 __SS__ <<
"A Unique Link can only point to one record. "
4788 <<
"The specified link '" << colName <<
"' of record '"
4789 << recordName <<
"' in table '" << tableName <<
"' has "
4790 << linkRecords.size() <<
" children records specified. "
4795 if(linkRecords.size() == 0)
4797 __GEN_COUTT__ <<
"No child records, so leaving link disconnected."
4802 __GEN_COUTT__ <<
"Setting Link at columns [" << linkPair.first <<
","
4803 << linkPair.second <<
"]" << __E__;
4804 view->
setValue(linkTableName, r, linkPair.first);
4808 __GEN_COUTT__ <<
"Setting up Unique link to " << linkRecords[0]
4811 view->
setValue(linkRecords[0], r, linkPair.second);
4813 recursiveInitFromFhiclPSet(
4815 linkPset.get<fhicl::ParameterSet>(
4822 std::string childLinkIndex =
4824 std::string groupName = recordName +
"Group";
4826 view->
setValue(groupName, r, linkPair.second);
4828 for(
const auto& groupRecord : linkRecords)
4830 __GEN_COUTT__ <<
"Setting '" << childLinkIndex
4831 <<
"' Group link to '" << groupName <<
"' record '"
4832 << groupRecord <<
"'" << __E__;
4834 recursiveInitFromFhiclPSet(
4836 linkPset.get<fhicl::ParameterSet>(
4846 else if(groupName !=
"")
4850 __GEN_COUTTV__(groupName);
4851 auto psets = pset.get_pset_names();
4852 for(
const auto& ps : psets)
4855 recursiveInitFromFhiclPSet(
4857 pset.get<fhicl::ParameterSet>(ps) ,
4865 __SS__ <<
"Illegal recursive parameters!" << __E__;
4868 __GEN_COUT__ <<
"recursiveInitFromFhiclPSet() "
4869 <<
"Done adding table '" << tableName <<
"' record(s)..." << __E__;
4872 std::stringstream ss;
4874 __GEN_COUTT__ <<
"view->print()" << ss.str() << __E__;
4886 __GEN_COUTS__(11) <<
"Checking if owner '" << ownerContextUID_ <<
"/" << ownerAppUID_
4887 <<
"' is first App in Context:\n"
4890 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
4892 __GEN_COUTTV__(!forceNotFirstInContext_);
4893 return !forceNotFirstInContext_;
4896 __GEN_COUTVS__(10, ownerContextUID_);
4897 __GEN_COUTVS__(10, ownerAppUID_);
4901 auto contextChildren =
4902 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" +
4903 ownerContextUID_ +
"/LinkToApplicationTable")
4906 if(contextChildren.size() == 0)
4909 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
"/" +
4910 ownerContextUID_ +
"/LinkToApplicationTable")
4917 bool isFirstAppInContext =
4918 contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
4920 __GEN_COUTVS__(10, isFirstAppInContext);
4922 return isFirstAppInContext;
4926 __GEN_COUTS__(10) <<
"Exception caught looking for XDAQ Context '"
4927 << ownerContextUID_ <<
"' in tree, so defaulting to 'yes'."
4937 const std::string& otherSubsystemUID,
4938 std::string* userDataPathPtr ,
4939 std::string* hostnamePtr ,
4940 std::string* usernamePtr ,
4941 std::string* fullNamePtr )
4943 __GEN_COUTTV__(otherSubsystemUID);
4946 getNode(ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
4948 std::string userPath = node.
getNode(
"SubsystemUserDataPath").
getValue();
4955 if(!splitPath.size() || splitPath.size() > 2)
4957 __GEN_SS__ <<
"Illegal user data path specified for subsystem '"
4958 << otherSubsystemUID <<
"': " << userPath << __E__;
4961 std::string userDataPath = splitPath[splitPath.size() - 1];
4964 for(
unsigned int i = 0; i < userDataPath.length(); ++i)
4965 if(!((userDataPath[i] >=
'a' && userDataPath[i] <=
'z') ||
4966 (userDataPath[i] >=
'A' && userDataPath[i] <=
'Z') ||
4967 (userDataPath[i] >=
'0' && userDataPath[i] <=
'9') ||
4968 userDataPath[i] ==
'-' || userDataPath[i] ==
'_' || userDataPath[i] ==
'/'))
4970 __GEN_SS__ <<
"Illegal user data path specified (no special characters "
4971 "allowed) for subsystem '"
4972 << otherSubsystemUID <<
"': " << userPath << __E__;
4977 *userDataPathPtr = userDataPath;
4979 std::string username, hostname;
4980 if(splitPath.size() == 2)
4983 std::vector<std::string> userHostSplit =
4985 __GEN_COUTTV__(userHostSplit.size());
4986 if(userHostSplit.size() == 1)
4987 hostname = userHostSplit[0];
4988 else if(userHostSplit.size() == 2)
4990 username = userHostSplit[0];
4991 hostname = userHostSplit[1];
4995 __GEN_SS__ <<
"Illegal remote username/host specified for subsystem '"
4996 << otherSubsystemUID <<
"': " << userPath << __E__;
5000 for(
unsigned int i = 0; userHostSplit.size() == 2 && i < username.length(); ++i)
5001 if(!((username[i] >=
'a' && username[i] <=
'z') ||
5002 (username[i] >=
'A' && username[i] <=
'Z') ||
5003 (username[i] >=
'0' && username[i] <=
'9') || username[i] ==
'-' ||
5004 username[i] ==
'_'))
5006 __GEN_SS__ <<
"Illegal remote username specified for subsystem '"
5007 << otherSubsystemUID <<
"': " << userPath << __E__;
5010 unsigned int ii = 0;
5011 for(
unsigned int i = 0; i < hostname.length(); ++i)
5012 if(!((hostname[i] >=
'a' && hostname[i] <=
'z') ||
5013 (hostname[i] >=
'A' && hostname[i] <=
'Z') ||
5014 (hostname[i] >=
'0' && hostname[i] <=
'9') || hostname[i] ==
'-' ||
5015 hostname[i] ==
'_'))
5017 if(hostname[i] ==
'.' && i > ii + 1)
5024 __GEN_SS__ <<
"Illegal remote hostname '" << hostname
5025 <<
"' specified for subsystem '" << otherSubsystemUID
5026 <<
"': " << userPath << __E__;
5031 else if(splitPath.size() == 1)
5033 __GEN_COUT__ <<
"Local user date path identified." << __E__;
5037 __GEN_SS__ <<
"Illegal user data path specified for subsystem '"
5038 << otherSubsystemUID <<
"': " << userPath << __E__;
5043 *hostnamePtr = hostname;
5045 *usernamePtr = username;
5050 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
5051 ConfigurationManager::getOtherSubsystemActiveTableGroups(
5052 const std::string& otherSubsystemUID,
5053 std::string* userDataPathPtr ,
5054 std::string* hostnamePtr ,
5055 std::string* usernamePtr )
5057 std::map<std::string ,
5061 __GEN_COUTTV__(otherSubsystemUID);
5063 std::string userDataPath;
5064 std::string username, hostname;
5068 __GEN_COUTTV__(userDataPath);
5069 __GEN_COUTTV__(username);
5070 __GEN_COUTTV__(hostname);
5073 *userDataPathPtr = userDataPath;
5075 *hostnamePtr = hostname;
5077 *usernamePtr = username;
5080 std::string filename = userDataPath +
"/ServiceData/ActiveTableGroups.cfg";
5082 std::string cmdResult;
5086 std::string tmpSubsystemFilename =
5088 __GEN_COUTTV__(tmpSubsystemFilename);
5092 (
"rm " + tmpSubsystemFilename +
" 2>/dev/null; scp " + username +
"@" +
5093 hostname +
":" + filename +
" " + tmpSubsystemFilename +
" 2>&1; cat " +
5094 tmpSubsystemFilename +
" 2>&1")
5099 (
"rm " + tmpSubsystemFilename +
" 2>/dev/null; scp " + hostname +
":" +
5100 filename +
" " + tmpSubsystemFilename +
" 2>&1; cat " +
5101 tmpSubsystemFilename +
" 2>&1")
5106 __GEN_COUT__ <<
"Local user date path identified." << __E__;
5110 __GEN_COUTTV__(cmdResult);
5111 if(cmdResult.find(
"Permission denied") != std::string::npos)
5114 <<
"\n\nPermission denied accessing user data path specified for subsystem '"
5115 << otherSubsystemUID <<
"': ";
5117 ss << username <<
"@";
5119 ss << hostname <<
":";
5120 ss << userDataPath << __E__;
5123 else if(cmdResult.find(
"No such file or directory") != std::string::npos)
5125 __GEN_SS__ <<
"\n\nActive tables groups file not found at user data path "
5126 "specified for subsystem '"
5127 << otherSubsystemUID <<
"': ";
5129 ss << username <<
"@";
5131 ss << hostname <<
":";
5132 ss << userDataPath << __E__;
5137 cmdResult, {
'\n'} , {
' ',
'\t'} );
5139 __GEN_COUTTV__(subsystemActiveGroupMap.size());
5143 for(
unsigned int i = 0; i + 1 < subsystemActiveGroupMap.size(); i += 2)
5145 if(subsystemActiveGroupMap[i] ==
"" || subsystemActiveGroupMap[i + 1] ==
"-1")
5148 __GEN_COUTT__ <<
"Loading type of subsystem '" << otherSubsystemUID <<
"' group "
5149 << subsystemActiveGroupMap[i] <<
"("
5150 << subsystemActiveGroupMap[i + 1] <<
")" << __E__;
5166 catch(
const std::runtime_error& e)
5168 __GEN_COUTT__ <<
"Ignoring error loading subsystem '" << otherSubsystemUID
5169 <<
"' group " << subsystemActiveGroupMap[i] <<
"("
5170 << subsystemActiveGroupMap[i + 1] <<
"): " << __E__ << e.what()
5172 groupType = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
5174 retMap[groupType] = std::make_pair(subsystemActiveGroupMap[i],
5184 std::set<std::string >
5187 std::set<std::string> retSet;
5189 __GEN_COUTTV__(otherSubsystemUID);
5191 std::map<std::string ,
5193 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
5198 auto it = retMap.find(
5200 if(it == retMap.end())
5203 <<
"No active Backbone group found in the active groups of remote subsystem '"
5204 << otherSubsystemUID <<
"!'" << __E__;
5207 auto it2 = retMap.find(
5209 if(it2 == retMap.end())
5212 <<
"No active Context group found in the active groups of remote subsystem '"
5213 << otherSubsystemUID <<
"!'" << __E__;
5217 std::string accumulatedWarnings;
5226 &accumulatedWarnings
5228 __GEN_COUTTV__(accumulatedWarnings);
5231 std::vector<std::pair<std::string, ConfigurationTree>> entries =
5234 for(
auto& entry : entries)
5236 if(entry.first.find(
"Context") == std::string::npos &&
5237 entry.first.find(
"Iterat") == std::string::npos)
5238 retSet.emplace(entry.first);
5246 std::set<std::string >
5248 const std::string& otherSubsystemUID,
const std::string& otherSubsystemFsmName)
5250 std::set<std::string> retSet;
5252 std::map<std::string ,
5254 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
5257 auto it = retMap.find(
5259 if(it == retMap.end())
5262 <<
"No active Backbone group found in the active groups of remote subsystem '"
5263 << otherSubsystemUID <<
"!'" << __E__;
5266 auto it2 = retMap.find(
5268 if(it2 == retMap.end())
5271 <<
"No active Context group found in the active groups of remote subsystem '"
5272 << otherSubsystemUID <<
"!'" << __E__;
5276 std::string accumulatedWarnings;
5285 &accumulatedWarnings
5292 &accumulatedWarnings
5294 __GEN_COUTTV__(accumulatedWarnings);
5297 std::vector<std::pair<std::string, ConfigurationTree>> entries =
5302 std::string stateMachineAliasFilter =
"*";
5307 otherGatewayNode.
getNode(
"LinkToStateMachineTable")
5308 .
getNode(otherSubsystemFsmName +
"/SystemAliasFilter");
5310 stateMachineAliasFilter = fsmFilterNode.
getValue<std::string>();
5312 __GEN_COUT_INFO__ <<
"FSM has no SystemAliasFilter value." << __E__;
5314 catch(std::runtime_error& e)
5316 __COUT__ <<
"Ignoring unsetup SystemAliasFilter value: " << e.what() << __E__;
5320 __COUT__ <<
"Ignoring unsetup SystemAliasFilter value." << __E__;
5323 __COUT__ <<
"Applying alias filter for other user_data path FSM '"
5324 << otherSubsystemFsmName
5325 <<
"' and stateMachineAliasFilter = " << stateMachineAliasFilter << __E__;
5332 stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
5333 std::vector<std::string> filterArr;
5340 while((f = stateMachineAliasFilter.find(
'*', i)) != std::string::npos)
5342 tmp = stateMachineAliasFilter.substr(i, f - i);
5344 filterArr.push_back(tmp);
5345 __COUTS__(20) << filterArr[filterArr.size() - 1] <<
" " << i <<
" of "
5346 << stateMachineAliasFilter.size() << __E__;
5348 if(i <= stateMachineAliasFilter.size())
5350 tmp = stateMachineAliasFilter.substr(i);
5351 filterArr.push_back(tmp);
5352 __COUTS__(20) << filterArr[filterArr.size() - 1] <<
" last." << __E__;
5357 for(
auto& aliasMapPair : entries)
5359 __COUTS__(20) <<
"aliasMapPair.first: " << aliasMapPair.first << __E__;
5363 if(filterArr.size() == 1)
5365 if(filterArr[0] !=
"" && filterArr[0] !=
"*" &&
5366 aliasMapPair.first != filterArr[0])
5367 filterMatch =
false;
5372 for(f = 0; f < filterArr.size(); ++f)
5374 if(!filterArr[f].size())
5379 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
5381 filterMatch =
false;
5385 else if(f == filterArr.size() - 1)
5387 if(aliasMapPair.first.rfind(filterArr[f]) !=
5388 aliasMapPair.first.size() - filterArr[f].size())
5390 filterMatch =
false;
5394 else if((i = aliasMapPair.first.find(filterArr[f])) ==
5397 filterMatch =
false;
5404 filterMatch = !filterMatch;
5406 __COUTS__(20) <<
"filterMatch=" << filterMatch << __E__;
5411 retSet.emplace(aliasMapPair.first);
5423 const std::string& otherSubsystemUID,
5424 const std::string& configAlias,
5425 std::pair<std::string, TableGroupKey>& groupTranslation,
5426 std::string& groupComment,
5427 std::string& groupAuthor,
5428 std::string& groupCreationTime)
5430 __GEN_COUTV__(otherSubsystemUID);
5432 std::map<std::string ,
5434 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
5437 auto it = retMap.find(
5439 if(it == retMap.end())
5442 <<
"No active Backbone group found in the active groups of remote subsystem '"
5443 << otherSubsystemUID <<
"!'" << __E__;
5446 auto it2 = retMap.find(
5448 if(it2 == retMap.end())
5451 <<
"No active Context group found in the active groups of remote subsystem '"
5452 << otherSubsystemUID <<
"!'" << __E__;
5456 std::string accumulatedWarnings;
5465 &accumulatedWarnings
5467 __GEN_COUTTV__(accumulatedWarnings);
5474 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).
getNode(configAlias);
5476 groupTranslation = std::pair<std::string, TableGroupKey>(
5479 __COUT__ <<
"Found " << configAlias <<
" translates to " << groupTranslation.first
5480 <<
"(" << groupTranslation.second <<
")" << __E__;
5486 groupTranslation.second,
5490 &accumulatedWarnings,
5498 __COUT_WARN__ <<
"Failed to load group metadata." << __E__;
5500 __COUT__ <<
"Found " << configAlias <<
" author: " << groupAuthor
5501 <<
", createTime: " << groupCreationTime <<
", comment: " << groupComment
5506 __GEN_SS__ <<
"Did not find the Configuration Alias '" << configAlias
5507 <<
"' in the active Backbone group of remote subsystem '"
5508 << otherSubsystemUID <<
"!'" << __E__;
5516 TableBase* ConfigurationManager::getDesktopIconTable(
void)
5518 if(nameToTableMap_.find(DESKTOP_ICON_TABLE_NAME) == nameToTableMap_.end())
5520 __SS__ <<
"Desktop icon table not found!" << __E__;
5525 return nameToTableMap_.at(DESKTOP_ICON_TABLE_NAME);
5529 void ConfigurationManager::saveGroupNameAndKey(
5530 const std::pair<std::string /*group name*/, TableGroupKey>& theGroup,
5531 const std::string& fileName,
5533 const std::string& associatedUser )
5535 std::string fullPath =
5536 ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/" + fileName;
5537 __COUTT__ <<
"Saving group " << theGroup.first <<
"(" << theGroup.second <<
") to "
5538 << (appendMode ?
"history " :
"") <<
"file: " << fullPath << __E__;
5540 std::ofstream groupFile;
5544 const size_t MAX_RECORDS = 200;
5546 while(records.size() >= MAX_RECORDS)
5547 records.erase(records.begin());
5549 groupFile.open(fullPath.c_str());
5550 for(
const auto& record : records)
5552 groupFile << record.at(
"groupName") <<
"\n"
5553 << record.at(
"groupKey") <<
"\n"
5554 << record.at(
"time") <<
" , " << record.at(
"user") <<
"\n";
5558 groupFile.open(fullPath.c_str());
5559 if(!groupFile.is_open())
5561 __SS__ <<
"Error. Can't open file to save group activity: " << fullPath << __E__;
5564 std::stringstream outss;
5565 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n";
5567 if(associatedUser !=
"")
5568 outss <<
" , " << associatedUser;
5570 groupFile << outss.str().c_str();
5582 std::string& returnedTimeString)
5584 std::string fullPath =
5585 ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/" + fileName;
5587 FILE* groupFile = fopen(fullPath.c_str(),
"r");
5590 __COUT__ <<
"Can't open file: " << fullPath
5591 <<
". Returning empty groupName and key -1" << __E__;
5600 fgets(line, 500, groupFile);
5601 if(strlen(line) && line[strlen(line) - 1] ==
'\n')
5602 line[strlen(line) - 1] =
'\0';
5603 theGroup.first = line;
5605 fgets(line, 500, groupFile);
5607 sscanf(line,
"%d", &key);
5608 theGroup.second = key;
5610 fgets(line, 500, groupFile);
5612 sscanf(line,
"%ld", ×tamp);
5619 __COUTS__(2) <<
"theGroup.first=" << theGroup.first
5620 <<
" theGroup.second=" << theGroup.second << __E__;
5628 std::map<std::string , std::string >>
5630 const std::string& groupType,
5633 __COUTTV__(groupAction);
5634 __COUTTV__(groupType);
5636 std::string fullPath = ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/";
5638 if(groupAction ==
"Activated")
5640 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5641 fullPath += ConfigurationManager::ACTIVATED_BACKBONES_FILE;
5642 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5643 fullPath += ConfigurationManager::ACTIVATED_CONTEXTS_FILE;
5644 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5645 fullPath += ConfigurationManager::ACTIVATED_CONFIGS_FILE;
5646 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5647 fullPath += ConfigurationManager::ACTIVATED_ITERATES_FILE;
5649 else if(groupAction ==
"Attempted Configure")
5651 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5652 fullPath += ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIGS_FILE;
5653 else if(groupType ==
"Config Alias")
5654 fullPath += ConfigurationManager::ATTEMPTED_CONFIGURE_CONFIG_ALIASES_FILE;
5656 else if(groupAction ==
"Configured")
5658 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5659 fullPath += ConfigurationManager::CONFIGURED_BACKBONES_FILE;
5660 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5661 fullPath += ConfigurationManager::CONFIGURED_CONTEXTS_FILE;
5662 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5663 fullPath += ConfigurationManager::CONFIGURED_CONFIGS_FILE;
5664 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5665 fullPath += ConfigurationManager::CONFIGURED_ITERATES_FILE;
5666 else if(groupType ==
"Config Alias")
5667 fullPath += ConfigurationManager::CONFIGURED_CONFIG_ALIASES_FILE;
5669 else if(groupAction ==
"Started")
5671 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5672 fullPath += ConfigurationManager::STARTED_BACKBONES_FILE;
5673 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5674 fullPath += ConfigurationManager::STARTED_CONTEXTS_FILE;
5675 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5676 fullPath += ConfigurationManager::STARTED_CONFIGS_FILE;
5677 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5678 fullPath += ConfigurationManager::STARTED_ITERATES_FILE;
5679 else if(groupType ==
"Config Alias")
5680 fullPath += ConfigurationManager::STARTED_CONFIG_ALIASES_FILE;
5682 else if(groupAction ==
"Configured or Started")
5684 if(groupType == ConfigurationManager::GROUP_TYPE_NAME_BACKBONE)
5685 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_BACKBONES_FILE;
5686 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONTEXT)
5687 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_CONTEXTS_FILE;
5688 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION)
5689 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_CONFIGS_FILE;
5690 else if(groupType == ConfigurationManager::GROUP_TYPE_NAME_ITERATE)
5691 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_ITERATES_FILE;
5692 else if(groupType ==
"Config Alias")
5693 fullPath += ConfigurationManager::CONFIGURED_OR_STARTED_CONFIG_ALIASES_FILE;
5696 if(fullPath == ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/")
5698 __SS__ <<
"Illegal attempted group history request combination of groupAction: "
5699 << groupAction <<
", and groupType: " << groupType << __E__;
5708 std::map<std::string , std::string >>
5713 std::map<std::string , std::string >>
5716 __COUTTV__(fullPath);
5717 FILE* groupFile = fopen(fullPath.c_str(),
"r");
5720 __COUT_WARN__ <<
"Can't open group history file (assuming no history yet): "
5721 << fullPath << __E__;
5723 __COUTTV__(retVec.size());
5730 std::string returnedTimeString, associatedUser;
5733 while(fgets(line, 500, groupFile))
5735 if(strlen(line) && line[strlen(line) - 1] ==
'\n')
5736 line[strlen(line) - 1] =
'\0';
5737 theGroup.first = line;
5739 fgets(line, 500, groupFile);
5741 sscanf(line,
"%d", &key);
5742 theGroup.second = key;
5744 fgets(line, 500, groupFile);
5747 sscanf(line,
"%ld , %s", ×tamp, user);
5752 __COUTS__(20) <<
"Read group from history file: " << theGroup.first <<
"("
5753 << theGroup.second <<
"), timestamp=" << timestamp
5754 <<
", user=" << user << __E__;
5756 retVec.push_back({{
"groupName", theGroup.first},
5757 {
"groupKey", theGroup.second.toString()},
5760 : std::to_string(timestamp)},
5766 __COUTTV__(retVec.size());
5776 __COUTT__ <<
"Initializing prerequisites for artdaq!" << __E__;
5779 for(
auto& tablePair : activeTables)
5781 __COUTVS__(2, tablePair.first);
5784 nameToTableMap_.at(tablePair.first)->initPrereqsForARTDAQ(
this);
5786 catch(
const std::runtime_error& e)
5788 __COUTVS__(2, e.what());
5789 if(std::string(e.what()).find(
5790 "initPrereqsForARTDAQ() is not implemented for this table") ==
5797 __COUTT__ <<
"Done initializing prerequisites for artdaq!" << __E__;
5801 __SS__ <<
"Error caught while initializing prerequisites for artdaq!";
5806 catch(
const std::runtime_error& e)
5808 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
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={})
TableBase * getVersionedTableByName(const std::string &tableName, TableVersion version, bool looseColumnMatching=false, std::string *accumulatedErrors=0, bool getRawData=false, bool touchLastAccessTime=true)
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.
void applyContextCommonTables(const std::map< std::string, TableVersion > &mergeInTables, const std::map< std::string, TableVersion > &overrideTables)
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 const std::string READONLY_USER
Static members.
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)