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
46
48OksConfigObject::get_type(const std::string& name) const
49{
50 try
51 {
52 return m_obj->GetAttributeValue(name)->type;
53 }
54 catch (oks::exception& ex)
55 {
56 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
57 }
58}
59
60// helper function to extract value out of OKS database
61template<class T>
62 void
63 OksConfigObject::get_value(const std::string& name, T& value)
64 {
65 std::lock_guard<std::mutex> scoped_lock(m_mutex);
66
67 try
68 {
70 OksData * data(m_obj->GetAttributeValue(name));
71 value = *reinterpret_cast<T*>(&data->data); // really ugly stuff here, but should come out right
72 }
73 catch (oks::exception& ex)
74 {
75 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
76 }
77 }
78
79
80// helper function to extract vector of values out of OKS database
81template<class T>
82 void
83 OksConfigObject::get_vector(const std::string& name, std::vector<T>& value)
84 {
85 OksData * data = 0;
86
87 std::lock_guard<std::mutex> scoped_lock(m_mutex);
88
89 try
90 {
92 data = m_obj->GetAttributeValue(name);
93 }
94 catch (oks::exception& ex)
95 {
96 throw dunedaq::conffwk::Generic( ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
97 }
98
99 if (data->type != OksData::list_type)
100 {
101 std::ostringstream text;
102 text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
103 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
104 }
105
106 value.clear();
107 for (const auto& it : *data->data.LIST)
108 {
109 value.push_back(*reinterpret_cast<T*>(&it->data));
110 }
111 }
112
113
119
123
124const std::string
126{
127 std::lock_guard<std::mutex> scoped_lock(m_mutex);
129 return m_obj->get_file()->get_full_file_name();
130}
131
132void
133OksConfigObject::get(const std::string& name, bool& value)
134{
135 get_value(name, value);
136}
137
138void
139OksConfigObject::get(const std::string& name, uint8_t& value)
140{
141 get_value(name, value);
142}
143
144void
145OksConfigObject::get(const std::string& name, int8_t& value)
146{
147 get_value(name, value);
148}
149
150void
151OksConfigObject::get(const std::string& name, uint16_t& value)
152{
153 get_value(name, value);
154}
155
156void
157OksConfigObject::get(const std::string& name, int16_t& value)
158{
159 get_value(name, value);
160}
161
162void
163OksConfigObject::get(const std::string& name, uint32_t& value)
164{
165 get_value(name, value);
166}
167
168void
169OksConfigObject::get(const std::string& name, int32_t& value)
170{
171 get_value(name, value);
172}
173
174void
175OksConfigObject::get(const std::string& name, uint64_t& value)
176{
177 get_value(name, value);
178}
179
180void
181OksConfigObject::get(const std::string& name, int64_t& value)
182{
183 get_value(name, value);
184}
185
186void
187OksConfigObject::get(const std::string& name, float& value)
188{
189 get_value(name, value);
190}
191
192void
193OksConfigObject::get(const std::string& name, double& value)
194{
195 get_value(name, value);
196}
197
198void
199OksConfigObject::get(const std::string& name, std::string& value)
200{
201 OksData * data = 0;
202
203 std::lock_guard<std::mutex> scoped_lock(m_mutex);
204
205 try
206 {
208 data = m_obj->GetAttributeValue(name);
209 }
210 catch (oks::exception& ex)
211 {
212 throw dunedaq::conffwk::Generic( ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
213 }
214
215 if ((data->type == OksData::string_type) || (data->type == OksData::enum_type))
216 {
217 value = *data->data.STRING;
218 return;
219 }
220 else if (data->type == OksData::date_type || data->type == OksData::time_type)
221 {
222 value = data->str();
223 return;
224 }
225 else if (data->type == OksData::class_type)
226 {
227 value = data->data.CLASS->get_name();
228 return;
229 }
230 else
231 {
232 std::ostringstream text;
233 text << "read wrong attribute type instead of expected \'string\' for attribute \"" << name << "\" of object " << m_obj;
234 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
235 }
236}
237
238void
240{
241 OksData * data = 0;
242
243 std::lock_guard<std::mutex> scoped_lock(m_mutex);
244
245 try
246 {
248 data = m_obj->GetRelationshipValue(name);
249 }
250 catch (oks::exception& ex)
251 {
252 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
253 }
254
255 if (data->type != OksData::object_type)
256 {
257 if (data->type == OksData::uid_type || data->type == OksData::uid2_type)
258 {
259 std::ostringstream text;
260 text << "referenced object " << *data << " is not loaded";
261 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj, text.str().c_str()).c_str());
262 }
263
264 std::ostringstream text;
265 text << "bad value of relationship \"" << name << "\" of object " << m_obj << ": ";
266
267 if(data->type == OksData::list_type)
268 {
269 text << "the relationship is multi-value";
270 }
271 else
272 {
273 text << "non-object type was read";
274 }
275 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
276 }
277
278 if (data->data.OBJECT != nullptr)
279 {
280 value = static_cast<OksConfiguration *>(m_impl)->new_object(data->data.OBJECT);
281 }
282 else
283 {
284 value = nullptr;
285 }
286}
287
288void
289OksConfigObject::get(const std::string& name, std::vector<bool>& value)
290{
291 get_vector(name, value);
292}
293
294void
295OksConfigObject::get(const std::string& name, std::vector<uint8_t>& value)
296{
297 get_vector(name, value);
298}
299
300void
301OksConfigObject::get(const std::string& name, std::vector<int8_t>& value)
302{
303 get_vector(name, value);
304}
305
306void
307OksConfigObject::get(const std::string& name, std::vector<uint16_t>& value)
308{
309 get_vector(name, value);
310}
311
312void
313OksConfigObject::get(const std::string& name, std::vector<int16_t>& value)
314{
315 get_vector(name, value);
316}
317
318void
319OksConfigObject::get(const std::string& name, std::vector<uint32_t>& value)
320{
321 get_vector(name, value);
322}
323
324void
325OksConfigObject::get(const std::string& name, std::vector<int32_t>& value)
326{
327 get_vector(name, value);
328}
329
330void
331OksConfigObject::get(const std::string& name, std::vector<uint64_t>& value)
332{
333 get_vector(name, value);
334}
335
336void
337OksConfigObject::get(const std::string& name, std::vector<int64_t>& value)
338{
339 get_vector(name, value);
340}
341
342void
343OksConfigObject::get(const std::string& name, std::vector<float>& value)
344{
345 get_vector(name, value);
346}
347
348void
349OksConfigObject::get(const std::string& name, std::vector<double>& value)
350{
351 get_vector(name, value);
352}
353
354void
355OksConfigObject::get(const std::string& name, std::vector<std::string>& value)
356{
357 OksData * data = 0;
358
359 std::lock_guard<std::mutex> scoped_lock(m_mutex);
360
361 try
362 {
364 data = m_obj->GetAttributeValue(name);
365 }
366 catch (oks::exception& ex)
367 {
368 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("attribute", name, m_obj).c_str(), ex);
369 }
370
371 if (data->type != OksData::list_type)
372 {
373 std::ostringstream text;
374 text << "attribute \"" << name << "\" of object " << m_obj << " is not of a multi-value";
375 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
376 }
377
378 value.clear();
379
380 for (const auto & it : *data->data.LIST)
381 {
382 if ((it->type == OksData::string_type) || (it->type == OksData::enum_type))
383 {
384 value.emplace_back(*it->data.STRING);
385 }
386 else if (it->type == OksData::class_type)
387 {
388 value.emplace_back(it->data.CLASS->get_name());
389 }
390 else if (it->type == OksData::date_type || it->type == OksData::time_type)
391 {
392 value.emplace_back(it->str());
393 }
394 else
395 {
396 std::ostringstream text;
397 text << "wrong type of attribute \"" << name << "\" of object " << m_obj << " (instead of expected string)";
398 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str() );
399 }
400 }
401}
402
403
404void
405OksConfigObject::get(const std::string& name, std::vector<dunedaq::conffwk::ConfigObject>& value)
406{
407 OksData * data = 0;
408
409 std::lock_guard<std::mutex> scoped_lock(m_mutex);
410
411 try
412 {
414 data = m_obj->GetRelationshipValue(name);
415 }
416 catch (oks::exception& ex)
417 {
418 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
419 }
420
421 if (data->type != OksData::list_type)
422 {
423 std::ostringstream text;
424 text << "the value of relationship \"" << name << "\" of object " << m_obj << " is not multi-value";
425 throw dunedaq::conffwk::Generic( ERS_HERE, text.str().c_str());
426 }
427
428 value.clear();
429
430 for (const auto& it : *data->data.LIST)
431 {
432 if (it->type != OksData::object_type)
433 {
434 TLOG_DEBUG(1) << "object " << *it << " is not loaded (relationship \'" << name << "\' of object " << m_obj << ')' ;
435 }
436 else if (!it->data.OBJECT)
437 {
438 TLOG_DEBUG(1) << "skip (null) object in relationship \'" << name << "\' of object " << m_obj ;
439 }
440 else
441 {
442 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(it->data.OBJECT)));
443 }
444 }
445}
446
447bool
448OksConfigObject::rel(const std::string& name, std::vector<conffwk::ConfigObject>& value)
449{
450 std::lock_guard<std::mutex> scoped_lock(m_mutex);
451
452 try
453 {
455
456 if (OksDataInfo * di = m_obj->GetClass()->get_data_info(name))
457 {
458 if (di->relationship)
459 {
460 OksData * data = m_obj->GetRelationshipValue(di);
461
462 if (data->type == OksData::object_type)
463 {
464 if (data->data.OBJECT != nullptr)
465 {
466 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(data->data.OBJECT)));
467 }
468 }
469 else if (data->type == OksData::list_type)
470 {
471 for (const auto& it : *data->data.LIST)
472 {
473 if (it->type == OksData::object_type)
474 {
475 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(it->data.OBJECT)));
476 }
477 }
478 }
479
480 return true;
481 }
482 }
483
484 return false;
485 }
486 catch (oks::exception& ex)
487 {
488 throw dunedaq::conffwk::Generic(ERS_HERE, mk_get_error_text("relationship", name, m_obj).c_str(), ex);
489 }
490}
491
492void
493OksConfigObject::referenced_by(std::vector<conffwk::ConfigObject>& value, const std::string& rname, bool check_composite_only, unsigned long /* rlevel */, const std::vector<std::string> * /* rclasses */) const
494{
495 value.clear();
496
497 std::lock_guard<std::mutex> scoped_lock(m_mutex);
499
500 if (check_composite_only)
501 {
502 bool any_name = (rname == "*");
503
504 if (const std::list<OksRCR *> * rcr = m_obj->reverse_composite_rels())
505 {
506 for (const auto& i : *rcr)
507 {
508 if (any_name || rname == i->relationship->get_name())
509 {
510 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(i->obj)));
511 }
512 }
513 }
514 }
515 else
516 {
517 if (OksObject::FList * objs = m_obj->get_all_rels(rname))
518 {
519 for (const auto& i : *objs)
520 {
521 value.push_back(conffwk::ConfigObject(static_cast<OksConfiguration *>(m_impl)->new_object(i)));
522 }
523
524 delete objs;
525 }
526 }
527}
528
530 //
531 // set functions
532 //
534
535void
536OksConfigObject::set_attr_value(const std::string& name, OksData & data)
537{
538 std::lock_guard<std::mutex> scoped_lock(m_mutex);
539
540 try
541 {
543 //test_checkout_needs();
544 m_obj->SetAttributeValue(name, &data);
545 }
546 catch (dunedaq::conffwk::Generic& ex)
547 {
548 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
549 }
550 catch(oks::exception& ex)
551 {
552 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
553 }
554}
555
556void
557OksConfigObject::set_rel_value(const std::string& name, OksData & data, bool skip_non_null_check)
558{
559 std::lock_guard<std::mutex> scoped_lock(m_mutex);
560
561 try
562 {
564 //test_checkout_needs();
565 m_obj->SetRelationshipValue(name, &data, skip_non_null_check);
566 }
567 catch (dunedaq::conffwk::Generic& ex)
568 {
569 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex );
570 }
571 catch(oks::exception& ex)
572 {
573 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("relationship", name, m_obj).c_str(), ex);
574 }
575}
576
577
578template<class T>
579 void
580 OksConfigObject::set_value(const std::string& name, const T& value)
581 {
582 OksData d(value);
583 set_attr_value(name, d);
584 }
585
586template<class T>
587 void
588 OksConfigObject::set_vector(const std::string& name, const std::vector<T>& value)
589 {
590 OksData d(new OksData::List());
591
592 for (const auto& i : value)
593 {
594 d.data.LIST->push_back(new OksData(i));
595 }
596
597 set_attr_value(name, d);
598 }
599
600
601void OksConfigObject::set(const std::string& name, bool value)
602{
603 set_value(name, value);
604}
605
606void OksConfigObject::set(const std::string& name, uint8_t value)
607{
608 set_value(name, value);
609}
610
611void OksConfigObject::set(const std::string& name, int8_t value)
612{
613 set_value(name, value);
614}
615
616void OksConfigObject::set(const std::string& name, uint16_t value)
617{
618 set_value(name, value);
619}
620
621void OksConfigObject::set(const std::string& name, int16_t value)
622{
623 set_value(name, value);
624}
625
626void OksConfigObject::set(const std::string& name, uint32_t value)
627{
628 set_value(name, value);
629}
630
631void OksConfigObject::set(const std::string& name, int32_t value)
632{
633 set_value(name, value);
634}
635
636void OksConfigObject::set(const std::string& name, uint64_t value)
637{
638 set_value(name, value);
639}
640
641void OksConfigObject::set(const std::string& name, int64_t value)
642{
643 set_value(name, value);
644}
645
646void OksConfigObject::set(const std::string& name, float value)
647{
648 set_value(name, value);
649}
650
651void OksConfigObject::set(const std::string& name, double value)
652{
653 set_value(name, value);
654}
655
656void OksConfigObject::set(const std::string& name, const std::string& value)
657{
658 set_value(name, value);
659}
660
661void
662OksConfigObject::set_enum(const std::string& name, const std::string& value)
663{
664 OksData d;
665
666 {
667 std::lock_guard<std::mutex> scoped_lock(m_mutex);
669
670 if (OksAttribute * a = m_obj->GetClass()->find_attribute(name))
671 {
672 try
673 {
674 d.data.ENUMERATION = a->get_enum_value(value);
675 d.type = OksData::enum_type;
676 }
677 catch (std::exception& ex)
678 {
679 throw(dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, ex.what()).c_str()) );
680 }
681 }
682 else
683 {
684 throw ( dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str()) );
685 }
686 }
687
688 set_attr_value(name, d);
689}
690
691void OksConfigObject::set_class(const std::string& name, const std::string& value)
692{
693 OksData d;
694
695 d.data.CLASS = nullptr;
696 d.type = OksData::class_type;
697
698 // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
699 {
700 std::lock_guard<std::mutex> scoped_lock(m_mutex);
702
703 const std::list<OksAttribute *> * attrs = m_obj->GetClass()->all_attributes();
704
705 if (!attrs || attrs->empty())
706 {
707 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
708 }
709
710 try
711 {
712 d.SetValue(value.c_str(), attrs->front());
713 }
714 catch (oks::exception & ex)
715 {
716 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
717 }
718 }
719
720 set_attr_value(name, d);
721}
722
723void
724OksConfigObject::set_date(const std::string& name, const std::string& value)
725{
726 OksData d;
727 d.type = OksData::date_type;
728
729 try
730 {
731 d.SetValue(value.c_str(), nullptr);
732 }
733 catch (oks::exception& ex)
734 {
735 throw dunedaq::conffwk::Generic(ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
736 }
737
738 set_attr_value(name, d);
739}
740
741void
742OksConfigObject::set_time(const std::string& name, const std::string& value)
743{
744 OksData d;
745 d.type = OksData::time_type;
746
747 try
748 {
749 d.SetValue(value.c_str(), nullptr);
750 }
751 catch (oks::exception& ex)
752 {
753 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
754 }
755
756 set_attr_value(name, d);
757}
758
759
760void
761OksConfigObject::set(const std::string& name, const std::vector<bool>& value)
762{
763 set_vector(name, value);
764}
765
766void
767OksConfigObject::set(const std::string& name, const std::vector<uint8_t>& value)
768{
769 set_vector(name, value);
770}
771
772void
773OksConfigObject::set(const std::string& name, const std::vector<int8_t>& value)
774{
775 set_vector(name, value);
776}
777
778void
779OksConfigObject::set(const std::string& name, const std::vector<uint16_t>& value)
780{
781 set_vector(name, value);
782}
783
784void
785OksConfigObject::set(const std::string& name, const std::vector<int16_t>& value)
786{
787 set_vector(name, value);
788}
789
790void
791OksConfigObject::set(const std::string& name, const std::vector<uint32_t>& value)
792{
793 set_vector(name, value);
794}
795
796void
797OksConfigObject::set(const std::string& name, const std::vector<int32_t>& value)
798{
799 set_vector(name, value);
800}
801
802void
803OksConfigObject::set(const std::string& name, const std::vector<uint64_t>& value)
804{
805 set_vector(name, value);
806}
807
808void
809OksConfigObject::set(const std::string& name, const std::vector<int64_t>& value)
810{
811 set_vector(name, value);
812}
813
814void
815OksConfigObject::set(const std::string& name, const std::vector<float>& value)
816{
817 set_vector(name, value);
818}
819
820void
821OksConfigObject::set(const std::string& name, const std::vector<double>& value)
822{
823 set_vector(name, value);
824}
825
826void
827OksConfigObject::set(const std::string& name, const std::vector<std::string>& value)
828{
829 set_vector(name, value);
830}
831
832void
833OksConfigObject::set_enum(const std::string& name, const std::vector<std::string>& value)
834{
835 OksData d(new OksData::List());
836
837 {
838 std::lock_guard<std::mutex> scoped_lock(m_mutex);
840
841 if (OksAttribute * a = m_obj->GetClass()->find_attribute(name))
842 {
843 for (const auto& i : value)
844 {
845 OksData * d2 = new OksData();
846 try
847 {
848 d2->data.ENUMERATION = a->get_enum_value(i); // new OksString(i);
850 d.data.LIST->push_back(d2);
851 }
852 catch (std::exception& ex)
853 {
854 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
855 }
856
857 }
858 }
859 else
860 {
861 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
862 }
863 }
864
865 set_attr_value(name, d);
866}
867
868void
869OksConfigObject::set_class(const std::string& name, const std::vector<std::string>& value)
870{
871 OksData d(new OksData::List());
872
873 // try to find any attribute in this class; throw exception "no such attribute", if the class has no attributes at all
874
875 {
876 std::lock_guard<std::mutex> scoped_lock(m_mutex);
878
879 const std::list<OksAttribute *> * attrs = m_obj->GetClass()->all_attributes();
880
881 if (!attrs || attrs->empty())
882 {
883 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj, "no such attribute").c_str());
884 }
885
886 for (const auto& i : value)
887 {
888 OksData * d2 = new OksData();
889 d2->data.CLASS = 0;
891
892 try
893 {
894 d2->SetValue(i.c_str(), attrs->front());
895 }
896 catch (oks::exception & ex)
897 {
898 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
899 }
900
901 d.data.LIST->push_back(d2);
902 }
903 }
904
905 set_attr_value(name, d);
906}
907
908void
909OksConfigObject::set_date(const std::string& name, const std::vector<std::string>& value)
910{
911 OksData d(new OksData::List());
912
913 for (const auto& i : value)
914 {
915 OksData * d2 = new OksData();
917 try
918 {
919 d2->SetValue(i.c_str(), nullptr);
920 }
921 catch (oks::exception& ex)
922 {
923 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
924 }
925 d.data.LIST->push_back(d2);
926 }
927
928 set_attr_value(name, d);
929}
930
931void
932OksConfigObject::set_time(const std::string& name, const std::vector<std::string>& value)
933{
934 OksData d(new OksData::List());
935
936 for (const auto& i : value)
937 {
938 OksData * d2 = new OksData();
940 try
941 {
942 d2->SetValue(i.c_str(), 0);
943 }
944 catch (oks::exception& ex)
945 {
946 throw dunedaq::conffwk::Generic( ERS_HERE, mk_set_error_text("attribute", name, m_obj).c_str(), ex);
947 }
948 d.data.LIST->push_back(d2);
949 }
950
951 set_attr_value(name, d);
952}
953
954void
955OksConfigObject::set(const std::string& name, const conffwk::ConfigObject * value, bool skip_non_null_check)
956{
957 OksData d((value != nullptr) ? static_cast<const OksConfigObject*>(value->implementation())->m_obj : (OksObject *) nullptr);
958 set_rel_value(name, d, skip_non_null_check);
959}
960
961void
962OksConfigObject::set(const std::string& name, const std::vector<const conffwk::ConfigObject*>& value, bool skip_non_null_check)
963{
964 OksData d(new OksData::List());
965
966 for (const auto& i : value)
967 {
968 d.data.LIST->push_back(new OksData(static_cast<const OksConfigObject*>(i->implementation())->m_obj));
969 }
970
971 set_rel_value(name, d, skip_non_null_check);
972}
973
974//void OksConfigObject::test_checkout_needs()
975//{
977//}
978
979void
980OksConfigObject::move(const std::string& at)
981{
982 std::lock_guard<std::mutex> scoped_lock(m_mutex);
983
985
986 if (OksFile * new_file_h = m_obj->GetClass()->get_kernel()->find_data_file(at))
987 {
988 OksFile * old_file_h = m_obj->get_file();
989 if (old_file_h != new_file_h)
990 {
991 try
992 {
993// static_cast<OksConfiguration *>(m_impl)->test_and_checkout(old_file_h);
994// static_cast<OksConfiguration *>(m_impl)->test_and_checkout(new_file_h);
995 m_obj->set_file(new_file_h, false);
996 }
997 catch (oks::exception& ex)
998 {
999 throw dunedaq::conffwk::Generic(ERS_HERE, ex.what());
1000 }
1001 }
1002 }
1003 else
1004 {
1005 std::ostringstream text;
1006 text << "file \"" << at << "\" is not loaded";
1007 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
1008 }
1009}
1010
1011
1012void
1013OksConfigObject::rename(const std::string& new_id)
1014{
1015 try
1016 {
1018
1019// std::set<OksFile *> files;
1020//
1021// files.insert(m_obj->get_file());
1022//
1023// if (OksObject::FList * objs = m_obj->get_all_rels())
1024// {
1025// for (auto & f : *objs)
1026// {
1027// files.insert(f->get_file());
1028// }
1029//
1030// delete objs;
1031// }
1032//
1033// for (auto & f : files)
1034// {
1035// static_cast<OksConfiguration *>(m_impl)->test_and_checkout(f);
1036// }
1037
1038 m_obj->set_id(new_id);
1039 }
1040 catch (oks::exception& ex)
1041 {
1042 std::ostringstream text;
1043 text << "cannot rename object " << m_obj << " to new name \'" << new_id << "\' because " << ex.what();
1044 throw dunedaq::conffwk::Generic(ERS_HERE, text.str().c_str());
1045 }
1046}
1047
1048void
1050{
1051 if (OksClass * c = static_cast<OksConfiguration *>(m_impl)->m_kernel->find_class(*m_class_name))
1052 {
1053 m_obj = c->get_object(m_id);
1054 }
1055 else
1056 {
1057 m_obj = nullptr;
1058 }
1059
1061}
#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.
The OKS class.
Definition class.hpp:205
Provides interface to the OKS XML schema and data files.
Definition file.hpp:345
OksObject describes instance of OksClass.
Definition object.hpp:841
OksData * GetRelationshipValue(const std::string &) const
Get value of relationship by name.
Definition object.cpp:2009
std::list< OksObject *, boost::fast_pool_allocator< OksObject * > > FList
Definition object.hpp:882
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:112
Including Qt Headers.
Definition module.cpp:16
msgpack::object obj
Struct OKS data information.
Definition object.hpp:347
the structure to pass common parameters to various read() methods of OksData and OksObject class
Definition object.hpp:454
union dunedaq::oks::OksData::Data data
std::list< OksData *, boost::fast_pool_allocator< OksData * > > List
Definition object.hpp:460
void SetValue(const char *s, const OksAttribute *a)
enum dunedaq::oks::OksData::Type type
Factory couldn t std::string alg_name Invalid configuration error
Definition Issues.hpp:34
const OksClass * CLASS
Definition object.hpp:498
const std::string * ENUMERATION
Definition object.hpp:512