otsdaq  3.10.00
ConfigurationManagerRW.h
1 #ifndef _ots_ConfigurationManagerRW_h_
2 #define _ots_ConfigurationManagerRW_h_
3 
4 #include "otsdaq/ConfigurationInterface/ConfigurationManager.h"
5 
6 // clang-format off
7 
8 namespace ots
9 {
10 struct TableInfo
11 {
12  TableInfo()
13  : // constructor
14  tablePtr_(0)
15  {
16  }
17 
18  std::set<TableVersion> versions_;
19  TableBase* tablePtr_;
20  std::string accumulatedWarnings_;
21 }; //end TableInfo struct
22 
23 struct GroupInfo
24 {
25  friend class
26  ConfigurationManagerRW; //ConfigurationManagerRW can access GroupInfo private members
27 
28  GroupInfo()
29  : //constructor
30  latestKeyGroupAuthor_ (ConfigurationManager::UNKNOWN_INFO)
31  , latestKeyGroupComment_ (ConfigurationManager::UNKNOWN_INFO)
32  , latestKeyGroupCreationTime_ (ConfigurationManager::UNKNOWN_TIME)
33  , latestKeyGroupTypeString_ (ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN)
34  {
35  }
36 
37  const std::set<TableGroupKey>& getKeys() const { return keys_; }
38  const TableGroupKey& getLatestKey() const { return latestKey_; }
39  const std::string& getLatestKeyGroupAuthor() const { return latestKeyGroupAuthor_; }
40  const std::string& getLatestKeyGroupComment() const { return latestKeyGroupComment_; }
41  const std::string& getLatestKeyGroupCreationTime() const { return latestKeyGroupCreationTime_; }
42  const std::string& getLatestKeyGroupTypeString() const { return latestKeyGroupTypeString_; }
43  const std::map<std::string /*name*/,
44  TableVersion /*version*/>& getLatestKeyMemberMap() const { return latestKeyMemberMap_; }
45  TableGroupKey getLastKey() const { if(keys_.size()) return *(keys_.rbegin()); else return TableGroupKey(); }
46 
47  private:
48  std::set<TableGroupKey> keys_;
49  TableGroupKey latestKey_;
50  std::string latestKeyGroupAuthor_, latestKeyGroupComment_,
51  latestKeyGroupCreationTime_, latestKeyGroupTypeString_;
52  std::map<std::string /*name*/,
53  TableVersion /*version*/> latestKeyMemberMap_;
54 }; //end GroupInfo struct
55 
56 #define __GET_TABLE_PTR__(X) getTablePtr<X>(QUOTE(X))
57 
58 //==============================================================================
64 {
65  public:
66  ConfigurationManagerRW(const std::string& username);
67 
68 
69  //==============================================================================
71  const std::string& getUsername (void) const { return username_; }
72  ConfigurationInterface* getConfigurationInterface (void) const { return theInterface_; }
73 
74  const std::map<std::string, TableInfo>& getAllTableInfo (bool refresh = false,
75  std::string* accumulatedWarnings = 0,
76  const std::string& errorFilterName = "",
77  bool getGroupKeys = false,
78  bool getGroupInfo = false,
79  bool initializeActiveGroups = false);
80  std::map<std::string /*tableName*/,
81  std::map<std::string /*aliasName*/,
82  TableVersion /*version*/> > getVersionAliases (void) const;
83 
84  template<class T>
85  T* getTablePtr (const std::string& tableName) { return (T*)getTableByName(tableName); }
86  TableBase* getVersionedTableByName (const std::string& tableName, TableVersion version, bool looseColumnMatching = false, std::string* accumulatedErrors = 0, bool getRawData = false, bool touchLastAccessTime = true) /* make protected function accessible to RW users */ { return ConfigurationManager::getVersionedTableByName(tableName, version, looseColumnMatching, accumulatedErrors, getRawData, touchLastAccessTime); }
87  time_t getVersionCreationTime (const std::string& tableName, TableVersion version);
88  time_t getVersionLastAccessTime (const std::string& tableName, TableVersion version);
89  void preloadVersionCreationTimes (void);
90  TableBase* getTableByName (const std::string& tableName);
91  TableGroupKey findTableGroup (const std::string& groupName,
92  const std::map<std::string, TableVersion>& groupMembers,
93  const std::map<std::string /*name*/, std::string /*alias*/>& groupAliases = std::map<std::string /*name*/, std::string /*alias*/>());
94  TableBase* getMetadataTable (TableVersion fillVersion = TableVersion());
95 
96  //==============================================================================
98  const std::string& setUsername (const std::string& username) { username_ = username; return username_; }
99 
100  //==============================================================================
102  TableVersion saveNewTable (const std::string& tableName, TableVersion temporaryVersion = TableVersion(), bool makeTemporary = false);
104  const std::string& tableName,
105  TableVersion originalVersion,
106  bool makeTemporary,
107  TableBase* config,
108  TableVersion temporaryModifiedVersion,
109  bool ignoreDuplicates = false,
110  bool lookForEquivalent = false,
111  bool* foundEquivalent = nullptr);
112 
114  const std::string& tableName,
115  const std::map<std::string /*uid*/,
116  std::map<std::string /*colName*/, std::string /*value*/>>& cellUpdates,
117  const std::string& author,
118  TableVersion sourceVersion = TableVersion(),
119  const std::string& versionAlias = "",
120  const std::string& sourceAlias = "",
121  const std::string& comment = "");
122 
123  TableVersion copyViewToCurrentColumns (const std::string& tableName, TableVersion sourceVersion);
124  void eraseTemporaryVersion (const std::string& tableName, TableVersion targetVersion = TableVersion());
125  void clearCachedVersions (const std::string& tableName);
126  void clearAllCachedVersions (void);
127 
128  //==============================================================================
130  void activateTableGroup (const std::string& tableGroupName, TableGroupKey tableGroupKey, std::string* accumulatedTreeErrors = 0, std::string* groupTypeString = 0);
131 
133  TableVersion saveNewBackbone (TableVersion temporaryVersion = TableVersion());
134 
135  //==============================================================================
137  TableGroupKey saveNewTableGroup (const std::string& groupName, std::map<std::string, TableVersion>& groupMembers,
138  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
139  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
140 
141  //==============================================================================
143  const GroupInfo& getGroupInfo (const std::string& groupName, bool attemptToReloadKeys = false);
144  const std::map<std::string, GroupInfo>& getAllGroupInfo (void) { return allGroupInfo_; }
145  void loadTableGroup (
146  const std::string& tableGroupName,
147  const TableGroupKey& tableGroupKey,
148  bool doActivate = false,
149  std::map<std::string, TableVersion>* groupMembers = 0,
150  ProgressBar* progressBar = 0,
151  std::string* accumulateWarnings = 0,
152  std::string* groupComment = 0,
153  std::string* groupAuthor = 0,
154  std::string* groupCreateTime = 0,
155  bool doNotLoadMember = false,
156  std::string* groupTypeString = 0,
157  std::map<std::string /*name*/, std::string /*alias*/>* groupAliases = 0,
158  ConfigurationManager::LoadGroupType groupTypeToLoad = ConfigurationManager::LoadGroupType::ALL_TYPES,
159  bool ignoreVersionTracking = false);
160 
161  void testXDAQContext (void);
162 
163  public:
164  static void loadTableInfoThread (ConfigurationManagerRW* cfgMgr,
165  std::string tableName,
166  TableBase* existingTable,
167  std::shared_ptr<ots::TableInfo> tableInfo,
168  std::shared_ptr<std::atomic<bool>> threadDone);
169  static void loadTableGroupThread (ConfigurationManagerRW* cfgMgr,
170  std::string groupName,
171  ots::TableGroupKey groupKey,
172  std::shared_ptr<ots::GroupInfo> theGroupInfo,
173  std::shared_ptr<std::atomic<bool>> theThreadDone);
174  static void compareTableGroupThread (ConfigurationManagerRW* cfgMgr,
175  std::string groupName,
176  ots::TableGroupKey groupKeyToCompare,
177  const std::map<std::string, TableVersion>& groupMemberMap,
178  const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
179  std::atomic<bool>* theFoundIdentical,
180  ots::TableGroupKey* theIdenticalKey,
181  std::mutex* theThreadMutex,
182  std::shared_ptr<std::atomic<bool>> theThreadDone);
183  private:
184 
185  //==============================================================================
187  std::map<std::string, TableInfo> allTableInfo_; //local cache of table info
188  std::map<std::string, GroupInfo> allGroupInfo_; //local cache of group info
189 
190  //process-wide version creation time cache: persistent versions are immutable, so
191  // creation times can be cached forever; shared by all instances (i.e. all user
192  // sessions) within this process
193  static std::mutex versionCreationTimeCacheMutex_;
194  static std::map<std::string /*tableName*/,
195  std::map<TableVersion, time_t>> versionCreationTimeCache_;
196 
197  static std::atomic<bool> firstTimeConstructed_;
198 };
199 
200 //==============================================================================
204 {
207  TableView* tableView_;
208  TableVersion temporaryVersion_, originalVersion_;
210  bool modified_;
211  std::string tableName_;
212  const std::string mfSubject_;
213 
216  {
217  __SS__ << "impossible!" << std::endl;
218  ss << StringMacros::stackTrace();
219  __SS_THROW__;
220  }
221  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr, bool markModified = false)
222  : createdTemporaryVersion_(false), modified_(markModified), tableName_(tableName)
223  , mfSubject_(cfgMgr->getUsername())
224  {
225  //__COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
226  table_ = cfgMgr->getTableByName(tableName_);
227 
228  //if no active version or if not temporary, setup new temporary version
229  if(!table_->isActive() ||
230  !(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
231  {
232  //__COUT__ << "Original '" << tableName_ << "' version is v" << originalVersion_ << std::endl;
233 
234  // create temporary version for editing
235  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
236  cfgMgr->saveNewTable(
237  tableName_,
238  temporaryVersion_,
239  true);
240 
241  __COUT__ << "Created '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
243  }
244  //else // else table is already temporary version
245  //__COUT__ << "Using '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
246 
247  tableView_ = table_->getViewP();
248  }
249 }; // end TableEditStruct declaration
250 
251 //==============================================================================
255 {
257 private:
258  std::map<std::string, TableVersion> groupMembers_;
259  std::map<std::string, TableEditStruct> groupTables_;
260 public:
261  const ConfigurationManager::GroupType groupType_;
262  const std::string originalGroupName_;
263  const TableGroupKey originalGroupKey_;
264 private:
265  ConfigurationManagerRW* cfgMgr_;
266  const std::string mfSubject_;
267 
268 public:
271  : groupType_(ConfigurationManager::GroupType::CONFIGURATION_TYPE) {__SS__ << "impossible!" << __E__; __SS_THROW__;}
272  GroupEditStruct(const ConfigurationManager::GroupType& groupType, ConfigurationManagerRW* cfgMgr);
273 
274  ~GroupEditStruct();
275 
276  void dropChanges (void);
277  void saveChanges (
278  const std::string& groupNameToSave,
279  TableGroupKey& newGroupKey,
280  bool* foundEquivalentGroupKey = nullptr,
281  bool activateNewGroup = false,
282  bool updateGroupAliases = false,
283  bool updateTableAliases = false,
284  TableGroupKey* newBackboneKey = nullptr,
285  bool* foundEquivalentBackboneKey = nullptr,
286  std::string* accumulatedWarnings = nullptr);
287 
288  TableEditStruct& getTableEditStruct (const std::string& tableName, bool markModified = false);
289 
290 }; // end GroupEditStruct declaration
291 
292 // clang-format on
293 } // namespace ots
294 
295 #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 >())
TableVersion updateTableCells(const std::string &tableName, const std::map< std::string, std::map< std::string, std::string >> &cellUpdates, const std::string &author, TableVersion sourceVersion=TableVersion(), const std::string &versionAlias="", const std::string &sourceAlias="", const std::string &comment="")
void testXDAQContext(void)
for debugging
TableVersion saveNewBackbone(TableVersion temporaryVersion=TableVersion())
const std::string & setUsername(const std::string &username)
Setters.
const GroupInfo & getGroupInfo(const std::string &groupName, bool attemptToReloadKeys=false)
public group cache handling
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)
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)
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
TableBase * getMetadataTable(TableVersion fillVersion=TableVersion())
created for use in otsdaq_flatten_system_aliases and otsdaq_export_system_aliases,...
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
void clearCachedVersions(const std::string &tableName)
time_t getVersionLastAccessTime(const std::string &tableName, TableVersion version)
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())
void preloadVersionCreationTimes(void)
parallel load of all version creation times into the process-wide cache
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)
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()
time_t getVersionCreationTime(const std::string &tableName, TableVersion version)
static void loadTableInfoThread(ConfigurationManagerRW *cfgMgr, std::string tableName, TableBase *existingTable, std::shared_ptr< ots::TableInfo > tableInfo, std::shared_ptr< std::atomic< bool >> threadDone)
loadTableInfoThread()
TableBase * getVersionedTableByName(const std::string &tableName, TableVersion version, bool looseColumnMatching=false, std::string *accumulatedErrors=0, bool getRawData=false, bool touchLastAccessTime=true)
TableVersion createTemporaryView(TableVersion sourceViewVersion=TableVersion(), TableVersion destTemporaryViewVersion=TableVersion::getNextTemporaryVersion())
source of -1, from MockUp, else from valid view version
Definition: TableBase.cc:1773
bool isActive(void)
isActive
Definition: TableBase.cc:950
defines used also by OtsConfigurationWizardSupervisor
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