Line data Source code
1 : /**
2 : * @file ConfigObjectFactory.hpp
3 : *
4 : * Define a helper class for SmartDaqApplication module generators
5 : *
6 : * This is part of the DUNE DAQ Software Suite, copyright 2023.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 : #ifndef APPMODEL_INCLUDE_OBJECTFACTORY_HPP_
11 : #define APPMODEL_INCLUDE_OBJECTFACTORY_HPP_
12 :
13 : #include "appmodel/appmodelIssues.hpp"
14 : #include "appmodel/NetworkConnectionDescriptor.hpp"
15 : #include "appmodel/QueueDescriptor.hpp"
16 : #include "appmodel/SmartDaqApplication.hpp"
17 :
18 : #include "conffwk/ConfigObject.hpp"
19 : #include "conffwk/Configuration.hpp"
20 :
21 : #include "confmodel/DaqModule.hpp"
22 : #include "confmodel/DetectorStream.hpp"
23 :
24 : #include <cstdint>
25 : #include <string>
26 : #include <vector>
27 :
28 : namespace dunedaq::appmodel {
29 :
30 : class ConfigObjectFactory
31 : {
32 :
33 : conffwk::Configuration* m_config;
34 : std::string m_dbfile;
35 : std::string m_app_uid;
36 :
37 : public:
38 : explicit ConfigObjectFactory(const SmartDaqApplication* );
39 :
40 : ~ConfigObjectFactory();
41 :
42 : [[nodiscard]] conffwk::ConfigObject
43 : create(const std::string& class_name, const std::string& id) const;
44 :
45 : //---
46 : [[nodiscard]] conffwk::ConfigObject
47 0 : create_queue_obj(const QueueDescriptor* qdesc, std::string uid = "") const;
48 :
49 : //---
50 : [[nodiscard]] conffwk::ConfigObject
51 : create_queue_sid_obj(const QueueDescriptor* qdesc, uint32_t src_id) const;
52 :
53 : //---
54 : [[nodiscard]] conffwk::ConfigObject
55 : create_queue_sid_obj(const QueueDescriptor* qdesc, const confmodel::DetectorStream* stream) const;
56 : //---
57 :
58 : /**
59 : * \brief Helper function that gets a network connection config
60 : *
61 : * \param uid Unique ID name of the config object
62 : * \param ndesc Network connection descriptor object
63 : *
64 : * \ret OKS configuration object for the network connection
65 : */
66 : [[nodiscard]] conffwk::ConfigObject
67 : create_net_obj(const NetworkConnectionDescriptor* ndesc, std::string uid) const;
68 :
69 : [[nodiscard]] conffwk::ConfigObject
70 : create_net_obj(const NetworkConnectionDescriptor* ndesc) const;
71 :
72 : template<class T>
73 0 : const T* get_dal(std::string uid) const {
74 0 : return m_config->get<T>(uid);
75 : }
76 :
77 : template<class T>
78 0 : const T* get_dal(conffwk::ConfigObject& obj) const {
79 0 : return m_config->get<T>(obj);
80 : }
81 :
82 : void
83 0 : update_modules(const std::vector<const confmodel::DaqModule*>& modules) {
84 0 : auto app = m_config->get<SmartDaqApplication>(m_app_uid);
85 0 : if (!app->get_modules().empty()) {
86 0 : throw (BadConf(ERS_HERE,
87 0 : "SmartDaqApplication contains DaqModules which would be overwritten by generated DaqModules"));
88 : }
89 0 : if (!modules.empty()) {
90 0 : const_cast<SmartDaqApplication*>(app)->set_modules(modules);
91 0 : m_config->update<SmartDaqApplication>({m_app_uid}, {}, {});
92 : }
93 0 : }
94 :
95 : };
96 :
97 : } // namespace dunedaq::appmodel
98 :
99 : #endif // APPMODEL_INCLUDE_OBJECTFACTORY_HPP_
|