DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigObject.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/ConfigObject.h to include/conffwk/ConfigObject.hpp).
6//
7
14
15#ifndef CONFFWK_CONFIGOBJECT_H_
16#define CONFFWK_CONFIGOBJECT_H_
17
18#include <iostream>
19#include <string>
20#include <vector>
21
22#include <mutex>
23
25#include "conffwk/Errors.hpp"
26
27namespace dunedaq {
28namespace conffwk {
29
30class Configuration;
31
52
54{
55
56 friend class Configuration;
57 friend class ConfigurationImpl;
58 friend class DalObject;
59 friend class DalRegistry;
60
61public:
70
71 ConfigObject() noexcept;
72
79
80 ConfigObject(const ConfigObject& other) noexcept;
81
85
86 ConfigObject(ConfigObjectImpl* impl) noexcept;
87
91
92 ~ConfigObject() noexcept;
93
100
101 ConfigObject& operator=(const ConfigObject& other) noexcept;
102
106
107 ConfigObject& operator=(ConfigObjectImpl* impl) noexcept;
108
112
113 bool operator==(const ConfigObject& other) const noexcept;
114
115 ConfigObject* get_obj_pybind(const std::string& attrname);
116
117 template<typename T>
118 T get_value_pybind(const std::string& attrname)
119 {
120 T attrval;
121 this->get(attrname, attrval);
122 return attrval;
123 }
124
125 template<typename T>
126 std::vector<T> get_list_pybind(const std::string& attrname)
127 {
128 std::vector<T> attrvals;
129 this->get(attrname, attrvals);
130 return attrvals;
131 }
132
133 template<typename T>
134 void set_list_pybind(const std::string& attrname, std::vector<T> l)
135 {
136 this->set_by_ref(attrname, l);
137 }
138
139 // private:
140 // void set_string_list_generic(ConfigObject& co, const std::string& attrname, std::vector<std::string> data,
141 // void (ConfigObject::*f)(const std::string&, const std::vector<std::string>&)) {
142 // (co.*f)(attrname, data);
143 // }
144
145 // public:
146
147 // void set_string_list
148 // (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
149 // set_string_list_generic(co, attrname, l,
150 // &ConfigObject::set_by_ref<const std::vector<std::string> >);
151 // }
152
153 // void set_enum_list
154 // (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
155 // set_string_list_generic(co, attrname, l, &ConfigObject::set_enum);
156 // }
157
158 // void set_class_list
159 // (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
160 // set_string_list_generic(co, attrname, l, &ConfigObject::set_class);
161 // }
162
163 // void set_date_list
164 // (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
165 // set_string_list_generic(co, attrname, l, &ConfigObject::set_date);
166 // }
167
168 // void set_time_list
169 // (ConfigObject& co, const std::string& attrname, boost::python::list& l) {
170 // set_string_list_generic(co, attrname, l, &ConfigObject::set_time);
171 // }
172
181
182 bool is_null() const noexcept { return (m_impl == nullptr); }
183
187
188 bool is_deleted() const { return (m_impl->is_deleted()); }
189
190private:
191 void action_on_object_update(Configuration* db, const std::string& name);
192
193public:
204
205 const std::string& UID() const noexcept { return m_impl->m_id; }
206
216
217 const std::string& class_name() const noexcept { return *m_impl->m_class_name; }
218
225
226 const std::string full_name() const noexcept { return UID() + '@' + class_name(); }
227
232
233 const std::string contained_in() const { return m_impl->contained_in(); }
234
257
258 template<class T>
259 void get(const std::string& name, T& value)
260 {
261 m_impl->get(name, value);
262 m_impl->convert(value, *this, name);
263 }
264
276
277 bool rel(const std::string& name, std::vector<ConfigObject>& value)
278 {
279 if (m_impl->rel(name, value)) {
280 m_impl->convert(value, *this, name);
281 return true;
282 }
283
284 return false;
285 }
286
306
307 void referenced_by(std::vector<ConfigObject>& value,
308 const std::string& relationship_name = "*",
309 bool check_composite_only = true,
310 unsigned long rlevel = 0,
311 const std::vector<std::string>* rclasses = nullptr) const
312 {
313 m_impl->referenced_by(value, relationship_name, check_composite_only, rlevel, rclasses);
314 }
315
318
328
329 void set_obj(const std::string& name, const ConfigObject* o, bool skip_non_null_check = false)
330 {
331 m_impl->set(name, o, skip_non_null_check);
333 }
334
344
345 void set_objs(const std::string& name, const std::vector<const ConfigObject*>& o, bool skip_non_null_check = false)
346 {
347 m_impl->set(name, o, skip_non_null_check);
349 }
350
370
371 template<class T>
372 void set_by_val(const std::string& name, T value)
373 {
374 m_impl->set(name, value);
376 }
377
392
393 template<class T>
394 void set_by_ref(const std::string& name, T& value)
395 {
396 m_impl->set(name, value);
398 }
399
410
411 void set_enum(const std::string& name, const std::string& value)
412 {
413 m_impl->set_enum(name, value);
415 }
416
427
428 void set_class(const std::string& name, const std::string& value)
429 {
430 m_impl->set_class(name, value);
432 }
433
444
445 void set_date(const std::string& name, const std::string& value)
446 {
447 m_impl->set_date(name, value);
449 }
450
461
462 void set_time(const std::string& name, const std::string& value)
463 {
464 m_impl->set_time(name, value);
466 }
467
478
479 void set_enum(const std::string& name, const std::vector<std::string>& value)
480 {
481 m_impl->set_enum(name, value);
483 }
484
495
496 void set_class(const std::string& name, const std::vector<std::string>& value)
497 {
498 m_impl->set_class(name, value);
500 }
501
512
513 void set_date(const std::string& name, const std::vector<std::string>& value)
514 {
515 m_impl->set_date(name, value);
517 }
518
529
530 void set_time(const std::string& name, const std::vector<std::string>& value)
531 {
532 m_impl->set_time(name, value);
534 }
535
545
546 void move(const std::string& at) { m_impl->move(at); }
547
557
558 void rename(const std::string& new_id);
559
563
564 void print_ptr(std::ostream& s) const noexcept;
565
569
570 void print_ref(std::ostream& s,
571 Configuration& conf,
572 const std::string& prefix = "",
573 bool show_contained_in = false
574 ) const noexcept;
575
581
582 const ConfigObjectImpl* implementation() const noexcept { return m_impl; }
583
584private:
585 void _clear() noexcept
586 {
587 if (m_impl) {
588 m_impl->clear();
589 }
590 }
591
592private:
594};
595
597
598std::ostream&
599operator<<(std::ostream&, const ConfigObject*);
600
602
603std::ostream&
604operator<<(std::ostream&, const ConfigObject&);
605
606} // namespace conffwk
607} // namespace dunedaq
608
609#endif // CONFFWK_CONFIGOBJECT_H_
Implements database objects.
void convert(bool &value, const ConfigObject &obj, const std::string &attr_name) noexcept
virtual void clear() noexcept
Virtual method to clean resources used by the implementation object.
virtual const std::string contained_in() const =0
Virtual method to get object's database file name.
virtual void set(const std::string &attribute, bool value)=0
Virtual method to set boolean attribute value.
virtual void referenced_by(std::vector< ConfigObject > &value, const std::string &association, bool check_composite_only, unsigned long rlevel, const std::vector< std::string > *rclasses) const =0
Virtual method to read vector-of-conffwk-object referencing this object.
virtual bool rel(const std::string &name, std::vector< ConfigObject > &value)=0
bool is_deleted() const
Check object and return true if the object has been deleted.
virtual void set_time(const std::string &attribute, const std::string &value)=0
Virtual method to set time attribute value.
virtual void move(const std::string &at)=0
Virtual method to move object to a file.
virtual void set_enum(const std::string &attribute, const std::string &value)=0
Virtual method to set enumeration attribute value.
virtual void get(const std::string &attribute, bool &value)=0
Virtual method to read boolean attribute value.
virtual void set_class(const std::string &attribute, const std::string &value)=0
Virtual method to set enumeration attribute value.
virtual void set_date(const std::string &attribute, const std::string &value)=0
Virtual method to set date attribute value.
Represents database objects.
void set_time(const std::string &name, const std::string &value)
Set attribute time value.
void set_by_val(const std::string &name, T value)
Set attribute value.
ConfigObject * get_obj_pybind(const std::string &attrname)
void set_time(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-times value.
T get_value_pybind(const std::string &attrname)
ConfigObject() noexcept
Default constructor.
void set_class(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-class value.
void set_date(const std::string &name, const std::string &value)
Set attribute date value.
void print_ptr(std::ostream &s) const noexcept
Print object's pointer in format 'obj-id@class-name'.
void set_objs(const std::string &name, const std::vector< const ConfigObject * > &o, bool skip_non_null_check=false)
Set relationship multi-value.
void move(const std::string &at)
Move object to a different database.
const std::string & UID() const noexcept
Return object identity.
void set_enum(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-enumerations value.
Configuration * get_configuration() const
Get pointer to configuration object.
void set_class(const std::string &name, const std::string &value)
Set attribute class value.
void set_by_ref(const std::string &name, T &value)
Set attribute value.
bool is_deleted() const
Check if object was deleted.
void action_on_object_update(Configuration *db, const std::string &name)
void set_list_pybind(const std::string &attrname, std::vector< T > l)
void set_date(const std::string &name, const std::vector< std::string > &value)
Set attribute vector-of-dates value.
void print_ref(std::ostream &s, Configuration &conf, const std::string &prefix="", bool show_contained_in=false) const noexcept
Print details of object's attributes and relationships.
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
void set_enum(const std::string &name, const std::string &value)
Set attribute enumeration value.
void referenced_by(std::vector< ConfigObject > &value, const std::string &relationship_name="*", bool check_composite_only=true, unsigned long rlevel=0, const std::vector< std::string > *rclasses=nullptr) const
Get objects which have references to given object.
const std::string full_name() const noexcept
Return full object name.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
bool is_null() const noexcept
Check if object's implementation points to null.
const ConfigObjectImpl * implementation() const noexcept
Returns pointer on implementation.
void rename(const std::string &new_id)
Rename object.
std::vector< T > get_list_pybind(const std::string &attrname)
const std::string & class_name() const noexcept
Return object's class name.
bool rel(const std::string &name, std::vector< ConfigObject > &value)
Get value of object's relationship.
const std::string contained_in() const
Return the name of the database file this object belongs to.
Defines base class for cache of template objects.
std::ostream & operator<<(std::ostream &, const ConfigurationChange &)
The DUNE-DAQ namespace.