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 <list>
19#include <map>
20#include <set>
21#include <string>
22#include <vector>
23
25#include "conffwk/map.hpp"
26#include "conffwk/set.hpp"
27
28class ConfigurationChange;
29class ConfigObject;
30class ConfigObjectImpl;
31
32namespace dunedaq {
33namespace conffwk {
34
35struct class_t;
36
47
49{
50
51 friend class ConfigObject;
52 friend class ConfigObjectImpl;
53 friend class Configuration;
54
55public:
57
58 ConfigurationImpl() noexcept;
59
61
62 virtual ~ConfigurationImpl();
63
64 // methods to open/close database
65
66public:
68
69 virtual void open_db(const std::string& db_name) = 0;
70
72
73 virtual void close_db() = 0;
74
76
77 virtual bool loaded() const noexcept = 0;
78
80
81 virtual void create(const std::string& db_name, const std::list<std::string>& includes) = 0;
82
84
85 virtual bool is_writable(const std::string& db_name) = 0;
86
88
89 virtual void add_include(const std::string& db_name, const std::string& include) = 0;
90
92
93 virtual void remove_include(const std::string& db_name, const std::string& include) = 0;
94
96
97 virtual void get_includes(const std::string& db_name, std::list<std::string>& includes) const = 0;
98
100
101 virtual void get_updated_dbs(std::list<std::string>& dbs) const = 0;
102
104
105 virtual void set_commit_credentials(const std::string& user, const std::string& password) = 0;
106
108
109 virtual void commit(const std::string& log_message) = 0;
110
112
113 virtual void abort() = 0;
114
116
117 virtual void prefetch_all_data() = 0;
118
120
121 virtual std::vector<dunedaq::conffwk::Version> get_changes() = 0;
122
124
125 virtual std::vector<dunedaq::conffwk::Version> get_versions(const std::string& since,
126 const std::string& until,
127 dunedaq::conffwk::Version::QueryType type,
128 bool skip_irrelevant) = 0;
129
130 // methods to get data from database
131
132public:
134
135 virtual void get(const std::string& class_name,
136 const std::string& id,
137 ConfigObject& object,
138 unsigned long rlevel,
139 const std::vector<std::string>* rclasses) = 0;
140
142
143 virtual void get(const std::string& class_name,
144 std::vector<ConfigObject>& objects,
145 const std::string& query,
146 unsigned long rlevel,
147 const std::vector<std::string>* rclasses) = 0;
148
150
151 virtual void get(const ConfigObject& obj_from,
152 const std::string& query,
153 std::vector<ConfigObject>& objects,
154 unsigned long rlevel,
155 const std::vector<std::string>* rclasses) = 0;
156
158
159 virtual bool test_object(const std::string& class_name,
160 const std::string& id,
161 unsigned long rlevel,
162 const std::vector<std::string>* rclasses) = 0;
163
164 // methods to create and destroy objects
165
166public:
168
169 virtual void create(const std::string& at,
170 const std::string& class_name,
171 const std::string& id,
172 ConfigObject& object) = 0;
173
175
176 virtual void create(const ConfigObject& at,
177 const std::string& class_name,
178 const std::string& id,
179 ConfigObject& object) = 0;
180
182
183 virtual void destroy(ConfigObject& object) = 0;
184
185 // get meta-data
186
187public:
189
190 virtual dunedaq::conffwk::class_t* get(const std::string& class_name, bool direct_only) = 0;
191
193
194 virtual void get_superclasses(conffwk::fmap<conffwk::fset>& schema) = 0;
195
196 // notification
197
198public:
200
201 typedef void (*notify)(std::vector<ConfigurationChange*>& changes, Configuration*);
202
204
205 typedef void (*pre_notify)(Configuration*);
206
208
209 virtual void subscribe(const std::set<std::string>& class_names,
210 const std::map<std::string, std::set<std::string>>& objs,
211 notify cb,
212 pre_notify pre_cb) = 0;
213
215
216 virtual void unsubscribe() = 0;
217
219
220 virtual void print_profiling_info() noexcept = 0;
221
223
224 void print_cache_info() noexcept;
225
227
228private:
230 std::vector<ConfigObjectImpl*> m_tangled_objects; // deleted and replaced by others as result of rename
231
232 mutable unsigned long p_number_of_cache_hits;
233 mutable unsigned long p_number_of_object_read;
234
235protected:
237
238 ConfigObjectImpl* get_impl_object(const std::string& class_name, const std::string& id) const noexcept;
239
241
242 void put_impl_object(const std::string& class_name, const std::string& id, ConfigObjectImpl* obj) noexcept;
243
245
246 template<class T, class OBJ>
247 T* insert_object(OBJ& obj, const std::string& id, const std::string& class_name) noexcept
248 {
249 ConfigObjectImpl* p = get_impl_object(class_name, id);
250
251 if (p == nullptr) {
252 p = static_cast<ConfigObjectImpl*>(new T(obj, this));
253 put_impl_object(class_name, id, p);
254 } else {
255 static_cast<T*>(p)->set(obj);
257 }
258
259 return static_cast<T*>(p);
260 }
261
263
264 void clean() noexcept;
265
267
268protected:
270
272
273 std::mutex& get_conf_impl_mutex() const;
274
275public:
277
278 void set(Configuration* db) noexcept { m_conf = db; }
279
280public:
282
283 void rename_impl_object(const std::string* class_name, const std::string& old_id, const std::string& new_id) noexcept;
284};
285
286} // namespace conffwk
287} // namespace dunedaq
288
289#endif // CONFFWK_CONFIGURATIONIMPL_H_
dunedaq::conffwk::ObjectState m_state
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:43
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)
conffwk::pmap< conffwk::map< ConfigObjectImpl * > * > m_impl_objects
cache of implementation objects (class-name::->object_id->implementation)
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.
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
std::vector< ConfigObjectImpl * > m_tangled_objects
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.
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.
virtual void open_db(const std::string &db_name)=0
Open database implementation in accordance with given name.
void(*) notify(std::vector< ConfigurationChange * > &changes, Configuration *)
Callback to notify database changes.
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:19
The DUNE-DAQ namespace.
msgpack::object obj