DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
OksConfigObject.cpp
Go to the documentation of this file.
1//
2// DUNE DAQ modification notice:
3// This file has been modified from the original ATLAS oksconfig source for the DUNE DAQ project.
4// Fork baseline commit: oksconfig-03-02-00 (2021-04-20).
5// Renamed since fork: no.
6//
7
8#include "ers/ers.hpp"
9
10#include "oks/file.hpp"
11#include "oks/relationship.hpp"
12
14
17
18#include "logging/Logging.hpp"
19
20using namespace dunedaq;
21using namespace dunedaq::oks;
22using namespace dunedaq::oksconflibs;
23
24static std::string
25mk_error_text(const char* op, const char* what, const std::string& name, const OksObject* o, const char* error)
26{
27 std::ostringstream text;
28 text << "failed to " << op << ' ' << what << " \"" << name << "\" of object " << o;
29 if (error)
30 text << ": " << error;
31 return text.str();
32}
33
34static std::string
35mk_get_error_text(const char* what, const std::string& name, const OksObject* o, const char* error = nullptr)
36{
37 return mk_error_text("read", what, name, o, error);
38}
39
40static std::string
41mk_set_error_text(const char* what, const std::string& name, const OksObject* o, const char* error = nullptr)
42{
43 return mk_error_text("set value", what, name, o, error);
44}
45
47OksConfigObject::get_type(const std::string& name) const
48{
49 try {
50 return m_obj->GetAttributeValue(name)->type;
51 } catch (oks::exception& ex) {
52 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
53 }
54}
55
56// helper function to extract value out of OKS database
57template<class T>
58void
59OksConfigObject::get_value(const std::string& name, T& value)
60{
61 std::lock_guard<std::mutex> scoped_lock(m_mutex);
62
63 try {
65 OksData* data(m_obj->GetAttributeValue(name));
66 value = *reinterpret_cast<T*>(&data->data); // really ugly stuff here, but should come out right
67 } catch (oks::exception& ex) {
68 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
69 }
70}
71
72// helper function to extract vector of values out of OKS database
73template<class T>
74void
75OksConfigObject::get_vector(const std::string& name, std::vector<T>& value)
76{
77 OksData* data = 0;
78
79 std::lock_guard<std::mutex> scoped_lock(m_mutex);
80
81 try {
83 data = m_obj->GetAttributeValue(name);
84 } catch (oks::exception& ex) {
85 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
86 }
87
88 if (data->type != OksData::list_type) {
89 std::ostringstream text;
90 text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
91 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
92 }
93
94 value.clear();
95 for (const auto& it : *data->data.LIST) {
96 value.push_back(*reinterpret_cast<T*>(&it->data));
97 }
98}
99
105
107
108const std::string
110{
111 std::lock_guard<std::mutex> scoped_lock(m_mutex);
113 return m_obj->get_file()->get_full_file_name();
114}
115
116void
117OksConfigObject::get(const std::string& name, bool& value)
118{
119 get_value(name, value);
120}
121
122void
123OksConfigObject::get(const std::string& name, uint8_t& value)
124{
125 get_value(name, value);
126}
127
128void
129OksConfigObject::get(const std::string& name, int8_t& value)
130{
131 get_value(name, value);
132}
133
134void
135OksConfigObject::get(const std::string& name, uint16_t& value)
136{
137 get_value(name, value);
138}
139
140void
141OksConfigObject::get(const std::string& name, int16_t& value)
142{
143 get_value(name, value);
144}
145
146void
147OksConfigObject::get(const std::string& name, uint32_t& value)
148{
149 get_value(name, value);
150}
151
152void
153OksConfigObject::get(const std::string& name, int32_t& value)
154{
155 get_value(name, value);
156}
157
158void
159OksConfigObject::get(const std::string& name, uint64_t& value)
160{
161 get_value(name, value);
162}
163
164void
165OksConfigObject::get(const std::string& name, int64_t& value)
166{
167 get_value(name, value);
168}
169
170void
171OksConfigObject::get(const std::string& name, float& value)
172{
173 get_value(name, value);
174}
175
176void
177OksConfigObject::get(const std::string& name, double& value)
178{
179 get_value(name, value);
180}
181
182void
183OksConfigObject::get(const std::string& name, std::string& value)
184{
185 OksData* data = 0;
186
187 std::lock_guard<std::mutex> scoped_lock(m_mutex);
188
189 try {
191 data = m_obj->GetAttributeValue(name);
192 } catch (oks::exception& ex) {
193 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
194 }
195
196 if ((data->type == OksData::string_type) || (data->type == OksData::enum_type)) {
197 value = *data->data.STRING;
198 return;
199 } else if (data->type == OksData::date_type || data->type == OksData::time_type) {
200 value = data->str();
201 return;
202 } else if (data->type == OksData::class_type) {
203 value = data->data.CLASS->get_name();
204 return;
205 } else {
206 std::ostringstream text;
207 text << "read wrong attribute type instead of expected \'string\' for attribute \"" << name << "\" of object "
208 << m_obj;
209 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
210 }
211}
212
213void
215{
216 OksData* data = 0;
217
218 std::lock_guard<std::mutex> scoped_lock(m_mutex);
219
220 try {
222 data = m_obj->GetRelationshipValue(name);
223 } catch (oks::exception& ex) {
224 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
225 }
226
227 if (data->type != OksData::object_type) {
228 if (data->type == OksData::uid_type || data->type == OksData::uid2_type) {
229 std::ostringstream text;
230 text << "referenced object " << *data << " is not loaded";
231 throw dunedaq::conffwk::Generic(ERS_HERE,
232 mk_get_error_text("relationship", name, m_obj, text.str().c_str()).c_str());
233 }
234
235 std::ostringstream text;
236 text << "bad value of relationship \"" << name << "\" of object " << m_obj << ": ";
237
238 if (data->type == OksData::list_type) {
239 text << "the relationship is multi-value";
240 } else {
241 text << "non-object type was read";
242 }
243 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
244 }
245
246 if (data->data.OBJECT != nullptr) {
247 value = static_cast<OksConfiguration*>(m_impl)->new_object(data->data.OBJECT);
248 } else {
249 value = nullptr;
250 }
251}
252
253void
254OksConfigObject::get(const std::string& name, std::vector<bool>& value)
255{
256 get_vector(name, value);
257}
258
259void
260OksConfigObject::get(const std::string& name, std::vector<uint8_t>& value)
261{
262 get_vector(name, value);
263}
264
265void
266OksConfigObject::get(const std::string& name, std::vector<int8_t>& value)
267{
268 get_vector(name, value);
269}
270
271void
272OksConfigObject::get(const std::string& name, std::vector<uint16_t>& value)
273{
274 get_vector(name, value);
275}
276
277void
278OksConfigObject::get(const std::string& name, std::vector<int16_t>& value)
279{
280 get_vector(name, value);
281}
282
283void
284OksConfigObject::get(const std::string& name, std::vector<uint32_t>& value)
285{
286 get_vector(name, value);
287}
288
289void
290OksConfigObject::get(const std::string& name, std::vector<int32_t>& value)
291{
292 get_vector(name, value);
293}
294
295void
296OksConfigObject::get(const std::string& name, std::vector<uint64_t>& value)
297{
298 get_vector(name, value);
299}
300
301void
302OksConfigObject::get(const std::string& name, std::vector<int64_t>& value)
303{
304 get_vector(name, value);
305}
306
307void
308OksConfigObject::get(const std::string& name, std::vector<float>& value)
309{
310 get_vector(name, value);
311}
312
313void
314OksConfigObject::get(const std::string& name, std::vector<double>& value)
315{
316 get_vector(name, value);
317}
318
319void
320OksConfigObject::get(const std::string& name, std::vector<std::string>& value)
321{
322 OksData* data = 0;
323
324 std::lock_guard<std::mutex> scoped_lock(m_mutex);
325
326 try {
328 data = m_obj->GetAttributeValue(name);
329 } catch (oks::exception& ex) {
330 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
331 }
332
333 if (data->type != OksData::list_type) {
334 std::ostringstream text;
335 text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
336 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
337 }
338
339 value.clear();
340
341 for (const auto& it : *data->data.LIST) {
342 if ((it->type == OksData::string_type) || (it->type == OksData::enum_type)) {
343 value.emplace_back(*it->data.STRING);
344 } else if (it->type == OksData::class_type) {
345 value.emplace_back(it->data.CLASS->get_name());
346 } else if (it->type == OksData::date_type || it->type == OksData::time_type) {
347 value.emplace_back(it->str());
348 } else {
349 std::ostringstream text;
350 text << "wrong type of attribute \"" << name << "\" of object " << m_obj << " (instead of expected string)";
351 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
352 }
353 }
354}
355
356void
357OksConfigObject::get(const std::string& name, std::vector<dunedaq::conffwk::ConfigObject>& value)
358{
359 OksData* data = 0;
360
361 std::lock_guard<std::mutex> scoped_lock(m_mutex);
362
363 try {
365 data = m_obj->GetRelationshipValue(name);
366 } catch (oks::exception& ex) {
367 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
368 }
369
370 if (data->type != OksData::list_type) {
371 std::ostringstream text;
372 text << "the value of relationship \"" << name << "\" of object " << m_obj << " is not multi-value";
373 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
374 }
375
376 value.clear();
377
378 for (const auto& it : *data->data.LIST) {
379 if (it->type != OksData::object_type) {
380 TLOG_DEBUG(1) << "object " << *it << " is not loaded (relationship \'" << name << "\' of object " << m_obj << ')';
381 } else if (!it->data.OBJECT) {
382 TLOG_DEBUG(1) << "skip (null) object in relationship \'" << name << "\' of object " << m_obj;
383 } else {
384 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration*>(m_impl)->new_object(it->data.OBJECT)));
385 }
386 }
387}
388
389bool
390OksConfigObject::rel(const std::string& name, std::vector<conffwk::ConfigObject>& value)
391{
392 std::lock_guard<std::mutex> scoped_lock(m_mutex);
393
394 try {
396
397 if (OksDataInfo* di = m_obj->GetClass()->get_data_info(name)) {
398 if (di->relationship) {
400
401 if (data->type == OksData::object_type) {
402 if (data->data.OBJECT != nullptr) {
403 value.push_back(
404 conffwk::ConfigObject(static_cast<OksConfiguration*>(m_impl)->new_object(data->data.OBJECT)));
405 }
406 } else if (data->type == OksData::list_type) {
407 for (const auto& it : *data->data.LIST) {
408 if (it->type == OksData::object_type) {
409 value.push_back(
410 conffwk::ConfigObject(static_cast<OksConfiguration*>(m_impl)->new_object(it->data.OBJECT)));
411 }
412 }
413 }
414
415 return true;
416 }
417 }
418
419 return false;
420 } catch (oks::exception& ex) {
421 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
422 }
423}
424
425void
426OksConfigObject::referenced_by(std::vector<conffwk::ConfigObject>& value,
427 const std::string& rname,
428 bool check_composite_only,
429 unsigned long /* rlevel */,
430 const std::vector<std::string>* /* rclasses */) const
431{
432 value.clear();
433
434 std::lock_guard<std::mutex> scoped_lock(m_mutex);
436
437 if (check_composite_only) {
438 bool any_name = (rname == "*");
439
440 if (const std::list<OksRCR*>* rcr = m_obj->reverse_composite_rels()) {
441 for (const auto& i : *rcr) {
442 if (any_name || rname == i->relationship->get_name()) {
443 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration*>(m_impl)->new_object(i->obj)));
444 }
445 }
446 }
447 } else {
448 if (OksObject::FList* objs = m_obj->get_all_rels(rname)) {
449 for (const auto& i : *objs) {
450 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration*>(m_impl)->new_object(i)));
451 }
452
453 delete objs;
454 }
455 }
456}
457
459//
460// set functions
461//
463
464void
465OksConfigObject::set_attr_value(const std::string& name, OksData& data)
466{
467 std::lock_guard<std::mutex> scoped_lock(m_mutex);
468
469 try {
471 // test_checkout_needs();
472 m_obj->SetAttributeValue(name, &data);
473 } catch (dunedaq::conffwk::Generic& ex) {
474 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
475 } catch (oks::exception& ex) {
476 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
477 }
478}
479
480void
481OksConfigObject::set_rel_value(const std::string& name, OksData& data, bool skip_non_null_check)
482{
483 std::lock_guard<std::mutex> scoped_lock(m_mutex);
484
485 try {
487 // test_checkout_needs();
488 m_obj->SetRelationshipValue(name, &data, skip_non_null_check);
489 } catch (dunedaq::conffwk::Generic& ex) {
490 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex);
491 } catch (oks::exception& ex) {
492 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex);
493 }
494}
495
496template<class T>
497void
498OksConfigObject::set_value(const std::string& name, const T& value)
499{
500 OksData d(value);
501 set_attr_value(name, d);
502}
503
504template<class T>
505void
506OksConfigObject::set_vector(const std::string& name, const std::vector<T>& value)
507{
508 OksData d(new OksData::List());
509
510 for (const auto& i : value) {
511 d.data.LIST->push_back(new OksData(i));
512 }
513
514 set_attr_value(name, d);
515}
516
517void
518OksConfigObject::set(const std::string& name, bool value)
519{
520 set_value(name, value);
521}
522
523void
524OksConfigObject::set(const std::string& name, uint8_t value)
525{
526 set_value(name, value);
527}
528
529void
530OksConfigObject::set(const std::string& name, int8_t value)
531{
532 set_value(name, value);
533}
534
535void
536OksConfigObject::set(const std::string& name, uint16_t value)
537{
538 set_value(name, value);
539}
540
541void
542OksConfigObject::set(const std::string& name, int16_t value)
543{
544 set_value(name, value);
545}
546
547void
548OksConfigObject::set(const std::string& name, uint32_t value)
549{
550 set_value(name, value);
551}
552
553void
554OksConfigObject::set(const std::string& name, int32_t value)
555{
556 set_value(name, value);
557}
558
559void
560OksConfigObject::set(const std::string& name, uint64_t value)
561{
562 set_value(name, value);
563}
564
565void
566OksConfigObject::set(const std::string& name, int64_t value)
567{
568 set_value(name, value);
569}
570
571void
572OksConfigObject::set(const std::string& name, float value)
573{
574 set_value(name, value);
575}
576
577void
578OksConfigObject::set(const std::string& name, double value)
579{
580 set_value(name, value);
581}
582
583void
584OksConfigObject::set(const std::string& name, const std::string& value)
585{
586 set_value(name, value);
587}
588
589void
590OksConfigObject::set_enum(const std::string& name, const std::string& value)
591{
592 OksData d;
593
594 {
595 std::lock_guard<std::mutex> scoped_lock(m_mutex);
597
598 if (OksAttribute* a = m_obj->GetClass()->find_attribute(name)) {
599 try {
600 d.data.ENUMERATION = a->get_enum_value(value);
601 d.type = OksData::enum_type;
602 } catch (std::exception& ex) {
603 throw(dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj, ex.what()).c_str()));
604 }
605 } else {
606 throw(
607 dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str()));
608 }
609 }
610
611 set_attr_value(name, d);
612}
613
614void
615OksConfigObject::set_class(const std::string& name, const std::string& value)
616{
617 OksData d;
618
619 d.data.CLASS = nullptr;
620 d.type = OksData::class_type;
621
622 // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
623 {
624 std::lock_guard<std::mutex> scoped_lock(m_mutex);
626
627 const std::list<OksAttribute*>* attrs = m_obj->GetClass()->all_attributes();
628
629 if (!attrs || attrs->empty()) {
630 throw dunedaq::conffwk::Generic(ERS_HERE,
631 mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
632 }
633
634 try {
635 d.SetValue(value.c_str(), attrs->front());
636 } catch (oks::exception& ex) {
637 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
638 }
639 }
640
641 set_attr_value(name, d);
642}
643
644void
645OksConfigObject::set_date(const std::string& name, const std::string& value)
646{
647 OksData d;
648 d.type = OksData::date_type;
649
650 try {
651 d.SetValue(value.c_str(), nullptr);
652 } catch (oks::exception& ex) {
653 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
654 }
655
656 set_attr_value(name, d);
657}
658
659void
660OksConfigObject::set_time(const std::string& name, const std::string& value)
661{
662 OksData d;
663 d.type = OksData::time_type;
664
665 try {
666 d.SetValue(value.c_str(), nullptr);
667 } catch (oks::exception& ex) {
668 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
669 }
670
671 set_attr_value(name, d);
672}
673
674void
675OksConfigObject::set(const std::string& name, const std::vector<bool>& value)
676{
677 set_vector(name, value);
678}
679
680void
681OksConfigObject::set(const std::string& name, const std::vector<uint8_t>& value)
682{
683 set_vector(name, value);
684}
685
686void
687OksConfigObject::set(const std::string& name, const std::vector<int8_t>& value)
688{
689 set_vector(name, value);
690}
691
692void
693OksConfigObject::set(const std::string& name, const std::vector<uint16_t>& value)
694{
695 set_vector(name, value);
696}
697
698void
699OksConfigObject::set(const std::string& name, const std::vector<int16_t>& value)
700{
701 set_vector(name, value);
702}
703
704void
705OksConfigObject::set(const std::string& name, const std::vector<uint32_t>& value)
706{
707 set_vector(name, value);
708}
709
710void
711OksConfigObject::set(const std::string& name, const std::vector<int32_t>& value)
712{
713 set_vector(name, value);
714}
715
716void
717OksConfigObject::set(const std::string& name, const std::vector<uint64_t>& value)
718{
719 set_vector(name, value);
720}
721
722void
723OksConfigObject::set(const std::string& name, const std::vector<int64_t>& value)
724{
725 set_vector(name, value);
726}
727
728void
729OksConfigObject::set(const std::string& name, const std::vector<float>& value)
730{
731 set_vector(name, value);
732}
733
734void
735OksConfigObject::set(const std::string& name, const std::vector<double>& value)
736{
737 set_vector(name, value);
738}
739
740void
741OksConfigObject::set(const std::string& name, const std::vector<std::string>& value)
742{
743 set_vector(name, value);
744}
745
746void
747OksConfigObject::set_enum(const std::string& name, const std::vector<std::string>& value)
748{
749 OksData d(new OksData::List());
750
751 {
752 std::lock_guard<std::mutex> scoped_lock(m_mutex);
754
755 if (OksAttribute* a = m_obj->GetClass()->find_attribute(name)) {
756 for (const auto& i : value) {
757 OksData* d2 = new OksData();
758 try {
759 d2->data.ENUMERATION = a->get_enum_value(i); // new OksString(i);
761 d.data.LIST->push_back(d2);
762 } catch (std::exception& ex) {
763 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
764 }
765 }
766 } else {
767 throw dunedaq::conffwk::Generic(ERS_HERE,
768 mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
769 }
770 }
771
772 set_attr_value(name, d);
773}
774
775void
776OksConfigObject::set_class(const std::string& name, const std::vector<std::string>& value)
777{
778 OksData d(new OksData::List());
779
780 // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
781
782 {
783 std::lock_guard<std::mutex> scoped_lock(m_mutex);
785
786 const std::list<OksAttribute*>* attrs = m_obj->GetClass()->all_attributes();
787
788 if (!attrs || attrs->empty()) {
789 throw dunedaq::conffwk::Generic(ERS_HERE,
790 mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
791 }
792
793 for (const auto& i : value) {
794 OksData* d2 = new OksData();
795 d2->data.CLASS = 0;
797
798 try {
799 d2->SetValue(i.c_str(), attrs->front());
800 } catch (oks::exception& ex) {
801 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
802 }
803
804 d.data.LIST->push_back(d2);
805 }
806 }
807
808 set_attr_value(name, d);
809}
810
811void
812OksConfigObject::set_date(const std::string& name, const std::vector<std::string>& value)
813{
814 OksData d(new OksData::List());
815
816 for (const auto& i : value) {
817 OksData* d2 = new OksData();
819 try {
820 d2->SetValue(i.c_str(), nullptr);
821 } catch (oks::exception& ex) {
822 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
823 }
824 d.data.LIST->push_back(d2);
825 }
826
827 set_attr_value(name, d);
828}
829
830void
831OksConfigObject::set_time(const std::string& name, const std::vector<std::string>& value)
832{
833 OksData d(new OksData::List());
834
835 for (const auto& i : value) {
836 OksData* d2 = new OksData();
838 try {
839 d2->SetValue(i.c_str(), 0);
840 } catch (oks::exception& ex) {
841 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
842 }
843 d.data.LIST->push_back(d2);
844 }
845
846 set_attr_value(name, d);
847}
848
849void
850OksConfigObject::set(const std::string& name, const conffwk::ConfigObject* value, bool skip_non_null_check)
851{
852 OksData d((value != nullptr) ? static_cast<const OksConfigObject*>(value->implementation())->m_obj
853 : (OksObject*)nullptr);
854 set_rel_value(name, d, skip_non_null_check);
855}
856
857void
858OksConfigObject::set(const std::string& name,
859 const std::vector<const conffwk::ConfigObject*>& value,
860 bool skip_non_null_check)
861{
862 OksData d(new OksData::List());
863
864 for (const auto& i : value) {
865 d.data.LIST->push_back(new OksData(static_cast<const OksConfigObject*>(i->implementation())->m_obj));
866 }
867
868 set_rel_value(name, d, skip_non_null_check);
869}
870
871// void OksConfigObject::test_checkout_needs()
872//{
874//}
875
876void
877OksConfigObject::move(const std::string& at)
878{
879 std::lock_guard<std::mutex> scoped_lock(m_mutex);
880
882
883 if (OksFile* new_file_h = m_obj->GetClass()->get_kernel()->find_data_file(at)) {
884 OksFile* old_file_h = m_obj->get_file();
885 if (old_file_h != new_file_h) {
886 try {
887 // static_cast<OksConfiguration *>(m_impl)->test_and_checkout(old_file_h);
888 // static_cast<OksConfiguration *>(m_impl)->test_and_checkout(new_file_h);
889 m_obj->set_file(new_file_h, false);
890 } catch (oks::exception& ex) {
891 throw dunedaq::conffwk::Generic(ERS_HERE, ex.what());
892 }
893 }
894 } else {
895 std::ostringstream text;
896 text << "file \"" << at << "\" is not loaded";
897 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
898 }
899}
900
901void
902OksConfigObject::rename(const std::string& new_id)
903{
904 try {
906
907 // std::set<OksFile *> files;
908 //
909 // files.insert(m_obj->get_file());
910 //
911 // if (OksObject::FList * objs = m_obj->get_all_rels())
912 // {
913 // for (auto & f : *objs)
914 // {
915 // files.insert(f->get_file());
916 // }
917 //
918 // delete objs;
919 // }
920 //
921 // for (auto & f : files)
922 // {
923 // static_cast<OksConfiguration *>(m_impl)->test_and_checkout(f);
924 // }
925
926 m_obj->set_id(new_id);
927 } catch (oks::exception& ex) {
928 std::ostringstream text;
929 text << "cannot rename object " << m_obj << " to new name \'" << new_id << "\' because " << ex.what();
930 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
931 }
932}
933
934void
936{
937 if (OksClass* c = static_cast<OksConfiguration*>(m_impl)->m_kernel->find_class(*m_class_name)) {
938 m_obj = c->get_object(m_id);
939 } else {
940 m_obj = nullptr;
941 }
942
944}
#define ERS_HERE
static std::string mk_error_text(const char *op, const char *what, const std::string &name, const OksObject *o, const char *error)
static std::string mk_get_error_text(const char *what, const std::string &name, const OksObject *o, const char *error=nullptr)
static std::string mk_set_error_text(const char *what, const std::string &name, const OksObject *o, const char *error=nullptr)
dunedaq::conffwk::ObjectState m_state
ConfigObjectImpl(ConfigurationImpl *impl, const std::string &id, dunedaq::conffwk::ObjectState state=dunedaq::conffwk::Valid) noexcept
The constructor stores configuration implementation pointer.
Represents database objects.
const ConfigObjectImpl * implementation() const noexcept
Returns pointer on implementation.
Provides pure virtual interface used by the Configuration class.
OKS attribute class.
Definition attribute.hpp:94
The OKS class.
Definition class.hpp:223
OksDataInfo * get_data_info(const std::string &s) const noexcept
Get OKS data information for attribute or relationship.
Definition class.hpp:825
const std::list< OksAttribute * > * all_attributes() const noexcept
Definition class.hpp:470
OksKernel * get_kernel() const noexcept
Definition class.hpp:348
OksAttribute * find_attribute(const std::string &name) const noexcept
Find attribute (search in this and base classes).
Definition class.cpp:985
Provides interface to the OKS XML schema and data files.
Definition file.hpp:355
const std::string & get_full_file_name() const
Definition file.hpp:528
OksFile * find_data_file(const std::string &s) const
Finds OKS data file.
Definition kernel.cpp:2119
OksObject describes instance of OksClass.
Definition object.hpp:1144
const std::list< OksRCR * > * reverse_composite_rels() const
Return information about composite parents. The method returns list of the OKS object's reverse compo...
Definition object.hpp:1589
OksData * GetRelationshipValue(const std::string &) const
Get value of relationship by name.
Definition object.cpp:1944
OksFile * get_file() const
Definition object.hpp:1306
void SetRelationshipValue(const std::string &name, OksData *data, bool skip_non_null_check=false)
Set value of relationship by name.
Definition object.cpp:2125
void set_file(OksFile *file, bool update_owner=true)
Move object to different file.
Definition object.cpp:1468
FList * get_all_rels(const std::string &name="*") const
Return objects referencing this one via relationship with given name.
Definition object.cpp:3062
std::list< OksObject *, boost::fast_pool_allocator< OksObject * > > FList
Definition object.hpp:1181
const OksClass * GetClass() const
Definition object.hpp:1286
void set_id(const std::string &id)
Set object ID.
Definition object.cpp:1488
void SetAttributeValue(const std::string &name, OksData *data)
Set value of attribute by name.
Definition object.cpp:1930
OksData * GetAttributeValue(const std::string &name) const
Get value of attribute by name.
Definition object.cpp:1852
virtual const char * what() const noexcept
void set_vector(const std::string &name, const std::vector< T > &value)
virtual const std::string contained_in() const
Virtual method to get object's database file name.
virtual void set_date(const std::string &attribute, const std::string &value)
Virtual method to set date attribute value.
void set_value(const std::string &name, const T &value)
virtual void set_enum(const std::string &attribute, const std::string &value)
Virtual method to set enumeration attribute value.
virtual void set(const std::string &name, bool value)
Virtual method to set boolean attribute value.
virtual void move(const std::string &at)
Virtual method to move object to a file.
void set_attr_value(const std::string &name, oks::OksData &value)
virtual void set_class(const std::string &attribute, const std::string &value)
Virtual method to set enumeration attribute value.
void set_rel_value(const std::string &name, oks::OksData &value, bool skip_non_null_check)
void get_value(const std::string &name, T &value)
void get_vector(const std::string &name, std::vector< T > &value)
virtual void set_time(const std::string &attribute, const std::string &value)
Virtual method to set time attribute value.
virtual void referenced_by(std::vector< conffwk::ConfigObject > &value, const std::string &association, bool check_composite_only, unsigned long rlevel, const std::vector< std::string > *rclasses) const
oks::OksData::Type get_type(const std::string &attribute) const
virtual void get(const std::string &name, bool &value)
Virtual method to read boolean attribute value.
virtual void rename(const std::string &new_id)
Virtual method to change object ID.
virtual bool rel(const std::string &name, std::vector< conffwk::ConfigObject > &value)
OksConfigObject(oks::OksObject *obj, conffwk::ConfigurationImpl *impl) noexcept
virtual void reset()
Virtual method to reset the implementation object from unknown state.
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116
The DUNE-DAQ namespace.
msgpack::object obj
CIB Buffer std::string descriptor Message from std::string descriptor CIB process error
Struct OKS data information.
Definition object.hpp:379
Struct OKS data.
Definition object.hpp:510
union dunedaq::oks::OksData::Data data
void SetValue(const char *s, const OksAttribute *a)
enum dunedaq::oks::OksData::Type type
std::list< OksData *, boost::fast_pool_allocator< OksData * > > List
Definition object.hpp:515
const OksClass * CLASS
Definition object.hpp:555
const std::string * ENUMERATION
Definition object.hpp:571