DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigurationImpl.hpp
Go to the documentation of this file.
1//
2// DUNE DAQ modification notice:
3// This file has been modified from the original ATLAS config source for the DUNE DAQ project.
4// Fork baseline commit: 67a24e731 (2022-10-27).
5// Renamed since fork: yes (from config/ConfigurationImpl.h to include/conffwk/ConfigurationImpl.hpp).
6//
7
14
15#ifndef CONFFWK_CONFIGURATIONIMPL_H_
16#define CONFFWK_CONFIGURATIONIMPL_H_
17
18#include <string>
19#include <vector>
20#include <list>
21#include <set>
22#include <map>
23
24#include "conffwk/map.hpp"
25#include "conffwk/set.hpp"
27
28class ConfigurationChange;
29class ConfigObject;
30class ConfigObjectImpl;
31
32namespace dunedaq {
33namespace conffwk {
34
35
36struct class_t;
37
38
49
51
52 friend class ConfigObject;
53 friend class ConfigObjectImpl;
54 friend class Configuration;
55
56 public:
57
59
60 ConfigurationImpl() noexcept;
61
63
64 virtual ~ConfigurationImpl();
65
66
67 // methods to open/close database
68
69 public:
70
72
73 virtual void open_db(const std::string& db_name) = 0;
74
76
77 virtual void close_db() = 0;
78
80
81 virtual bool loaded() const noexcept = 0;
82
84
85 virtual void create(const std::string& db_name, const std::list<std::string>& includes) = 0;
86
88
89 virtual bool is_writable(const std::string& db_name) = 0;
90
92
93 virtual void add_include(const std::string& db_name, const std::string& include)= 0;
94
96
97 virtual void remove_include(const std::string& db_name, const std::string& include)= 0;
98
100
101 virtual void get_includes(const std::string& db_name, std::list<std::string>& includes) const = 0;
102
104
105 virtual void get_updated_dbs(std::list<std::string>& dbs) const = 0;
106
108
109 virtual void set_commit_credentials(const std::string& user, const std::string& password) = 0;
110
112
113 virtual void commit(const std::string& log_message) = 0;
114
116
117 virtual void abort() = 0;
118
120
121 virtual void prefetch_all_data() = 0;
122
124
125 virtual std::vector<dunedaq::conffwk::Version> get_changes() = 0;
126
128
129 virtual std::vector<dunedaq::conffwk::Version> get_versions(const std::string& since, const std::string& until, dunedaq::conffwk::Version::QueryType type, bool skip_irrelevant) = 0;
130
131
132 // methods to get data from database
133
134 public:
135
137
138 virtual void get(const std::string& class_name, const std::string& id, ConfigObject& object, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
139
141
142 virtual void get(const std::string& class_name, std::vector<ConfigObject>& objects, const std::string& query, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
143
145
146 virtual void get(const ConfigObject& obj_from, const std::string& query, std::vector<ConfigObject>& objects, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
147
149
150 virtual bool test_object(const std::string& class_name, const std::string& id, unsigned long rlevel, const std::vector<std::string> * rclasses) = 0;
151
152
153 // methods to create and destroy objects
154
155 public:
156
158
159 virtual void create(const std::string& at, const std::string& class_name, const std::string& id, ConfigObject& object) = 0;
160
162
163 virtual void create(const ConfigObject& at, const std::string& class_name, const std::string& id, ConfigObject& object) = 0;
164
166
167 virtual void destroy(ConfigObject& object) = 0;
168
169
170 // get meta-data
171
172 public:
173
175
176 virtual dunedaq::conffwk::class_t * get(const std::string& class_name, bool direct_only) = 0;
177
179
180 virtual void get_superclasses(conffwk::fmap<conffwk::fset>& schema) = 0;
181
182
183 // notification
184
185 public:
186
188
189 typedef void (*notify)(std::vector<ConfigurationChange *> & changes, Configuration *);
190
192
193 typedef void (*pre_notify)(Configuration *);
194
196
197 virtual void subscribe(const std::set<std::string>& class_names, const std::map< std::string, std::set<std::string> >& objs, notify cb, pre_notify pre_cb) = 0;
198
200
201 virtual void unsubscribe() = 0;
202
204
205 virtual void print_profiling_info() noexcept = 0;
206
208
209 void print_cache_info() noexcept;
210
211
213
214 private:
215
217 std::vector<ConfigObjectImpl *> m_tangled_objects; // deleted and replaced by others as result of rename
218
219 mutable unsigned long p_number_of_cache_hits;
220 mutable unsigned long p_number_of_object_read;
221
222
223 protected:
224
226
227 ConfigObjectImpl * get_impl_object(const std::string& class_name, const std::string& id) const noexcept;
228
229
231
232 void put_impl_object(const std::string& class_name, const std::string& id, ConfigObjectImpl * obj) noexcept;
233
234
236
237 template<class T, class OBJ>
238 T *
239 insert_object(OBJ& obj, const std::string& id, const std::string& class_name) noexcept
240 {
241 ConfigObjectImpl * p = get_impl_object(class_name, id);
242
243 if (p == nullptr)
244 {
245 p = static_cast<ConfigObjectImpl *>(new T(obj, this));
246 put_impl_object(class_name, id, p);
247 }
248 else
249 {
250 static_cast<T *>(p)->set(obj);
252 }
253
254 return static_cast<T *>(p);
255 }
256
257
259
260 void clean() noexcept;
261
262
264
265 protected:
266
268
269
271
272 std::mutex& get_conf_impl_mutex() const;
273
274
275 public:
276
278
279 void set(Configuration * db) noexcept { m_conf = db; }
280
281
282 public:
283
285
286 void rename_impl_object(const std::string * class_name, const std::string& old_id, const std::string& new_id) noexcept;
287
288};
289
290} // namespace conffwk
291} // namespace dunedaq
292
293#endif // CONFFWK_CONFIGURATIONIMPL_H_
dunedaq::conffwk::ObjectState m_state
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:42
virtual bool test_object(const std::string &class_name, const std::string &id, unsigned long rlevel, const std::vector< std::string > *rclasses)=0
Test object existence (used by Python binding).
void put_impl_object(const std::string &class_name, const std::string &id, ConfigObjectImpl *obj) noexcept
put object to cache
ConfigurationImpl() noexcept
The constructor.
virtual void subscribe(const std::set< std::string > &class_names, const std::map< std::string, std::set< std::string > > &objs, notify cb, pre_notify pre_cb)=0
Subscribe on database changes.
virtual void set_commit_credentials(const std::string &user, const std::string &password)=0
Set commit credentials.
void clean() noexcept
clean cache (e.g. to be used by destructor)
virtual void close_db()=0
Close database implementation.
virtual void get_superclasses(conffwk::fmap< conffwk::fset > &schema)=0
Get inheritance hierarchy.
virtual void abort()=0
Abort database changes.
virtual void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel, const std::vector< std::string > *rclasses)=0
Get object of class by id.
virtual void get_includes(const std::string &db_name, std::list< std::string > &includes) const =0
Get included files.
virtual void print_profiling_info() noexcept=0
Print implementation specific profiling information.
virtual void prefetch_all_data()=0
Prefetch all data into client cache.
virtual void get_updated_dbs(std::list< std::string > &dbs) const =0
Get uncommitted files.
void(* pre_notify)(Configuration *)
Callback to pre-notify database changes.
virtual bool is_writable(const std::string &db_name)=0
Return write access status.
std::vector< ConfigObjectImpl * > m_tangled_objects
virtual std::vector< dunedaq::conffwk::Version > get_changes()=0
Get newly available versions.
ConfigObjectImpl * get_impl_object(const std::string &class_name, const std::string &id) const noexcept
get object from cache
virtual bool loaded() const noexcept=0
Check if a database is loaded.
void rename_impl_object(const std::string *class_name, const std::string &old_id, const std::string &new_id) noexcept
rename object in cache
virtual void destroy(ConfigObject &object)=0
Destroy object of class by id.
virtual void add_include(const std::string &db_name, const std::string &include)=0
Add include file.
virtual void commit(const std::string &log_message)=0
Commit database changes.
void print_cache_info() noexcept
Print profiling information about objects in cache.
virtual std::vector< dunedaq::conffwk::Version > get_versions(const std::string &since, const std::string &until, dunedaq::conffwk::Version::QueryType type, bool skip_irrelevant)=0
Get archived versions.
virtual void remove_include(const std::string &db_name, const std::string &include)=0
Remove include file.
void(* notify)(std::vector< ConfigurationChange * > &changes, Configuration *)
Callback to notify database changes.
Configuration * m_conf
Configuration pointer is needed for notification on changes, e.g. in case of subscription or an objec...
std::mutex & get_conf_impl_mutex() const
Is required by reload methods.
void set(Configuration *db) noexcept
set configuration object
virtual void create(const std::string &db_name, const std::list< std::string > &includes)=0
Create database.
conffwk::pmap< conffwk::map< ConfigObjectImpl * > * > m_impl_objects
cache of implementation objects (class-name::->object_id->implementation)
virtual void open_db(const std::string &db_name)=0
Open database implementation in accordance with given name.
virtual void unsubscribe()=0
Remove subscription on database changes.
T * insert_object(OBJ &obj, const std::string &id, const std::string &class_name) noexcept
insert new object (update cache or create-and-insert)
Represents configuration version.
std::unordered_set< const std::string *, string_ptr_hash > fset
Definition set.hpp:20
std::unordered_set< std::string > set
Definition set.hpp:17
Including Qt Headers.
Definition module.cpp:16
msgpack::object obj