tdaq-develop-2025-02-12
ConfigurationInterface.h
1 #ifndef _ots_ConfigurationInterface_h_
2 #define _ots_ConfigurationInterface_h_
3 
4 #include <memory>
5 #include <mutex>
6 #include <set>
7 #include <sstream>
8 #include "otsdaq/Macros/CoutMacros.h"
9 
10 #include "otsdaq/TableCore/MakeTable.h"
11 #include "otsdaq/TableCore/TableBase.h"
12 #include "otsdaq/TableCore/TableGroupKey.h"
13 #include "otsdaq/TableCore/TableVersion.h"
14 #include "otsdaq/TableCore/TableView.h"
15 
16 namespace ots
17 {
18 // clang-format off
19 
20 class ConfigurationHandlerBase;
21 
23 {
24  friend class ConfigurationManagerRW;
25  friend class ConfigurationManager;
26 
27 protected:
29 public:
30  virtual ~ConfigurationInterface() { ; }
31 
32  enum class CONFIGURATION_MODE
33  {
34  DO_NOT_CREATE,
35  XML_FILE,
36  ARTDAQ_DATABASE
37  };
38 
39  static ConfigurationInterface* getInstance (CONFIGURATION_MODE mode = CONFIGURATION_MODE::DO_NOT_CREATE);
40  static bool isVersionTrackingEnabled (void);
41  static void setVersionTrackingEnabled (bool setValue);
42 
43  static const std::string GROUP_METADATA_TABLE_NAME;
44 
46  #include "otsdaq/ConfigurationInterface/ConfigurationInterface.icc"
47  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)."); }
48  virtual std::set<TableVersion> getVersions (const TableBase* configuration) const = 0;
49  static const CONFIGURATION_MODE& getMode (void);
50  TableVersion saveNewVersion (TableBase* configuration, TableVersion temporaryVersion, TableVersion newVersion = TableVersion());
51 
53  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)."); }
54  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)."); }
55 
56 
60  virtual std::map<std::string /*name*/,
61  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)."); }
62  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)."); }
63 
64  virtual std::pair<std::string, TableVersion> saveCustomJSON (const std::string& JSON, const std::string& documentNameToSave) const { __COUTV__(JSON); __COUTV__(documentNameToSave); return std::make_pair("",TableVersion());}
65  virtual std::string loadCustomJSON (const std::string& documentNameToLoad, TableVersion documentVersionToLoad) const {__COUTV__(documentNameToLoad); __COUTV__(documentVersionToLoad); return "{}";};
66 
67 
68 protected:
69  virtual void fill (TableBase* configuration, TableVersion version) const = 0;
70 
71 public: // was protected,.. unfortunately, must be public to allow
73  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)."); }
74  virtual TableVersion findLatestVersion (const TableBase* configuration) const = 0;
75  virtual void saveActiveVersion (const TableBase* configuration, bool overwrite = false) const = 0;
76 
77 protected:
78  ConfigurationHandlerBase* theConfigurationHandler_;
79 
80 private:
81  static ConfigurationInterface* theInstance_;
82  static CONFIGURATION_MODE theMode_;
83  static bool theVersionTrackingEnabled_;
84 
85  std::mutex tableReaderMutex_;
86 
87 };
88 
89 // clang-format on
90 } // namespace ots
91 #endif
virtual std::set< std::string > getAllTableGroupNames(const std::string &="") const
group handling
ConfigurationInterface(void)
Protected constructor.
virtual std::set< std::string > getAllTableNames(void) const
virtual TableGroupKey findLatestGroupKey(const std::string &) const
otsdaq_database_migrate and otsdaq_import_system_aliases to compile
TableVersion saveNewVersion(TableBase *configuration, TableVersion temporaryVersion, TableVersion newVersion=TableVersion())
virtual std::map< std::string, TableVersion > getTableGroupMembers(std::string const &, bool=false) const
virtual TableVersion findLatestVersion(const TableBase *configuration) const =0
return INVALID if no existing versions