DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigurationImpl.cpp
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: no.
6//
7
8#include <stdlib.h>
9
12#include "conffwk/Schema.hpp"
13
14namespace dunedaq {
15 namespace conffwk {
16
17 const char * bool2str(bool value) { return (value ? "yes" : "no"); }
18
20 const std::string& name, type_t type, const std::string& range,
21 int_format_t int_format, bool is_not_null, bool is_multi_value,
22 const std::string& default_value, const std::string& description
23 ) :
24 p_name (name),
25 p_type (type),
26 p_range (range),
27 p_int_format (int_format),
28 p_is_not_null (is_not_null),
29 p_is_multi_value (is_multi_value),
30 p_default_value (default_value),
31 p_description (description)
32 { ; }
33
35 {
36 switch(type) {
37 case bool_type: return "boolean";
38 case s8_type: return "8-bits signed integer";
39 case u8_type: return "8-bits unsigned integer";
40 case s16_type: return "16-bits signed integer";
41 case u16_type: return "16-bits unsigned integer";
42 case s32_type: return "32-bits signed integer";
43 case u32_type: return "32-bits unsigned integer";
44 case s64_type: return "64-bits signed integer";
45 case u64_type: return "64-bits unsigned integer";
46 case float_type: return "float";
47 case double_type: return "double";
48 case date_type: return "date";
49 case time_type: return "time";
50 case string_type: return "string";
51 case enum_type: return "enumeration";
52 case class_type: return "class reference";
53 default: return "unknown";
54 }
55 }
56
58 {
59 switch(type) {
60 case bool_type: return "bool";
61 case s8_type: return "s8";
62 case u8_type: return "u8";
63 case s16_type: return "s16";
64 case u16_type: return "u16";
65 case s32_type: return "s32";
66 case u32_type: return "u32";
67 case s64_type: return "s64";
68 case u64_type: return "u64";
69 case float_type: return "float";
70 case double_type: return "double";
71 case date_type: return "date";
72 case time_type: return "time";
73 case string_type: return "string";
74 case enum_type: return "enum";
75 case class_type: return "class";
76 default: return "unknown";
77 }
78 }
79
81 {
82 switch(type) {
83 case oct_int_format: return "octal";
84 case dec_int_format: return "decimal";
85 case hex_int_format: return "hexadecimal";
86 default: return "not applicable";
87 }
88 }
89
90 void attribute_t::print(std::ostream& out, const std::string& prefix) const
91 {
92 out
93 << prefix << "attribute \'" << p_name << "\'\n"
94 << prefix << " type: \'" << type2str(p_type) << "\'\n"
95 << prefix << " range: \'" << p_range << "\'\n";
96
98 out << prefix << " integer format: \'" << format2str(p_int_format) << "\'\n";
99 }
100
101 out
102 << prefix << " is not null: " << bool2str(p_is_not_null) << '\n'
103 << prefix << " is multi-value: " << bool2str(p_is_multi_value) << '\n'
104 << prefix << " default value: \'" << p_default_value << "\'\n"
105 << prefix << " description: \'" << p_description << '\'';
106 }
107
108 std::ostream& operator<<(std::ostream& out, const attribute_t& a)
109 {
110 a.print(out);
111 return out;
112 }
113
114
116 const std::string& name, const std::string& type, bool can_be_null,
117 bool is_multi_value, bool is_aggregation, const std::string& description
118 ) :
119 p_name (name),
120 p_type (type),
122 (can_be_null && !is_multi_value) ? zero_or_one :
123 (can_be_null && is_multi_value ) ? zero_or_many :
124 (!can_be_null && is_multi_value ) ? one_or_many :
126 ),
127 p_is_aggregation (is_aggregation),
128 p_description (description)
129 { ; }
130
131 const char * relationship_t::card2str(cardinality_t cardinality)
132 {
133 switch(cardinality) {
134 case zero_or_one: return "zero or one";
135 case zero_or_many: return "zero or many";
136 case only_one: return "one";
137 case one_or_many: return "one or many";
138 default: return "unknown";
139 }
140 }
141
142 void relationship_t::print(std::ostream& out, const std::string& prefix) const
143 {
144 out
145 << prefix << "relationship \'" << p_name << "\'\n"
146 << prefix << " class type: \'" << p_type << "\'\n"
147 << prefix << " cardinality: \'" << card2str(p_cardinality) << "\'\n"
148 << prefix << " is aggregation: \'" << bool2str(p_is_aggregation) << "\'\n"
149 << prefix << " description: \'" << p_description << '\'';
150 }
151
152 std::ostream& operator<<(std::ostream& out, const relationship_t& r)
153 {
154 r.print(out);
155 return out;
156 }
157
159 const std::string& name,
160 const std::string& description,
161 const std::string& schema_path,
162 bool is_abstract
163 ) :
164 p_name (name),
165 p_description (description),
166 p_schema_path (schema_path),
167 p_abstract (is_abstract)
168 { ; }
169
170 void class_t::print(std::ostream& out, const std::string& prefix) const
171 {
172 out
173 << prefix << "class \'" << p_name << "\'\n"
174 << prefix << " is abstract: \'" << bool2str(p_abstract) << "\'\n"
175 << prefix << " description: \'" << p_description << "\'\n"
176 << prefix << " path: \'" << p_schema_path << "\'\n";
177
178 if(p_superclasses.empty()) {
179 out << prefix << " there are no superclasses\n";
180 }
181 else {
182 out << prefix << " " << p_superclasses.size() << " superclass(es):\n";
183 for(std::vector<std::string>::const_iterator i = p_superclasses.begin(); i != p_superclasses.end(); ++i) {
184 out << prefix << " \'" << *i << "\'\n";
185 }
186 }
187
188 if(p_subclasses.empty()) {
189 out << prefix << " there are no subclasses\n";
190 }
191 else {
192 out << prefix << " " << p_subclasses.size() << " subclass(es):\n";
193 for(std::vector<std::string>::const_iterator i = p_subclasses.begin(); i != p_subclasses.end(); ++i) {
194 out << prefix << " \'" << *i << "\'\n";
195 }
196 }
197
198 std::string new_prefix(prefix);
199 new_prefix += " ";
200
201 if(p_attributes.empty()) {
202 out << prefix << " there are no attributes\n";
203 }
204 else {
205 out << prefix << " " << p_attributes.size() << " attribute(s):\n";
206 for(std::vector<attribute_t>::const_iterator i = p_attributes.begin(); i != p_attributes.end(); ++i) {
207 (*i).print(out, new_prefix.c_str());
208 out << std::endl;
209 }
210 }
211
212 if(p_relationships.empty()) {
213 out << prefix << " there are no relationships\n";
214 }
215 else {
216 out << prefix << " " << p_relationships.size() << " relationship(s):\n";
217 for(std::vector<relationship_t>::const_iterator i = p_relationships.begin(); i != p_relationships.end(); ++i) {
218 (*i).print(out, new_prefix.c_str());
219 out << std::endl;
220 }
221 }
222 }
223
224 std::ostream& operator<<(std::ostream& out, const class_t& c)
225 {
226 c.print(out);
227 return out;
228 }
229
230
237
242
243void
245{
246 std::cout <<
247 "Configuration implementation profiler report:\n"
248 " number of read objects: " << p_number_of_object_read << "\n"
249 " number of cache hits: " << p_number_of_cache_hits << std::endl;
250}
251
253ConfigurationImpl::get_impl_object(const std::string& name, const std::string& id) const noexcept
254{
255
256 conffwk::pmap<conffwk::map<ConfigObjectImpl *> *>::const_iterator i = m_impl_objects.find(&name);
257
258 const std::string * class_name = nullptr;
259
260 if(i != m_impl_objects.end()) {
262
263 if(j != i->second->end()) {
265 TLOG_DEBUG(4) << "\n * found the object with id = \'" << id << "\' in class \'" << name << '\'' ;
266 return j->second;
267 }
268
269 class_name = i->first;
270
271
272 // prepare and print out debug message
273
274 if(ers::debug_level() >= 4) {
275 TLOG_DEBUG(40) << " * there is no object with id = \'" << id << "\' found in the class \'" << name
276 << "\' that has " << i->second->size() << " objects in cache: ";
277 for(j=i->second->begin(); j != i->second->end();++j) {
278 TLOG_DEBUG(40) << '\'' << j->first << '\'';
279 }
280 }
281
282 }
283 else {
284 class_name = &DalFactory::instance().get_known_class_name_ref(name);
285 TLOG_DEBUG(40) << " * there is no object with id = \'" << id << "\' found in the class \'" << name
286 << "\' that has no objects in cache";
287 }
288
289 // check implementation objects of subclasses
290
291 if(m_conf) {
292 conffwk::fmap<conffwk::fset>::const_iterator subclasses = m_conf->subclasses().find(class_name);
293
294 if(subclasses != m_conf->subclasses().end()) {
295 for(conffwk::fset::const_iterator k = subclasses->second.begin(); k != subclasses->second.end(); ++k) {
296 i = m_impl_objects.find(*k);
297 if(i != m_impl_objects.end()) {
299
300 if(j != i->second->end()) {
302 TLOG_DEBUG(40) << " * found the object with id = \'" << id << "\' in class \'" << *k << '\'';
303
304 return j->second;
305 }
306
307
308 // prepare and print out debug message
309
310 else if(ers::debug_level() >= 4) {
311 TLOG_DEBUG(40) << " * there is no object with id = \'" << id << "\' found in the class \'" << *k
312 << "\' that has " << i->second->size() << " objects in cache: ";
313 for(j=i->second->begin(); j != i->second->end();++j) {
314 TLOG_DEBUG(40) << '\'' << j->first << '\'';
315 }
316 }
317
318
319 }
320 else {
321 TLOG_DEBUG(40) << " * there is no object with id = \'" << id << "\' found in the class \'" << *k
322 << "\' that has no objects in cache\n";
323 }
324
325 }
326 }
327
328 TLOG_DEBUG(40) << " * there is no object \'" << id << "\' in class \'" << name
329 << "\' and it's subclasses, returning NULL ...";
330 }
331 else {
332 TLOG_DEBUG(40) << " * there is no object \'" << id << "\' in class \'" << name << "\', returning NULL ...";
333 }
334
335 return nullptr;
336}
337
338
339void
340ConfigurationImpl::put_impl_object(const std::string& name, const std::string& id, ConfigObjectImpl * obj) noexcept
341{
343
345
346 if(i != m_impl_objects.end()) {
347 (*i->second)[id] = obj;
348 obj->m_class_name = i->first;
349 }
350 else {
352 obj->m_class_name = &DalFactory::instance().get_known_class_name_ref(name);
353 m_impl_objects[obj->m_class_name] = m;
354 (*m)[id] = obj;
355 }
356}
357
358void
359ConfigurationImpl::rename_impl_object(const std::string * class_name, const std::string& old_id, const std::string& new_id) noexcept
360{
361 conffwk::pmap<conffwk::map<ConfigObjectImpl *> *>::iterator i = m_impl_objects.find(class_name);
362
363 if (i != m_impl_objects.end())
364 {
365 conffwk::map<ConfigObjectImpl *>::iterator j = i->second->find(old_id);
366
367 if (j != i->second->end())
368 {
369 ConfigObjectImpl*& obj = (*i->second)[new_id];
370
371 if (obj != nullptr)
372 {
374 m_tangled_objects.push_back(obj);
375 }
376
377 obj = j->second;
378
379 TLOG_DEBUG(2) << "rename implementation " << (void *)j->second << " of object \'" << old_id << '@' << *class_name << "\' to \'" << new_id << '\'';
380 i->second->erase(j);
381 }
382 }
383}
384
385void
387{
388 for (auto& i : m_impl_objects)
389 {
390 for (auto& j : *i.second)
391 delete j.second;
392
393 delete i.second;
394 }
395
396 m_impl_objects.clear();
397
398 for (auto& x : m_tangled_objects)
399 delete x;
400
401 m_tangled_objects.clear();
402}
403
404std::mutex&
406{
407 return m_conf->m_impl_mutex;
408}
409
410void
411ConfigObjectImpl::convert(bool& value, const ConfigObject& obj, const std::string& attr_name) noexcept
412{
413 m_impl->m_conf->convert(value, obj, attr_name);
414}
415
416void
417ConfigObjectImpl::convert(uint8_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
418{
419 m_impl->m_conf->convert(value, obj, attr_name);
420}
421
422void
423ConfigObjectImpl::convert(int8_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
424{
425 m_impl->m_conf->convert(value, obj, attr_name);
426}
427
428void
429ConfigObjectImpl::convert(uint16_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
430{
431 m_impl->m_conf->convert(value, obj, attr_name);
432}
433
434void
435ConfigObjectImpl::convert(int16_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
436{
437 m_impl->m_conf->convert(value, obj, attr_name);
438}
439
440void
441ConfigObjectImpl::convert(uint32_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
442{
443 m_impl->m_conf->convert(value, obj, attr_name);
444}
445
446void
447ConfigObjectImpl::convert(int32_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
448{
449 m_impl->m_conf->convert(value, obj, attr_name);
450}
451
452void
453ConfigObjectImpl::convert(uint64_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
454{
455 m_impl->m_conf->convert(value, obj, attr_name);
456}
457
458void
459ConfigObjectImpl::convert(int64_t& value, const ConfigObject& obj, const std::string& attr_name) noexcept
460{
461 m_impl->m_conf->convert(value, obj, attr_name);
462}
463
464void
465ConfigObjectImpl::convert(float& value, const ConfigObject& obj, const std::string& attr_name) noexcept
466{
467 m_impl->m_conf->convert(value, obj, attr_name);
468}
469
470void
471ConfigObjectImpl::convert(double& value, const ConfigObject& obj, const std::string& attr_name) noexcept
472{
473 m_impl->m_conf->convert(value, obj, attr_name);
474}
475
476void
477ConfigObjectImpl::convert(std::string& value, const ConfigObject& obj, const std::string& attr_name) noexcept
478{
479 m_impl->m_conf->convert(value, obj, attr_name);
480}
481
482
483void
484ConfigObjectImpl::convert(std::vector<bool>& /*value*/, const ConfigObject& /*obj*/, const std::string& /*attr_name*/) noexcept
485{
486 //m_impl->m_conf->convert2(value, obj, attr_name);
487}
488
489void
490ConfigObjectImpl::convert(std::vector<uint8_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
491{
492 m_impl->m_conf->convert2(value, obj, attr_name);
493}
494
495void
496ConfigObjectImpl::convert(std::vector<int8_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
497{
498 m_impl->m_conf->convert2(value, obj, attr_name);
499}
500
501void
502ConfigObjectImpl::convert(std::vector<uint16_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
503{
504 m_impl->m_conf->convert2(value, obj, attr_name);
505}
506
507void
508ConfigObjectImpl::convert(std::vector<int16_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
509{
510 m_impl->m_conf->convert2(value, obj, attr_name);
511}
512
513void
514ConfigObjectImpl::convert(std::vector<uint32_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
515{
516 m_impl->m_conf->convert2(value, obj, attr_name);
517}
518
519void
520ConfigObjectImpl::convert(std::vector<int32_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
521{
522 m_impl->m_conf->convert2(value, obj, attr_name);
523}
524
525void
526ConfigObjectImpl::convert(std::vector<uint64_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
527{
528 m_impl->m_conf->convert2(value, obj, attr_name);
529}
530
531void
532ConfigObjectImpl::convert(std::vector<int64_t>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
533{
534 m_impl->m_conf->convert2(value, obj, attr_name);
535}
536
537void
538ConfigObjectImpl::convert(std::vector<float>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
539{
540 m_impl->m_conf->convert2(value, obj, attr_name);
541}
542
543void
544ConfigObjectImpl::convert(std::vector<double>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
545{
546 m_impl->m_conf->convert2(value, obj, attr_name);
547}
548
549void
550ConfigObjectImpl::convert(std::vector<std::string>& value, const ConfigObject& obj, const std::string& attr_name) noexcept
551{
552 m_impl->m_conf->convert2(value, obj, attr_name);
553}
554
555} // namespace conffwk
556} // namespace dunedaq
Implements database objects.
void convert(bool &value, const ConfigObject &obj, const std::string &attr_name) noexcept
void put_impl_object(const std::string &class_name, const std::string &id, ConfigObjectImpl *obj) noexcept
put object to cache
ConfigurationImpl() noexcept
The constructor.
void clean() noexcept
clean cache (e.g. to be used by destructor)
std::vector< ConfigObjectImpl * > m_tangled_objects
ConfigObjectImpl * get_impl_object(const std::string &class_name, const std::string &id) const noexcept
get object from cache
virtual ~ConfigurationImpl()
Virtual destructor.
void rename_impl_object(const std::string *class_name, const std::string &old_id, const std::string &new_id) noexcept
rename object in cache
void print_cache_info() noexcept
Print profiling information about objects in cache.
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.
conffwk::pmap< conffwk::map< ConfigObjectImpl * > * > m_impl_objects
cache of implementation objects (class-name::->object_id->implementation)
conffwk entry point
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
const char * bool2str(bool value)
std::ostream & operator<<(std::ostream &, const ConfigurationChange &)
Including Qt Headers.
Definition module.cpp:16
DAC value out of range
Message.
Definition DACNode.hpp:32
FELIX Initialization std::string initerror FELIX queue timed out
msgpack::object obj
int debug_level()
Definition ers.hpp:77
static const char * type(type_t type)
void print(std::ostream &out, const std::string &prefix="") const
static const char * type2str(type_t type)
static const char * format2str(int_format_t format)
const std::vector< attribute_t > p_attributes
Definition Schema.hpp:170
const std::vector< relationship_t > p_relationships
Definition Schema.hpp:171
void print(std::ostream &out, const std::string &prefix="") const
const std::vector< std::string > p_subclasses
Definition Schema.hpp:169
std::string p_description
Definition Schema.hpp:165
std::string p_schema_path
Definition Schema.hpp:166
const std::vector< std::string > p_superclasses
Definition Schema.hpp:168
void print(std::ostream &out, const std::string &prefix="") const
static const char * card2str(cardinality_t cardinality)