Line data Source code
1 :
2 : #include "ConfigObjectFactory.hpp"
3 : #include "confmodel/Service.hpp"
4 : #include "oks/file.hpp"
5 :
6 : #include <fmt/core.h> // Replace with std::format when we switch to a newer compiler?
7 :
8 : namespace dunedaq {
9 : namespace appmodel {
10 :
11 0 : ConfigObjectFactory::ConfigObjectFactory(const SmartDaqApplication* parent) :
12 0 : m_config(&parent->configuration()),
13 0 : m_dbfile(parent->config_object().contained_in()),
14 0 : m_app_uid(parent->UID()) {
15 :
16 : //FIXME: remove this hacky hack
17 0 : oks::OksFile::set_nolock_mode(true);
18 0 : }
19 :
20 0 : ConfigObjectFactory::~ConfigObjectFactory() {
21 : //FIXME: remove this hacky hack
22 0 : oks::OksFile::set_nolock_mode(false);
23 0 : }
24 :
25 : conffwk::ConfigObject
26 0 : ConfigObjectFactory::create(const std::string& class_name,
27 : const std::string& id) const {
28 0 : conffwk::ConfigObject cfg_obj;
29 0 : m_config->create(m_dbfile, class_name, id, cfg_obj);
30 0 : return cfg_obj;
31 0 : }
32 :
33 : //---
34 : conffwk::ConfigObject
35 0 : ConfigObjectFactory::create_queue_obj(const QueueDescriptor* qdesc, std::string uid) const {
36 :
37 0 : std::string queue_uid(qdesc->get_uid_base() + uid);
38 0 : auto queue_obj = create("Queue", queue_uid);
39 0 : queue_obj.set_by_val<std::string>("data_type", qdesc->get_data_type());
40 0 : queue_obj.set_by_val<std::string>("queue_type", qdesc->get_queue_type());
41 0 : queue_obj.set_by_val<uint32_t>("capacity", qdesc->get_capacity());
42 :
43 0 : return queue_obj;
44 0 : }
45 :
46 : //---
47 : conffwk::ConfigObject
48 0 : ConfigObjectFactory::create_queue_sid_obj(const QueueDescriptor* qdesc, uint32_t src_id) const {
49 0 : std::string queue_uid(fmt::format("{}{}", qdesc->get_uid_base(), src_id));
50 0 : auto queue_obj = create("QueueWithSourceId", queue_uid);
51 :
52 0 : queue_obj.set_by_val<std::string>("data_type", qdesc->get_data_type());
53 0 : queue_obj.set_by_val<std::string>("queue_type", qdesc->get_queue_type());
54 0 : queue_obj.set_by_val<uint32_t>("capacity", qdesc->get_capacity());
55 0 : queue_obj.set_by_val<uint32_t>("source_id", src_id);
56 :
57 0 : return queue_obj;
58 0 : }
59 :
60 : //---
61 : conffwk::ConfigObject
62 0 : ConfigObjectFactory::create_queue_sid_obj(const QueueDescriptor* qdesc,
63 : const confmodel::DetectorStream* stream) const {
64 0 : return create_queue_sid_obj(qdesc, stream->get_source_id());
65 : }
66 :
67 : //---
68 :
69 : /**
70 : * \brief Helper function that gets a network connection config
71 : *
72 : * \param uid Unique ID name of the config object
73 : * \param ndesc Network connection descriptor object
74 : *
75 : * \ret OKS configuration object for the network connection
76 : */
77 : conffwk::ConfigObject
78 0 : ConfigObjectFactory::create_net_obj(const NetworkConnectionDescriptor* ndesc,
79 : std::string app_uid) const {
80 :
81 0 : auto svc_obj = ndesc->get_associated_service()->config_object();
82 0 : std::string net_id = ndesc->get_uid_base() + app_uid;
83 0 : auto net_obj = create("NetworkConnection", net_id);
84 :
85 0 : net_obj.set_by_val<std::string>("data_type", ndesc->get_data_type());
86 0 : net_obj.set_by_val<std::string>("connection_type", ndesc->get_connection_type());
87 0 : net_obj.set_by_val<uint32_t>("capacity", ndesc->get_capacity());
88 0 : net_obj.set_obj("associated_service", &svc_obj);
89 :
90 0 : return net_obj;
91 0 : }
92 :
93 : conffwk::ConfigObject
94 0 : ConfigObjectFactory::create_net_obj(const NetworkConnectionDescriptor* ndesc) const {
95 0 : return create_net_obj(ndesc, this->m_app_uid);
96 : }
97 :
98 : } // namespace appmodel
99 : } // namespace dunedaq
|