otsdaq  v2_04_01
ConfigurationManagerRW.h
1 #ifndef _ots_ConfigurationManagerRW_h_
2 #define _ots_ConfigurationManagerRW_h_
3 
4 #include "otsdaq-core/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  public:
42  ConfigurationManagerRW(std::string username);
43 
44  //==============================================================================
45  // Getters
46  const std::string& getUsername(void) const { return username_; }
47  ConfigurationInterface* getConfigurationInterface(void) const
48  {
49  return theInterface_;
50  }
51 
52  const std::map<std::string, TableInfo>& getAllTableInfo(
53  bool refresh = false,
54  std::string* accumulatedErrors = 0,
55  const std::string& errorFilterName = "");
56  std::map<std::string /*tableName*/,
57  std::map<std::string /*aliasName*/, TableVersion /*version*/> >
58  getVersionAliases(void) const;
59 
60  template<class T>
61  T* getConfigurationRW(std::string name)
62  {
63  return (T*)getTableByName(name);
64  }
65  TableBase* getVersionedTableByName(const std::string& tableName,
66  TableVersion version,
67  bool looseColumnMatching = false);
68  TableBase* getTableByName(const std::string& tableName);
69  TableGroupKey findTableGroup(
70  const std::string& groupName,
71  const std::map<std::string, TableVersion>& groupMembers,
72  const std::map<std::string /*name*/, std::string /*alias*/>& groupAliases =
73  std::map<std::string /*name*/, std::string /*alias*/>());
74  TableBase* getMetadataTable(void)
75  {
76  return &groupMetadataTable_; /* created for use in otsdaq_flatten_system_aliases,
77  e.g. */
78  }
79 
80  //==============================================================================
81  // modifiers of generic TableBase
82 
83  TableVersion saveNewTable(
84  const std::string& tableName,
85  TableVersion temporaryVersion = TableVersion(),
86  bool makeTemporary = false); //, bool saveToScratchVersion = false);
87  TableVersion copyViewToCurrentColumns(const std::string& tableName,
88  TableVersion sourceVersion);
89  void eraseTemporaryVersion(const std::string& tableName,
90  TableVersion targetVersion = TableVersion());
91  void clearCachedVersions(const std::string& tableName);
92  void clearAllCachedVersions();
93 
94  //==============================================================================
95  // modifiers of table groups
96 
97  void activateTableGroup(const std::string& configGroupName,
98  TableGroupKey tableGroupKey,
99  std::string* accumulatedTreeErrors = 0);
100 
101  TableVersion createTemporaryBackboneView(
102  TableVersion sourceViewVersion =
103  TableVersion()); //-1, from MockUp, else from valid backbone view version
104  TableVersion saveNewBackbone(TableVersion temporaryVersion = TableVersion());
105 
106  //==============================================================================
107  // modifiers of a table group based on alias, e.g. "Physics"
108  TableGroupKey saveNewTableGroup(
109  const std::string& groupName,
110  std::map<std::string, TableVersion>& groupMembers,
111  const std::string& groupComment = TableViewColumnInfo::DATATYPE_COMMENT_DEFAULT,
112  std::map<std::string /*table*/, std::string /*alias*/>* groupAliases = 0);
113 
114  //==============================================================================
115  // public group cache handling
116  const GroupInfo& getGroupInfo(const std::string& groupName);
117  const std::map<std::string, GroupInfo>& getAllGroupInfo() { return allGroupInfo_; }
118 
119  void testXDAQContext(); // for debugging
120 
121  private:
122  //==============================================================================
123  // group cache handling
124  void cacheGroupKey(const std::string& groupName, TableGroupKey key);
125 
126  //==============================================================================
127  // private members
128  std::map<std::string, TableInfo> allTableInfo_;
129  std::map<std::string, GroupInfo> allGroupInfo_;
130 };
131 
134 {
135  // everything needed for editing a table
136  TableBase* table_;
137  TableView* tableView_;
138  TableVersion temporaryVersion_, originalVersion_;
139  bool createdTemporaryVersion_; // indicates if temp version was created here
140  bool modified_; // indicates if temp version was modified
141  std::string tableName_;
144  {
145  __SS__ << "impossible!" << std::endl;
146  __SS_THROW__;
147  }
148  TableEditStruct(const std::string& tableName, ConfigurationManagerRW* cfgMgr)
149  : createdTemporaryVersion_(false), modified_(false), tableName_(tableName)
150  {
151  __COUT__ << "Creating Table-Edit Struct for " << tableName_ << std::endl;
152  table_ = cfgMgr->getTableByName(tableName_);
153 
154  if(!(originalVersion_ = table_->getView().getVersion()).isTemporaryVersion())
155  {
156  __COUT__ << "Start version " << originalVersion_ << std::endl;
157  // create temporary version for editing
158  temporaryVersion_ = table_->createTemporaryView(originalVersion_);
159  cfgMgr->saveNewTable(
160  tableName_,
161  temporaryVersion_,
162  true); // proper bookkeeping for temporary version with the new version
163 
164  __COUT__ << "Created temporary version " << temporaryVersion_ << std::endl;
165  createdTemporaryVersion_ = true;
166  }
167  else // else table is already temporary version
168  __COUT__ << "Using temporary version " << temporaryVersion_ << std::endl;
169 
170  tableView_ = table_->getViewP();
171  }
172 }; // end TableEditStruct declaration
173 
174 } // namespace ots
175 
176 #endif