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