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/DataMoveCallbackDescriptor.hpp"
14 : #include "appmodel/NetworkConnectionDescriptor.hpp"
15 : #include "appmodel/QueueDescriptor.hpp"
16 : #include "appmodel/SmartDaqApplication.hpp"
17 : #include "appmodel/appmodelIssues.hpp"
18 :
19 : #include "conffwk/ConfigObject.hpp"
20 : #include "conffwk/Configuration.hpp"
21 :
22 : #include "confmodel/DaqModule.hpp"
23 : #include "confmodel/DetectorStream.hpp"
24 :
25 : #include <cstdint>
26 : #include <string>
27 : #include <vector>
28 :
29 : namespace dunedaq::appmodel {
30 :
31 : class ConfigObjectFactory
32 : {
33 :
34 : conffwk::Configuration* m_config;
35 : std::string m_dbfile;
36 : std::string m_app_uid;
37 :
38 : public:
39 : explicit ConfigObjectFactory(const SmartDaqApplication*);
40 :
41 : ~ConfigObjectFactory();
42 :
43 : [[nodiscard]] conffwk::ConfigObject create(const std::string& class_name, const std::string& id) const;
44 :
45 : //---
46 0 : [[nodiscard]] conffwk::ConfigObject create_queue_obj(const QueueDescriptor* qdesc, std::string uid = "") const;
47 :
48 : //---
49 : [[nodiscard]] conffwk::ConfigObject create_queue_sid_obj(const QueueDescriptor* qdesc, uint32_t src_id) const;
50 :
51 : //---
52 : [[nodiscard]] conffwk::ConfigObject create_queue_sid_obj(const QueueDescriptor* qdesc,
53 : const confmodel::DetectorStream* stream) const;
54 :
55 : //---
56 : [[nodiscard]] conffwk::ConfigObject create_callback_sid_obj(const DataMoveCallbackDescriptor* cdesc,
57 : uint32_t src_id) const;
58 :
59 : /**
60 : * \brief Helper function that gets a network connection config
61 : *
62 : * \param uid Unique ID name of the config object
63 : * \param ndesc Network connection descriptor object
64 : *
65 : * \ret OKS configuration object for the network connection
66 : */
67 : [[nodiscard]] conffwk::ConfigObject create_net_obj(const NetworkConnectionDescriptor* ndesc, std::string uid) const;
68 :
69 : [[nodiscard]] conffwk::ConfigObject create_net_obj(const NetworkConnectionDescriptor* ndesc) const;
70 :
71 : template<class T>
72 0 : const T* get_dal(std::string uid) const
73 : {
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 : {
80 0 : return m_config->get<T>(obj);
81 : }
82 :
83 0 : void update_modules(const std::vector<const confmodel::DaqModule*>& modules)
84 : {
85 0 : auto app = m_config->get<SmartDaqApplication>(m_app_uid);
86 0 : if (!app->get_modules().empty()) {
87 0 : throw(BadConf(ERS_HERE,
88 0 : "SmartDaqApplication contains DaqModules which would be overwritten by generated DaqModules"));
89 : }
90 0 : if (!modules.empty()) {
91 0 : const_cast<SmartDaqApplication*>(app)->set_modules(modules);
92 0 : m_config->update<SmartDaqApplication>({ m_app_uid }, {}, {});
93 : }
94 0 : }
95 : };
96 :
97 : } // namespace dunedaq::appmodel
98 :
99 : #endif // APPMODEL_INCLUDE_OBJECTFACTORY_HPP_
|