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