otsdaq  v2_05_02_indev
ConfigurationInterface.h
1 #ifndef _ots_ConfigurationInterface_h_
2 #define _ots_ConfigurationInterface_h_
3 
4 #include <memory>
5 #include <set>
6 #include <sstream>
7 #include "otsdaq/Macros/CoutMacros.h"
8 
9 #include "otsdaq/PluginMakers/MakeTable.h"
10 #include "otsdaq/TableCore/TableBase.h"
11 #include "otsdaq/TableCore/TableGroupKey.h"
12 #include "otsdaq/TableCore/TableVersion.h"
13 #include "otsdaq/TableCore/TableView.h"
14 
15 namespace ots
16 {
17 // clang-format off
18 
19 class ConfigurationHandlerBase;
20 
22 {
23  friend class ConfigurationManagerRW; // because need access to latestVersion() call for group metadata
24  friend class ConfigurationManager; // because need access to fill() call for group metadata
25 
26 protected:
27  ConfigurationInterface(void); // Protected constructor
28 public:
29  virtual ~ConfigurationInterface() { ; }
30 
31  static ConfigurationInterface* getInstance (bool mode);
32  static bool isVersionTrackingEnabled (void);
33  static void setVersionTrackingEnabled (bool setValue);
34 
35  static const std::string GROUP_METADATA_TABLE_NAME;
36 
37  // table handling
38  #include "otsdaq/ConfigurationInterface/ConfigurationInterface.icc" //define ConfigurationInterface::get() source code
39  virtual std::set<std::string /*name*/> getAllTableNames (void) const { __SS__; __THROW__(ss.str() + "ConfigurationInterface::... Must only call getAllTableNames in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface)."); }
40  virtual std::set<TableVersion> getVersions (const TableBase* configuration) const = 0;
41  const bool& getMode (void) const { return theMode_; }
42  TableVersion saveNewVersion (TableBase* configuration, TableVersion temporaryVersion, TableVersion newVersion = TableVersion());
43 
44  // group handling
45  virtual std::set<std::string /*name*/> getAllTableGroupNames (const std::string& /*filterString*/ = "") const { __SS__; __THROW__(ss.str() + "ConfigurationInterface::... Must only call getAllTableGroupNames in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface)."); }
46  virtual std::set<TableGroupKey> getKeys (const std::string& /*groupName*/) const { __SS__; __THROW__(ss.str() + "ConfigurationInterface::... Must only call getKeys in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface)."); }
47 
48 
49  // Caution: getTableGroupMembers must be carefully used.. the table versions
50  // are as initially defined for table versions aliases, i.e. not converted according
51  // to the metadata groupAliases!
52  virtual std::map<std::string /*name*/,
53  TableVersion /*version*/> getTableGroupMembers (std::string const& /*groupName*/, bool /*includeMetaDataTable*/ = false) const { __SS__; __THROW__(ss.str() + "ConfigurationInterface::... Must only call getTableGroupMembers in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface)."); }
54  virtual void saveTableGroup (std::map<std::string /*name*/,TableVersion /*version*/> const& /*tableToVersionMap*/, std::string const& /*groupName*/) const { __SS__; __THROW__(ss.str() + "ConfigurationInterface::... Must only call saveTableGroup in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface)."); }
55 
56 
57 protected:
58  virtual void fill (TableBase* configuration, TableVersion version) const = 0;
59 
60 public: // was protected,.. unfortunately, must be public to allow
61  // otsdaq_database_migrate and otsdaq_import_system_aliases to compile
62  virtual TableGroupKey findLatestGroupKey (const std::string& /*groupName*/) const /* return INVALID if no existing versions */ { __SS__; __THROW__(ss.str() + "ConfigurationInterface::... Must only call findLatestGroupKey in a mode with this functionality implemented (e.g. DatabaseConfigurationInterface)."); }
63  virtual TableVersion findLatestVersion (const TableBase* configuration) const = 0; // return INVALID if no existing versions
64  virtual void saveActiveVersion (const TableBase* configuration, bool overwrite = false) const = 0;
65 
66 protected:
67  ConfigurationHandlerBase* theConfigurationHandler_;
68 
69 private:
70  static ConfigurationInterface* theInstance_;
71  static bool theMode_; // 1 is FILE, 0 is artdaq-DB
72  static bool theVersionTrackingEnabled_; // tracking versions 1 is enabled, 0 is disabled
73 
74 };
75 
76 // clang-format on
77 } // namespace ots
78 #endif