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"
9 #include "otsdaq/TableCore/TableGroupKey.h"
10 #include "otsdaq/TablePlugins/DesktopIconTable.h"
15 #define __MF_SUBJECT__ "ConfigurationManager"
19 std::thread::hardware_concurrency();
21 const std::string ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH =
22 ((getenv(
"SERVICE_DATA_PATH") == NULL)
23 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
24 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
26 const std::string ConfigurationManager::LAST_ACTIVATED_CONFIG_GROUP_FILE =
27 "CFGLastActivatedConfigGroup.hist";
28 const std::string ConfigurationManager::LAST_ACTIVATED_CONTEXT_GROUP_FILE =
29 "CFGLastActivatedContextGroup.hist";
30 const std::string ConfigurationManager::LAST_ACTIVATED_BACKBONE_GROUP_FILE =
31 "CFGLastActivatedBackboneGroup.hist";
32 const std::string ConfigurationManager::LAST_ACTIVATED_ITERATOR_GROUP_FILE =
33 "CFGLastActivatedIteratorGroup.hist";
35 const std::string ConfigurationManager::READONLY_USER =
"READONLY_USER";
37 const std::string ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME =
"XDAQContextTable";
38 const std::string ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME =
39 "XDAQApplicationTable";
40 const std::string ConfigurationManager::XDAQ_APP_PROPERTY_TABLE_NAME =
41 "XDAQApplicationPropertyTable";
42 const std::string ConfigurationManager::GROUP_ALIASES_TABLE_NAME =
"GroupAliasesTable";
43 const std::string ConfigurationManager::VERSION_ALIASES_TABLE_NAME =
44 "VersionAliasesTable";
45 const std::string ConfigurationManager::ARTDAQ_TOP_TABLE_NAME =
"ARTDAQSupervisorTable";
46 const std::string ConfigurationManager::DESKTOP_ICON_TABLE_NAME =
"DesktopIconTable";
50 ((getenv(
"SERVICE_DATA_PATH") == NULL)
51 ? (std::string(__ENV__(
"USER_DATA")) +
"/ServiceData")
52 : (std::string(__ENV__(
"SERVICE_DATA_PATH")))) +
53 "/ActiveTableGroups.cfg";
54 const std::string ConfigurationManager::ALIAS_VERSION_PREAMBLE =
"ALIAS:";
55 const std::string ConfigurationManager::SCRATCH_VERSION_ALIAS =
"Scratch";
57 const std::string ConfigurationManager::GROUP_TYPE_NAME_CONTEXT =
"Context";
58 const std::string ConfigurationManager::GROUP_TYPE_NAME_BACKBONE =
"Backbone";
59 const std::string ConfigurationManager::GROUP_TYPE_NAME_ITERATE =
"Iterate";
60 const std::string ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION =
"Configuration";
61 const std::string ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN =
"UNKNOWN";
63 const std::string ConfigurationManager::UNKNOWN_INFO =
"UNKNOWN";
64 const std::string ConfigurationManager::UNKNOWN_TIME =
"0";
66 const uint8_t ConfigurationManager::METADATA_COL_ALIASES = 1;
67 const uint8_t ConfigurationManager::METADATA_COL_COMMENT = 2;
68 const uint8_t ConfigurationManager::METADATA_COL_AUTHOR = 3;
69 const uint8_t ConfigurationManager::METADATA_COL_TIMESTAMP = 4;
71 const std::string ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE =
72 "SubsystemUserDataPathsTable";
73 const std::set<std::string> ConfigurationManager::fixedContextMemberNames_ = {
74 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
75 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
76 "XDAQApplicationPropertyTable",
77 ConfigurationManager::DESKTOP_ICON_TABLE_NAME,
78 "MessageFacilityTable",
79 "GatewaySupervisorTable",
81 "DesktopWindowParameterTable",
82 "SlowControlsDashboardSupervisorTable"};
83 const std::set<std::string> ConfigurationManager::backboneMemberNames_ = {
84 ConfigurationManager::GROUP_ALIASES_TABLE_NAME,
85 ConfigurationManager::VERSION_ALIASES_TABLE_NAME};
86 const std::set<std::string> ConfigurationManager::iterateMemberNames_ = {
89 "IterationTargetTable",
90 "IterationCommandBeginLabelTable",
91 "IterationCommandChooseFSMTable",
92 "IterationCommandConfigureAliasTable",
93 "IterationCommandConfigureGroupTable",
94 "IterationCommandExecuteFEMacroTable",
95 "IterationCommandExecuteMacroTable",
96 "IterationCommandMacroDimensionalLoopTable",
97 "IterationCommandMacroDimensionalLoopParameterTable",
98 "IterationCommandModifyGroupTable",
99 "IterationCommandRepeatLabelTable",
100 "IterationCommandRunTable"};
104 bool doInitializeFromFhicl )
105 : startClockTime_(std::chrono::steady_clock::now())
106 , deltaClockTime_(std::chrono::steady_clock::now())
110 , theConfigurationTableGroupKey_(0)
111 , theContextTableGroupKey_(0)
112 , theBackboneTableGroupKey_(0)
113 , theConfigurationTableGroup_(
"")
114 , theContextTableGroup_(
"")
115 , theBackboneTableGroup_(
"")
116 , groupMetadataTable_(true ,
TableBase::GROUP_METADATA_TABLE_NAME)
118 __GEN_COUTTV__(runTimeSeconds());
119 theInterface_ = ConfigurationInterface::getInstance(
120 ConfigurationInterface::CONFIGURATION_MODE::
123 __GEN_COUTTV__(runTimeSeconds());
195 if(doInitializeFromFhicl)
198 initializeFromFhicl(__ENV__(
"CONFIGURATION_INIT_FCL"));
203 __GEN_COUTTV__(runTimeSeconds());
204 if(!initForWriteAccess)
205 init(0 , initForWriteAccess);
206 __GEN_COUTTV__(runTimeSeconds());
214 __GEN_COUT__ <<
"Private constructor for write access called." << __E__;
216 mfSubject_ = username;
217 username_ = username;
221 ConfigurationManager::~ConfigurationManager() { destroy(); }
230 bool initForWriteAccess ,
231 std::string* accumulatedWarnings )
243 __GEN_COUTTV__(username_);
248 ConfigurationManager::LoadGroupType onlyLoadIfBackboneOrContext =
249 ConfigurationManager::LoadGroupType::ALL_TYPES;
250 if(username_ == ConfigurationManager::READONLY_USER && !initForWriteAccess)
251 onlyLoadIfBackboneOrContext =
252 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_OR_CONTEXT_TYPES;
257 onlyLoadIfBackboneOrContext,
258 accumulatedWarnings);
261 catch(std::runtime_error& e)
263 __GEN_COUT_ERR__ <<
"Error caught in init(): " << e.what();
264 if(accumulatedErrors)
265 *accumulatedErrors += e.what();
282 const std::string& pathToActiveGroupsFile ,
283 ConfigurationManager::LoadGroupType
284 onlyLoadIfBackboneOrContext ,
285 std::string* accumulatedWarnings )
291 FILE* fp = fopen(fn.c_str(),
"r");
293 __GEN_COUT__ <<
"ACTIVE_GROUPS_FILENAME = " << fn << __E__;
294 __GEN_COUT__ <<
"ARTDAQ_DATABASE_URI = "
295 << std::string(__ENV__(
"ARTDAQ_DATABASE_URI")) << __E__;
299 __GEN_COUT_WARN__ <<
"No active groups file found at " << fn << __E__;
308 std::string groupName;
309 std::string errorStr =
"";
314 while(fgets(tmp, 500, fp))
319 sscanf(tmp,
"%d", &numberCheck);
323 <<
"Out of sync with active groups file lines, attempting to resync."
330 sscanf(tmp,
"%s", strVal);
331 for(
unsigned int j = 0; j < strlen(strVal); ++j)
332 if(!((strVal[j] >=
'a' && strVal[j] <=
'z') ||
333 (strVal[j] >=
'A' && strVal[j] <=
'Z') ||
334 (strVal[j] >=
'0' && strVal[j] <=
'9')))
337 __GEN_COUT_INFO__ <<
"Illegal character found in group name '" << strVal
338 <<
"', so skipping! Check active groups file: " << fn
350 sscanf(tmp,
"%s", strVal);
352 for(
unsigned int j = 0; j < strlen(strVal); ++j)
353 if(!((strVal[j] >=
'0' && strVal[j] <=
'9')))
357 if(groupName.size() > 3)
359 <<
"Skipping active group with illegal character in group key '"
360 << strVal <<
".' Check active groups file: " << fn << __E__;
366 if(groupName.size() <= 3)
379 <<
"illegal group according to TableGroupKey::getFullGroupString... "
380 "Check active groups file: "
391 std::string groupAccumulatedErrors =
"";
393 if(accumulatedWarnings)
394 __GEN_COUT__ <<
"Ignoring warnings while loading and activating group '"
395 << groupName <<
"(" << strVal <<
")'" << __E__;
403 (accumulatedWarnings ? &groupAccumulatedErrors
411 onlyLoadIfBackboneOrContext
414 if(accumulatedWarnings)
415 *accumulatedWarnings += groupAccumulatedErrors;
417 catch(std::runtime_error& e)
419 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
420 << groupName <<
"(" << strVal
421 <<
")' specified active by active groups file: " << fn << __E__;
422 ss << e.what() << __E__;
424 errorStr += ss.str();
428 ss <<
"Failed to load group in ConfigurationManager::init() with name '"
429 << groupName <<
"(" << strVal
430 <<
")' specified active by active groups file: " << fn << __E__;
435 catch(
const std::exception& e)
437 ss <<
"Exception message: " << e.what();
442 errorStr += ss.str();
448 if(throwErrors && errorStr !=
"")
450 __SS__ <<
"\n" << errorStr;
453 else if(errorStr !=
"")
454 __GEN_COUT_INFO__ <<
"\n" << errorStr;
467 bool isContext = theGroup ==
"" || theGroup == theContextTableGroup_;
468 bool isBackbone = theGroup ==
"" || theGroup == theBackboneTableGroup_;
469 bool isIterate = theGroup ==
"" || theGroup == theIterateTableGroup_;
470 bool isConfiguration = theGroup ==
"" || theGroup == theConfigurationTableGroup_;
472 if(!isContext && !isBackbone && !isIterate && !isConfiguration)
474 __SS__ <<
"Invalid configuration group to destroy: " << theGroup << __E__;
475 __GEN_COUT_ERR__ << ss.str();
479 std::string dbgHeader = onlyDeactivate ?
"Deactivating" :
"Destroying";
483 __GEN_COUT__ << dbgHeader <<
" Context group: " << theGroup << __E__;
485 __GEN_COUT__ << dbgHeader <<
" Backbone group: " << theGroup << __E__;
487 __GEN_COUT__ << dbgHeader <<
" Iterate group: " << theGroup << __E__;
489 __GEN_COUT__ << dbgHeader <<
" Configuration group: " << theGroup << __E__;
492 getActiveContextMemberNames();
494 std::set<std::string>::const_iterator contextFindIt, backboneFindIt, iterateFindIt;
495 for(
auto it = nameToTableMap_.begin(); it != nameToTableMap_.end();
498 contextFindIt = contextMemberNames_.find(it->first);
499 backboneFindIt = backboneMemberNames_.find(it->first);
500 iterateFindIt = iterateMemberNames_.find(it->first);
502 __GEN_COUTT__ <<
"Considering table: " << it->first <<
" contextFindIt:"
503 << (contextFindIt != contextMemberNames_.end() ?
"Y" :
"N")
504 <<
" backboneFindIt:"
505 << (backboneFindIt != backboneMemberNames_.end() ?
"Y" :
"N")
507 << (iterateFindIt != iterateMemberNames_.end() ?
"Y" :
"N")
517 CONTEXT_SUBSYSTEM_OPTIONAL_TABLE) ||
518 (isBackbone && backboneFindIt != backboneMemberNames_.end()) ||
519 (isIterate && iterateFindIt != iterateMemberNames_.end()) ||
521 contextFindIt == contextMemberNames_.end() &&
522 it->first != ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE &&
523 backboneFindIt == backboneMemberNames_.end() &&
524 iterateFindIt == iterateMemberNames_.end())))
526 __GEN_COUTT__ <<
"\t" << dbgHeader <<
".. " << it->first
527 << (it->second->isActive()
528 ?
"_v" + it->second->getViewVersion().str()
534 it->second->deactivate();
540 nameToTableMap_.erase(it++);
549 theConfigurationTableGroup_ =
"";
550 if(theConfigurationTableGroupKey_ != 0)
552 __GEN_COUT__ <<
"Destroying Configuration Key: "
553 << *theConfigurationTableGroupKey_ << __E__;
554 theConfigurationTableGroupKey_.reset();
559 theBackboneTableGroup_ =
"";
560 if(theBackboneTableGroupKey_ != 0)
562 __GEN_COUT__ <<
"Destroying Backbone Key: " << *theBackboneTableGroupKey_
564 theBackboneTableGroupKey_.reset();
569 theIterateTableGroup_ =
"";
570 if(theIterateTableGroupKey_ != 0)
572 __GEN_COUT__ <<
"Destroying Iterate Key: " << *theIterateTableGroupKey_
574 theIterateTableGroupKey_.reset();
579 theContextTableGroup_ =
"";
580 if(theContextTableGroupKey_ != 0)
582 __GEN_COUT__ <<
"Destroying Context Key: " << *theContextTableGroupKey_
584 theContextTableGroupKey_.reset();
599 const ConfigurationManager::GroupType& groupTypeId)
601 return groupTypeId == ConfigurationManager::GroupType::CONTEXT_TYPE
602 ? ConfigurationManager::GROUP_TYPE_NAME_CONTEXT
603 : (groupTypeId == ConfigurationManager::GroupType::BACKBONE_TYPE
604 ? ConfigurationManager::GROUP_TYPE_NAME_BACKBONE
605 : (groupTypeId == ConfigurationManager::GroupType::ITERATE_TYPE
606 ? ConfigurationManager::GROUP_TYPE_NAME_ITERATE
607 : (groupTypeId == ConfigurationManager::GroupType::
609 ? ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION
610 : ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN)));
621 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
623 bool isContext =
true;
624 bool isBackbone =
true;
625 bool isIterate =
true;
627 bool inContext =
false;
628 bool inBackbone =
false;
629 bool inIterate =
false;
630 unsigned int matchCount = 0;
632 for(
auto& memberPair : memberMap)
637 if(memberPair.first == CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
643 for(
auto& contextMemberString : fixedContextMemberNames_)
644 if(memberPair.first == contextMemberString)
656 __SS__ <<
"This group is an incomplete match to a Context group.\n";
657 ss <<
"\nTo be a Context group, the members must exactly match "
658 <<
"the following members (w/ or wo/ the optional table "
659 << CONTEXT_SUBSYSTEM_OPTIONAL_TABLE <<
"):\n";
661 for(
const auto& memberName : fixedContextMemberNames_)
662 ss << ++i <<
". " << memberName <<
"\n";
663 ss <<
"\nThe members are as follows::\n";
665 for(
const auto& memberPairTmp : memberMap)
666 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
673 for(
auto& backboneMemberString : backboneMemberNames_)
674 if(memberPair.first == backboneMemberString)
686 __SS__ <<
"This group is an incomplete match to a Backbone group.\n";
687 ss <<
"\nTo be a Backbone group, the members must exactly match "
688 <<
"the following members:\n";
690 for(
auto& memberName : backboneMemberNames_)
691 ss << ++i <<
". " << memberName <<
"\n";
692 ss <<
"\nThe members are as follows::\n";
694 for(
const auto& memberPairTmp : memberMap)
695 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
703 for(
auto& iterateMemberString : iterateMemberNames_)
704 if(memberPair.first == iterateMemberString)
716 __SS__ <<
"This group is an incomplete match to a Iterate group.\n";
717 ss <<
"\nTo be a Iterate group, the members must exactly match "
718 <<
"the following members:\n";
720 for(
auto& memberName : iterateMemberNames_)
721 ss << ++i <<
". " << memberName <<
"\n";
722 ss <<
"\nThe members are as follows::\n";
724 for(
const auto& memberPairTmp : memberMap)
725 ss << ++i <<
". " << memberPairTmp.first <<
"\n";
732 if((isContext || inContext) && matchCount != fixedContextMemberNames_.size())
734 __SS__ <<
"This group is an incomplete match to a Context group: "
735 <<
" Size=" << matchCount <<
" but should be "
736 << fixedContextMemberNames_.size() << __E__;
737 ss <<
"\nThe members currently are...\n";
739 for(
auto& memberPair : memberMap)
740 ss << ++i <<
". " << memberPair.first <<
"\n";
741 ss <<
"\nThe expected Context members are...\n";
743 for(
auto& memberName : fixedContextMemberNames_)
744 ss << ++i <<
". " << memberName <<
"\n";
745 ss <<
"optional. (" << CONTEXT_SUBSYSTEM_OPTIONAL_TABLE <<
")\n";
750 if((isBackbone || inBackbone) && matchCount != backboneMemberNames_.size())
752 __SS__ <<
"This group is an incomplete match to a Backbone group: "
753 <<
" Size=" << matchCount <<
" but should be "
754 << backboneMemberNames_.size() << __E__;
755 ss <<
"\nThe members currently are...\n";
757 for(
auto& memberPair : memberMap)
758 ss << ++i <<
". " << memberPair.first <<
"\n";
759 ss <<
"\nThe expected Backbone members are...\n";
761 for(
auto& memberName : backboneMemberNames_)
762 ss << ++i <<
". " << memberName <<
"\n";
767 if((isIterate || inIterate) && matchCount != iterateMemberNames_.size())
769 __SS__ <<
"This group is an incomplete match to a Iterate group: "
770 <<
" Size=" << matchCount <<
" but should be "
771 << iterateMemberNames_.size() << __E__;
772 ss <<
"\nThe members currently are...\n";
774 for(
auto& memberPair : memberMap)
775 ss << ++i <<
". " << memberPair.first <<
"\n";
776 ss <<
"\nThe expected Iterate members are...\n";
778 for(
auto& memberName : iterateMemberNames_)
779 ss << ++i <<
". " << memberName <<
"\n";
785 ? ConfigurationManager::GroupType::CONTEXT_TYPE
787 ? ConfigurationManager::GroupType::BACKBONE_TYPE
789 ? ConfigurationManager::GroupType::ITERATE_TYPE
790 : ConfigurationManager::GroupType::CONFIGURATION_TYPE));
797 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap)
808 #define OUT out << tabStr << commentStr
809 #define PUSHTAB tabStr += "\t"
810 #define POPTAB tabStr.resize(tabStr.size() - 1)
811 #define PUSHCOMMENT commentStr += "# "
812 #define POPCOMMENT commentStr.resize(commentStr.size() - 2)
814 void ConfigurationManager::dumpMacroMakerModeFhicl()
816 std::string filepath =
817 __ENV__(
"USER_DATA") + std::string(
"/") +
"MacroMakerModeConfigurations";
818 mkdir(filepath.c_str(), 0755);
819 filepath +=
"/MacroMakerModeFhiclDump.fcl";
820 __GEN_COUT__ <<
"dumpMacroMakerModeFhicl: " << filepath << __E__;
826 std::string tabStr =
"";
827 std::string commentStr =
"";
829 out.open(filepath, std::fstream::out | std::fstream::trunc);
832 __SS__ <<
"Failed to open MacroMaker mode fcl file for configuration dump: "
833 << filepath << __E__;
839 std::vector<std::pair<std::string, ConfigurationTree>> fes =
845 if(!fe.second.status())
850 OUT << fe.first <<
": {" << __E__;
855 OUT <<
"FEInterfacePluginName"
857 <<
"\"" << fe.second.getNode(
"FEInterfacePluginName").getValueAsString()
860 recursiveTreeToFhicl(
861 fe.second.getNode(
"LinkToFETypeTable"), out, tabStr, commentStr);
864 OUT <<
"} //end " << fe.first << __E__ << __E__;
870 __SS__ <<
"Failed to complete MacroMaker mode fcl "
871 "file configuration dump due to error."
877 catch(
const std::runtime_error& e)
879 ss <<
"Exception message: " << e.what();
881 catch(
const std::exception& e)
883 ss <<
"Exception message: " << e.what();
885 __GEN_COUT_ERR__ << ss.str();
903 std::string& tabStr ,
904 std::string& commentStr ,
909 __COUT__ << __COUT_HDR_P__ <<
"Depth limit reached. Ending recursion." << __E__;
915 if(depth == (
unsigned int)-1)
935 std::vector<std::pair<std::string, ConfigurationTree>> children =
937 for(
auto& child : children)
938 recursiveTreeToFhicl(child.second, out, tabStr, commentStr, depth - 1);
942 <<
" group link record" << __E__;
954 std::vector<std::pair<std::string, ConfigurationTree>> fields =
958 for(
unsigned int i = 0; i < fields.size() - 3; ++i)
962 if(fields[i].second.isLinkNode())
964 recursiveTreeToFhicl(
965 fields[i].second, out, tabStr, commentStr, depth - 1);
970 OUT << fields[i].second.getFieldName() <<
": \t";
971 if(fields[i].second.isValueNumberDataType())
972 OUT << fields[i].second.getValueAsString() << __E__;
974 OUT <<
"\"" << fields[i].second.getValueAsString() <<
"\"" << __E__;
987 <<
" link record" << __E__;
996 const std::string& dumpType,
997 const std::string& configurationAlias,
998 const std::string& logEntry,
999 const std::string& activeUsers,
1000 std::ostream& altOut )
1002 time_t rawtime = time(0);
1003 __GEN_COUT__ <<
"filePath = " << filePath << __E__;
1004 __GEN_COUT__ <<
"dumpType = " << dumpType << __E__;
1008 fs.open(filePath, std::fstream::out | std::fstream::trunc);
1019 __SS__ <<
"Invalid file path to dump active configuration. File " << filePath
1020 <<
" could not be opened!" << __E__;
1021 __GEN_COUT_ERR__ << ss.str();
1027 (*out) <<
"#################################" << __E__;
1028 (*out) <<
"This is an ots configuration dump.\n" << __E__;
1029 (*out) <<
"Source database is $ARTDAQ_DATABASE_URI: "
1030 << __ENV__(
"ARTDAQ_DATABASE_URI") << __E__;
1032 (*out) <<
"Original location of dump: " << __ENV__(
"HOSTNAME")
1033 <<
":" << filePath << __E__;
1034 (*out) <<
"\nActive ots users: \t"
1035 << (activeUsers.size() ? activeUsers :
"no active users") << __E__;
1036 (*out) <<
"Type of dump: \t\t" << dumpType << __E__;
1037 (*out) <<
"Time of dump: \t\t" << rawtime;
1039 struct tm* timeinfo = localtime(&rawtime);
1041 strftime(buffer, 100,
"%c %Z", timeinfo);
1042 (*out) <<
" \t" << buffer << __E__;
1046 std::pair<std::string, ots::TableGroupKey> configurationTableGroup =
1048 (*out) <<
"Configuration Alias: \t\t\t" << configurationAlias <<
"\n";
1049 (*out) <<
"Configuration Alias translation: \t" << configurationTableGroup.first
1050 <<
"(" << configurationTableGroup.second <<
")\n\n";
1053 (*out) <<
"User Log Entry (" << logEntry.size() <<
" chars):\n"
1054 << logEntry << __E__;
1063 std::ostream* out) {
1064 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
1067 (*out) <<
"\n\n************************" << __E__;
1068 (*out) <<
"Active Groups:" << __E__;
1069 for(
auto& group : activeGroups)
1071 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
1072 << group.second.second <<
")" << __E__;
1077 std::ostream* out) {
1080 (*out) <<
"\n\n************************" << __E__;
1081 (*out) <<
"Active Tables:" << __E__;
1082 (*out) <<
"Active Tables count = " << activeTables.size() << __E__;
1085 for(
auto& table : activeTables)
1087 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
1092 std::ostream* out) {
1093 std::map<std::string, std::pair<std::string, TableGroupKey>> activeGroups =
1095 (*out) <<
"\n\n************************" << __E__;
1096 (*out) <<
"Active Group Members:" << __E__;
1098 for(
auto& group : activeGroups)
1100 (*out) <<
"\t" << group.first <<
" := " << group.second.first <<
" ("
1101 << group.second.second <<
")" << __E__;
1103 if(group.second.first ==
"")
1106 <<
"Empty group name. Assuming no active group." << __E__;
1111 std::map<std::string , std::string > groupAliases;
1112 std::string groupComment;
1113 std::string groupAuthor;
1114 std::string groupCreateTime;
1115 time_t groupCreateTime_t;
1118 group.second.second,
1130 (*out) <<
"\t\tGroup Comment: \t" << groupComment << __E__;
1131 (*out) <<
"\t\tGroup Author: \t" << groupAuthor << __E__;
1133 sscanf(groupCreateTime.c_str(),
"%ld", &groupCreateTime_t);
1134 (*out) <<
"\t\tGroup Create Time: \t" << ctime(&groupCreateTime_t) << __E__;
1138 (*out) <<
"\t\tMember table count = " << memberMap.size() << __E__;
1139 tableCount += memberMap.size();
1142 for(
auto& member : memberMap)
1144 (*out) <<
"\t\t\t" << ++i <<
". " << member.first <<
"-v" << member.second
1148 (*out) <<
"\nActive Group Members total table count = " << tableCount << __E__;
1152 std::ostream* out) {
1155 (*out) <<
"\n\n************************" << __E__;
1156 (*out) <<
"Active Table Contents (table count = " << activeTables.size()
1159 for(
auto& table : activeTables)
1161 (*out) <<
"\n\n=============================================================="
1164 (*out) <<
"=================================================================="
1167 (*out) <<
"\t" << ++i <<
". " << table.first <<
"-v" << table.second << __E__;
1169 cfgMgr->nameToTableMap_.find(table.first)->second->print(*out);
1173 if(dumpType ==
"GroupKeys")
1175 localDumpActiveGroups(
this, out);
1177 else if(dumpType ==
"TableVersions")
1179 localDumpActiveTables(
this, out);
1181 else if(dumpType ==
"GroupKeysAndTableVersions")
1183 localDumpActiveGroups(
this, out);
1184 localDumpActiveTables(
this, out);
1186 else if(dumpType ==
"All")
1188 localDumpActiveGroups(
this, out);
1189 localDumpActiveGroupMembers(
this, out);
1190 localDumpActiveTables(
this, out);
1191 localDumpActiveTableContents(
this, out);
1196 <<
"Invalid dump type '" << dumpType
1197 <<
"' given during dumpActiveConfiguration(). Valid types are as follows:\n"
1205 <<
"GroupsKeysAndTableVersions"
1210 "\n\nPlease change the State Machine configuration to a valid dump type."
1227 const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap,
1228 std::string* accumulatedWarnings )
1230 __GEN_COUTTV__(runTimeSeconds());
1235 bool usingCache =
false;
1236 if(memberMap.size() > 10 && nameToTableMap_.size() &&
1237 nameToTableMap_.find(memberMap.begin()->first) != nameToTableMap_.end() &&
1238 nameToTableMap_.at(memberMap.begin()->first)->isStored(memberMap.begin()->second))
1243 __GEN_COUTT__ <<
"Using cache!" << __E__;
1247 const int numOfThreads =
1249 if(memberMap.size() <= 2 || usingCache ||
1254 for(
auto& memberPair : memberMap)
1266 tmpTableBasePtr =
nullptr;
1267 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1268 tmpTableBasePtr = nameToTableMap_.at(memberPair.first);
1270 std::string getError =
"";
1273 theInterface_->get(tmpTableBasePtr,
1282 catch(
const std::runtime_error& e)
1284 __SS__ <<
"Failed to load member table '" << memberPair.first <<
"-v"
1285 << memberPair.second <<
"' - here is the error: \n\n"
1286 << e.what() << __E__;
1288 ss <<
"\nIf the table '" << memberPair.first
1289 <<
"' should not exist, then please remove it from the group. If it "
1290 "should exist, then it "
1291 <<
"seems to have a problem; use the Table Editor to fix the table "
1293 "edit the table content to match the table definition."
1297 if(accumulatedWarnings)
1298 getError = ss.str();
1304 __SS__ <<
"Failed to load member table '" << memberPair.first <<
" -v"
1305 << memberPair.second <<
"' due to unknown error!" << __E__;
1310 catch(
const std::exception& e)
1312 ss <<
"Exception message: " << e.what();
1318 ss <<
"\nIf the table '" << memberPair.first
1319 <<
"' should not exist, then please remove it from the group. If it "
1320 "should exist, then it "
1321 <<
"seems to have a problem; use the Table Editor to fix the table "
1323 "edit the table content to match the table definition."
1327 if(accumulatedWarnings)
1328 getError = ss.str();
1334 if(!tmpTableBasePtr)
1336 __SS__ <<
"Null pointer returned for table '" << memberPair.first <<
" -v"
1337 << memberPair.second <<
".' Was the table info deleted?" << __E__;
1338 __GEN_COUT_ERR__ << ss.str();
1340 nameToTableMap_.erase(memberPair.first);
1341 if(accumulatedWarnings)
1343 *accumulatedWarnings += ss.str();
1350 nameToTableMap_[memberPair.first] = tmpTableBasePtr;
1351 if(nameToTableMap_[memberPair.first]->getViewP())
1356 if(accumulatedWarnings && getError !=
"")
1358 __SS__ <<
"Error caught during '" << memberPair.first <<
" -v"
1359 << memberPair.second <<
"' table retrieval: \n"
1360 << getError << __E__;
1361 __GEN_COUT_ERR__ << ss.str();
1362 *accumulatedWarnings += ss.str();
1367 __SS__ << nameToTableMap_[memberPair.first]->getTableName() <<
" -v"
1368 << memberPair.second <<
": View version not activated properly!";
1375 __GEN_COUT__ <<
" PROCESSOR_COUNT " <<
PROCESSOR_COUNT <<
" ==> " << numOfThreads
1376 <<
" threads for loading member map of size " << memberMap.size()
1379 int threadsLaunched = 0;
1380 int foundThreadIndex = 0;
1381 std::string threadErrors;
1382 std::mutex threadMutex;
1383 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
1384 for(
int i = 0; i < numOfThreads; ++i)
1385 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
1386 std::vector<TableBase*> tmpTableBasePtrs;
1387 for(
int i = 0; i < numOfThreads; ++i)
1388 tmpTableBasePtrs.push_back(
nullptr);
1390 for(
auto& memberPair : memberMap)
1392 if(threadsLaunched >= numOfThreads)
1395 foundThreadIndex = -1;
1396 while(foundThreadIndex == -1)
1398 for(
int i = 0; i < numOfThreads; ++i)
1399 if(*(threadDone[i]))
1401 foundThreadIndex = i;
1404 if(foundThreadIndex == -1)
1406 __GEN_COUTT__ <<
"Waiting for available thread..." << __E__;
1410 threadsLaunched = numOfThreads - 1;
1412 __GEN_COUTT__ <<
"Starting filling thread... " << foundThreadIndex <<
" for "
1413 << memberPair.first <<
" -v" << memberPair.second << __E__;
1414 *(threadDone[foundThreadIndex]) =
false;
1422 tmpTableBasePtrs[foundThreadIndex] =
nullptr;
1423 if(nameToTableMap_.find(memberPair.first) != nameToTableMap_.end())
1424 tmpTableBasePtrs[foundThreadIndex] = nameToTableMap_.at(memberPair.first);
1428 std::map<std::string, ots::TableBase*>* theNameToTableMap,
1430 std::string theTableName,
1432 std::string* theThreadErrors,
1433 std::mutex* theThreadMutex,
1434 std::shared_ptr<std::atomic<bool>> theThreadDone) {
1435 ConfigurationManager::fillTableThread(theInterface,
1446 tmpTableBasePtrs[foundThreadIndex],
1451 threadDone[foundThreadIndex])
1461 foundThreadIndex = -1;
1462 for(
int i = 0; i < numOfThreads; ++i)
1463 if(!*(threadDone[i]))
1465 foundThreadIndex = i;
1468 if(foundThreadIndex != -1)
1470 __GEN_COUT_TYPE__(TLVL_DEBUG + 2)
1471 << __COUT_HDR__ <<
"Waiting for thread to finish... "
1472 << foundThreadIndex << __E__;
1475 }
while(foundThreadIndex != -1);
1476 __GEN_COUTT__ <<
"All threads done." << __E__;
1478 if(threadErrors !=
"")
1480 __SS__ <<
"Error identified in threads during loading of member map: \n"
1481 << threadErrors << __E__;
1482 __GEN_COUTT__ <<
"\n" << ss.str() << __E__;
1483 if(accumulatedWarnings)
1484 *accumulatedWarnings += ss.str();
1490 __GEN_COUTT__ <<
"loadMemberMap end runTimeSeconds()=" << runTimeSeconds() << __E__;
1516 const std::string& groupName,
1519 std::map<std::string /*table name*/, TableVersion>*
1522 std::string* accumulatedWarnings ,
1523 std::string* groupComment ,
1524 std::string* groupAuthor ,
1525 std::string* groupCreateTime ,
1526 bool doNotLoadMembers ,
1527 std::string* groupTypeString ,
1528 std::map<std::string /*name*/, std::string /*alias*/>*
1530 ConfigurationManager::LoadGroupType
1532 bool ignoreVersionTracking )
1536 *groupComment = ConfigurationManager::UNKNOWN_INFO;
1538 *groupAuthor = ConfigurationManager::UNKNOWN_INFO;
1540 *groupCreateTime = ConfigurationManager::UNKNOWN_TIME;
1542 *groupTypeString = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
1544 __GEN_COUTT__ <<
"No group type requested." << __E__;
1571 __GEN_COUTT__ <<
"Loading Table Group: " << groupName <<
"(" << groupKey <<
")"
1572 <<
" accumulatedWarnings=" << (accumulatedWarnings ? 1 : 0) << __E__;
1584 progressBar->
step();
1587 auto metaTablePair = memberMap.find(TableBase::GROUP_METADATA_TABLE_NAME);
1588 if(metaTablePair != memberMap.end())
1591 if(groupAliases || groupComment || groupAuthor || groupCreateTime)
1593 std::lock_guard<std::mutex> lock(metaDataTableMutex_);
1596 while(groupMetadataTable_.getView().getNumberOfRows())
1597 groupMetadataTable_.getViewP()->
deleteRow(0);
1602 theInterface_->fill(&groupMetadataTable_, metaTablePair->second);
1604 catch(
const std::runtime_error& e)
1607 <<
"Failed to load " << groupMetadataTable_.
getTableName() <<
"-v"
1608 << metaTablePair->second <<
". Metadata error: " << e.what()
1614 <<
"Failed to load " << groupMetadataTable_.
getTableName() <<
"-v"
1615 << metaTablePair->second <<
". Ignoring unknown metadata error. "
1620 if(groupMetadataTable_.getView().getNumberOfRows() != 1)
1622 groupMetadataTable_.
print();
1623 __GEN_COUT_ERR__ <<
"Ignoring that groupMetadataTable_ has wrong "
1624 "number of rows for '"
1625 << groupName <<
"(" << groupKey
1627 "be 1. Going with anonymous defaults."
1631 while(groupMetadataTable_.getViewP()->getNumberOfRows() > 1)
1632 groupMetadataTable_.getViewP()->
deleteRow(0);
1633 if(groupMetadataTable_.getViewP()->getNumberOfRows() == 0)
1634 groupMetadataTable_.getViewP()->
addRow();
1643 0, ConfigurationManager::METADATA_COL_ALIASES),
1647 0, ConfigurationManager::METADATA_COL_COMMENT);
1650 0, ConfigurationManager::METADATA_COL_AUTHOR);
1653 0, ConfigurationManager::METADATA_COL_TIMESTAMP);
1657 memberMap.erase(metaTablePair);
1662 __GEN_COUT_ERR__ <<
"Ignoring that groupMetadataTable_ is missing for group '"
1663 << groupName <<
"(" << groupKey
1664 <<
"). Going with anonymous defaults." << __E__;
1675 std::map<std::string, std::string>& aliasMap = *groupAliases;
1676 std::map<std::string , std::map<std::string ,
TableVersion>>
1686 for(
auto& aliasPair : aliasMap)
1689 if(memberMap.find(aliasPair.first) != memberMap.end())
1691 __GEN_COUT__ <<
"Group member '" << aliasPair.first
1692 <<
"' was found in group member map!" << __E__;
1693 __GEN_COUT__ <<
"Looking for alias '" << aliasPair.second
1694 <<
"' in active version aliases..." << __E__;
1696 if(versionAliases.find(aliasPair.first) == versionAliases.end() ||
1697 versionAliases[aliasPair.first].find(aliasPair.second) ==
1698 versionAliases[aliasPair.first].end())
1700 __SS__ <<
"Group '" << groupName <<
"(" << groupKey
1701 <<
")' requires table version alias '" << aliasPair.first
1702 <<
":" << aliasPair.second
1703 <<
",' which was not found in the active Backbone!"
1708 memberMap[aliasPair.first] =
1709 versionAliases[aliasPair.first][aliasPair.second];
1710 __GEN_COUT__ <<
"Version alias translated to " << aliasPair.first
1717 *groupMembers = memberMap;
1720 progressBar->
step();
1722 ConfigurationManager::GroupType groupType =
1723 ConfigurationManager::GroupType::CONFIGURATION_TYPE;
1732 __GEN_COUTT__ <<
"No group type requested." << __E__;
1734 if(doNotLoadMembers)
1738 if(!groupTypeString)
1741 if(groupTypeToLoad ==
1742 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_OR_CONTEXT_TYPES &&
1743 groupType != ConfigurationManager::GroupType::CONTEXT_TYPE &&
1744 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
1746 __GEN_COUT__ <<
"Not loading group because it is not of type Context or "
1747 "Backbone (it is type '"
1751 else if(groupTypeToLoad ==
1752 ConfigurationManager::LoadGroupType::ONLY_BACKBONE_TYPE &&
1753 groupType != ConfigurationManager::GroupType::BACKBONE_TYPE)
1755 __GEN_COUT__ <<
"Not loading group because it is not of type "
1756 "Backbone (it is type '"
1764 <<
"------------------------------------- init start \t [for all "
1772 std::string groupToDeactivate =
1773 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
1774 ? theContextTableGroup_
1775 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
1776 ? theBackboneTableGroup_
1778 ConfigurationManager::GroupType::ITERATE_TYPE
1779 ? theIterateTableGroup_
1780 : theConfigurationTableGroup_));
1783 if(groupToDeactivate !=
"")
1785 __GEN_COUT__ <<
"groupToDeactivate '" << groupToDeactivate
1794 __GEN_COUT__ <<
"no group to deactivate of type "
1801 progressBar->
step();
1806 progressBar->
step();
1808 __GEN_COUTT__ <<
"loadMemberMap() completed." << __E__;
1810 if(accumulatedWarnings)
1812 __GEN_COUTT__ <<
"Checking chosen group for tree errors... here are the "
1813 "current warnings: "
1814 << *accumulatedWarnings << __E__;
1817 if(*accumulatedWarnings !=
"")
1820 <<
"Errors detected while loading Table Group: " << groupName
1821 <<
"(" << groupKey <<
"). Ignoring the following errors: "
1823 << *accumulatedWarnings << __E__;
1825 __GEN_COUTT__ <<
"After checking children warnings: "
1826 << *accumulatedWarnings << __E__;
1830 progressBar->
step();
1832 __GEN_COUTT__ <<
"Tree view check complete." << __E__;
1843 <<
" threads for initializing tables for Table Group '"
1844 << groupName <<
"(" << groupKey <<
")'." << __E__;
1845 if(groupType != ConfigurationManager::GroupType::CONFIGURATION_TYPE ||
1848 for(
auto& memberPair : memberMap)
1851 if(!ignoreVersionTracking &&
1852 ConfigurationInterface::isVersionTrackingEnabled() &&
1853 memberPair.second.isScratchVersion())
1856 <<
"Error while activating member Table '"
1857 << nameToTableMap_[memberPair.first]->getTableName()
1858 <<
"-v" << memberPair.second <<
" for Table Group '"
1859 << groupName <<
"(" << groupKey
1860 <<
")'. When version tracking is enabled, Scratch views"
1861 <<
" are not allowed! Please only use unique, persistent "
1862 "versions when version tracking is enabled."
1871 nameToTableMap_.at(memberPair.first)->init(
this);
1873 catch(std::runtime_error& e)
1875 __SS__ <<
"Error detected calling " << memberPair.first
1876 <<
".init()!\n\n " << e.what() << __E__;
1878 if(accumulatedWarnings)
1880 *accumulatedWarnings += ss.str();
1890 __SS__ <<
"Unknown Error detected calling "
1891 << memberPair.first <<
".init()!\n\n " << __E__;
1896 catch(
const std::exception& e)
1898 ss <<
"Exception message: " << e.what();
1905 if(accumulatedWarnings)
1907 *accumulatedWarnings += ss.str();
1910 __GEN_COUT_WARN__ << ss.str();
1916 int threadsLaunched = 0;
1917 int foundThreadIndex = 0;
1918 std::string threadErrors;
1919 std::mutex threadMutex;
1920 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
1921 for(
int i = 0; i < numOfThreads; ++i)
1922 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
1924 if(!ignoreVersionTracking &&
1925 ConfigurationInterface::isVersionTrackingEnabled())
1926 for(
auto& memberPair : memberMap)
1929 if(memberPair.second.isScratchVersion())
1932 <<
"Error while activating member Table '"
1933 << nameToTableMap_[memberPair.first]->getTableName()
1934 <<
"-v" << memberPair.second <<
" for Table Group '"
1935 << groupName <<
"(" << groupKey
1936 <<
")'. When version tracking is enabled, Scratch "
1938 <<
" are not allowed! Please only use unique, "
1940 "versions when version tracking is enabled."
1946 for(
auto& memberPair : memberMap)
1948 if(threadsLaunched >= numOfThreads)
1951 foundThreadIndex = -1;
1952 while(foundThreadIndex == -1)
1954 for(
int i = 0; i < numOfThreads; ++i)
1955 if(*(threadDone[i]))
1957 foundThreadIndex = i;
1960 if(foundThreadIndex == -1)
1962 __GEN_COUTT__ <<
"Waiting for available thread..."
1967 threadsLaunched = numOfThreads - 1;
1969 __GEN_COUTT__ <<
"Starting init table thread... "
1970 << foundThreadIndex <<
" for " << memberPair.first
1972 *(threadDone[foundThreadIndex]) =
false;
1977 std::string* theThreadErrors,
1978 std::mutex* theThreadMutex,
1979 std::shared_ptr<std::atomic<bool>> theThreadDone) {
1980 ConfigurationManager::initTableThread(cfgMgr,
1987 nameToTableMap_.at(memberPair.first),
1990 threadDone[foundThreadIndex])
2000 foundThreadIndex = -1;
2001 for(
int i = 0; i < numOfThreads; ++i)
2002 if(!*(threadDone[i]))
2004 foundThreadIndex = i;
2007 if(foundThreadIndex != -1)
2009 __GEN_COUTT__ <<
"Waiting for thread to finish... "
2010 << foundThreadIndex << __E__;
2013 }
while(foundThreadIndex != -1);
2014 __GEN_COUTT__ <<
"All threads done." << __E__;
2016 if(threadErrors !=
"")
2018 __SS__ <<
"Error identified in threads during init of table "
2020 << threadErrors << __E__;
2021 __GEN_COUTT__ <<
"\n" << ss.str() << __E__;
2022 if(accumulatedWarnings)
2023 *accumulatedWarnings += ss.str();
2033 progressBar->
step();
2042 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
2048 theContextTableGroup_ = groupName;
2049 theContextTableGroupKey_ =
2050 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2052 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
2057 theBackboneTableGroup_ = groupName;
2058 theBackboneTableGroupKey_ =
2059 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2061 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
2067 theIterateTableGroup_ = groupName;
2068 theIterateTableGroupKey_ =
2069 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2076 theConfigurationTableGroup_ = groupName;
2077 theConfigurationTableGroupKey_ =
2078 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2083 progressBar->
step();
2087 <<
"------------------------------------- init complete \t [for all "
2097 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2103 catch(
const std::runtime_error& e)
2105 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
2106 << groupKey <<
")': \n"
2107 << e.what() << __E__;
2109 if(accumulatedWarnings)
2110 *accumulatedWarnings += ss.str();
2116 __SS__ <<
"An unknown error occurred while loading table group '"
2117 << groupName <<
"(" << groupKey <<
")." << __E__;
2122 catch(
const std::exception& e)
2124 ss <<
"Exception message: " << e.what();
2129 if(accumulatedWarnings)
2130 *accumulatedWarnings += ss.str();
2136 __GEN_COUTT__ <<
"loadTableGroup() complete for Table Group '" << groupName <<
"("
2137 << groupKey <<
")'." << __E__;
2139 std::make_pair(std::make_pair(groupName,
TableGroupKey(groupKey)), memberMap);
2144 __GEN_COUTT__ <<
"loadTableGroup() failed." << __E__;
2147 lastFailedGroupLoad_[ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN] =
2148 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2154 catch(
const std::runtime_error& e)
2156 __SS__ <<
"Error occurred while loading table group '" << groupName <<
"("
2157 << groupKey <<
")': \n"
2158 << e.what() << __E__;
2160 if(accumulatedWarnings)
2161 *accumulatedWarnings += ss.str();
2167 __SS__ <<
"An unknown error occurred while loading table group '" << groupName
2168 <<
"(" << groupKey <<
")." << __E__;
2173 catch(
const std::exception& e)
2175 ss <<
"Exception message: " << e.what();
2182 if(accumulatedWarnings)
2183 *accumulatedWarnings += ss.str();
2195 const std::map<std::string, TableVersion>& memberMap,
2196 const std::string& groupName ,
2199 bool ignoreVersionTracking )
2204 ConfigurationManager::GroupType groupType =
getTypeOfGroup(memberMap);
2208 __GEN_COUT__ <<
"------------------------------------- cacheCopy init start "
2210 "plug-ins in member map"
2215 std::string groupToDeactivate =
2216 groupType == ConfigurationManager::GroupType::CONTEXT_TYPE
2217 ? theContextTableGroup_
2218 : (groupType == ConfigurationManager::GroupType::BACKBONE_TYPE
2219 ? theBackboneTableGroup_
2220 : (groupType == ConfigurationManager::GroupType::ITERATE_TYPE
2221 ? theIterateTableGroup_
2222 : theConfigurationTableGroup_));
2225 if(groupToDeactivate !=
"")
2242 for(
auto& memberPair : memberMap)
2244 __GEN_COUTT__ <<
"Copying " << memberPair.first <<
"-v" << memberPair.second
2248 if(nameToTableMap_.find(memberPair.first) == nameToTableMap_.end())
2251 theInterface_->get(table,
2258 nameToTableMap_[memberPair.first] = table;
2260 nameToTableMap_.at(memberPair.first)
2262 ->getView(memberPair.second),
2265 ->getView(memberPair.second)
2273 __GEN_COUTT__ <<
"Done with member copy loop." << __E__;
2279 std::string accumulatedWarnings;
2282 << numOfThreads <<
" threads for initializing tables." << __E__;
2283 if(groupType != ConfigurationManager::GroupType::CONFIGURATION_TYPE ||
2286 for(
auto& memberPair : memberMap)
2289 if(!ignoreVersionTracking &&
2290 ConfigurationInterface::isVersionTrackingEnabled() &&
2291 memberPair.second.isScratchVersion())
2293 __SS__ <<
"Error while activating member Table '"
2294 << nameToTableMap_[memberPair.first]->getTableName()
2295 <<
"-v" << memberPair.second
2296 <<
" for member map. When version tracking is enabled, "
2298 <<
" are not allowed! Please only use unique, persistent "
2299 "versions when version tracking is enabled."
2308 nameToTableMap_.at(memberPair.first)->init(
this);
2310 catch(std::runtime_error& e)
2312 __SS__ <<
"Error detected calling " << memberPair.first
2313 <<
".init()!\n\n " << e.what() << __E__;
2314 accumulatedWarnings += ss.str();
2318 __SS__ <<
"Unknown Error detected calling " << memberPair.first
2319 <<
".init()!\n\n " << __E__;
2324 catch(
const std::exception& e)
2326 ss <<
"Exception message: " << e.what();
2331 accumulatedWarnings += ss.str();
2337 int threadsLaunched = 0;
2338 int foundThreadIndex = 0;
2339 std::mutex threadMutex;
2340 std::vector<std::shared_ptr<std::atomic<bool>>> threadDone;
2341 for(
int i = 0; i < numOfThreads; ++i)
2342 threadDone.push_back(std::make_shared<std::atomic<bool>>(
true));
2344 if(!ignoreVersionTracking &&
2345 ConfigurationInterface::isVersionTrackingEnabled())
2346 for(
auto& memberPair : memberMap)
2349 if(memberPair.second.isScratchVersion())
2352 <<
"Error while activating member Table '"
2353 << nameToTableMap_[memberPair.first]->getTableName()
2354 <<
"-v" << memberPair.second
2355 <<
" for member map. When version tracking is enabled, "
2357 <<
" are not allowed! Please only use unique, persistent "
2358 "versions when version tracking is enabled."
2364 for(
auto& memberPair : memberMap)
2366 if(threadsLaunched >= numOfThreads)
2369 foundThreadIndex = -1;
2370 while(foundThreadIndex == -1)
2372 for(
int i = 0; i < numOfThreads; ++i)
2373 if(*(threadDone[i]))
2375 foundThreadIndex = i;
2378 if(foundThreadIndex == -1)
2380 __GEN_COUTT__ <<
"Waiting for available thread..."
2385 threadsLaunched = numOfThreads - 1;
2387 __GEN_COUTT__ <<
"Starting init table thread... " << foundThreadIndex
2388 <<
" for " << memberPair.first << __E__;
2389 *(threadDone[foundThreadIndex]) =
false;
2394 std::string* theAccumulatedWarnings,
2395 std::mutex* theThreadMutex,
2396 std::shared_ptr<std::atomic<bool>> theThreadDone) {
2397 ConfigurationManager::initTableThread(cfgMgr,
2399 theAccumulatedWarnings,
2404 nameToTableMap_.at(memberPair.first),
2405 &accumulatedWarnings,
2407 threadDone[foundThreadIndex])
2417 foundThreadIndex = -1;
2418 for(
int i = 0; i < numOfThreads; ++i)
2419 if(!*(threadDone[i]))
2421 foundThreadIndex = i;
2424 if(foundThreadIndex != -1)
2426 __GEN_COUTT__ <<
"Waiting for thread to finish... "
2427 << foundThreadIndex << __E__;
2430 }
while(foundThreadIndex != -1);
2434 if(accumulatedWarnings !=
"")
2436 __GEN_COUT__ <<
"Activating the member map after copying cache had the "
2437 "following warnings: "
2438 << accumulatedWarnings << __E__;
2449 if(groupType == ConfigurationManager::GroupType::CONTEXT_TYPE)
2455 theContextTableGroup_ = groupName;
2456 theContextTableGroupKey_ =
2457 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2459 else if(groupType == ConfigurationManager::GroupType::BACKBONE_TYPE)
2464 theBackboneTableGroup_ = groupName;
2465 theBackboneTableGroupKey_ =
2466 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2468 else if(groupType == ConfigurationManager::GroupType::ITERATE_TYPE)
2474 theIterateTableGroup_ = groupName;
2475 theIterateTableGroupKey_ =
2476 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2483 theConfigurationTableGroup_ = groupName;
2484 theConfigurationTableGroupKey_ =
2485 std::shared_ptr<TableGroupKey>(
new TableGroupKey(groupKey));
2490 __GEN_COUT__ <<
"------------------------------------- cacheCopy init "
2491 "complete \t [for all "
2492 "plug-ins in member map"
2495 __GEN_COUTT__ <<
"Completed cache copy." << __E__;
2498 make_pair(make_pair(groupName,
TableGroupKey(groupKey)), memberMap);
2502 __GEN_COUT__ <<
"Unknown failure in cache copy." << __E__;
2505 std::pair<std::string, TableGroupKey>(groupName,
TableGroupKey(groupKey));
2512 ConfigurationManager::getGroupOfLoadedTable(
const std::string& tableName)
const
2514 for(
const auto& loadedGroup : lastGroupLoad_)
2515 if(loadedGroup.second.second.find(tableName) != loadedGroup.second.second.end())
2516 return loadedGroup.second.first;
2517 return std::make_pair(
"",
TableGroupKey(TableGroupKey::INVALID));
2524 std::string* threadErrors,
2525 std::mutex* threadMutex,
2526 std::shared_ptr<std::atomic<bool>> threadDone)
2529 __COUTT__ <<
"Thread init of " << table->
getTableName() <<
"-v"
2530 << table->
getViewVersion() <<
" threadErrors=" << (threadErrors ? 1 : 0)
2538 table->init(cfgMgr);
2540 catch(std::runtime_error& e)
2542 __SS__ <<
"Error detected calling " << table->
getTableName() <<
".init()!\n\n "
2543 << e.what() << __E__;
2547 std::lock_guard<std::mutex> lock(*threadMutex);
2548 *threadErrors += ss.str();
2558 __SS__ <<
"Unknown Error detected calling " << table->
getTableName()
2559 <<
".init()!\n\n " << __E__;
2564 catch(
const std::exception& e)
2566 ss <<
"Exception message: " << e.what();
2574 std::lock_guard<std::mutex> lock(*threadMutex);
2575 *threadErrors += ss.str();
2584 *(threadDone) =
true;
2588 __SS__ <<
"Error occurred initializing table '" << table->
getTableName() <<
"-v"
2594 catch(
const std::runtime_error& e)
2596 ss <<
" Run-time Exception message: " << e.what();
2598 catch(
const std::exception& e)
2600 ss <<
" Exception message: " << e.what();
2602 __COUT_WARN__ << ss.str() << __E__;
2606 std::lock_guard<std::mutex> lock(*threadMutex);
2607 *threadErrors += ss.str();
2610 *(threadDone) =
true;
2615 void ConfigurationManager::fillTableThread(
2617 std::map<std::string, ots::TableBase*>* nameToTableMap,
2619 std::string tableName,
2621 std::string* threadErrors,
2622 std::mutex* threadMutex,
2623 std::shared_ptr<std::atomic<bool>> threadDone)
2626 __COUTT__ <<
"Thread fill of " << tableName <<
"-v" << version << __E__;
2636 std::string getError =
"";
2641 theInterface->get(table,
2650 catch(
const std::runtime_error& e)
2652 __SS__ <<
"Failed to load member table '" << tableName <<
"-v" << version
2653 <<
"' - here is the error: \n\n"
2654 << e.what() << __E__;
2656 ss <<
"\nIf the table '" << tableName
2657 <<
"' should not exist, then please remove it from the group. If it "
2658 "should exist, then it "
2659 <<
"seems to have a problem; use the Table Editor to fix the table "
2661 "edit the table content to match the table definition."
2666 getError = ss.str();
2672 __SS__ <<
"Failed to load member table '" << tableName <<
"-v" << version
2673 <<
"' due to unknown error!" << __E__;
2678 catch(
const std::exception& e)
2680 ss <<
"Exception message: " << e.what();
2685 ss <<
"\nIf the table '" << tableName
2686 <<
"' should not exist, then please remove it from the group. If it "
2687 "should exist, then it "
2688 <<
"seems to have a problem; use the Table Editor to fix the table "
2690 "edit the table content to match the table definition."
2695 getError = ss.str();
2701 __COUTV__(getError);
2703 __COUT_TYPE__(TLVL_TRACE + 1)
2704 << __COUT_HDR__ <<
"Checking ptr.. " << (table ?
"GOOD" :
"BAD") << __E__;
2707 __SS__ <<
"Null pointer returned for table '" << tableName
2708 <<
".' Was the table info deleted?" << __E__;
2709 __COUT_ERR__ << ss.str();
2711 std::lock_guard<std::mutex> lock(*threadMutex);
2712 nameToTableMap->erase(tableName);
2716 *threadErrors += ss.str();
2717 *(threadDone) =
true;
2725 std::lock_guard<std::mutex> lock(*threadMutex);
2726 (*nameToTableMap)[tableName] = table;
2729 if(nameToTableMap->at(tableName)->getViewP())
2731 __COUT_TYPE__(TLVL_TRACE + 1)
2733 <<
"Activated version: " << nameToTableMap->at(tableName)->getViewVersion()
2736 if(threadErrors && getError !=
"")
2738 __SS__ <<
"Error caught during '" << tableName <<
"' table retrieval: \n"
2739 << getError << __E__;
2740 __COUT_ERR__ << ss.str();
2741 std::lock_guard<std::mutex> lock(*threadMutex);
2742 *threadErrors += ss.str();
2747 __SS__ << tableName <<
": View version not activated properly!";
2751 __COUTT__ <<
"end Thread fill of " << tableName <<
"-v" << version << __E__;
2752 *(threadDone) =
true;
2754 catch(
const std::runtime_error& e)
2756 __SS__ <<
"Error occurred filling table '" << tableName <<
"-v" << version
2757 <<
"': " << e.what() << __E__;
2758 __COUT_ERR__ << ss.str();
2762 std::lock_guard<std::mutex> lock(*threadMutex);
2763 *threadErrors += ss.str();
2766 *(threadDone) =
true;
2770 __SS__ <<
"Unknwon error occurred filling table '" << tableName <<
"-v" << version
2776 catch(
const std::exception& e)
2778 ss <<
"Exception message: " << e.what();
2783 __COUT_ERR__ << ss.str();
2787 std::lock_guard<std::mutex> lock(*threadMutex);
2788 *threadErrors += ss.str();
2791 *(threadDone) =
true;
2800 std::map<std::string, std::pair<std::string, TableGroupKey>>
2804 std::map<std::string, std::pair<std::string, TableGroupKey>> retMap;
2806 retMap[ConfigurationManager::GROUP_TYPE_NAME_CONTEXT] =
2807 std::pair<std::string, TableGroupKey>(
2808 theContextTableGroup_,
2809 theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey());
2810 retMap[ConfigurationManager::GROUP_TYPE_NAME_BACKBONE] =
2811 std::pair<std::string, TableGroupKey>(
2812 theBackboneTableGroup_,
2813 theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey());
2814 retMap[ConfigurationManager::GROUP_TYPE_NAME_ITERATE] =
2815 std::pair<std::string, TableGroupKey>(
2816 theIterateTableGroup_,
2817 theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey());
2818 retMap[ConfigurationManager::GROUP_TYPE_NAME_CONFIGURATION] =
2819 std::pair<std::string, TableGroupKey>(theConfigurationTableGroup_,
2820 theConfigurationTableGroupKey_
2821 ? *theConfigurationTableGroupKey_
2827 const std::string& ConfigurationManager::getActiveGroupName(
2828 const ConfigurationManager::GroupType& type)
const
2830 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
2831 return theConfigurationTableGroup_;
2832 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
2833 return theContextTableGroup_;
2834 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
2835 return theBackboneTableGroup_;
2836 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
2837 return theIterateTableGroup_;
2839 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
2845 const ConfigurationManager::GroupType& type)
const
2847 if(type == ConfigurationManager::GroupType::CONFIGURATION_TYPE)
2848 return theConfigurationTableGroupKey_ ? *theConfigurationTableGroupKey_
2850 else if(type == ConfigurationManager::GroupType::CONTEXT_TYPE)
2851 return theContextTableGroupKey_ ? *theContextTableGroupKey_ :
TableGroupKey();
2852 else if(type == ConfigurationManager::GroupType::BACKBONE_TYPE)
2853 return theBackboneTableGroupKey_ ? *theBackboneTableGroupKey_ :
TableGroupKey();
2854 else if(type == ConfigurationManager::GroupType::ITERATE_TYPE)
2855 return theIterateTableGroupKey_ ? *theIterateTableGroupKey_ :
TableGroupKey();
2857 __SS__ <<
"IMPOSSIBLE! Invalid type requested '" << (int)type <<
"'" << __E__;
2863 const std::string& contextUID,
const std::string& )
const
2871 const std::string& contextUID,
const std::string& applicationUID)
const
2874 contextUID +
"/LinkToApplicationTable/" + applicationUID);
2879 const std::string& contextUID,
const std::string& applicationUID)
const
2882 contextUID +
"/LinkToApplicationTable/" + applicationUID +
2883 "/LinkToSupervisorTable");
2890 auto contextChildren =
2893 for(
const auto& contextChild : contextChildren)
2895 auto appChildren = contextChild.second.getNode(
"LinkToApplicationTable")
2897 for(
const auto& appChild : appChildren)
2899 if(appChild.second.getNode(
"Class").getValue() ==
2900 "ots::GatewaySupervisor")
2901 return appChild.second;
2904 __SS__ <<
"No Gateway Supervisor node found!" << __E__;
2910 bool doNotThrowOnBrokenUIDLinks)
const
2915 if(nodeString.length() < 1)
2917 __SS__ << (
"Invalid empty node name") << __E__;
2922 size_t startingIndex = 0;
2923 while(startingIndex < nodeString.length() && nodeString[startingIndex] ==
'/')
2925 size_t endingIndex = nodeString.find(
'/', startingIndex);
2926 if(endingIndex == std::string::npos)
2927 endingIndex = nodeString.length();
2929 std::string nodeName = nodeString.substr(startingIndex, endingIndex - startingIndex);
2931 if(nodeName.length() < 1)
2941 std::string childPath =
2942 (endingIndex >= nodeString.length() ?
"" : nodeString.substr(endingIndex));
2948 if(childPath.length() > 1)
2949 return configTree.
getNode(childPath, doNotThrowOnBrokenUIDLinks);
2955 std::map<std::string, ConfigurationTree> ConfigurationManager::getNodes(
2956 const std::string& nodeString)
const
2968 std::string path =
"/";
2979 std::map<std::string, TableVersion>* memberMap,
2980 std::string* accumulatedTreeErrors)
const
2982 std::vector<std::pair<std::string, ConfigurationTree>> retVector;
2987 bool filtering = memberMap && memberMap->size();
2990 for(
auto& tablePair : nameToTableMap_)
2995 if(memberMap->find(tablePair.first) == memberMap->end())
3001 if(!tablePair.second->isActive())
3003 __SS__ <<
"Get Children with member map requires a child '"
3004 << tablePair.first <<
"' that is not active!" << __E__;
3008 catch(
const std::runtime_error& e)
3010 if(accumulatedTreeErrors)
3012 *accumulatedTreeErrors += e.what();
3013 __GEN_COUT_ERR__ <<
"Skipping " << tablePair.first
3014 <<
" since the table "
3023 if(!tablePair.second->isActive())
3027 if(accumulatedTreeErrors)
3031 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren =
3033 for(
auto& newNodeChild : newNodeChildren)
3035 if(newNodeChild.second.getTableName() ==
3036 ConfigurationManager::DESKTOP_ICON_TABLE_NAME &&
3037 !newNodeChild.second.isEnabled())
3040 std::vector<std::pair<std::string, ConfigurationTree>>
3041 twoDeepChildren = newNodeChild.second.getChildren();
3043 for(
auto& twoDeepChild : twoDeepChildren)
3048 if(twoDeepChild.second.isLinkNode() &&
3049 twoDeepChild.second.isDisconnected() &&
3050 twoDeepChild.second.getDisconnectedTableName() !=
3051 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
3053 __SS__ <<
"At node '" + tablePair.first +
3054 "' with entry UID '" + newNodeChild.first +
3055 "' there is a disconnected child node at link "
3057 twoDeepChild.first +
"'" +
3058 " that points to table named '" +
3059 twoDeepChild.second.getDisconnectedTableName() +
3061 *accumulatedTreeErrors += ss.str();
3066 catch(std::runtime_error& e)
3068 __SS__ <<
"At node '" + tablePair.first +
3069 "' error detected descending through children:\n" +
3071 *accumulatedTreeErrors += ss.str();
3075 retVector.push_back(
3076 std::pair<std::string, ConfigurationTree>(tablePair.first, newNode));
3090 std::string* accumulatedTreeErrors)
const
3097 bool filtering = memberMap && memberMap->size();
3100 for(
auto& tablePair : nameToTableMap_)
3105 if(memberMap->find(tablePair.first) == memberMap->end())
3111 if(!tablePair.second->isActive())
3113 __SS__ <<
"Get Children with member map requires a child '"
3114 << tablePair.first <<
"' that is not active!" << __E__;
3118 catch(
const std::runtime_error& e)
3120 if(accumulatedTreeErrors)
3122 *accumulatedTreeErrors += e.what();
3123 __GEN_COUT_ERR__ <<
"Skipping " << tablePair.first
3124 <<
" since the table "
3133 if(!tablePair.second->isActive())
3137 if(accumulatedTreeErrors)
3141 std::vector<std::pair<std::string, ConfigurationTree>> newNodeChildren =
3143 for(
auto& newNodeChild : newNodeChildren)
3145 if(newNodeChild.second.getTableName() ==
3146 ConfigurationManager::DESKTOP_ICON_TABLE_NAME &&
3147 !newNodeChild.second.isEnabled())
3150 std::vector<std::pair<std::string, ConfigurationTree>>
3151 twoDeepChildren = newNodeChild.second.getChildren();
3153 for(
auto& twoDeepChild : twoDeepChildren)
3158 if(twoDeepChild.second.isLinkNode() &&
3159 twoDeepChild.second.isDisconnected() &&
3160 twoDeepChild.second.getDisconnectedTableName() !=
3161 TableViewColumnInfo::DATATYPE_LINK_DEFAULT)
3163 __SS__ <<
"At node '" + tablePair.first +
3164 "' with entry UID '" + newNodeChild.first +
3165 "' there is a disconnected child node at link "
3167 twoDeepChild.first +
"'" +
3168 " that points to table named '" +
3169 twoDeepChild.second.getDisconnectedTableName() +
3171 *accumulatedTreeErrors += ss.str();
3176 catch(std::runtime_error& e)
3178 __SS__ <<
"At node '" + tablePair.first +
3179 "' error detected descending through children:\n" +
3181 *accumulatedTreeErrors += ss.str();
3186 std::pair<std::string, ConfigurationTree>(tablePair.first, newNode));
3199 std::map<std::string, TableBase*>::const_iterator it;
3200 if((it = nameToTableMap_.find(tableName)) == nameToTableMap_.end())
3202 __SS__ <<
"Can not find table named '" << tableName
3203 <<
"' - you need to load the table before it can be used.";
3205 if(nameToTableMap_.size() == 0)
3206 ss <<
"\n\nAll tables are missing. Your configuration database connection "
3207 "may have been interrupted. Did an ssh tunnel disconnect?"
3211 ss <<
" It probably is missing from the member list of the Table "
3212 "Group that was loaded.\n"
3213 <<
"\nYou may need to enter wiz mode to remedy the situation, use the "
3237 if(!theBackboneTableGroupKey_)
3239 __GEN_COUT_WARN__ <<
"getTableGroupKey() Failed! No active backbone currently."
3245 loadTableGroup(theBackboneTableGroup_, *theBackboneTableGroupKey_);
3247 return *theBackboneTableGroupKey_;
3264 std::string systemAlias,
ProgressBar* progressBar)
3274 progressBar->
step();
3276 if(systemAlias.find(
"GROUP:") == 0)
3279 progressBar->
step();
3281 unsigned int i = strlen(
"GROUP:");
3282 unsigned int j = systemAlias.find(
':', i);
3285 progressBar->
step();
3287 return std::pair<std::string, TableGroupKey>(
3288 systemAlias.substr(i, j - i),
TableGroupKey(systemAlias.substr(j + 1)));
3290 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
3296 progressBar->
step();
3302 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).
getNode(systemAlias);
3305 progressBar->
step();
3307 return std::pair<std::string, TableGroupKey>(
3318 progressBar->
step();
3320 return std::pair<std::string, TableGroupKey>(
"",
TableGroupKey());
3326 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
3332 ConfigurationManager::LoadGroupType::
3333 ONLY_BACKBONE_TYPE);
3336 std::map<std::string ,
3340 std::vector<std::pair<std::string, ConfigurationTree>> entries =
3342 for(
auto& entryPair : entries)
3344 retMap[entryPair.first] = std::pair<std::string, TableGroupKey>(
3345 entryPair.second.getNode(
"GroupName").getValueAsString(),
3346 TableGroupKey(entryPair.second.getNode(
"GroupKey").getValueAsString()));
3354 std::map<std::string ,
3360 std::map<std::string ,
3365 std::string versionAliasesTableName =
3366 ConfigurationManager::VERSION_ALIASES_TABLE_NAME;
3367 if(activeVersions.find(versionAliasesTableName) == activeVersions.end())
3369 __SS__ <<
"Active version of VersionAliases missing!"
3370 <<
" Make sure you have a valid active Backbone Group." << __E__;
3371 __GEN_COUT_WARN__ <<
"\n" << ss.str();
3377 std::vector<std::pair<std::string, ConfigurationTree>> aliasNodePairs =
3383 std::string tableName, versionAlias;
3384 for(
auto& aliasNodePair : aliasNodePairs)
3386 tableName = aliasNodePair.second.getNode(
"TableName").getValueAsString();
3387 versionAlias = aliasNodePair.second.getNode(
"VersionAlias").getValueAsString();
3389 if(retMap.find(tableName) != retMap.end() &&
3390 retMap[tableName].find(versionAlias) != retMap[tableName].end())
3395 retMap[tableName][versionAlias] =
3396 TableVersion(aliasNodePair.second.getNode(
"Version").getValueAsString());
3406 std::map<std::string, TableVersion> retMap;
3407 for(
auto& table : nameToTableMap_)
3409 __GEN_COUTS__(2) << table.first << __E__;
3412 if(table.second && table.second->
isActive())
3414 __GEN_COUTS__(2) << table.first <<
"_v" << table.second->
getViewVersion()
3416 retMap.insert(std::pair<std::string, TableVersion>(
3450 if(theConfigurationTableGroupKey_)
3452 if(*theConfigurationTableGroupKey_ != key)
3455 return theConfigurationTableGroupKey_;
3457 return std::shared_ptr<TableGroupKey>(
new TableGroupKey(key));
3461 const std::set<std::string>& ConfigurationManager::getActiveContextMemberNames()
3464 contextMemberNames_ = ConfigurationManager::fixedContextMemberNames_;
3467 nameToTableMap_.find(ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE);
3468 if(it == nameToTableMap_.end())
3469 return contextMemberNames_;
3471 if(!it->second->isActive())
3473 contextMemberNames_.emplace(
3474 ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE);
3476 return contextMemberNames_;
3480 const std::set<std::string>& ConfigurationManager::getFixedContextMemberNames()
3482 return ConfigurationManager::fixedContextMemberNames_;
3486 const std::set<std::string>& ConfigurationManager::getBackboneMemberNames()
3488 return ConfigurationManager::backboneMemberNames_;
3492 const std::set<std::string>& ConfigurationManager::getIterateMemberNames()
3494 return ConfigurationManager::iterateMemberNames_;
3498 const std::set<std::string>& ConfigurationManager::getConfigurationMemberNames(
void)
3500 configurationMemberNames_.clear();
3504 for(
auto& tablePair : activeTables)
3507 ConfigurationManager::fixedContextMemberNames_.find(tablePair.first) ==
3508 ConfigurationManager::fixedContextMemberNames_.end() &&
3509 tablePair.first != ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE &&
3512 ConfigurationManager::backboneMemberNames_.find(tablePair.first) ==
3513 ConfigurationManager::backboneMemberNames_.end() &&
3516 ConfigurationManager::iterateMemberNames_.find(tablePair.first) ==
3517 ConfigurationManager::iterateMemberNames_.end())
3520 configurationMemberNames_.emplace(tablePair.first);
3523 return configurationMemberNames_;
3527 void ConfigurationManager::initializeFromFhicl(
const std::string& fhiclPath)
3529 __GEN_COUT__ <<
"Initializing from fhicl: " << fhiclPath << __E__;
3534 fhicl::ParameterSet pset = LoadParameterSet(fhiclPath);
3536 if(pset.get_names().size() == 0)
3538 __GEN_SS__ <<
"Empty fcl configuration parameter set found! File: " << fhiclPath
3570 theInterface_->get(table,
3571 ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME,
3577 nameToTableMap_[ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME] = table;
3580 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
3583 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
3588 auto colMap = view->getColumnNamesMap();
3590 view->
setValue(
"MacroMakerFEContext", 0, colMap[
"ContextUID"]);
3591 view->
setValue(
"XDAQApplicationTable", 0, colMap[
"LinkToApplicationTable"]);
3592 view->
setValue(
"MacroMakerFEContextApps", 0, colMap[
"LinkToApplicationGroupID"]);
3593 view->
setValue(
"1", 0, colMap[TableViewColumnInfo::COL_NAME_STATUS]);
3595 __GEN_COUT__ <<
"Done adding context record..." << __E__;
3605 ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME,
3611 nameToTableMap_[ConfigurationManager::XDAQ_APPLICATION_TABLE_NAME] = table;
3614 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
3617 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
3622 auto colMap = view->getColumnNamesMap();
3624 view->
setValue(
"MacroMakerFEContextApps", 0, colMap[
"ApplicationGroupID"]);
3625 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"ApplicationUID"]);
3626 view->
setValue(
"FESupervisorTable", 0, colMap[
"LinkToSupervisorTable"]);
3627 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"LinkToSupervisorUID"]);
3628 view->
setValue(
"1", 0, colMap[TableViewColumnInfo::COL_NAME_STATUS]);
3629 view->
setValue(__ENV__(
"FE_SUPERVISOR_ID"), 0, colMap[
"Id"]);
3631 __GEN_COUT__ <<
"Done adding application record..." << __E__;
3638 theInterface_->get(table,
3639 "FESupervisorTable",
3645 nameToTableMap_[
"FESupervisorTable"] = table;
3648 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
3651 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
3656 auto colMap = view->getColumnNamesMap();
3658 view->
setValue(
"MacroMakerFESupervisor", 0, colMap[
"SupervisorUID"]);
3659 view->
setValue(
"FEInterfaceTable", 0, colMap[
"LinkToFEInterfaceTable"]);
3661 "MacroMakerFESupervisorInterfaces", 0, colMap[
"LinkToFEInterfaceGroupID"]);
3663 __GEN_COUT__ <<
"Done adding supervisor record..." << __E__;
3668 recursiveInitFromFhiclPSet(
"FEInterfaceTable" ,
3671 "MacroMakerFESupervisorInterfaces" ,
3675 for(
auto& table : nameToTableMap_)
3677 table.second->getViewP()->
init();
3683 __GEN_COUT__ <<
"================================================" << __E__;
3684 nameToTableMap_[
"FESupervisorTable"]->getViewP()->print();
3685 nameToTableMap_[
"FEInterfaceTable"]->getViewP()->print();
3688 __GEN_COUT__ <<
"Supervisors extracted from fhicl: " << sups.size() << __E__;
3690 __GEN_COUT__ <<
"Front-ends extracted from fhicl: " << fes.size() << __E__;
3692 auto a =
getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME);
3693 __GEN_COUTV__(a.getValueAsString());
3695 auto b = a.getNode(
"MacroMakerFEContext");
3696 __GEN_COUTV__(b.getValueAsString());
3698 auto c = b.getNode(
"LinkToApplicationTable");
3699 __GEN_COUTV__(c.getValueAsString());
3701 auto d = c.getNode(
"MacroMakerFESupervisor");
3702 __GEN_COUTV__(d.getValueAsString());
3704 auto e = d.getNode(
"LinkToSupervisorTable");
3705 __GEN_COUTV__(e.getValueAsString());
3707 auto f = e.getNode(
"LinkToFEInterfaceTable");
3708 __GEN_COUTV__(f.getValueAsString());
3710 auto z = f.getChildrenNames();
3712 __GEN_COUTV__(z.size());
3713 auto y = f.getChildrenNames(
false ,
true );
3715 __GEN_COUTV__(y.size());
3716 auto x = f.getChildrenNames(
true ,
true );
3718 __GEN_COUTV__(x.size());
3720 auto g = f.getNode(
"dtc0");
3721 __GEN_COUTV__(g.getValueAsString());
3722 auto h = f.getNode(
"interface0");
3723 __GEN_COUTV__(h.getValueAsString());
3726 getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME)
3728 "MacroMakerFEContext/LinkToApplicationTable/"
3729 "MacroMakerFESupervisor/LinkToSupervisorTable")
3730 .
getNode(
"LinkToFEInterfaceTable")
3732 __GEN_COUTV__(fes.size());
3744 void ConfigurationManager::recursiveInitFromFhiclPSet(
const std::string& tableName,
3745 const fhicl::ParameterSet& pset,
3746 const std::string& recordName,
3747 const std::string& groupName,
3748 const std::string& groupLinkIndex)
3750 __GEN_COUT__ << __COUT_HDR_P__ <<
"Adding table '" << tableName <<
"' record(s)..."
3757 if(nameToTableMap_.find(tableName) == nameToTableMap_.end())
3759 __GEN_COUT__ <<
"Table not found, so making '" << tableName <<
"' instance..."
3761 theInterface_->get(table,
3768 nameToTableMap_[tableName] = table;
3773 __GEN_COUT__ <<
"Existing table found, so using '" << tableName
3774 <<
"'instance..." << __E__;
3775 table = nameToTableMap_[tableName];
3778 table->setActiveView(
TableVersion(TableVersion::DEFAULT));
3781 __GEN_COUT__ <<
"Activated version: " << view->getVersion() << __E__;
3784 if(recordName !=
"")
3792 __GEN_COUTV__(recordName);
3795 unsigned int r = view->
addRow();
3796 auto colMap = view->getColumnNamesMap();
3806 __GEN_COUT__ <<
"No status column to set for '" << recordName <<
"'"
3812 __GEN_COUT__ <<
"Setting group ID for group link index '"
3813 << groupLinkIndex <<
"'" << __E__;
3816 __GEN_COUT__ <<
"Setting group ID for group link index '"
3817 << groupLinkIndex <<
"' at column " << groupIDCol <<
" to '"
3818 << groupName <<
".'" << __E__;
3820 view->
setValue(groupName, r, groupIDCol);
3824 auto names = pset.get_names();
3825 for(
const auto& colName : names)
3827 if(!pset.is_key_to_atom(colName))
3830 auto colIt = colMap.find(colName);
3831 if(colIt == colMap.end())
3833 __SS__ <<
"Field '" << colName <<
"' of record '" << recordName
3834 <<
"' in table '" << tableName <<
"' was not found in columns."
3835 <<
"\n\nHere are the existing column names:\n";
3837 for(
const auto& col : colMap)
3838 ss <<
"\n" << ++i <<
".\t" << col.first;
3843 if(view->getColumnInfo(colIt->second).
isGroupID())
3846 const std::string value = pset.get<std::string>(colName);
3847 __GEN_COUT__ <<
"Setting '" << recordName <<
"' parameter at column "
3848 << colIt->second <<
", '" << colName <<
"'\t = " << value
3854 for(
const auto& linkName : names)
3856 if(pset.is_key_to_atom(linkName))
3859 __GEN_COUTV__(linkName);
3862 unsigned int c = linkName.size() - 1;
3864 if(linkName[c] ==
'_')
3869 __SS__ <<
"Illegal link name '" << linkName
3870 <<
"' found. The format must be <Column name>_<Target table "
3871 "name>,.. for example '"
3872 <<
"LinkToFETypeTable_FEOtsUDPTemplateInterfaceTable'"
3876 std::string colName = linkName.substr(0, c);
3877 __GEN_COUTV__(colName);
3879 auto colIt = colMap.find(colName);
3880 if(colIt == colMap.end())
3882 __SS__ <<
"Link '" << colName <<
"' of record '" << recordName
3883 <<
"' in table '" << tableName <<
"' was not found in columns."
3884 <<
"\n\nHere are the existing column names:\n";
3886 for(
const auto& col : colMap)
3887 ss <<
"\n" << i <<
".\t" << col.first << __E__;
3892 std::pair<
unsigned int ,
unsigned int >
3895 view->
getChildLink(colIt->second, isGroupLink, linkPair);
3901 std::string linkTableName = linkName.substr(c + 1);
3902 __GEN_COUTV__(linkTableName);
3904 auto linkPset = pset.get<fhicl::ParameterSet>(linkName);
3905 auto linkRecords = linkPset.get_pset_names();
3906 if(!isGroupLink && linkRecords.size() > 1)
3908 __SS__ <<
"A Unique Link can only point to one record. "
3909 <<
"The specified link '" << colName <<
"' of record '"
3910 << recordName <<
"' in table '" << tableName <<
"' has "
3911 << linkRecords.size() <<
" children records specified. "
3916 if(linkRecords.size() == 0)
3918 __GEN_COUT__ <<
"No child records, so leaving link disconnected."
3923 __GEN_COUT__ <<
"Setting Link at columns [" << linkPair.first <<
","
3924 << linkPair.second <<
"]" << __E__;
3925 view->
setValue(linkTableName, r, linkPair.first);
3929 __GEN_COUT__ <<
"Setting up Unique link to " << linkRecords[0]
3932 view->
setValue(linkRecords[0], r, linkPair.second);
3934 recursiveInitFromFhiclPSet(
3936 linkPset.get<fhicl::ParameterSet>(
3943 std::string childLinkIndex =
3945 std::string groupName = recordName +
"Group";
3947 view->
setValue(groupName, r, linkPair.second);
3949 for(
const auto& groupRecord : linkRecords)
3951 __GEN_COUT__ <<
"Setting '" << childLinkIndex
3952 <<
"' Group link to '" << groupName <<
"' record '"
3953 << groupRecord <<
"'" << __E__;
3955 recursiveInitFromFhiclPSet(
3957 linkPset.get<fhicl::ParameterSet>(
3967 else if(groupName !=
"")
3971 __GEN_COUTV__(groupName);
3972 auto psets = pset.get_pset_names();
3973 for(
const auto& ps : psets)
3976 recursiveInitFromFhiclPSet(
3978 pset.get<fhicl::ParameterSet>(ps) ,
3986 __SS__ <<
"Illegal recursive parameters!" << __E__;
3989 __GEN_COUT__ << __COUT_HDR_P__ <<
"Done adding table '" << tableName
3990 <<
"' record(s)..." << __E__;
3997 bool ConfigurationManager::isOwnerFirstAppInContext()
4000 if(ownerContextUID_ ==
"" || ownerAppUID_ ==
"")
4008 auto contextChildren =
getNode(ConfigurationManager::XDAQ_CONTEXT_TABLE_NAME +
4009 "/" + ownerContextUID_)
4012 bool isFirstAppInContext =
4013 contextChildren.size() == 0 || contextChildren[0] == ownerAppUID_;
4017 return isFirstAppInContext;
4026 void ConfigurationManager::getOtherSubsystemInstanceInfo(
4027 const std::string& otherSubsystemUID,
4028 std::string* userDataPathPtr ,
4029 std::string* hostnamePtr ,
4030 std::string* usernamePtr ,
4031 std::string* fullNamePtr )
4033 __GEN_COUTTV__(otherSubsystemUID);
4036 getNode(ConfigurationManager::CONTEXT_SUBSYSTEM_OPTIONAL_TABLE)
4038 std::string userPath = node.
getNode(
"SubsystemUserDataPath").
getValue();
4045 if(!splitPath.size() || splitPath.size() > 2)
4047 __GEN_SS__ <<
"Illegal user data path specified for subsystem '"
4048 << otherSubsystemUID <<
"': " << userPath << __E__;
4051 std::string userDataPath = splitPath[splitPath.size() - 1];
4054 for(
unsigned int i = 0; i < userDataPath.length(); ++i)
4055 if(!((userDataPath[i] >=
'a' && userDataPath[i] <=
'z') ||
4056 (userDataPath[i] >=
'A' && userDataPath[i] <=
'Z') ||
4057 (userDataPath[i] >=
'0' && userDataPath[i] <=
'9') ||
4058 userDataPath[i] ==
'-' || userDataPath[i] ==
'_' || userDataPath[i] ==
'/'))
4060 __GEN_SS__ <<
"Illegal user data path specified (no special characters "
4061 "allowed) for subsystem '"
4062 << otherSubsystemUID <<
"': " << userPath << __E__;
4067 *userDataPathPtr = userDataPath;
4069 std::string username, hostname;
4070 if(splitPath.size() == 2)
4073 std::vector<std::string> userHostSplit =
4075 __GEN_COUTTV__(userHostSplit.size());
4076 if(userHostSplit.size() == 1)
4077 hostname = userHostSplit[0];
4078 else if(userHostSplit.size() == 2)
4080 username = userHostSplit[0];
4081 hostname = userHostSplit[1];
4085 __GEN_SS__ <<
"Illegal remote username/host specified for subsystem '"
4086 << otherSubsystemUID <<
"': " << userPath << __E__;
4090 for(
unsigned int i = 0; userHostSplit.size() == 2 && i < username.length(); ++i)
4091 if(!((username[i] >=
'a' && username[i] <=
'z') ||
4092 (username[i] >=
'A' && username[i] <=
'Z') ||
4093 (username[i] >=
'0' && username[i] <=
'9') || username[i] ==
'-' ||
4094 username[i] ==
'_'))
4096 __GEN_SS__ <<
"Illegal remote username specified for subsystem '"
4097 << otherSubsystemUID <<
"': " << userPath << __E__;
4100 unsigned int ii = 0;
4101 for(
unsigned int i = 0; i < hostname.length(); ++i)
4102 if(!((hostname[i] >=
'a' && hostname[i] <=
'z') ||
4103 (hostname[i] >=
'A' && hostname[i] <=
'Z') ||
4104 (hostname[i] >=
'0' && hostname[i] <=
'9') || hostname[i] ==
'-' ||
4105 hostname[i] ==
'_'))
4107 if(hostname[i] ==
'.' && i > ii + 1)
4114 __GEN_SS__ <<
"Illegal remote hostname '" << hostname
4115 <<
"' specified for subsystem '" << otherSubsystemUID
4116 <<
"': " << userPath << __E__;
4121 else if(splitPath.size() == 1)
4123 __GEN_COUT__ <<
"Local user date path identified." << __E__;
4127 __GEN_SS__ <<
"Illegal user data path specified for subsystem '"
4128 << otherSubsystemUID <<
"': " << userPath << __E__;
4133 *hostnamePtr = hostname;
4135 *usernamePtr = username;
4140 std::map<std::string , std::pair<std::string ,
TableGroupKey>>
4141 ConfigurationManager::getOtherSubsystemActiveTableGroups(
4142 const std::string& otherSubsystemUID,
4143 std::string* userDataPathPtr ,
4144 std::string* hostnamePtr ,
4145 std::string* usernamePtr )
4147 std::map<std::string ,
4151 __GEN_COUTTV__(otherSubsystemUID);
4153 std::string userDataPath;
4154 std::string username, hostname;
4156 getOtherSubsystemInstanceInfo(otherSubsystemUID, &userDataPath, &hostname, &username);
4158 __GEN_COUTTV__(userDataPath);
4159 __GEN_COUTTV__(username);
4160 __GEN_COUTTV__(hostname);
4163 *userDataPathPtr = userDataPath;
4165 *hostnamePtr = hostname;
4167 *usernamePtr = username;
4170 std::string filename = userDataPath +
"/ServiceData/ActiveTableGroups.cfg";
4172 std::string cmdResult;
4176 std::string tmpSubsystemFilename =
4178 __GEN_COUTTV__(tmpSubsystemFilename);
4182 (
"rm " + tmpSubsystemFilename +
" 2>/dev/null; scp " + username +
"@" +
4183 hostname +
":" + filename +
" " + tmpSubsystemFilename +
" 2>&1; cat " +
4184 tmpSubsystemFilename +
" 2>&1")
4189 (
"rm " + tmpSubsystemFilename +
" 2>/dev/null; scp " + hostname +
":" +
4190 filename +
" " + tmpSubsystemFilename +
" 2>&1; cat " +
4191 tmpSubsystemFilename +
" 2>&1")
4196 __GEN_COUT__ <<
"Local user date path identified." << __E__;
4200 __GEN_COUTTV__(cmdResult);
4201 if(cmdResult.find(
"Permission denied") != std::string::npos)
4204 <<
"Permission denied accessing user data path specified for subsystem '"
4205 << otherSubsystemUID <<
"': ";
4207 ss << username <<
"@";
4209 ss << hostname <<
":";
4210 ss << userDataPath << __E__;
4215 cmdResult, {
'\n'} , {
' ',
'\t'} );
4217 __GEN_COUTTV__(subsystemActiveGroupMap.size());
4221 for(
unsigned int i = 0; i + 1 < subsystemActiveGroupMap.size(); i += 2)
4223 if(subsystemActiveGroupMap[i] ==
"" || subsystemActiveGroupMap[i + 1] ==
"-1")
4226 __GEN_COUTT__ <<
"Loading type of subsystem '" << otherSubsystemUID <<
"' group "
4227 << subsystemActiveGroupMap[i] <<
"("
4228 << subsystemActiveGroupMap[i + 1] <<
")" << __E__;
4244 catch(
const std::runtime_error& e)
4246 __GEN_COUT__ <<
"Ignoring error loading subsystem '" << otherSubsystemUID
4247 <<
"' group " << subsystemActiveGroupMap[i] <<
"("
4248 << subsystemActiveGroupMap[i + 1] <<
"): " << __E__ << e.what()
4250 groupType = ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN;
4252 retMap[groupType] = std::make_pair(subsystemActiveGroupMap[i],
4262 std::set<std::string >
4265 std::set<std::string> retSet;
4267 std::map<std::string ,
4269 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
4272 auto it = retMap.find(
4274 if(it == retMap.end())
4277 <<
"No active Backbone group found in the active groups of remote subsystem '"
4278 << otherSubsystemUID <<
"!'" << __E__;
4281 auto it2 = retMap.find(
4283 if(it2 == retMap.end())
4286 <<
"No active Context group found in the active groups of remote subsystem '"
4287 << otherSubsystemUID <<
"!'" << __E__;
4291 std::string accumulatedWarnings;
4300 &accumulatedWarnings
4302 __GEN_COUTTV__(accumulatedWarnings);
4305 std::vector<std::pair<std::string, ConfigurationTree>> entries =
4308 for(
auto& entry : entries)
4310 if(entry.first.find(
"Context") == std::string::npos &&
4311 entry.first.find(
"Iterat") == std::string::npos)
4312 retSet.emplace(entry.first);
4319 std::set<std::string >
4321 const std::string& otherSubsystemUID,
const std::string& otherSubsystemFsmName)
4323 std::set<std::string> retSet;
4325 std::map<std::string ,
4327 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
4330 auto it = retMap.find(
4332 if(it == retMap.end())
4335 <<
"No active Backbone group found in the active groups of remote subsystem '"
4336 << otherSubsystemUID <<
"!'" << __E__;
4339 auto it2 = retMap.find(
4341 if(it2 == retMap.end())
4344 <<
"No active Context group found in the active groups of remote subsystem '"
4345 << otherSubsystemUID <<
"!'" << __E__;
4349 std::string accumulatedWarnings;
4358 &accumulatedWarnings
4365 &accumulatedWarnings
4367 __GEN_COUTTV__(accumulatedWarnings);
4370 std::vector<std::pair<std::string, ConfigurationTree>> entries =
4375 std::string stateMachineAliasFilter =
"*";
4380 otherGatewayNode.
getNode(
"LinkToStateMachineTable")
4381 .
getNode(otherSubsystemFsmName +
"/SystemAliasFilter");
4383 stateMachineAliasFilter = fsmFilterNode.
getValue<std::string>();
4385 __GEN_COUT_INFO__ <<
"FSM has no SystemAliasFilter value." << __E__;
4387 catch(std::runtime_error& e)
4389 __COUT__ <<
"Ignoring unsetup SystemAliasFilter value: " << e.what() << __E__;
4393 __COUT__ <<
"Ignoring unsetup SystemAliasFilter value." << __E__;
4396 __COUT__ <<
"Applying alias filter for other user_data path FSM '"
4397 << otherSubsystemFsmName
4398 <<
"' and stateMachineAliasFilter = " << stateMachineAliasFilter << __E__;
4405 stateMachineAliasFilter.size() && stateMachineAliasFilter[0] ==
'!';
4406 std::vector<std::string> filterArr;
4413 while((f = stateMachineAliasFilter.find(
'*', i)) != std::string::npos)
4415 tmp = stateMachineAliasFilter.substr(i, f - i);
4417 filterArr.push_back(tmp);
4418 __COUTS__(20) << filterArr[filterArr.size() - 1] <<
" " << i <<
" of "
4419 << stateMachineAliasFilter.size() << __E__;
4421 if(i <= stateMachineAliasFilter.size())
4423 tmp = stateMachineAliasFilter.substr(i);
4424 filterArr.push_back(tmp);
4425 __COUTS__(20) << filterArr[filterArr.size() - 1] <<
" last." << __E__;
4430 for(
auto& aliasMapPair : entries)
4432 __COUTS__(20) <<
"aliasMapPair.first: " << aliasMapPair.first << __E__;
4436 if(filterArr.size() == 1)
4438 if(filterArr[0] !=
"" && filterArr[0] !=
"*" &&
4439 aliasMapPair.first != filterArr[0])
4440 filterMatch =
false;
4445 for(f = 0; f < filterArr.size(); ++f)
4447 if(!filterArr[f].size())
4452 if((i = aliasMapPair.first.find(filterArr[f])) != 0)
4454 filterMatch =
false;
4458 else if(f == filterArr.size() - 1)
4460 if(aliasMapPair.first.rfind(filterArr[f]) !=
4461 aliasMapPair.first.size() - filterArr[f].size())
4463 filterMatch =
false;
4467 else if((i = aliasMapPair.first.find(filterArr[f])) ==
4470 filterMatch =
false;
4477 filterMatch = !filterMatch;
4479 __COUTS__(20) <<
"filterMatch=" << filterMatch << __E__;
4484 retSet.emplace(aliasMapPair.first);
4496 const std::string& otherSubsystemUID,
4497 const std::string& configAlias,
4498 std::pair<std::string, TableGroupKey>& groupTranslation,
4499 std::string& groupComment,
4500 std::string& groupAuthor,
4501 std::string& groupCreationTime)
4503 __GEN_COUTV__(otherSubsystemUID);
4505 std::map<std::string ,
4507 retMap = getOtherSubsystemActiveTableGroups(otherSubsystemUID);
4510 auto it = retMap.find(
4512 if(it == retMap.end())
4515 <<
"No active Backbone group found in the active groups of remote subsystem '"
4516 << otherSubsystemUID <<
"!'" << __E__;
4519 auto it2 = retMap.find(
4521 if(it2 == retMap.end())
4524 <<
"No active Context group found in the active groups of remote subsystem '"
4525 << otherSubsystemUID <<
"!'" << __E__;
4529 std::string accumulatedWarnings;
4538 &accumulatedWarnings
4540 __GEN_COUTTV__(accumulatedWarnings);
4547 getNode(ConfigurationManager::GROUP_ALIASES_TABLE_NAME).
getNode(configAlias);
4549 groupTranslation = std::pair<std::string, TableGroupKey>(
4552 __COUT__ <<
"Found " << configAlias <<
" translates to " << groupTranslation.first
4553 <<
"(" << groupTranslation.second <<
")" << __E__;
4559 groupTranslation.second,
4563 &accumulatedWarnings,
4571 __COUT_WARN__ <<
"Failed to load group metadata." << __E__;
4573 __COUT__ <<
"Found " << configAlias <<
" author: " << groupAuthor
4574 <<
", createTime: " << groupCreationTime <<
", comment: " << groupComment
4579 __GEN_SS__ <<
"Did not find the Configuration Alias '" << configAlias
4580 <<
"' in the active Backbone group of remote subsystem '"
4581 << otherSubsystemUID <<
"!'" << __E__;
4589 TableBase* ConfigurationManager::getDesktopIconTable(
void)
4591 if(nameToTableMap_.find(DESKTOP_ICON_TABLE_NAME) == nameToTableMap_.end())
4593 __SS__ <<
"Desktop icon table not found!" << __E__;
4598 return nameToTableMap_.at(DESKTOP_ICON_TABLE_NAME);
4602 void ConfigurationManager::saveGroupNameAndKey(
4603 const std::pair<std::string /*group name*/, TableGroupKey>& theGroup,
4604 const std::string& fileName,
4607 std::string fullPath =
4608 ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/" + fileName;
4610 std::ofstream groupFile;
4612 groupFile.open(fullPath.c_str(), std::ios::app);
4614 groupFile.open(fullPath.c_str());
4615 if(!groupFile.is_open())
4617 __SS__ <<
"Error. Can't open file to save group activity: " << fullPath << __E__;
4620 std::stringstream outss;
4621 outss << theGroup.first <<
"\n" << theGroup.second <<
"\n" << time(0);
4622 groupFile << outss.str().c_str();
4634 std::string& returnedTimeString)
4636 std::string fullPath =
4637 ConfigurationManager::LAST_TABLE_GROUP_SAVE_PATH +
"/" + fileName;
4639 FILE* groupFile = fopen(fullPath.c_str(),
"r");
4642 __COUT__ <<
"Can't open file: " << fullPath << __E__;
4644 __COUT__ <<
"Returning empty groupName and key -1" << __E__;
4653 fgets(line, 500, groupFile);
4654 if(strlen(line) && line[strlen(line) - 1] ==
'\n')
4655 line[strlen(line) - 1] =
'\0';
4656 theGroup.first = line;
4658 fgets(line, 500, groupFile);
4660 sscanf(line,
"%d", &key);
4661 theGroup.second = key;
4663 fgets(line, 500, groupFile);
4665 sscanf(line,
"%ld", ×tamp);
4672 __COUT__ <<
"theGroup.first=" << theGroup.first
4673 <<
" theGroup.second=" << theGroup.second << __E__;
virtual std::map< std::string, TableVersion > getTableGroupMembers(std::string const &, bool=false) const
std::map< std::string, std::map< std::string, TableVersion > > getVersionAliases(void) const
static const unsigned int PROCESSOR_COUNT
Static members.
static const std::string & convertGroupTypeToName(const ConfigurationManager::GroupType &groupTypeId)
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 loadMemberMap(const std::map< std::string, TableVersion > &memberMap, std::string *accumulateWarnings=0)
void dumpActiveConfiguration(const std::string &filePath, const std::string &dumpType, const std::string &configurationAlias, const std::string &logEntry, const std::string &activeUsers, std::ostream &altOut=std::cout)
std::map< std::string, TableVersion > getActiveVersions(void) const
getActiveVersions
ConfigurationManager(bool initForWriteAccess=false, bool initializeFromFhicl=false)
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::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)
ConfigurationTree getNode(const std::string &nodeString, bool doNotThrowOnBrokenUIDLinks=false) const
"root/parent/parent/"
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 getOtherSubsystemConfigAliasInfo(const std::string &otherSubsystemUID, const std::string &configAlias, std::pair< std::string, TableGroupKey > &groupTranslation, std::string &groupComment, std::string &groupAuthor, std::string &groupCreationTime)
returns configAlias translation group info by reference
ConfigurationTree getGatewaySupervisorNode(void) const
There can only be one active Gateway Superivsor app, so find it.
static const std::string ACTIVE_GROUPS_FILENAME
added env check for otsdaq_flatten_active_to_version to function
std::set< std::string > getOtherSubsystemFilteredConfigAliases(const std::string &otherSubsystemUID, const std::string &otherSubsystemFsmName)
Ignore any System Aliases with "Context" or "Iterat" in the name.
TableGroupKey loadConfigurationBackbone(void)
const TableBase * getTableByName(const std::string &configurationName) const
static std::pair< std::string, TableGroupKey > loadGroupNameAndKey(const std::string &fileName, std::string &returnedTimeString)
std::map< std::string, std::pair< std::string, TableGroupKey > > getActiveGroupAliases(void)
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="")
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
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="")
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 vectorToString(const std::vector< T > &setToReturn, const std::string &delimeter=", ")
vectorToString ~
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)