otsdaq  3.09.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 
113  TableVersion copyViewToCurrentColumns (const std::string& tableName, TableVersion sourceVersion);
114  void eraseTemporaryVersion (const std::string& tableName, TableVersion targetVersion = TableVersion());
115  void clearCachedVersions (const std::string& tableName);
116  void clearAllCachedVersions (void);
117 
118  //==============================================================================
120  void activateTableGroup (const std::string& tableGroupName, TableGroupKey tableGroupKey, std::string* accumulatedTreeErrors = 0, std::string* groupTypeString = 0);
121 
123  TableVersion saveNewBackbone (TableVersion temporaryVersion = TableVersion());
124 
125  //==============================================================================
127  TableGroupKey saveNewTableGroup (const std::string& groupName, std::map<std::string, TableVersion>& groupMembers,
128  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
129  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
130 
131  //==============================================================================
133  const GroupInfo& getGroupInfo (const std::string& groupName, bool attemptToReloadKeys = false);
134  const std::map<std::string, GroupInfo>& getAllGroupInfo (void) { return allGroupInfo_; }
135  void loadTableGroup (
136  const std::string& tableGroupName,
137  const TableGroupKey& tableGroupKey,
138  bool doActivate = false,
139  std::map<std::string, TableVersion>* groupMembers = 0,
140  ProgressBar* progressBar = 0,
141  std::string* accumulateWarnings = 0,
142  std::string* groupComment = 0,
143  std::string* groupAuthor = 0,
144  std::string* groupCreateTime = 0,
145  bool doNotLoadMember = false,
146  std::string* groupTypeString = 0,
147  std::map<std::string /*name*/, std::string /*alias*/>* groupAliases = 0,
148  ConfigurationManager::LoadGroupType groupTypeToLoad = ConfigurationManager::LoadGroupType::ALL_TYPES,
149  bool ignoreVersionTracking = false);
150 
151  void testXDAQContext (void);
152 
153  public:
154  static void loadTableInfoThread (ConfigurationManagerRW* cfgMgr,
155  std::string tableName,
156  TableBase* existingTable,
157  std::shared_ptr<ots::TableInfo> tableInfo,
158  std::shared_ptr<std::atomic<bool>> threadDone);
159  static void loadTableGroupThread (ConfigurationManagerRW* cfgMgr,
160  std::string groupName,
161  ots::TableGroupKey groupKey,
162  std::shared_ptr<ots::GroupInfo> theGroupInfo,
163  std::shared_ptr<std::atomic<bool>> theThreadDone);
164  static void compareTableGroupThread (ConfigurationManagerRW* cfgMgr,
165  std::string groupName,
166  ots::TableGroupKey groupKeyToCompare,
167  const std::map<std::string, TableVersion>& groupMemberMap,
168  const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
169  std::atomic<bool>* theFoundIdentical,
170  ots::TableGroupKey* theIdenticalKey,
171  std::mutex* theThreadMutex,
172  std::shared_ptr<std::atomic<bool>> theThreadDone);
173  private:
174 
175  //==============================================================================
177  std::map<std::string, TableInfo> allTableInfo_; //local cache of table info
178  std::map<std::string, GroupInfo> allGroupInfo_; //local cache of group info
179 
180  //process-wide version creation time cache: persistent versions are immutable, so
181  // creation times can be cached forever; shared by all instances (i.e. all user
182  // sessions) within this process
183  static std::mutex versionCreationTimeCacheMutex_;
184  static std::map<std::string /*tableName*/,
185  std::map<TableVersion, time_t>> versionCreationTimeCache_;
186 
187  static std::atomic<bool> firstTimeConstructed_;
188 };
189 
190 //==============================================================================
194 {
197  TableView* tableView_;
198  TableVersion temporaryVersion_, originalVersion_;
200  bool modified_;
201  std::string tableName_;
202  const std::string mfSubject_;
203 
206  {
207  __SS__ << "impossible!" << std::endl;
208  ss << StringMacros::stackTrace();
209  __SS_THROW__;
210  }
211  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr, bool markModified = false)
212  : createdTemporaryVersion_(false), modified_(markModified), tableName_(tableName)
213  , mfSubject_(cfgMgr->getUsername())
214  {
215  //__COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
216  table_ = cfgMgr->getTableByName(tableName_);
217 
218  //if no active version or if not temporary, setup new temporary version
219  if(!table_->isActive() ||
220  !(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
221  {
222  //__COUT__ << "Original '" << tableName_ << "' version is v" << originalVersion_ << std::endl;
223 
224  // create temporary version for editing
225  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
226  cfgMgr->saveNewTable(
227  tableName_,
228  temporaryVersion_,
229  true);
230 
231  __COUT__ << "Created '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
233  }
234  //else // else table is already temporary version
235  //__COUT__ << "Using '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
236 
237  tableView_ = table_->getViewP();
238  }
239 }; // end TableEditStruct declaration
240 
241 //==============================================================================
245 {
247 private:
248  std::map<std::string, TableVersion> groupMembers_;
249  std::map<std::string, TableEditStruct> groupTables_;
250 public:
251  const ConfigurationManager::GroupType groupType_;
252  const std::string originalGroupName_;
253  const TableGroupKey originalGroupKey_;
254 private:
255  ConfigurationManagerRW* cfgMgr_;
256  const std::string mfSubject_;
257 
258 public:
261  : groupType_(ConfigurationManager::GroupType::CONFIGURATION_TYPE) {__SS__ << "impossible!" << __E__; __SS_THROW__;}
262  GroupEditStruct(const ConfigurationManager::GroupType& groupType, ConfigurationManagerRW* cfgMgr);
263 
264  ~GroupEditStruct();
265 
266  void dropChanges (void);
267  void saveChanges (
268  const std::string& groupNameToSave,
269  TableGroupKey& newGroupKey,
270  bool* foundEquivalentGroupKey = nullptr,
271  bool activateNewGroup = false,
272  bool updateGroupAliases = false,
273  bool updateTableAliases = false,
274  TableGroupKey* newBackboneKey = nullptr,
275  bool* foundEquivalentBackboneKey = nullptr,
276  std::string* accumulatedWarnings = nullptr);
277 
278  TableEditStruct& getTableEditStruct (const std::string& tableName, bool markModified = false);
279 
280 }; // end GroupEditStruct declaration
281 
282 // clang-format on
283 } // namespace ots
284 
285 #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::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:1769
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