tdaq-develop-2025-02-12
ConfigurationManagerRW.h
1 #ifndef _ots_ConfigurationManagerRW_h_
2 #define _ots_ConfigurationManagerRW_h_
3 
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 
6 namespace ots
7 {
8 struct TableInfo
9 {
10  TableInfo()
11  : // constructor
12  tablePtr_(0)
13  {
14  }
15 
16  std::set<TableVersion> versions_;
17  TableBase* tablePtr_;
18  std::string accumulatedWarnings_;
19 };
20 
21 struct GroupInfo
22 {
23  GroupInfo()
24  : //constructor
25  latestKeyGroupAuthor_(ConfigurationManager::UNKNOWN_INFO)
26  , latestKeyGroupComment_(ConfigurationManager::UNKNOWN_INFO)
27  , latestKeyGroupCreationTime_(ConfigurationManager::UNKNOWN_TIME)
28  , latestKeyGroupTypeString_(ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN)
29  {
30  }
31 
32  std::set<TableGroupKey> keys_;
33  std::string latestKeyGroupAuthor_, latestKeyGroupComment_,
34  latestKeyGroupCreationTime_, latestKeyGroupTypeString_;
35  std::map<std::string /*name*/, TableVersion /*version*/> latestKeyMemberMap_;
36 
37  TableGroupKey getLatestKey()
38  {
39  if(keys_.size())
40  return *(keys_.rbegin());
41  else
42  return TableGroupKey();
43  }
44 };
45 
46 #define __GETCFG_RW__(X) getConfigurationRW<X>(QUOTE(X))
47 
48 //==============================================================================
54 {
55  // clang-format off
56  public:
57  ConfigurationManagerRW(const std::string& username);
58 
59 
60  //==============================================================================
62  const std::string& getUsername (void) const { return username_; }
63  ConfigurationInterface* getConfigurationInterface (void) const { return theInterface_; }
64 
65  const std::map<std::string, TableInfo>& getAllTableInfo (bool refresh = false,
66  std::string* accumulatedWarnings = 0,
67  const std::string& errorFilterName = "",
68  bool getGroupKeys = false,
69  bool getGroupInfo = false,
70  bool initializeActiveGroups = false);
71  std::map<std::string /*tableName*/,
72  std::map<std::string /*aliasName*/,
73  TableVersion /*version*/> > getVersionAliases (void) const;
74 
75  template<class T>
76  T* getConfigurationRW (std::string name) { return (T*)getTableByName(name); }
77  TableBase* getVersionedTableByName (const std::string& tableName, TableVersion version, bool looseColumnMatching = false, std::string* accumulatedErrors = 0, bool getRawData = false);
78  TableBase* getTableByName (const std::string& tableName);
79  TableGroupKey findTableGroup (const std::string& groupName, const std::map<std::string, TableVersion>& groupMembers,
80  const std::map<std::string /*name*/, std::string /*alias*/>& groupAliases = std::map<std::string /*name*/, std::string /*alias*/>());
81  TableBase* getMetadataTable (void) { return &groupMetadataTable_; /* created for use in otsdaq_flatten_system_aliases, e.g. */ }
82 
83  //==============================================================================
85  TableVersion saveNewTable (const std::string& tableName, TableVersion temporaryVersion = TableVersion(), bool makeTemporary = false);
86  TableVersion saveModifiedVersion (
87  const std::string& tableName,
88  TableVersion originalVersion,
89  bool makeTemporary,
90  TableBase* config,
91  TableVersion temporaryModifiedVersion,
92  bool ignoreDuplicates = false,
93  bool lookForEquivalent = false,
94  bool* foundEquivalent = nullptr);
95 
96  TableVersion copyViewToCurrentColumns (const std::string& tableName, TableVersion sourceVersion);
97  void eraseTemporaryVersion (const std::string& tableName, TableVersion targetVersion = TableVersion());
98  void clearCachedVersions (const std::string& tableName);
99  void clearAllCachedVersions (void);
100 
101  //==============================================================================
103  void activateTableGroup (const std::string& tableGroupName, TableGroupKey tableGroupKey, std::string* accumulatedTreeErrors = 0, std::string* groupTypeString = 0);
104 
105  TableVersion createTemporaryBackboneView (TableVersion sourceViewVersion = TableVersion());
106  TableVersion saveNewBackbone (TableVersion temporaryVersion = TableVersion());
107 
108  //==============================================================================
110  TableGroupKey saveNewTableGroup (const std::string& groupName, std::map<std::string, TableVersion>& groupMembers,
111  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
112  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
113 
114  //==============================================================================
116  const GroupInfo& getGroupInfo (const std::string& groupName);
117  const std::map<std::string, GroupInfo>& getAllGroupInfo (void) { return allGroupInfo_; }
118 
119  void testXDAQContext (void);
120 
121  public:
122  static void loadTableInfoThread (ConfigurationManagerRW* cfgMgr,
123  std::string tableName,
124  TableBase* existingTable,
125  std::shared_ptr<ots::TableInfo> tableInfo,
126  std::shared_ptr<std::atomic<bool>> threadDone);
127  static void loadTableGroupThread (ConfigurationManagerRW* cfgMgr,
128  std::string groupName,
129  ots::TableGroupKey groupKey,
130  std::shared_ptr<ots::GroupInfo> theGroupInfo,
131  std::shared_ptr<std::atomic<bool>> theThreadDone);
132  static void compareTableGroupThread (ConfigurationManagerRW* cfgMgr,
133  std::string groupName,
134  ots::TableGroupKey groupKeyToCompare,
135  const std::map<std::string, TableVersion>& groupMemberMap,
136  const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
137  std::atomic<bool>* theFoundIdentical,
138  ots::TableGroupKey* theIdenticalKey,
139  std::mutex* theThreadMutex,
140  std::shared_ptr<std::atomic<bool>> theThreadDone);
141  private:
142 
143  //==============================================================================
145  void cacheGroupKey (const std::string& groupName, TableGroupKey key);
146 
147  //==============================================================================
149  std::map<std::string, TableInfo> allTableInfo_;
150  std::map<std::string, GroupInfo> allGroupInfo_;
151 
152  static std::atomic<bool> firstTimeConstructed_;
153 };
154 
155 //==============================================================================
159 {
162  TableView* tableView_;
163  TableVersion temporaryVersion_, originalVersion_;
165  bool modified_;
166  std::string tableName_;
167  const std::string mfSubject_;
168 
171  {
172  __SS__ << "impossible!" << std::endl;
173  ss << StringMacros::stackTrace();
174  __SS_THROW__;
175  }
176  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr, bool markModified = false)
177  : createdTemporaryVersion_(false), modified_(markModified), tableName_(tableName)
178  , mfSubject_(cfgMgr->getUsername())
179  {
180  //__COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
181  table_ = cfgMgr->getTableByName(tableName_);
182 
183  //if no active version or if not temporary, setup new temporary version
184  if(!table_->isActive() ||
185  !(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
186  {
187  //__COUT__ << "Original '" << tableName_ << "' version is v" << originalVersion_ << std::endl;
188 
189  // create temporary version for editing
190  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
191  cfgMgr->saveNewTable(
192  tableName_,
193  temporaryVersion_,
194  true);
195 
196  __COUT__ << "Created '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
198  }
199  //else // else table is already temporary version
200  //__COUT__ << "Using '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
201 
202  tableView_ = table_->getViewP();
203  }
204 }; // end TableEditStruct declaration
205 
206 
207 //==============================================================================
211 {
213 private:
214  std::map<std::string, TableVersion> groupMembers_;
215  std::map<std::string, TableEditStruct> groupTables_;
216 public:
217  const ConfigurationManager::GroupType groupType_;
218  const std::string originalGroupName_;
219  const TableGroupKey originalGroupKey_;
220 private:
221  ConfigurationManagerRW* cfgMgr_;
222  const std::string mfSubject_;
223 
224 public:
227  : groupType_(ConfigurationManager::GroupType::CONFIGURATION_TYPE) {__SS__ << "impossible!" << __E__; __SS_THROW__;}
228  GroupEditStruct(const ConfigurationManager::GroupType& groupType, ConfigurationManagerRW* cfgMgr);
229 
230  ~GroupEditStruct();
231 
232  void dropChanges (void);
233  void saveChanges (
234  const std::string& groupNameToSave,
235  TableGroupKey& newGroupKey,
236  bool* foundEquivalentGroupKey = nullptr,
237  bool activateNewGroup = false,
238  bool updateGroupAliases = false,
239  bool updateTableAliases = false,
240  TableGroupKey* newBackboneKey = nullptr,
241  bool* foundEquivalentBackboneKey = nullptr,
242  std::string* accumulatedWarnings = nullptr);
243 
244  TableEditStruct& getTableEditStruct (const std::string& tableName, bool markModified = false);
245 
246 }; // end GroupEditStruct declaration
247 
248 // clang-format on
249 } // namespace ots
250 
251 #endif
TableVersion saveNewTable(const std::string &tableName, TableVersion temporaryVersion=TableVersion(), bool makeTemporary=false)
modifiers of generic TableBase
TableGroupKey findTableGroup(const std::string &groupName, const std::map< std::string, TableVersion > &groupMembers, const std::map< std::string, std::string > &groupAliases=std::map< std::string, std::string >())
void testXDAQContext(void)
for debugging
TableVersion saveNewBackbone(TableVersion temporaryVersion=TableVersion())
const std::map< std::string, TableInfo > & getAllTableInfo(bool refresh=false, std::string *accumulatedWarnings=0, const std::string &errorFilterName="", bool getGroupKeys=false, bool getGroupInfo=false, bool initializeActiveGroups=false)
TableVersion copyViewToCurrentColumns(const std::string &tableName, TableVersion sourceVersion)
copyViewToCurrentColumns
TableGroupKey saveNewTableGroup(const std::string &groupName, std::map< std::string, TableVersion > &groupMembers, const std::string &groupComment=TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT, std::map< std::string, std::string > *groupAliases=0)
modifiers of a table group based on alias, e.g. "Physics"
void activateTableGroup(const std::string &tableGroupName, TableGroupKey tableGroupKey, std::string *accumulatedTreeErrors=0, std::string *groupTypeString=0)
modifiers of table groups
TableVersion saveModifiedVersion(const std::string &tableName, TableVersion originalVersion, bool makeTemporary, TableBase *config, TableVersion temporaryModifiedVersion, bool ignoreDuplicates=false, bool lookForEquivalent=false, bool *foundEquivalent=nullptr)
TableVersion createTemporaryBackboneView(TableVersion sourceViewVersion=TableVersion())
-1, from MockUp, else from valid backbone view version
const GroupInfo & getGroupInfo(const std::string &groupName)
public group cache handling
void clearCachedVersions(const std::string &tableName)
const std::string & getUsername(void) const
Getters.
std::map< std::string, std::map< std::string, TableVersion > > getVersionAliases(void) const
void eraseTemporaryVersion(const std::string &tableName, TableVersion targetVersion=TableVersion())
TableBase * getVersionedTableByName(const std::string &tableName, TableVersion version, bool looseColumnMatching=false, std::string *accumulatedErrors=0, bool getRawData=false)
static void compareTableGroupThread(ConfigurationManagerRW *cfgMgr, std::string groupName, ots::TableGroupKey groupKeyToCompare, const std::map< std::string, TableVersion > &groupMemberMap, const std::map< std::string, std::string > &memberTableAliases, std::atomic< bool > *theFoundIdentical, ots::TableGroupKey *theIdenticalKey, std::mutex *theThreadMutex, std::shared_ptr< std::atomic< bool >> theThreadDone)
compareTableGroupThread()
static void loadTableGroupThread(ConfigurationManagerRW *cfgMgr, std::string groupName, ots::TableGroupKey groupKey, std::shared_ptr< ots::GroupInfo > theGroupInfo, std::shared_ptr< std::atomic< bool >> theThreadDone)
loadTableGroupThread()
static void loadTableInfoThread(ConfigurationManagerRW *cfgMgr, std::string tableName, TableBase *existingTable, std::shared_ptr< ots::TableInfo > tableInfo, std::shared_ptr< std::atomic< bool >> threadDone)
loadTableInfoThread()
TableVersion createTemporaryView(TableVersion sourceViewVersion=TableVersion(), TableVersion destTemporaryViewVersion=TableVersion::getNextTemporaryVersion())
source of -1, from MockUp, else from valid view version
Definition: TableBase.cc:1601
bool isActive(void)
isActive
Definition: TableBase.cc:817
TableEditStruct & getTableEditStruct(const std::string &tableName, bool markModified=false)
Note: if markModified, and table not found in group, this function will try to add it to group.
static std::string stackTrace(void)
TableEditStruct(const std::string &tableName, ConfigurationManagerRW *cfgMgr, bool markModified=false)
TableBase * table_
everything needed for editing a table
bool createdTemporaryVersion_
indicates if temp version was created here
bool modified_
indicates if temp version was modified