DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
Configuration.hpp
Go to the documentation of this file.
1//
2// DUNE DAQ modification notice:
3// This file has been modified from the original ATLAS config source for the DUNE DAQ project.
4// Fork baseline commit: 67a24e731 (2022-10-27).
5// Renamed since fork: yes (from config/Configuration.h to include/conffwk/Configuration.hpp).
6//
7
15
16#ifndef CONFFWK_CONFIGURATION_H_
17#define CONFFWK_CONFIGURATION_H_
18
19#include <string.h>
20
21#include <atomic>
22#include <typeinfo>
23#include <string>
24#include <vector>
25#include <list>
26#include <set>
27
28#include <mutex>
29
30#include <boost/property_tree/ptree.hpp>
31
32#include "ers/ers.hpp"
33
37#include "conffwk/Errors.hpp"
40
41#include "conffwk/map.hpp"
42#include "conffwk/set.hpp"
43
44namespace dunedaq {
45namespace conffwk {
46
47class ConfigAction;
50class DalObject;
51class DalRegistry;
52
53
54struct class_t;
55
56class Configuration;
57
66
67// class CacheBase
68// {
69
70// friend class Configuration;
71
72// protected:
73
74// CacheBase(const DalFactoryFunctions& f) :
75// m_functions(f)
76// {
77// ;
78// }
79
80// /** Method for configuration profiling */
81
82// void
83// increment_gets(Configuration& db) noexcept;
84
85// virtual
86// ~CacheBase() noexcept
87// {
88// ;
89// }
90
91// protected:
92
93// const DalFactoryFunctions& m_functions;
94
95// private:
96
97// conffwk::map<DalObject*> m_cache;
98// conffwk::multimap<DalObject*> m_t_cache;
99// };
100
101
227
229
230 friend class DalObject;
231 friend class ConfigObject;
232 friend class ConfigurationImpl;
233 // friend class CacheBase;
234 friend class DalObject;
235 friend class DalRegistry;
236
237 public:
238
239
253
254 Configuration(const std::string& spec);
255
257
258
260
261 const std::string& get_impl_spec() const noexcept {return m_impl_spec;}
262
263
265
266 const std::string& get_impl_name() const noexcept {return m_impl_name;}
267
268
270
271 const std::string& get_impl_param() const noexcept {return m_impl_param;}
272
273
280
281 ~Configuration() noexcept;
282
283
284 public:
285
293
294 typedef void (*notify)(
295 const std::vector<ConfigurationChange *> & changed_classes,
296 void * parameter
297 );
298
305
306 typedef void (*pre_notify)(
307 void * parameter
308 );
309
310
311 private: // Types to be used in public API below
312
313 // structure keeps information about callback subscriptions
314
320
325
326
327 public:
328
336
338
339
357
358 CallbackId subscribe(const ConfigurationSubscriptionCriteria& criteria, notify user_cb, void * user_param = nullptr);
359
360
380
381 CallbackId subscribe(pre_notify user_cb, void * user_param = nullptr);
382
383
393
394 void unsubscribe(CallbackId cb_handler = 0);
395
396
397
406
407 template<class T> bool is_valid(const T * object) noexcept;
408
409
410 private:
411
413 void reset_subscription();
414
415
416 public:
417
428
429 template<class T> void update(const std::vector<std::string>& modified,
430 const std::vector<std::string>& removed,
431 const std::vector<std::string>& created) noexcept;
432
433
440
441 void update_cache(std::vector<ConfigurationChange *>& changes) noexcept;
442
443
450
451 static void system_cb(std::vector<ConfigurationChange *>&, Configuration *) noexcept;
452
453
460
461 static void system_pre_cb(Configuration *) noexcept;
462
463
469
470 template<class T> void _reset_objects() noexcept;
471
472
473 // /**
474 // * \brief Mark object of given template class as unread (multi-thread unsafe).
475 // *
476 // * Is used by automatically generated data access libraries code after reading parameters for substitution,
477 // * since cache contains objects with non-substituted attributes. Should not be explicitly used by user.
478 // *
479 // * The method is used by the unread_all_objects() method.
480 // * \param cache_ptr pointer to the cache of template object of given template class (has to be downcasted)
481 // */
482
483 // template<class T> static void _unread_objects(CacheBase * cache_ptr) noexcept;
484
485
486 // /**
487 // * \brief Rename object of given template class (multi-thread unsafe).
488 // *
489 // * Is used by automatically generated data access libraries when an object has been renamed by user's code.
490 // * Should not be explicitly used by user.
491 // *
492 // * The method is used by the unread_all_objects() method.
493 // * \param cache_ptr pointer to the cache of template object of given template class (has to be downcasted)
494 // * \param old_id old object ID
495 // * \param new_id new object ID
496 // */
497
498 // template<class T> static void _rename_object(CacheBase* cache_ptr, const std::string& old_id, const std::string& new_id) noexcept;
499
500
501 // /**
502 // * \brief Update state of all objects in cache after abort / commit operations.
503 // *
504 // * It is used by automatically generated data access libraries.
505 // */
506
507 // void _reset_all_objects() noexcept;
508
509
521
522 void
523 unread_all_objects(bool unread_implementation_objs = false) noexcept;
524
525
532
533 void
535 {
536 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
538 }
539
540
548
549 void
551 {
552 std::lock_guard<std::mutex> scoped_lock(m_impl_mutex);
554 }
555
556
557 private:
558
559 static void
560 update_impl_objects(conffwk::pmap<conffwk::map<ConfigObjectImpl *> * >& cache, ConfigurationChange& change, const std::string * class_name);
561
562 void
563 _unread_template_objects() noexcept;
564
565 void
567
568
569 public:
570
584
585 void create(const std::string& at, const std::string& class_name, const std::string& id, ConfigObject& object);
586
587
601
602 void create(const ConfigObject& at, const std::string& class_name, const std::string& id, ConfigObject& object);
603
604
618
619 template<class T> const T * create(const std::string& at, const std::string& id, bool init_object = false);
620
621
635
636 template<class T> const T * create(const DalObject& at, const std::string& id, bool init_object = false);
637
638
648
649 void destroy_obj(ConfigObject& object);
650
651
661
662 template<class T> void destroy(T& obj);
663
664
665 public:
666
680
681 bool test_object(const std::string& class_name, const std::string& id, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0);
682
683
697
698 void get(const std::string& class_name, const std::string& id, ConfigObject& object, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0);
699
700
714
715 void get(const std::string& class_name, std::vector<ConfigObject>& objects, const std::string& query = "", unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0);
716
717
732
733 void get(const ConfigObject& obj_from, const std::string& query, std::vector<ConfigObject>& objects, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0);
734
735
751
752 template<class T>
753 const T *
754 get(const std::string& id, bool init_children = false, bool init = true, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0)
755 {
756 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
757 return _get<T>(id, init_children, init, rlevel, rclasses);
758 }
759
760
761
775
776 template<class T>
777 const T *
778 get(ConfigObject& obj, bool init_children = false, bool init = true)
779 {
780 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
781 return _get<T>(obj, init_children, init);
782 }
783
784
800
801 template<class T>
802 void
803 get(std::vector<const T*>& objects, bool init_children = false, bool init = true, const std::string& query = "", unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0)
804 {
805 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
806 _get<T>(objects, init_children, init, query, rlevel, rclasses);
807 }
808
821
822 template<class T>
823 const T *
824 get(ConfigObject& obj, const std::string& id)
825 {
826 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
827 return _get<T>(obj, id);
828 }
829
830
842
843 template<class T>
844 const T *
845 find(const std::string& id)
846 {
847 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
848 return _find<T>(id);
849 }
850
851
867
868 template<class T> const T * ref(ConfigObject& obj, const std::string& name, bool init = false) {
869 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
870 return _ref<T>(obj, name, init);
871 }
872
873
874
887
888 template<class T> void ref(ConfigObject& obj, const std::string& name, std::vector<const T*>& objects, bool init = false) {
889 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
890 _ref<T>(obj, name, objects, init);
891 }
892
893
894
914
915 template<class T, class V> void referenced_by(const T& obj, std::vector<const V*>& objects, const std::string& relationship_name = "*", bool check_composite_only = true, bool init = false, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = nullptr);
916
917
943
944 std::vector<const DalObject*>
945 referenced_by(const DalObject& obj, const std::string& relationship_name = "*", bool check_composite_only = true, bool upcast_unregistered = true, bool init = false, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = nullptr);
946
947
956
957 template<class TARGET, class SOURCE> const TARGET *cast(const SOURCE *s) noexcept {
958 return s->template cast<TARGET>();
959 }
960
961
962 private:
963
965 void _get(const std::string& class_name, const std::string& id, ConfigObject& object, unsigned long rlevel, const std::vector<std::string> * rclasses);
966
968 template<class T> const T * _get(const std::string& id, bool init_children = false, bool init = true, unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0);
969
971 template<class T> const T * _get(ConfigObject& obj, bool init_children = false, bool init = true);
972
973 // /// \throw dunedaq::conffwk::Generic
974 // template<class T> const T * _get(ConfigObject& obj, const std::string& id);
975
977 template<class T> void _get(std::vector<const T*>& objects, bool init_children = false, bool init = true, const std::string& query = "", unsigned long rlevel = 0, const std::vector<std::string> * rclasses = 0);
978
980 template<class T> DalObject * _make_instance(ConfigObject& obj, const std::string& uid)
981 {
982 // note upcast since the _get() returns pointer to T
983 return const_cast<T*>(_get<T>(obj, uid));
984 }
985
986 // std::vector<const DalObject*> make_dal_objects(std::vector<ConfigObject>& objs, bool upcast_unregistered);
987
988 // const DalObject* make_dal_object(ConfigObject& obj, const std::string& uid, const std::string& class_name);
989
990
991 // should be made private
992
993 public:
994
995 template<class T>
996 void
997 downcast_dal_objects(const std::vector<const T *>& objs,
998 bool /*upcast_unregistered*/, std::vector<const DalObject*>& result)
999 {
1000 for (auto& i : objs)
1001 result.push_back(i);
1002 }
1003
1004 template<class T>
1005 void
1006 downcast_dal_object(const T * obj, bool /*upcast_unregistered*/, std::vector<const DalObject*>& result)
1007 {
1008 if(obj)
1009 result.push_back(obj);
1010 }
1011
1012
1017
1018 template<class T> const T * _find(const std::string& id);
1019
1020
1026
1027 template<class T> const T * _ref(ConfigObject& obj, const std::string& name, bool read_children);
1028
1029
1035
1036 template<class T> void _ref(ConfigObject& obj, const std::string& name, std::vector<const T*>& results, bool read_children);
1037
1038
1047
1048 bool try_cast(const std::string& target, const std::string& source) noexcept;
1049
1050 bool try_cast(const std::string* target, const std::string* source) noexcept;
1051
1052 bool is_superclass_of(const std::string& target, const std::string& source) noexcept;
1053
1054 bool is_superclass_of(const std::string* target, const std::string* source) noexcept;
1055
1056 private:
1057
1059
1060 static std::string mk_ref_ex_text(const char * what, const std::string& cname, const std::string& rname, const ConfigObject& obj) noexcept;
1061
1062
1064
1065 static std::string mk_ref_by_ex_text(const std::string& cname, const std::string& rname, const ConfigObject& obj) noexcept;
1066
1067
1068 // database manipulations
1069
1070 public:
1071
1079
1080 bool loaded() const noexcept;
1081
1082
1090
1091 void load(const std::string& db_name);
1092
1093
1104
1105 void unload();
1106
1107
1119
1120 void create(const std::string& db_name, const std::list<std::string>& includes);
1121
1122
1134
1135 bool is_writable(const std::string& db_name) const;
1136
1137
1148
1149 void add_include(const std::string& db_name, const std::string& include);
1150
1151
1162
1163 void remove_include(const std::string& db_name, const std::string& include);
1164
1165
1176
1177 void get_includes(const std::string& db_name, std::list<std::string>& includes) const;
1178
1179
1189
1190 void get_updated_dbs(std::list<std::string>& dbs) const;
1191
1192
1203
1204 void set_commit_credentials(const std::string& user, const std::string& password);
1205
1206
1216
1217 void commit(const std::string& log_message = "");
1218
1219
1227
1228 void abort();
1229
1230
1238
1239 void prefetch_all_data();
1240
1241
1242 // access versions
1243
1244 public:
1245
1251
1252 std::vector<dunedaq::conffwk::Version>
1253 get_changes();
1254
1255
1270
1271 std::vector<dunedaq::conffwk::Version>
1272 get_versions(const std::string& since, const std::string& until, dunedaq::conffwk::Version::QueryType type = dunedaq::conffwk::Version::query_by_date, bool skip_irrelevant = true);
1273
1274
1275
1276 // access to schema description
1277
1278 public:
1279
1289
1290 const dunedaq::conffwk::class_t& get_class_info(const std::string& class_name, bool direct_only = false);
1291
1292
1293 private:
1294
1295 const dunedaq::conffwk::class_t& _get_class_info(const std::string& class_name, bool direct_only = false);
1296
1297 // cache, storing descriptions of schema
1298
1301
1302 public:
1303
1313
1314 void
1315 export_schema(boost::property_tree::ptree& tree, const std::string& classes = "", bool direct_only = false);
1316
1317
1329
1330 void
1331 export_data(boost::property_tree::ptree& tree, const std::string& classes = "", const std::string& objects = "", const std::string& files = "", const std::string& empty_array_item = "");
1332
1333
1334 // user-defined converters
1335
1336 public:
1337
1339
1341
1342 public:
1343
1345
1346 };
1347
1348
1356
1357 template<class T> class AttributeConverter : public AttributeConverterBase {
1358
1359 public:
1360
1374
1375 virtual void convert(T& value, const Configuration& conf, const ConfigObject& obj, const std::string& attr_name) = 0;
1376
1377 };
1378
1379
1392
1393 template<class T> void register_converter(AttributeConverter<T> * object) noexcept;
1394
1395
1401
1402 template<class T> void convert(T& value, const ConfigObject& obj, const std::string& attr_name) noexcept;
1403
1404
1410
1411 template<class T> void convert2(std::vector<T>& value, const ConfigObject& obj, const std::string& attr_name) noexcept;
1412
1413
1414 public:
1415
1416
1423
1424 void print_profiling_info() noexcept;
1425
1426
1427 private:
1428
1429 std::atomic<uint_least64_t> p_number_of_cache_hits;
1431 std::atomic<uint_least64_t> p_number_of_template_object_read;
1432
1433
1434 private:
1435
1439
1440 void set_subclasses() noexcept;
1441
1442 void set_class_domain_map();
1443
1444 void update_classes() noexcept;
1445
1446 std::deque<std::set<std::string>> find_class_domains();
1447
1448 public:
1449
1451
1452 const conffwk::fmap<conffwk::fset>& superclasses() const noexcept {return p_superclasses;}
1453
1454
1456
1458
1459 std::vector<std::string> classes_in_python() const;
1460
1461
1462
1463 private:
1464
1466
1467
1468 // cache of objects for user-defined classes
1469
1470 public:
1471
1483
1484 // template<class T> class Cache : public CacheBase {
1485
1486 // friend class Configuration;
1487
1488 // public:
1489
1490 // Cache() :
1491 // CacheBase(DalFactory::instance().functions(T::s_class_name))
1492 // {
1493 // ;
1494 // }
1495
1496
1497 // virtual ~Cache() noexcept;
1498
1499
1500 // /**
1501 // * \brief Get template object from cache by conffwk object.
1502 // *
1503 // * The method searches an object with id of given conffwk object within the cache.
1504 // * If found, the method sets given conffwk object as implementation of the template
1505 // * object and returns pointer on the template object.
1506 // * If there is no such object in cache, then it is created from given conffwk object.
1507 // *
1508 // * In case of success, the new object is put into cache and pointer to the object is returned.
1509 // * If there is no such object for given template class, then \b null pointer is returned.
1510 // *
1511 // * \param conffwk the configuration object
1512 // * \param obj the conffwk object used to set for the template object
1513 // * \param init_children if true, the referenced objects are initialized (only applicable during creation of new object)
1514 // * \param init_object if true, the object's attributes and relationships are read(only applicable during creation of new object)
1515 // *
1516 // * \return Return pointer to object.
1517 // *
1518 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an error
1519 // */
1520
1521 // T * get(Configuration& conffwk, ConfigObject& obj, bool init_children, bool init_object);
1522
1523
1524 // /**
1525 // * \brief Get template object from cache by object's ID.
1526 // *
1527 // * The method searches an object with given id within the cache.
1528 // * If found, the method returns pointer on it.
1529 // * If there is no such object in cache, there is an attempt to create new object.
1530 // * In case of success, the new object is put into cache and pointer to the object is returned.
1531 // * If there is no such object for given template class, then \b null pointer is returned.
1532 // *
1533 // * \param conffwk the configuration object
1534 // * \param name object identity
1535 // * \param init_children if true, the referenced objects are initialized (only applicable during creation of new object)
1536 // * \param init_object if true, the object's attributes and relationships are read(only applicable during creation of new object)
1537 // * \param rlevel optional references level to optimize performance (defines how many objects referenced by given object have also to be read to the implementation cache during creation of new object)
1538 // * \param rclasses optional array of class names to optimize performance (defines which referenced objects have to be read to the implementation cache during creation of new object)
1539 // *
1540 // * \return Return pointer to object. It can be \b null, if there is no such object found.
1541 // *
1542 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an error
1543 // */
1544
1545 // T * get(Configuration& conffwk, const std::string& name, bool init_children, bool init_object, unsigned long rlevel, const std::vector<std::string> * rclasses);
1546
1547
1548 // /**
1549 // * \brief Find template object using ID.
1550 // *
1551 // * The method is suitable for generated template objects.
1552 // *
1553 // * In case of success, the new object is put into cache and pointer to the object is returned.
1554 // * If there is no such object for given template class, then \b null pointer is returned.
1555 // *
1556 // * \param id ID of generated object
1557 // *
1558 // * \return Return pointer to object.
1559 // *
1560 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an error
1561 // */
1562
1563
1564 // T *
1565 // find(const std::string& id);
1566
1567
1568 // /**
1569 // * \brief Generate template object using conffwk object and ID.
1570 // *
1571 // * The method searches an object with id of given conffwk object within the cache using given ID.
1572 // * If found, the method sets given conffwk object as implementation of the template
1573 // * object and returns pointer on the template object.
1574 // * If there is no such object in cache, then it is created from given conffwk object.
1575 // *
1576 // * In case of success, the new object is put into cache and pointer to the object is returned.
1577 // * If there is no such object for given template class, then \b null pointer is returned.
1578 // *
1579 // * \param conffwk the configuration object
1580 // * \param obj the conffwk object used to set for the template object
1581 // * \param id ID of generated object
1582 // *
1583 // * \return Return pointer to object.
1584 // *
1585 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an error
1586 // */
1587
1588 // T *
1589 // get(Configuration& conffwk, ConfigObject& obj, const std::string& id);
1590
1591
1592 // private:
1593
1594 // conffwk::map<T*> m_cache;
1595 // conffwk::multimap<T*> m_t_cache;
1596
1597
1598 // };
1599
1600 private:
1601
1602 // Get cache for this type of objects.
1603
1604 // template<class T> Cache<T> * get_cache() noexcept;
1605
1606 // template<class T> Cache<T> * get_cache( const std::string& class_name ) {
1607
1608 // const std::string& class_name_ref = DalFactory::instance().get_known_class_name_ref(class_name);
1609 // CacheBase*& c(m_cache_map[&class_name_ref]);
1610
1611 // if (c == nullptr)
1612 // // c = new CacheBase(DalFactory::instance().functions(class_name_ref));
1613 // c = new CacheBase(class_name_ref, DalFactory::instance().functions(*this, class_name_ref, true));
1614
1615 // return static_cast<Cache<T>*>(c);
1616
1617 // // return c;
1618 // }
1619
1620 // conffwk::fmap<CacheBase*> m_cache_map;
1621
1622 void rename_object(ConfigObject& obj, const std::string& new_id);
1623
1624 // template<class T>
1625 // void
1626 // set_cache_unread(const std::vector<std::string>& objects, Cache<T>& c) noexcept
1627 // {
1628 // for (const auto& i : objects)
1629 // {
1630 // // unread template objects
1631 // auto x = c.m_cache.find(i);
1632 // if (x != c.m_cache.end())
1633 // {
1634 // std::lock_guard<std::mutex> scoped_lock(x->second->m_mutex);
1635 // x->second->p_was_read = false;
1636 // }
1637
1638 // // unread generated objects if any
1639 // auto range = c.m_t_cache.equal_range(i);
1640 // for (auto it = range.first; it != range.second; it++)
1641 // {
1642 // std::lock_guard<std::mutex> scoped_lock(it->second->m_mutex);
1643 // it->second->p_was_read = false;
1644 // }
1645 // }
1646 // }
1647
1648
1649 public:
1650
1660
1661 void print(std::ostream&) const noexcept;
1662
1663
1664 // representation
1665
1666 private:
1667
1669 std::string m_impl_spec;
1670 std::string m_impl_name;
1671 std::string m_impl_param;
1672
1673
1674
1676
1677
1678 // user notification
1679
1680 private:
1681
1682 // user callbacks with parameters
1683
1684 typedef std::set< CallbackSubscription * , std::less<CallbackSubscription *> > CallbackSet;
1685 typedef std::set< CallbackPreSubscription * , std::less<CallbackPreSubscription *> > PreCallbackSet;
1686
1689
1690
1691 // method to find callback by handler
1692
1693 CallbackSubscription * find_callback(CallbackId cb_handler) const;
1694
1695
1696 public:
1697
1699 void
1701
1703 void
1705
1706 private:
1707
1708 std::list<ConfigAction *> m_actions;
1709 void action_on_update(const ConfigObject& obj, const std::string& name);
1710
1711
1712 private:
1714
1715 mutable std::mutex m_impl_mutex; // mutex used to access implementation objects (i.e. ConfigObjectImpl objects)
1716 mutable std::mutex m_tmpl_mutex; // mutex used to access template objects (i.e. generated DAL)
1717 mutable std::mutex m_actn_mutex; // mutex is used to access actions
1718 mutable std::mutex m_else_mutex; // mutex used to access subscription, attribute converter, etc. objects
1719
1720
1721 // prevent copy constructor and operator=
1722
1723 private:
1724
1727
1728 public:
1729
1730 // JCF, Jan-1-2023: a set of functions written specifically for Python bindings
1731
1732 std::unordered_map<std::string, std::unordered_map<std::string, std::string>> attributes_pybind(const std::string& class_name, bool all);
1733 std::vector<std::string> get_class_list() const;
1734 ConfigObject* create_and_return_obj_pybind(const std::string& at, const std::string& class_name, const std::string& id);
1735 ConfigObject* create_and_return_obj_pybind(const ConfigObject& at, const std::string& class_name, const std::string& id);
1736 ConfigObject* get_obj_pybind(const std::string& class_name, const std::string& id);
1737 std::vector<ConfigObject>* get_objs_pybind(const std::string& class_name, const std::string& query="");
1738 std::unordered_map<std::string, std::unordered_map<std::string, std::string>> relations_pybind(const std::string& class_name, bool all);
1739 std::list<std::string>* return_includes_pybind(const std::string& db_name);
1740 std::vector<std::string> subclasses_pybind(const std::string& class_name, bool all);
1741 std::vector<std::string> superclasses_pybind(const std::string& class_name, bool all);
1742 [[nodiscard]] const std::string& get_schema_path_pybind(const std::string& class_name);
1743};
1744
1748
1749std::ostream& operator<<(std::ostream& s, const Configuration & c);
1750
1754
1755} // namespace conffwk
1756} // namespace dunedaq
1757
1759
1760
1761
1762
1763#endif // CONFFWK_CONFIGURATION_H_
Represents database objects.
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:42
Provides pure virtual interface used by the Configuration class.
virtual void convert(T &value, const Configuration &conf, const ConfigObject &obj, const std::string &attr_name)=0
Defines base class for cache of template objects.
void register_converter(AttributeConverter< T > *object) noexcept
Register user function for attribute conversion.
const std::string & get_impl_name() const noexcept
const T * _find(const std::string &id)
Multi-thread unsafe version of find(const std::string&) method.
void(* notify)(const std::vector< ConfigurationChange * > &changed_classes, void *parameter)
The user notification callback function which is invoked in case of changes.
void update_cache(std::vector< ConfigurationChange * > &changes) noexcept
System function invoked in case of modifications.
std::vector< ConfigObject > * get_objs_pybind(const std::string &class_name, const std::string &query="")
void _get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel, const std::vector< std::string > *rclasses)
std::set< CallbackPreSubscription *, std::less< CallbackPreSubscription * > > PreCallbackSet
const conffwk::fmap< conffwk::fset > & superclasses() const noexcept
static void update_impl_objects(conffwk::pmap< conffwk::map< ConfigObjectImpl * > * > &cache, ConfigurationChange &change, const std::string *class_name)
conffwk::map< std::list< AttributeConverterBase * > * > m_convert_map
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
void _unread_implementation_objects(dunedaq::conffwk::ObjectState state) noexcept
const TARGET * cast(const SOURCE *s) noexcept
Cast objects from one class to another (multi-thread safe).
static void system_cb(std::vector< ConfigurationChange * > &, Configuration *) noexcept
System callback function invoked in case of modifications.
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > attributes_pybind(const std::string &class_name, bool all)
void destroy_obj(ConfigObject &object)
Destroy object.
std::unordered_map< std::string, std::unordered_map< std::string, std::string > > relations_pybind(const std::string &class_name, bool all)
void remove_include(const std::string &db_name, const std::string &include)
Remove include file.
void get_updated_dbs(std::list< std::string > &dbs) const
Get list of updated files to be committed.
std::vector< std::string > classes_in_python() const
void prefetch_all_data()
Prefetch all data into client cache.
void load(const std::string &db_name)
Load database according to the name. If name is empty, take it from TDAQ_DB_NAME and TDAQ_DB_DATA env...
Configuration(const std::string &spec)
Constructor to build a configuration object using implementation plug-in.
void action_on_update(const ConfigObject &obj, const std::string &name)
std::set< CallbackSubscription *, std::less< CallbackSubscription * > > CallbackSet
void remove_action(ConfigAction *ac)
Configuration & operator=(const Configuration &)
bool is_writable(const std::string &db_name) const
Get write access status.
std::list< ConfigAction * > m_actions
void update(const std::vector< std::string > &modified, const std::vector< std::string > &removed, const std::vector< std::string > &created) noexcept
Update cache of objects in case of modification.
void set_commit_credentials(const std::string &user, const std::string &password)
Set commit credentials.
void print(std::ostream &) const noexcept
Prints out details of configuration object.
~Configuration() noexcept
Destructor to destroy a configuration object.
std::vector< const DalObject * > referenced_by(const DalObject &obj, const std::string &relationship_name="*", bool check_composite_only=true, bool upcast_unregistered=true, bool init=false, unsigned long rlevel=0, const std::vector< std::string > *rclasses=nullptr)
Get DAL objects holding references on this object via given relationship (multi-thread safe).
Configuration(const Configuration &)
void add_action(ConfigAction *ac)
std::atomic< uint_least64_t > p_number_of_template_object_created
void unread_template_objects() noexcept
Unread all template (i.e. set their state as uninitialized) objects.
const std::string & get_impl_param() const noexcept
static void system_pre_cb(Configuration *) noexcept
System callback function invoked in case of pre-modifications.
conffwk::fmap< conffwk::fset > p_subclasses
void referenced_by(const T &obj, std::vector< const V * > &objects, const std::string &relationship_name="*", bool check_composite_only=true, bool init=false, unsigned long rlevel=0, const std::vector< std::string > *rclasses=nullptr)
Get template DAL objects holding references on this object via given relationship (multi-thread safe)...
std::vector< std::string > superclasses_pybind(const std::string &class_name, bool all)
CallbackSubscription * find_callback(CallbackId cb_handler) const
void create(const std::string &at, const std::string &class_name, const std::string &id, ConfigObject &object)
Create new object by class name and object id.
static std::string mk_ref_ex_text(const char *what, const std::string &cname, const std::string &rname, const ConfigObject &obj) noexcept
CallbackSubscription * CallbackId
Callback identifier.
const dunedaq::conffwk::class_t & _get_class_info(const std::string &class_name, bool direct_only=false)
std::vector< std::string > subclasses_pybind(const std::string &class_name, bool all)
const T * _ref(ConfigObject &obj, const std::string &name, bool read_children)
Multi-thread unsafe version of ref(ConfigObject&, const std::string&, bool); The method should not be...
std::list< std::string > * return_includes_pybind(const std::string &db_name)
bool loaded() const noexcept
Check if database is correctly loaded.
DalObject * _make_instance(ConfigObject &obj, const std::string &uid)
std::vector< std::string > get_class_list() const
const conffwk::fmap< conffwk::fset > & subclasses() const
conffwk::map< dunedaq::conffwk::class_t * > p_all_classes_desc_cache
void _reset_objects() noexcept
Update state of objects after abort operations.
void unread_all_objects(bool unread_implementation_objs=false) noexcept
Unread all template (i.e. set their state as uninitialized) and implementation objects (i....
std::deque< std::set< std::string > > find_class_domains()
const std::string & get_schema_path_pybind(const std::string &class_name)
const std::string & get_impl_spec() const noexcept
const dunedaq::conffwk::class_t & get_class_info(const std::string &class_name, bool direct_only=false)
The method provides access to description of class.
void destroy(T &obj)
Destroy object of given class.
void get_includes(const std::string &db_name, std::list< std::string > &includes) const
Get include files.
conffwk::fmap< conffwk::fset > p_superclasses
std::vector< dunedaq::conffwk::Version > get_changes()
Get new conffwk versions.
conffwk::map< dunedaq::conffwk::class_t * > p_direct_classes_desc_cache
void commit(const std::string &log_message="")
Commit database changes.
void ref(ConfigObject &obj, const std::string &name, std::vector< const T * > &objects, bool init=false)
Get multiple values of object's relation and instantiate result with them (multi-thread safe).
void downcast_dal_object(const T *obj, bool, std::vector< const DalObject * > &result)
conffwk::fmap< uint > p_class_domain_map
bool is_superclass_of(const std::string &target, const std::string &source) noexcept
const T * get(ConfigObject &obj, const std::string &id)
Generate object of given class by object reference and instantiate the template parameter with it (mu...
void export_data(boost::property_tree::ptree &tree, const std::string &classes="", const std::string &objects="", const std::string &files="", const std::string &empty_array_item="")
Export configuration data into ptree.
static std::string mk_ref_by_ex_text(const std::string &cname, const std::string &rname, const ConfigObject &obj) noexcept
void unread_implementation_objects(dunedaq::conffwk::ObjectState state) noexcept
Unread implementation objects (i.e. clear their cache).
ConfigObject * get_obj_pybind(const std::string &class_name, const std::string &id)
void downcast_dal_objects(const std::vector< const T * > &objs, bool, std::vector< const DalObject * > &result)
CallbackId subscribe(pre_notify user_cb, void *user_param=nullptr)
Subscribe on pre-notification on configuration changes.
void export_schema(boost::property_tree::ptree &tree, const std::string &classes="", bool direct_only=false)
Export configuration schema into ptree.
void unsubscribe(CallbackId cb_handler=0)
Remove callback function.
void(* pre_notify)(void *parameter)
The user notification callback function which is invoked before changes are going to be applied.
void print_profiling_info() noexcept
Print out profiling information.
std::vector< dunedaq::conffwk::Version > get_versions(const std::string &since, const std::string &until, dunedaq::conffwk::Version::QueryType type=dunedaq::conffwk::Version::query_by_date, bool skip_irrelevant=true)
Get repository versions in interval.
const T * ref(ConfigObject &obj, const std::string &name, bool init=false)
Get signle value of object's relation and instantiate result with it (multi-thread safe).
std::atomic< uint_least64_t > p_number_of_template_object_read
void abort()
Abort database changes.
void unload()
Unload database.
bool test_object(const std::string &class_name, const std::string &id, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Test the object existence.
void add_include(const std::string &db_name, const std::string &include)
Add include file to existing database.
std::atomic< uint_least64_t > p_number_of_cache_hits
void convert(T &value, const ConfigObject &obj, const std::string &attr_name) noexcept
Converts single value.
ConfigObject * create_and_return_obj_pybind(const std::string &at, const std::string &class_name, const std::string &id)
CallbackId subscribe(const ConfigurationSubscriptionCriteria &criteria, notify user_cb, void *user_param=nullptr)
Subscribe on configuration changes.
const T * get(ConfigObject &obj, bool init_children=false, bool init=true)
Get object of given class by object reference and instantiate the template parameter with it (multi-t...
bool try_cast(const std::string &target, const std::string &source) noexcept
Checks if cast from source class to target class is allowed.
void get(std::vector< const T * > &objects, bool init_children=false, bool init=true, const std::string &query="", unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get all objects of given class and instantiate a vector of the template parameters object with it (mu...
const T * find(const std::string &id)
Find object of given class (multi-thread safe).
void convert2(std::vector< T > &value, const ConfigObject &obj, const std::string &attr_name) noexcept
Converts vector of single values.
void rename_object(ConfigObject &obj, const std::string &new_id)
Cache of template object of given type.
bool is_valid(const T *object) noexcept
Checks validity of pointer to an objects of given user class.
bool is_superclass_of(const std::string *target, const std::string *source) noexcept
The base class for any generated DAL object.
Definition DalObject.hpp:52
DalRegistry: A registry of DalObjects It provides a single interface to create, cache and manage DalO...
Represents configuration version.
void init(unordered_map< std::string, std::string > params)
std::unordered_set< const std::string *, string_ptr_hash > fset
Definition set.hpp:20
std::unordered_set< std::string > set
Definition set.hpp:17
std::ostream & operator<<(std::ostream &, const ConfigurationChange &)
Including Qt Headers.
Definition module.cpp:16
msgpack::object obj