otsdaq  3.03.00
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 }; //end TableInfo struct
20 
21 struct GroupInfo
22 {
23  friend class
24  ConfigurationManagerRW; //ConfigurationManagerRW can access GroupInfo private members
25 
26  GroupInfo()
27  : //constructor
28  latestKeyGroupAuthor_(ConfigurationManager::UNKNOWN_INFO)
29  , latestKeyGroupComment_(ConfigurationManager::UNKNOWN_INFO)
30  , latestKeyGroupCreationTime_(ConfigurationManager::UNKNOWN_TIME)
31  , latestKeyGroupTypeString_(ConfigurationManager::GROUP_TYPE_NAME_UNKNOWN)
32  {
33  }
34 
35  const std::set<TableGroupKey>& getKeys() const { return keys_; }
36  const TableGroupKey& getLatestKey() const { return latestKey_; }
37  const std::string& getLatestKeyGroupAuthor() const { return latestKeyGroupAuthor_; }
38  const std::string& getLatestKeyGroupComment() const { return latestKeyGroupComment_; }
39  const std::string& getLatestKeyGroupCreationTime() const
40  {
41  return latestKeyGroupCreationTime_;
42  }
43  const std::string& getLatestKeyGroupTypeString() const
44  {
45  return latestKeyGroupTypeString_;
46  }
47  const std::map<std::string /*name*/, TableVersion /*version*/>&
48  getLatestKeyMemberMap() const
49  {
50  return latestKeyMemberMap_;
51  }
52  TableGroupKey getLastKey() const
53  {
54  if(keys_.size())
55  return *(keys_.rbegin());
56  else
57  return TableGroupKey();
58  } //end getLastKey()
59 
60  private:
61  std::set<TableGroupKey> keys_;
62  TableGroupKey latestKey_;
63  std::string latestKeyGroupAuthor_, latestKeyGroupComment_,
64  latestKeyGroupCreationTime_, latestKeyGroupTypeString_;
65  std::map<std::string /*name*/, TableVersion /*version*/> latestKeyMemberMap_;
66 }; //end GroupInfo struct
67 
68 #define __GET_TABLE_PTR__(X) getTablePtr<X>(QUOTE(X))
69 
70 //==============================================================================
76 {
77  // clang-format off
78  public:
79  ConfigurationManagerRW(const std::string& username);
80 
81 
82  //==============================================================================
84  const std::string& getUsername (void) const { return username_; }
85  ConfigurationInterface* getConfigurationInterface (void) const { return theInterface_; }
86 
87  const std::map<std::string, TableInfo>& getAllTableInfo (bool refresh = false,
88  std::string* accumulatedWarnings = 0,
89  const std::string& errorFilterName = "",
90  bool getGroupKeys = false,
91  bool getGroupInfo = false,
92  bool initializeActiveGroups = false);
93  std::map<std::string /*tableName*/,
94  std::map<std::string /*aliasName*/,
95  TableVersion /*version*/> > getVersionAliases (void) const;
96 
97  template<class T>
98  T* getTablePtr (const std::string& tableName) { return (T*)getTableByName(tableName); }
99  TableBase* getVersionedTableByName (const std::string& tableName, TableVersion version, bool looseColumnMatching = false, std::string* accumulatedErrors = 0, bool getRawData = false);
100  TableBase* getTableByName (const std::string& tableName);
101  TableGroupKey findTableGroup (const std::string& groupName, const std::map<std::string, TableVersion>& groupMembers,
102  const std::map<std::string /*name*/, std::string /*alias*/>& groupAliases = std::map<std::string /*name*/, std::string /*alias*/>());
103  TableBase* getMetadataTable (TableVersion fillVersion = TableVersion());
104 
105  //==============================================================================
107  const std::string& setUsername (const std::string& username) { username_ = username; return username_; }
108 
109  //==============================================================================
111  TableVersion saveNewTable (const std::string& tableName, TableVersion temporaryVersion = TableVersion(), bool makeTemporary = false);
113  const std::string& tableName,
114  TableVersion originalVersion,
115  bool makeTemporary,
116  TableBase* config,
117  TableVersion temporaryModifiedVersion,
118  bool ignoreDuplicates = false,
119  bool lookForEquivalent = false,
120  bool* foundEquivalent = nullptr);
121 
122  TableVersion copyViewToCurrentColumns (const std::string& tableName, TableVersion sourceVersion);
123  void eraseTemporaryVersion (const std::string& tableName, TableVersion targetVersion = TableVersion());
124  void clearCachedVersions (const std::string& tableName);
125  void clearAllCachedVersions (void);
126 
127  //==============================================================================
129  void activateTableGroup (const std::string& tableGroupName, TableGroupKey tableGroupKey, std::string* accumulatedTreeErrors = 0, std::string* groupTypeString = 0);
130 
132  TableVersion saveNewBackbone (TableVersion temporaryVersion = TableVersion());
133 
134  //==============================================================================
136  TableGroupKey saveNewTableGroup (const std::string& groupName, std::map<std::string, TableVersion>& groupMembers,
137  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
138  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
139 
140  //==============================================================================
142  const GroupInfo& getGroupInfo (const std::string& groupName, bool attemptToReloadKeys = false);
143  const std::map<std::string, GroupInfo>& getAllGroupInfo (void) { return allGroupInfo_; }
144  void loadTableGroup (
145  const std::string& tableGroupName,
146  const TableGroupKey& tableGroupKey,
147  bool doActivate = false,
148  std::map<std::string, TableVersion>* groupMembers = 0,
149  ProgressBar* progressBar = 0,
150  std::string* accumulateWarnings = 0,
151  std::string* groupComment = 0,
152  std::string* groupAuthor = 0,
153  std::string* groupCreateTime = 0,
154  bool doNotLoadMember = false,
155  std::string* groupTypeString = 0,
156  std::map<std::string /*name*/, std::string /*alias*/>* groupAliases = 0,
157  ConfigurationManager::LoadGroupType groupTypeToLoad = ConfigurationManager::LoadGroupType::ALL_TYPES,
158  bool ignoreVersionTracking = false);
159 
160  void testXDAQContext (void);
161 
162  public:
163  static void loadTableInfoThread (ConfigurationManagerRW* cfgMgr,
164  std::string tableName,
165  TableBase* existingTable,
166  std::shared_ptr<ots::TableInfo> tableInfo,
167  std::shared_ptr<std::atomic<bool>> threadDone);
168  static void loadTableGroupThread (ConfigurationManagerRW* cfgMgr,
169  std::string groupName,
170  ots::TableGroupKey groupKey,
171  std::shared_ptr<ots::GroupInfo> theGroupInfo,
172  std::shared_ptr<std::atomic<bool>> theThreadDone);
173  static void compareTableGroupThread (ConfigurationManagerRW* cfgMgr,
174  std::string groupName,
175  ots::TableGroupKey groupKeyToCompare,
176  const std::map<std::string, TableVersion>& groupMemberMap,
177  const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
178  std::atomic<bool>* theFoundIdentical,
179  ots::TableGroupKey* theIdenticalKey,
180  std::mutex* theThreadMutex,
181  std::shared_ptr<std::atomic<bool>> theThreadDone);
182  private:
183 
184  //==============================================================================
186  std::map<std::string, TableInfo> allTableInfo_; //local cache of table info
187  std::map<std::string, GroupInfo> allGroupInfo_; //local cache of group info
188 
189  static std::atomic<bool> firstTimeConstructed_;
190 };
191 
192 //==============================================================================
196 {
199  TableView* tableView_;
200  TableVersion temporaryVersion_, originalVersion_;
202  bool modified_;
203  std::string tableName_;
204  const std::string mfSubject_;
205 
208  {
209  __SS__ << "impossible!" << std::endl;
210  ss << StringMacros::stackTrace();
211  __SS_THROW__;
212  }
213  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr, bool markModified = false)
214  : createdTemporaryVersion_(false), modified_(markModified), tableName_(tableName)
215  , mfSubject_(cfgMgr->getUsername())
216  {
217  //__COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
218  table_ = cfgMgr->getTableByName(tableName_);
219 
220  //if no active version or if not temporary, setup new temporary version
221  if(!table_->isActive() ||
222  !(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
223  {
224  //__COUT__ << "Original '" << tableName_ << "' version is v" << originalVersion_ << std::endl;
225 
226  // create temporary version for editing
227  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
228  cfgMgr->saveNewTable(
229  tableName_,
230  temporaryVersion_,
231  true);
232 
233  __COUT__ << "Created '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
235  }
236  //else // else table is already temporary version
237  //__COUT__ << "Using '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
238 
239  tableView_ = table_->getViewP();
240  }
241 }; // end TableEditStruct declaration
242 
243 //==============================================================================
247 {
249 private:
250  std::map<std::string, TableVersion> groupMembers_;
251  std::map<std::string, TableEditStruct> groupTables_;
252 public:
253  const ConfigurationManager::GroupType groupType_;
254  const std::string originalGroupName_;
255  const TableGroupKey originalGroupKey_;
256 private:
257  ConfigurationManagerRW* cfgMgr_;
258  const std::string mfSubject_;
259 
260 public:
263  : groupType_(ConfigurationManager::GroupType::CONFIGURATION_TYPE) {__SS__ << "impossible!" << __E__; __SS_THROW__;}
264  GroupEditStruct(const ConfigurationManager::GroupType& groupType, ConfigurationManagerRW* cfgMgr);
265 
266  ~GroupEditStruct();
267 
268  void dropChanges (void);
269  void saveChanges (
270  const std::string& groupNameToSave,
271  TableGroupKey& newGroupKey,
272  bool* foundEquivalentGroupKey = nullptr,
273  bool activateNewGroup = false,
274  bool updateGroupAliases = false,
275  bool updateTableAliases = false,
276  TableGroupKey* newBackboneKey = nullptr,
277  bool* foundEquivalentBackboneKey = nullptr,
278  std::string* accumulatedWarnings = nullptr);
279 
280  TableEditStruct& getTableEditStruct (const std::string& tableName, bool markModified = false);
281 
282 }; // end GroupEditStruct declaration
283 
284 // clang-format on
285 } // namespace ots
286 
287 #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)
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)
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:1734
bool isActive(void)
isActive
Definition: TableBase.cc:950
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