otsdaq  3.04.02
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);
87  TableBase* getTableByName (const std::string& tableName);
88  TableGroupKey findTableGroup (const std::string& groupName,
89  const std::map<std::string, TableVersion>& groupMembers,
90  const std::map<std::string /*name*/, std::string /*alias*/>& groupAliases = std::map<std::string /*name*/, std::string /*alias*/>());
91  TableBase* getMetadataTable (TableVersion fillVersion = TableVersion());
92 
93  //==============================================================================
95  const std::string& setUsername (const std::string& username) { username_ = username; return username_; }
96 
97  //==============================================================================
99  TableVersion saveNewTable (const std::string& tableName, TableVersion temporaryVersion = TableVersion(), bool makeTemporary = false);
101  const std::string& tableName,
102  TableVersion originalVersion,
103  bool makeTemporary,
104  TableBase* config,
105  TableVersion temporaryModifiedVersion,
106  bool ignoreDuplicates = false,
107  bool lookForEquivalent = false,
108  bool* foundEquivalent = nullptr);
109 
110  TableVersion copyViewToCurrentColumns (const std::string& tableName, TableVersion sourceVersion);
111  void eraseTemporaryVersion (const std::string& tableName, TableVersion targetVersion = TableVersion());
112  void clearCachedVersions (const std::string& tableName);
113  void clearAllCachedVersions (void);
114 
115  //==============================================================================
117  void activateTableGroup (const std::string& tableGroupName, TableGroupKey tableGroupKey, std::string* accumulatedTreeErrors = 0, std::string* groupTypeString = 0);
118 
120  TableVersion saveNewBackbone (TableVersion temporaryVersion = TableVersion());
121 
122  //==============================================================================
124  TableGroupKey saveNewTableGroup (const std::string& groupName, std::map<std::string, TableVersion>& groupMembers,
125  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
126  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
127 
128  //==============================================================================
130  const GroupInfo& getGroupInfo (const std::string& groupName, bool attemptToReloadKeys = false);
131  const std::map<std::string, GroupInfo>& getAllGroupInfo (void) { return allGroupInfo_; }
132  void loadTableGroup (
133  const std::string& tableGroupName,
134  const TableGroupKey& tableGroupKey,
135  bool doActivate = false,
136  std::map<std::string, TableVersion>* groupMembers = 0,
137  ProgressBar* progressBar = 0,
138  std::string* accumulateWarnings = 0,
139  std::string* groupComment = 0,
140  std::string* groupAuthor = 0,
141  std::string* groupCreateTime = 0,
142  bool doNotLoadMember = false,
143  std::string* groupTypeString = 0,
144  std::map<std::string /*name*/, std::string /*alias*/>* groupAliases = 0,
145  ConfigurationManager::LoadGroupType groupTypeToLoad = ConfigurationManager::LoadGroupType::ALL_TYPES,
146  bool ignoreVersionTracking = false);
147 
148  void testXDAQContext (void);
149 
150  public:
151  static void loadTableInfoThread (ConfigurationManagerRW* cfgMgr,
152  std::string tableName,
153  TableBase* existingTable,
154  std::shared_ptr<ots::TableInfo> tableInfo,
155  std::shared_ptr<std::atomic<bool>> threadDone);
156  static void loadTableGroupThread (ConfigurationManagerRW* cfgMgr,
157  std::string groupName,
158  ots::TableGroupKey groupKey,
159  std::shared_ptr<ots::GroupInfo> theGroupInfo,
160  std::shared_ptr<std::atomic<bool>> theThreadDone);
161  static void compareTableGroupThread (ConfigurationManagerRW* cfgMgr,
162  std::string groupName,
163  ots::TableGroupKey groupKeyToCompare,
164  const std::map<std::string, TableVersion>& groupMemberMap,
165  const std::map<std::string /*name*/, std::string /*alias*/>& memberTableAliases,
166  std::atomic<bool>* theFoundIdentical,
167  ots::TableGroupKey* theIdenticalKey,
168  std::mutex* theThreadMutex,
169  std::shared_ptr<std::atomic<bool>> theThreadDone);
170  private:
171 
172  //==============================================================================
174  std::map<std::string, TableInfo> allTableInfo_; //local cache of table info
175  std::map<std::string, GroupInfo> allGroupInfo_; //local cache of group info
176 
177  static std::atomic<bool> firstTimeConstructed_;
178 };
179 
180 //==============================================================================
184 {
187  TableView* tableView_;
188  TableVersion temporaryVersion_, originalVersion_;
190  bool modified_;
191  std::string tableName_;
192  const std::string mfSubject_;
193 
196  {
197  __SS__ << "impossible!" << std::endl;
198  ss << StringMacros::stackTrace();
199  __SS_THROW__;
200  }
201  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr, bool markModified = false)
202  : createdTemporaryVersion_(false), modified_(markModified), tableName_(tableName)
203  , mfSubject_(cfgMgr->getUsername())
204  {
205  //__COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
206  table_ = cfgMgr->getTableByName(tableName_);
207 
208  //if no active version or if not temporary, setup new temporary version
209  if(!table_->isActive() ||
210  !(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
211  {
212  //__COUT__ << "Original '" << tableName_ << "' version is v" << originalVersion_ << std::endl;
213 
214  // create temporary version for editing
215  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
216  cfgMgr->saveNewTable(
217  tableName_,
218  temporaryVersion_,
219  true);
220 
221  __COUT__ << "Created '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
223  }
224  //else // else table is already temporary version
225  //__COUT__ << "Using '" << tableName_ << "' temporary version " << temporaryVersion_ << std::endl;
226 
227  tableView_ = table_->getViewP();
228  }
229 }; // end TableEditStruct declaration
230 
231 //==============================================================================
235 {
237 private:
238  std::map<std::string, TableVersion> groupMembers_;
239  std::map<std::string, TableEditStruct> groupTables_;
240 public:
241  const ConfigurationManager::GroupType groupType_;
242  const std::string originalGroupName_;
243  const TableGroupKey originalGroupKey_;
244 private:
245  ConfigurationManagerRW* cfgMgr_;
246  const std::string mfSubject_;
247 
248 public:
251  : groupType_(ConfigurationManager::GroupType::CONFIGURATION_TYPE) {__SS__ << "impossible!" << __E__; __SS_THROW__;}
252  GroupEditStruct(const ConfigurationManager::GroupType& groupType, ConfigurationManagerRW* cfgMgr);
253 
254  ~GroupEditStruct();
255 
256  void dropChanges (void);
257  void saveChanges (
258  const std::string& groupNameToSave,
259  TableGroupKey& newGroupKey,
260  bool* foundEquivalentGroupKey = nullptr,
261  bool activateNewGroup = false,
262  bool updateGroupAliases = false,
263  bool updateTableAliases = false,
264  TableGroupKey* newBackboneKey = nullptr,
265  bool* foundEquivalentBackboneKey = nullptr,
266  std::string* accumulatedWarnings = nullptr);
267 
268  TableEditStruct& getTableEditStruct (const std::string& tableName, bool markModified = false);
269 
270 }; // end GroupEditStruct declaration
271 
272 // clang-format on
273 } // namespace ots
274 
275 #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
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