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