otsdaq  v2_04_02
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 };
19 
20 struct GroupInfo
21 {
22  std::set<TableGroupKey> keys_;
23  std::string latestKeyGroupAuthor_, latestKeyGroupComment_,
24  latestKeyGroupCreationTime_, latestKeyGroupTypeString_;
25  std::map<std::string /*name*/, TableVersion /*version*/> latestKeyMemberMap_;
26 
27  TableGroupKey getLatestKey() { return *(keys_.rbegin()); }
28 };
29 
30 #define Q(X) #X
31 #define QUOTE(X) Q(X)
32 #define __GETCFG_RW__(X) getConfigurationRW<X>(QUOTE(X))
33 
34 //==============================================================================
35 // ConfigurationManagerRW
36 // This is the ConfigurationManger with write access
37 // This class inherits all public function from ConfigurationManager
38 // and is a "Friend" class of ConfigurationManager so has access to private members.
40 {
41  // clang-format off
42  public:
43  ConfigurationManagerRW(const std::string& username);
44 
45  //==============================================================================
46  // Getters
47  const std::string& getUsername (void) const { return username_; }
48  ConfigurationInterface* getConfigurationInterface (void) const { return theInterface_; }
49 
50  const std::map<std::string, TableInfo>& getAllTableInfo (bool refresh = false, std::string* accumulatedErrors = 0, const std::string& errorFilterName = "");
51  std::map<std::string /*tableName*/,
52  std::map<std::string /*aliasName*/,
53  TableVersion /*version*/> > getVersionAliases (void) const;
54 
55  template<class T>
56  T* getConfigurationRW (std::string name) { return (T*)getTableByName(name); }
57  TableBase* getVersionedTableByName (const std::string& tableName, TableVersion version, bool looseColumnMatching = false, std::string* accumulatedErrors = 0);
58  TableBase* getTableByName (const std::string& tableName);
59  TableGroupKey findTableGroup (const std::string& groupName, const std::map<std::string, TableVersion>& groupMembers,
60  const std::map<std::string /*name*/, std::string /*alias*/>& groupAliases = std::map<std::string /*name*/, std::string /*alias*/>());
61  TableBase* getMetadataTable (void) { return &groupMetadataTable_; /* created for use in otsdaq_flatten_system_aliases, e.g. */ }
62 
63  //==============================================================================
64  // modifiers of generic TableBase
65  TableVersion saveNewTable (const std::string& tableName, TableVersion temporaryVersion = TableVersion(), bool makeTemporary = false); //, bool saveToScratchVersion = false);
66  TableVersion copyViewToCurrentColumns (const std::string& tableName, TableVersion sourceVersion);
67  void eraseTemporaryVersion (const std::string& tableName, TableVersion targetVersion = TableVersion());
68  void clearCachedVersions (const std::string& tableName);
69  void clearAllCachedVersions (void);
70 
71  //==============================================================================
72  // modifiers of table groups
73  void activateTableGroup (const std::string& configGroupName, TableGroupKey tableGroupKey, std::string* accumulatedTreeErrors = 0);
74 
75  TableVersion createTemporaryBackboneView (TableVersion sourceViewVersion = TableVersion()); //-1, from MockUp, else from valid backbone view version
76  TableVersion saveNewBackbone (TableVersion temporaryVersion = TableVersion());
77 
78  //==============================================================================
79  // modifiers of a table group based on alias, e.g. "Physics"
80  TableGroupKey saveNewTableGroup (const std::string& groupName, std::map<std::string, TableVersion>& groupMembers,
81  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
82  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
83 
84  //==============================================================================
85  // public group cache handling
86  const GroupInfo& getGroupInfo (const std::string& groupName);
87  const std::map<std::string, GroupInfo>& getAllGroupInfo (void) { return allGroupInfo_; }
88 
89  void testXDAQContext (void); // for debugging
90 
91  private:
92  //==============================================================================
93  // group cache handling
94  void cacheGroupKey (const std::string& groupName, TableGroupKey key);
95 
96  //==============================================================================
97  // private members
98  std::map<std::string, TableInfo> allTableInfo_;
99  std::map<std::string, GroupInfo> allGroupInfo_;
100 };
101 
102 //==============================================================================
106 {
107  // everything needed for editing a table
108  TableBase* table_;
109  TableView* tableView_;
110  TableVersion temporaryVersion_, originalVersion_;
111  bool createdTemporaryVersion_; // indicates if temp version was created here
112  bool modified_; // indicates if temp version was modified
113  std::string tableName_;
116  {
117  __SS__ << "impossible!" << std::endl;
118  __SS_THROW__;
119  }
120  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr)
121  : createdTemporaryVersion_(false), modified_(false), tableName_(tableName)
122  {
123  __COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
124  table_ = cfgMgr->getTableByName(tableName_);
125 
126  if(!(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
127  {
128  __COUT__ << "Start version " << originalVersion_ << std::endl;
129  // create temporary version for editing
130  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
131  cfgMgr->saveNewTable(
132  tableName_,
133  temporaryVersion_,
134  true); // proper bookkeeping for temporary version with the new version
135 
136  __COUT__ << "Created temporary version " << temporaryVersion_ << std::endl;
137  createdTemporaryVersion_ = true;
138  }
139  else // else table is already temporary version
140  __COUT__ << "Using temporary version " << temporaryVersion_ << std::endl;
141 
142  tableView_ = table_->getViewP();
143  }
144 }; // end TableEditStruct declaration
145 
146 // clang-format on
147 } // namespace ots
148 
149 #endif