otsdaq  v2_04_02
ConfigurationManager.h
1 #ifndef _ots_ConfigurationManager_h_
2 #define _ots_ConfigurationManager_h_
3 
4 #include <map>
5 #include <set>
6 #include <string>
7 
8 #include "otsdaq/ConfigurationInterface/ConfigurationInterface.h"
9 #include "otsdaq/ConfigurationInterface/ConfigurationTree.h"
10 #include "otsdaq/TableCore/TableVersion.h"
11 
12 namespace ots
13 {
14 class ProgressBar;
15 
16 #define __GET_CONFIG__(X) getTable<X>(QUOTE(X))
17 
19 {
20  // ConfigurationManagerRW is a "Friend" class of ConfigurationManager so has access to
21  // private members.
22  friend class ConfigurationManagerRW;
23 
24  public:
25  //==============================================================================
26  // Static members
27  static const std::string READONLY_USER;
28  static const std::string ACTIVE_GROUPS_FILENAME;
29  static const std::string ALIAS_VERSION_PREAMBLE;
30  static const std::string SCRATCH_VERSION_ALIAS;
31 
32  static const std::string XDAQ_CONTEXT_TABLE_NAME;
33  static const std::string XDAQ_APPLICATION_TABLE_NAME;
34  static const std::string GROUP_ALIASES_TABLE_NAME;
35  static const std::string VERSION_ALIASES_TABLE_NAME;
36 
37  static const std::string ACTIVE_GROUP_NAME_CONTEXT;
38  static const std::string ACTIVE_GROUP_NAME_BACKBONE;
39  static const std::string ACTIVE_GROUP_NAME_ITERATE;
40  static const std::string ACTIVE_GROUP_NAME_CONFIGURATION;
41  static const std::string ACTIVE_GROUP_NAME_UNKNOWN;
42 
43  static const uint8_t METADATA_COL_ALIASES;
44  static const uint8_t METADATA_COL_COMMENT;
45  static const uint8_t METADATA_COL_AUTHOR;
46  static const uint8_t METADATA_COL_TIMESTAMP;
47 
48  static const std::set<std::string> contextMemberNames_; // list of context members
49  static const std::set<std::string> backboneMemberNames_; // list of backbone members
50  static const std::set<std::string> iterateMemberNames_; // list of iterate members
51 
52  enum
53  {
54  CONTEXT_TYPE,
55  BACKBONE_TYPE,
56  ITERATE_TYPE,
57  CONFIGURATION_TYPE
58  };
59 
60  // clang-format off
61 
62  static const std::set<std::string>& getContextMemberNames (void);
63  static const std::set<std::string>& getBackboneMemberNames (void);
64  static const std::set<std::string>& getIterateMemberNames (void);
65 
66  static const std::string& convertGroupTypeIdToName (int groupTypeId);
67  static int getTypeOfGroup (const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap);
68  static const std::string& getTypeNameOfGroup (const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap);
69 
70  //==============================================================================
71  // Construct/Destruct
72 
73  ConfigurationManager(bool initForWriteAccess = false,
74  bool initializeFromFhicl = false);
75  virtual ~ConfigurationManager(void);
76 
77 
78 
79  void init (std::string* accumulatedErrors = 0, bool initForWriteAccess = false);
80  void destroy (void);
81  void destroyTableGroup (const std::string& theGroup = "", bool onlyDeactivate = false);
82 
83  //==============================================================================
84  // Getters
85 
86  void loadTableGroup (
87  const std::string& configGroupName,
88  TableGroupKey tableGroupKey,
89  bool doActivate = false,
90  std::map<std::string, TableVersion>* groupMembers = 0,
91  ProgressBar* progressBar = 0,
92  std::string* accumulateWarnings = 0,
93  std::string* groupComment = 0,
94  std::string* groupAuthor = 0,
95  std::string* groupCreateTime = 0,
96  bool doNotLoadMember = false,
97  std::string* groupTypeString = 0,
98  std::map<std::string /*name*/, std::string /*alias*/>* groupAliases = 0,
99  bool onlyLoadIfBackboneOrContext = false);
100  void loadMemberMap (const std::map<std::string /*name*/, TableVersion /*version*/>& memberMap, std::string* accumulateWarnings = 0);
101  TableGroupKey loadConfigurationBackbone (void);
102 
103  //================
104  // getTable
105  // get configuration * with specific configuration type
106  template<class T>
107  const T* getTable (std::string name) const { return (T*)(getTableByName(name)); }
108  const TableBase* getTableByName (const std::string& configurationName) const;
109 
110  void dumpActiveConfiguration (const std::string& filePath, const std::string& dumpType);
111  void dumpMacroMakerModeFhicl (void);
112 
113  std::map<std::string /*groupAlias*/,
114  std::pair<std::string /*groupName*/,
115  TableGroupKey>> getActiveGroupAliases (void);
116  // Note: this ConfigurationManager::getVersionAliases is called internally and by
117  // ConfigurationManagerRW::getVersionAliases
118  std::map<std::string /*tableName*/,
119  std::map<std::string /*aliasName*/,
120  TableVersion>> getVersionAliases (void) const;
121  std::pair<std::string /*groupName*/,
122  TableGroupKey> getTableGroupFromAlias (std::string systemAlias, ProgressBar* progressBar = 0);
123  std::map<std::string /*groupType*/,
124  std::pair<std::string /*groupName*/,
125  TableGroupKey>> getActiveTableGroups (void) const;
126  const std::map<std::string /*groupType*/,
127  std::pair<std::string /*groupName*/,
128  TableGroupKey>>& getFailedTableGroups (void) const {return lastFailedGroupLoad_;}
129  const std::string& getActiveGroupName (const std::string& type = "") const;
130  TableGroupKey getActiveGroupKey (const std::string& type = "") const;
131 
132  ConfigurationTree getNode (const std::string& nodeString, bool doNotThrowOnBrokenUIDLinks = false) const; //"root/parent/parent/"
133  ConfigurationTree getContextNode (const std::string& contextUID, const std::string& applicationUID) const;
134  ConfigurationTree getSupervisorNode (const std::string& contextUID, const std::string& applicationUID) const;
135  ConfigurationTree getSupervisorTableNode (const std::string& contextUID, const std::string& applicationUID) const;
136 
137  std::vector<std::pair<std::string /*childName*/,
138  ConfigurationTree>> getChildren (std::map<std::string, TableVersion>* memberMap = 0, std::string* accumulatedTreeErrors = 0) const;
139  std::string getFirstPathToNode (const ConfigurationTree& node, const std::string& startPath = "/") const;
140 
141  std::map<std::string, TableVersion> getActiveVersions (void) const;
142 
143  const std::string& getOwnerContext (void) { return ownerContextUID_; }
144  const std::string& getOwnerApp (void) { return ownerAppUID_; }
145  bool isOwnerFirstAppInContext (void);
146 
147  //==============================================================================
148  // Setters/Modifiers
149  std::shared_ptr<TableGroupKey> makeTheTableGroupKey (TableGroupKey key);
150  void restoreActiveTableGroups (bool throwErrors = false, const std::string& pathToActiveGroupsFile = "", bool onlyLoadIfBackboneOrContext = false);
151 
152  void setOwnerContext (const std::string& contextUID) { ownerContextUID_ = contextUID; }
153  void setOwnerApp (const std::string& appUID) { ownerAppUID_ = appUID; }
154 
155  private:
156  ConfigurationManager(const std::string& userName); // private constructor called by ConfigurationManagerRW
157 
158  void initializeFromFhicl (const std::string& fhiclPath);
159  void recursiveInitFromFhiclPSet (const std::string& tableName, const fhicl::ParameterSet& pset, const std::string& recordName = "", const std::string& groupName = "", const std::string& groupLinkIndex = "");
160  void recursiveTreeToFhicl (ConfigurationTree node, std::ostream& out, std::string& tabStr, std::string& commentStr, unsigned int depth = -1);
161 
162  std::string username_; // user of the configuration is READONLY_USER unless using ConfigurationManagerRW
163  ConfigurationInterface* theInterface_;
164  std::shared_ptr<TableGroupKey> theConfigurationTableGroupKey_, theContextTableGroupKey_, theBackboneTableGroupKey_, theIterateTableGroupKey_;
165  std::string theConfigurationTableGroup_, theContextTableGroup_, theBackboneTableGroup_, theIterateTableGroup_;
166 
167  std::map<std::string,
168  std::pair<std::string, TableGroupKey>> lastFailedGroupLoad_;
169 
170  std::map<std::string, TableBase*> nameToTableMap_;
171 
172  TableBase groupMetadataTable_; // special table - version saved each time a group is created
173 
174  std::string ownerContextUID_; // optional, often there is a context that owns this configuration manager
175  std::string ownerAppUID_; // optional, often there is a supervisor that owns this configuration manager
176 
177  // clang-format on
178 };
179 } // namespace ots
180 
181 #endif