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 <list>
23#include <set>
24#include <string>
25#include <typeinfo>
26#include <vector>
27
28#include <mutex>
29
30#include <boost/property_tree/ptree.hpp>
31
32#include "ers/ers.hpp"
33
38#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
53struct class_t;
54
55class Configuration;
56
65
66// class CacheBase
67// {
68
69// friend class Configuration;
70
71// protected:
72
73// CacheBase(const DalFactoryFunctions& f) :
74// m_functions(f)
75// {
76// ;
77// }
78
79// /** Method for configuration profiling */
80
81// void
82// increment_gets(Configuration& db) noexcept;
83
84// virtual
85// ~CacheBase() noexcept
86// {
87// ;
88// }
89
90// protected:
91
92// const DalFactoryFunctions& m_functions;
93
94// private:
95
96// conffwk::map<DalObject*> m_cache;
97// conffwk::multimap<DalObject*> m_t_cache;
98// };
99
232
234{
235
236 friend class DalObject;
237 friend class ConfigObject;
238 friend class ConfigurationImpl;
239 // friend class CacheBase;
240 friend class DalObject;
241 friend class DalRegistry;
242
243public:
257
258 Configuration(const std::string& spec);
259
261
263
264 const std::string& get_impl_spec() const noexcept { return m_impl_spec; }
265
267
268 const std::string& get_impl_name() const noexcept { return m_impl_name; }
269
271
272 const std::string& get_impl_param() const noexcept { return m_impl_param; }
273
280
281 ~Configuration() noexcept;
282
283public:
291
292 typedef void (*notify)(const std::vector<ConfigurationChange*>& changed_classes, void* parameter);
293
300
301 typedef void (*pre_notify)(void* parameter);
302
303private: // Types to be used in public API below
304 // structure keeps information about callback subscriptions
305
312
318
319public:
327
329
347
348 CallbackId subscribe(const ConfigurationSubscriptionCriteria& criteria, notify user_cb, void* user_param = nullptr);
349
369
370 CallbackId subscribe(pre_notify user_cb, void* user_param = nullptr);
371
381
382 void unsubscribe(CallbackId cb_handler = 0);
383
392
393 template<class T>
394 bool is_valid(const T* object) noexcept;
395
396private:
398 void reset_subscription();
399
400public:
412
413 template<class T>
414 void update(const std::vector<std::string>& modified,
415 const std::vector<std::string>& removed,
416 const std::vector<std::string>& created) noexcept;
417
424
425 void update_cache(std::vector<ConfigurationChange*>& changes) noexcept;
426
433
434 static void system_cb(std::vector<ConfigurationChange*>&, Configuration*) noexcept;
435
442
443 static void system_pre_cb(Configuration*) noexcept;
444
450
451 template<class T>
452 void _reset_objects() noexcept;
453
454 // /**
455 // * \brief Mark object of given template class as unread (multi-thread unsafe).
456 // *
457 // * Is used by automatically generated data access libraries code after reading parameters for substitution,
458 // * since cache contains objects with non-substituted attributes. Should not be explicitly used by user.
459 // *
460 // * The method is used by the unread_all_objects() method.
461 // * \param cache_ptr pointer to the cache of template object of given template class (has to be downcasted)
462 // */
463
464 // template<class T> static void _unread_objects(CacheBase * cache_ptr) noexcept;
465
466 // /**
467 // * \brief Rename object of given template class (multi-thread unsafe).
468 // *
469 // * Is used by automatically generated data access libraries when an object has been renamed by user's code.
470 // * Should not be explicitly used by user.
471 // *
472 // * The method is used by the unread_all_objects() method.
473 // * \param cache_ptr pointer to the cache of template object of given template class (has to be downcasted)
474 // * \param old_id old object ID
475 // * \param new_id new object ID
476 // */
477
478 // template<class T> static void _rename_object(CacheBase* cache_ptr, const std::string& old_id, const std::string&
479 // new_id) noexcept;
480
481 // /**
482 // * \brief Update state of all objects in cache after abort / commit operations.
483 // *
484 // * It is used by automatically generated data access libraries.
485 // */
486
487 // void _reset_all_objects() noexcept;
488
502
503 void unread_all_objects(bool unread_implementation_objs = false) noexcept;
504
511
513 {
514 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
516 }
517
526
528 {
529 std::lock_guard<std::mutex> scoped_lock(m_impl_mutex);
531 }
532
533private:
535 ConfigurationChange& change,
536 const std::string* class_name);
537
538 void _unread_template_objects() noexcept;
539
541
542public:
556
557 void create(const std::string& at, const std::string& class_name, const std::string& id, ConfigObject& object);
558
572
573 void create(const ConfigObject& at, const std::string& class_name, const std::string& id, ConfigObject& object);
574
588
589 template<class T>
590 const T* create(const std::string& at, const std::string& id, bool init_object = false);
591
606
607 template<class T>
608 const T* create(const DalObject& at, const std::string& id, bool init_object = false);
609
619
620 void destroy_obj(ConfigObject& object);
621
631
632 template<class T>
633 void destroy(T& obj);
634
635public:
651
652 bool test_object(const std::string& class_name,
653 const std::string& id,
654 unsigned long rlevel = 0,
655 const std::vector<std::string>* rclasses = 0);
656
673
674 void get(const std::string& class_name,
675 const std::string& id,
676 ConfigObject& object,
677 unsigned long rlevel = 0,
678 const std::vector<std::string>* rclasses = 0);
679
696
697 void get(const std::string& class_name,
698 std::vector<ConfigObject>& objects,
699 const std::string& query = "",
700 unsigned long rlevel = 0,
701 const std::vector<std::string>* rclasses = 0);
702
719
720 void get(const ConfigObject& obj_from,
721 const std::string& query,
722 std::vector<ConfigObject>& objects,
723 unsigned long rlevel = 0,
724 const std::vector<std::string>* rclasses = 0);
725
743
744 template<class T>
745 const T* get(const std::string& id,
746 bool init_children = false,
747 bool init = true,
748 unsigned long rlevel = 0,
749 const std::vector<std::string>* rclasses = 0)
750 {
751 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
752 return _get<T>(id, init_children, init, rlevel, rclasses);
753 }
754
769
770 template<class T>
771 const T* get(ConfigObject& obj, bool init_children = false, bool init = true)
772 {
773 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
774 return _get<T>(obj, init_children, init);
775 }
776
794
795 template<class T>
796 void get(std::vector<const T*>& objects,
797 bool init_children = false,
798 bool init = true,
799 const std::string& query = "",
800 unsigned long rlevel = 0,
801 const std::vector<std::string>* rclasses = 0)
802 {
803 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
804 _get<T>(objects, init_children, init, query, rlevel, rclasses);
805 }
806
820
821 template<class T>
822 const T* get(ConfigObject& obj, const std::string& id)
823 {
824 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
825 return _get<T>(obj, id);
826 }
827
839
840 template<class T>
841 const T* find(const std::string& id)
842 {
843 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
844 return _find<T>(id);
845 }
846
863
864 template<class T>
865 const T* ref(ConfigObject& obj, const std::string& name, bool init = false)
866 {
867 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
868 return _ref<T>(obj, name, init);
869 }
870
884
885 template<class T>
886 void ref(ConfigObject& obj, const std::string& name, std::vector<const T*>& objects, bool init = false)
887 {
888 std::lock_guard<std::mutex> scoped_lock(m_tmpl_mutex);
889 _ref<T>(obj, name, objects, init);
890 }
891
913
914 template<class T, class V>
915 void referenced_by(const T& obj,
916 std::vector<const V*>& objects,
917 const std::string& relationship_name = "*",
918 bool check_composite_only = true,
919 bool init = false,
920 unsigned long rlevel = 0,
921 const std::vector<std::string>* rclasses = nullptr);
922
951
952 std::vector<const DalObject*> referenced_by(const DalObject& obj,
953 const std::string& relationship_name = "*",
954 bool check_composite_only = true,
955 bool upcast_unregistered = true,
956 bool init = false,
957 unsigned long rlevel = 0,
958 const std::vector<std::string>* rclasses = nullptr);
959
968
969 template<class TARGET, class SOURCE>
970 const TARGET* cast(const SOURCE* s) noexcept
971 {
972 return s->template cast<TARGET>();
973 }
974
975private:
977 void _get(const std::string& class_name,
978 const std::string& id,
979 ConfigObject& object,
980 unsigned long rlevel,
981 const std::vector<std::string>* rclasses);
982
984 template<class T>
985 const T* _get(const std::string& id,
986 bool init_children = false,
987 bool init = true,
988 unsigned long rlevel = 0,
989 const std::vector<std::string>* rclasses = 0);
990
992 template<class T>
993 const T* _get(ConfigObject& obj, bool init_children = false, bool init = true);
994
995 // /// \throw dunedaq::conffwk::Generic
996 // template<class T> const T * _get(ConfigObject& obj, const std::string& id);
997
999 template<class T>
1000 void _get(std::vector<const T*>& objects,
1001 bool init_children = false,
1002 bool init = true,
1003 const std::string& query = "",
1004 unsigned long rlevel = 0,
1005 const std::vector<std::string>* rclasses = 0);
1006
1008 template<class T>
1009 DalObject* _make_instance(ConfigObject& obj, const std::string& uid)
1010 {
1011 // note upcast since the _get() returns pointer to T
1012 return const_cast<T*>(_get<T>(obj, uid));
1013 }
1014
1015 // std::vector<const DalObject*> make_dal_objects(std::vector<ConfigObject>& objs, bool upcast_unregistered);
1016
1017 // const DalObject* make_dal_object(ConfigObject& obj, const std::string& uid, const std::string& class_name);
1018
1019 // should be made private
1020
1021public:
1022 template<class T>
1023 void downcast_dal_objects(const std::vector<const T*>& objs,
1024 bool /*upcast_unregistered*/,
1025 std::vector<const DalObject*>& result)
1026 {
1027 for (auto& i : objs)
1028 result.push_back(i);
1029 }
1030
1031 template<class T>
1032 void downcast_dal_object(const T* obj, bool /*upcast_unregistered*/, std::vector<const DalObject*>& result)
1033 {
1034 if (obj)
1035 result.push_back(obj);
1036 }
1037
1042
1043 template<class T>
1044 const T* _find(const std::string& id);
1045
1051
1052 template<class T>
1053 const T* _ref(ConfigObject& obj, const std::string& name, bool read_children);
1054
1060
1061 template<class T>
1062 void _ref(ConfigObject& obj, const std::string& name, std::vector<const T*>& results, bool read_children);
1063
1072
1073 bool try_cast(const std::string& target, const std::string& source) noexcept;
1074
1075 bool try_cast(const std::string* target, const std::string* source) noexcept;
1076
1077 bool is_superclass_of(const std::string& target, const std::string& source) noexcept;
1078
1079 bool is_superclass_of(const std::string* target, const std::string* source) noexcept;
1080
1081private:
1083
1084 static std::string mk_ref_ex_text(const char* what,
1085 const std::string& cname,
1086 const std::string& rname,
1087 const ConfigObject& obj) noexcept;
1088
1090
1091 static std::string mk_ref_by_ex_text(const std::string& cname,
1092 const std::string& rname,
1093 const ConfigObject& obj) noexcept;
1094
1095 // database manipulations
1096
1097public:
1105
1106 bool loaded() const noexcept;
1107
1115
1116 void load(const std::string& db_name);
1117
1128
1129 void unload();
1130
1142
1143 void create(const std::string& db_name, const std::list<std::string>& includes);
1144
1156
1157 bool is_writable(const std::string& db_name) const;
1158
1169
1170 void add_include(const std::string& db_name, const std::string& include);
1171
1182
1183 void remove_include(const std::string& db_name, const std::string& include);
1184
1195
1196 void get_includes(const std::string& db_name, std::list<std::string>& includes) const;
1197
1207
1208 void get_updated_dbs(std::list<std::string>& dbs) const;
1209
1220
1221 void set_commit_credentials(const std::string& user, const std::string& password);
1222
1232
1233 void commit(const std::string& log_message = "");
1234
1242
1243 void abort();
1244
1252
1253 void prefetch_all_data();
1254
1255 // access versions
1256
1257public:
1264
1265 std::vector<dunedaq::conffwk::Version> get_changes();
1266
1284
1286 const std::string& since,
1287 const std::string& until,
1288 dunedaq::conffwk::Version::QueryType type = dunedaq::conffwk::Version::query_by_date,
1289 bool skip_irrelevant = true);
1290
1291 // access to schema description
1292
1293public:
1305
1306 const dunedaq::conffwk::class_t& get_class_info(const std::string& class_name, bool direct_only = false);
1307
1308private:
1309 const dunedaq::conffwk::class_t& _get_class_info(const std::string& class_name, bool direct_only = false);
1310
1311 // cache, storing descriptions of schema
1312
1315
1316public:
1327
1328 void export_schema(boost::property_tree::ptree& tree, const std::string& classes = "", bool direct_only = false);
1329
1341
1342 void export_data(boost::property_tree::ptree& tree,
1343 const std::string& classes = "",
1344 const std::string& objects = "",
1345 const std::string& files = "",
1346 const std::string& empty_array_item = "");
1347
1348 // user-defined converters
1349
1350public:
1352
1354 {
1355
1356 public:
1358 };
1359
1367
1368 template<class T>
1370 {
1371
1372 public:
1386
1387 virtual void convert(T& value,
1388 const Configuration& conf,
1389 const ConfigObject& obj,
1390 const std::string& attr_name) = 0;
1391 };
1392
1405
1406 template<class T>
1407 void register_converter(AttributeConverter<T>* object) noexcept;
1408
1414
1415 template<class T>
1416 void convert(T& value, const ConfigObject& obj, const std::string& attr_name) noexcept;
1417
1423
1424 template<class T>
1425 void convert2(std::vector<T>& value, const ConfigObject& obj, const std::string& attr_name) noexcept;
1426
1427public:
1434
1435 void print_profiling_info() noexcept;
1436
1437private:
1438 std::atomic<uint_least64_t> p_number_of_cache_hits;
1440 std::atomic<uint_least64_t> p_number_of_template_object_read;
1441
1442private:
1446
1447 void set_subclasses() noexcept;
1448
1449 void set_class_domain_map();
1450
1451 void update_classes() noexcept;
1452
1453 std::deque<std::set<std::string>> find_class_domains();
1454
1455public:
1457
1458 const conffwk::fmap<conffwk::fset>& superclasses() const noexcept { return p_superclasses; }
1459
1461
1463
1464 std::vector<std::string> classes_in_python() const;
1465
1466private:
1468
1469 // cache of objects for user-defined classes
1470
1471public:
1484
1485 // template<class T> class Cache : public CacheBase {
1486
1487 // friend class Configuration;
1488
1489 // public:
1490
1491 // Cache() :
1492 // CacheBase(DalFactory::instance().functions(T::s_class_name))
1493 // {
1494 // ;
1495 // }
1496
1497 // virtual ~Cache() noexcept;
1498
1499 // /**
1500 // * \brief Get template object from cache by conffwk object.
1501 // *
1502 // * The method searches an object with id of given conffwk object within the cache.
1503 // * If found, the method sets given conffwk object as implementation of the template
1504 // * object and returns pointer on the template object.
1505 // * If there is no such object in cache, then it is created from given conffwk object.
1506 // *
1507 // * In case of success, the new object is put into cache and pointer to the object is returned.
1508 // * If there is no such object for given template class, then \b null pointer is returned.
1509 // *
1510 // * \param conffwk the configuration object
1511 // * \param obj the conffwk object used to set for the template object
1512 // * \param init_children if true, the referenced objects are initialized (only applicable during creation of
1513 // new object)
1514 // * \param init_object if true, the object's attributes and relationships are read(only applicable during
1515 // creation of new object)
1516 // *
1517 // * \return Return pointer to object.
1518 // *
1519 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an
1520 // error
1521 // */
1522
1523 // T * get(Configuration& conffwk, ConfigObject& obj, bool init_children, bool init_object);
1524
1525 // /**
1526 // * \brief Get template object from cache by object's ID.
1527 // *
1528 // * The method searches an object with given id within the cache.
1529 // * If found, the method returns pointer on it.
1530 // * If there is no such object in cache, there is an attempt to create new object.
1531 // * In case of success, the new object is put into cache and pointer to the object is returned.
1532 // * If there is no such object for given template class, then \b null pointer is returned.
1533 // *
1534 // * \param conffwk the configuration object
1535 // * \param name object identity
1536 // * \param init_children if true, the referenced objects are initialized (only applicable during creation of
1537 // new object)
1538 // * \param init_object if true, the object's attributes and relationships are read(only applicable during
1539 // creation of new object)
1540 // * \param rlevel optional references level to optimize performance (defines how many objects
1541 // referenced by given object have also to be read to the implementation cache during creation of new object)
1542 // * \param rclasses optional array of class names to optimize performance (defines which referenced
1543 // objects have to be read to the implementation cache during creation of new object)
1544 // *
1545 // * \return Return pointer to object. It can be \b null, if there is no such object found.
1546 // *
1547 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an
1548 // error
1549 // */
1550
1551 // T * get(Configuration& conffwk, const std::string& name, bool init_children, bool init_object, unsigned long
1552 // rlevel, const std::vector<std::string> * rclasses);
1553
1554 // /**
1555 // * \brief Find template object using ID.
1556 // *
1557 // * The method is suitable for generated template objects.
1558 // *
1559 // * In case of success, the new object is put into cache and pointer to the object is returned.
1560 // * If there is no such object for given template class, then \b null pointer is returned.
1561 // *
1562 // * \param id ID of generated object
1563 // *
1564 // * \return Return pointer to object.
1565 // *
1566 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an
1567 // error
1568 // */
1569
1570 // T *
1571 // find(const std::string& id);
1572
1573 // /**
1574 // * \brief Generate template object using conffwk object and ID.
1575 // *
1576 // * The method searches an object with id of given conffwk object within the cache using given ID.
1577 // * If found, the method sets given conffwk object as implementation of the template
1578 // * object and returns pointer on the template object.
1579 // * If there is no such object in cache, then it is created from given conffwk object.
1580 // *
1581 // * In case of success, the new object is put into cache and pointer to the object is returned.
1582 // * If there is no such object for given template class, then \b null pointer is returned.
1583 // *
1584 // * \param conffwk the configuration object
1585 // * \param obj the conffwk object used to set for the template object
1586 // * \param id ID of generated object
1587 // *
1588 // * \return Return pointer to object.
1589 // *
1590 // * \throw dunedaq::conffwk::Generic is no such class for loaded configuration DB schema or in case of an
1591 // error
1592 // */
1593
1594 // T *
1595 // get(Configuration& conffwk, ConfigObject& obj, const std::string& id);
1596
1597 // private:
1598
1599 // conffwk::map<T*> m_cache;
1600 // conffwk::multimap<T*> m_t_cache;
1601
1602 // };
1603
1604private:
1605 // Get cache for this type of objects.
1606
1607 // template<class T> Cache<T> * get_cache() noexcept;
1608
1609 // template<class T> Cache<T> * get_cache( const std::string& class_name ) {
1610
1611 // const std::string& class_name_ref = DalFactory::instance().get_known_class_name_ref(class_name);
1612 // CacheBase*& c(m_cache_map[&class_name_ref]);
1613
1614 // if (c == nullptr)
1615 // // c = new CacheBase(DalFactory::instance().functions(class_name_ref));
1616 // c = new CacheBase(class_name_ref, DalFactory::instance().functions(*this, class_name_ref, true));
1617
1618 // return static_cast<Cache<T>*>(c);
1619
1620 // // return c;
1621 // }
1622
1623 // conffwk::fmap<CacheBase*> m_cache_map;
1624
1625 void rename_object(ConfigObject& obj, const std::string& new_id);
1626
1627 // template<class T>
1628 // void
1629 // set_cache_unread(const std::vector<std::string>& objects, Cache<T>& c) noexcept
1630 // {
1631 // for (const auto& i : objects)
1632 // {
1633 // // unread template objects
1634 // auto x = c.m_cache.find(i);
1635 // if (x != c.m_cache.end())
1636 // {
1637 // std::lock_guard<std::mutex> scoped_lock(x->second->m_mutex);
1638 // x->second->p_was_read = false;
1639 // }
1640
1641 // // unread generated objects if any
1642 // auto range = c.m_t_cache.equal_range(i);
1643 // for (auto it = range.first; it != range.second; it++)
1644 // {
1645 // std::lock_guard<std::mutex> scoped_lock(it->second->m_mutex);
1646 // it->second->p_was_read = false;
1647 // }
1648 // }
1649 // }
1650
1651public:
1661
1662 void print(std::ostream&) const noexcept;
1663
1664 // representation
1665
1666private:
1668 std::string m_impl_spec;
1669 std::string m_impl_name;
1670 std::string m_impl_param;
1671
1673
1674 // user notification
1675
1676private:
1677 // user callbacks with parameters
1678
1679 typedef std::set<CallbackSubscription*, std::less<CallbackSubscription*>> CallbackSet;
1680 typedef std::set<CallbackPreSubscription*, std::less<CallbackPreSubscription*>> PreCallbackSet;
1681
1684
1685 // method to find callback by handler
1686
1688
1689public:
1691 void add_action(ConfigAction* ac);
1692
1694 void remove_action(ConfigAction* ac);
1695
1696private:
1697 std::list<ConfigAction*> m_actions;
1698 void action_on_update(const ConfigObject& obj, const std::string& name);
1699
1700private:
1702
1703 mutable std::mutex m_impl_mutex; // mutex used to access implementation objects (i.e. ConfigObjectImpl objects)
1704 mutable std::mutex m_tmpl_mutex; // mutex used to access template objects (i.e. generated DAL)
1705 mutable std::mutex m_actn_mutex; // mutex is used to access actions
1706 mutable std::mutex m_else_mutex; // mutex used to access subscription, attribute converter, etc. objects
1707
1708 // prevent copy constructor and operator=
1709
1710private:
1713
1714public:
1715 // JCF, Jan-1-2023: a set of functions written specifically for Python bindings
1716
1717 std::unordered_map<std::string, std::unordered_map<std::string, std::string>> attributes_pybind(
1718 const std::string& class_name,
1719 bool all);
1720 std::vector<std::string> get_class_list() const;
1721 ConfigObject* create_and_return_obj_pybind(const std::string& at,
1722 const std::string& class_name,
1723 const std::string& id);
1725 const std::string& class_name,
1726 const std::string& id);
1727 ConfigObject* get_obj_pybind(const std::string& class_name, const std::string& id);
1728 std::vector<ConfigObject>* get_objs_pybind(const std::string& class_name, const std::string& query = "");
1729 std::unordered_map<std::string, std::unordered_map<std::string, std::string>> relations_pybind(
1730 const std::string& class_name,
1731 bool all);
1732 std::list<std::string>* return_includes_pybind(const std::string& db_name);
1733 std::vector<std::string> subclasses_pybind(const std::string& class_name, bool all);
1734 std::vector<std::string> superclasses_pybind(const std::string& class_name, bool all);
1735 [[nodiscard]] const std::string& get_schema_path_pybind(const std::string& class_name);
1736};
1737
1741
1742std::ostream&
1743operator<<(std::ostream& s, const Configuration& c);
1744
1748
1749} // namespace conffwk
1750} // namespace dunedaq
1751
1753
1754#endif // CONFFWK_CONFIGURATION_H_
Represents database objects.
Describes changes inside a class returned by the notification mechanism.
Definition Change.hpp:43
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
Method to make the conversion of attribute value.
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 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)
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)
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
std::set< CallbackPreSubscription *, std::less< CallbackPreSubscription * > > PreCallbackSet
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)
void remove_action(ConfigAction *ac)
Configuration & operator=(const Configuration &)
bool is_writable(const std::string &db_name) const
Get write access status.
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.
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
conffwk::map< dunedaq::conffwk::class_t * > p_all_classes_desc_cache
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
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::list< ConfigAction * > m_actions
std::set< CallbackSubscription *, std::less< CallbackSubscription * > > CallbackSet
std::deque< std::set< std::string > > find_class_domains()
const std::string & get_schema_path_pybind(const std::string &class_name)
void(*) pre_notify(void *parameter)
The user notification callback function which is invoked before changes are going to be applied.
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::map< std::list< AttributeConverterBase * > * > m_convert_map
conffwk::fmap< conffwk::fset > p_superclasses
std::vector< dunedaq::conffwk::Version > get_changes()
Get new conffwk versions.
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)
void(*) notify(const std::vector< ConfigurationChange * > &changed_classes, void *parameter)
The user notification callback function which is invoked in case of changes.
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 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.
conffwk::map< dunedaq::conffwk::class_t * > p_direct_classes_desc_cache
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:51
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:19
std::unordered_set< std::string > set
Definition set.hpp:16
std::ostream & operator<<(std::ostream &, const ConfigurationChange &)
The DUNE-DAQ namespace.
msgpack::object obj