Line data Source code
1 : /**
2 : * @file CRTReaderApplication.cpp
3 : *
4 : * Implementation of CRTReaderApplication's generate_modules dal method
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 :
11 : #include "appmodel/CRTReaderApplication.hpp"
12 :
13 : #include "appmodel/appmodelIssues.hpp"
14 :
15 : #include "appmodel/DataReaderConf.hpp"
16 : #include "appmodel/SocketWriterConf.hpp"
17 : #include "appmodel/SocketWriterModule.hpp"
18 : #include "appmodel/DataMoveCallbackConf.hpp"
19 : #include "appmodel/QueueConnectionRule.hpp"
20 : #include "appmodel/QueueDescriptor.hpp"
21 :
22 : #include "ConfigObjectFactory.hpp"
23 :
24 : #include "confmodel/Connection.hpp"
25 : #include "confmodel/DetectorStream.hpp"
26 : #include "confmodel/DetectorToDaqConnection.hpp"
27 :
28 : #include "logging/Logging.hpp"
29 :
30 : #include <fmt/core.h>
31 :
32 : #include <string>
33 : #include <vector>
34 :
35 : namespace dunedaq::appmodel {
36 :
37 : std::vector<const confmodel::Resource*>
38 0 : CRTReaderApplication::contained_resources() const {
39 0 : return to_resources(get_detector_connections());
40 : }
41 :
42 : void
43 0 : CRTReaderApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
44 : {
45 :
46 0 : TLOG_DEBUG(6) << "Generating modules for application " << this->UID();
47 :
48 0 : std::vector<const confmodel::DaqModule*> modules;
49 :
50 0 : ConfigObjectFactory obj_fac(this);
51 :
52 : //
53 : // Extract basic configuration objects
54 : //
55 :
56 : // Data reader
57 0 : const auto reader_conf = get_data_reader();
58 0 : if (reader_conf == 0) {
59 : throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
60 : }
61 0 : const std::string reader_class = reader_conf->get_template_for();
62 :
63 : // Data writers
64 0 : const auto writer_confs = get_data_writers();
65 0 : if (writer_confs.size() == 0) {
66 0 : throw(BadConf(ERS_HERE, "No DataWriterModule configuration given"));
67 : }
68 :
69 : //
70 : // Get the callback descriptor
71 : //
72 0 : const DataMoveCallbackDescriptor* raw_data_callback_desc = get_callback_desc();
73 :
74 0 : if (raw_data_callback_desc == nullptr) {
75 : throw(BadConf(ERS_HERE, "No Raw Data Callback descriptor given"));
76 : }
77 :
78 : //
79 : // Scan Detector 2 DAQ connections to extract sender, receiver and stream information
80 : //
81 :
82 : // Loop over the detector to daq connections and generate one data reader per connection
83 :
84 : // Collect all streams
85 0 : std::map<uint32_t, const appmodel::DataMoveCallbackConf*> callback_confs_by_sid;
86 :
87 0 : uint16_t conn_idx = 0;
88 :
89 0 : for (auto d2d_conn : get_detector_connections()) {
90 :
91 : // Are we sure?
92 0 : if (helper->is_disabled(d2d_conn)) {
93 0 : TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
94 0 : continue;
95 0 : }
96 :
97 0 : TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
98 : // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
99 :
100 0 : std::vector<const confmodel::DetectorStream*> enabled_det_streams;
101 : // Loop over streams
102 0 : for (auto stream : d2d_conn->streams()) {
103 :
104 : // Are we sure?
105 0 : if (helper->is_disabled(stream)) {
106 0 : TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
107 0 : continue;
108 0 : }
109 :
110 0 : enabled_det_streams.push_back(stream);
111 0 : }
112 :
113 : // Create the raw data callbacks
114 0 : std::vector<const conffwk::ConfigObject*> raw_data_callback_objs;
115 :
116 : // Create data queues
117 0 : for (auto ds : enabled_det_streams) {
118 0 : conffwk::ConfigObject callback_obj = obj_fac.create_callback_sid_obj(raw_data_callback_desc, ds->get_source_id());
119 0 : const auto* callback_conf = obj_fac.get_dal<DataMoveCallbackConf>(callback_obj.UID());
120 0 : raw_data_callback_objs.push_back(&callback_conf->config_object());
121 0 : callback_confs_by_sid[ds->get_source_id()] = callback_conf;
122 0 : }
123 :
124 : //-----------------------------------------------------------------
125 : //
126 : // Create DataReaderModule object
127 : //
128 :
129 : //
130 : // Instantiate DataReaderModule of type CRTBernReaderModule/CRTGrenobleReaderModule
131 : //
132 :
133 : // Create the Data reader object
134 :
135 0 : std::string reader_uid(fmt::format("crtdatareader-{}-{}", this->UID(), std::to_string(conn_idx++)));
136 0 : TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
137 0 : auto reader_obj = obj_fac.create(reader_class, reader_uid);
138 :
139 : // Populate configuration and interfaces (leave output queues for later)
140 0 : reader_obj.set_obj("configuration", &reader_conf->config_object());
141 0 : reader_obj.set_objs("connections", { &d2d_conn->config_object() });
142 0 : reader_obj.set_objs("raw_data_callbacks", raw_data_callback_objs);
143 :
144 0 : modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(reader_obj.UID()));
145 :
146 : //-----------------------------------------------------------------
147 : //
148 : // Create DataWriterModule objects
149 : //
150 :
151 : //
152 : // Instantiate DataWriterModule of type SocketWriterModule
153 : //
154 :
155 : // Create the SocketWriterModule objects
156 :
157 0 : conn_idx = 0;
158 :
159 0 : for (const auto writer_conf : writer_confs) {
160 :
161 0 : const std::string writer_class = writer_conf->get_template_for();
162 :
163 0 : std::string writer_uid(fmt::format("socketdatawriter-{}-{}", this->UID(), std::to_string(conn_idx++)));
164 0 : TLOG_DEBUG(6) << fmt::format(
165 0 : "Creating OKS configuration object for socket data writer class {} with id {}", writer_class, writer_uid);
166 0 : auto writer_obj = obj_fac.create(writer_class, writer_uid);
167 :
168 : // Populate configuration and interfaces
169 0 : writer_obj.set_obj("configuration", &writer_conf->config_object());
170 0 : writer_obj.set_objs("connections", {&d2d_conn->config_object()});
171 :
172 0 : modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(writer_obj.UID()));
173 0 : }
174 0 : }
175 :
176 0 : obj_fac.update_modules(modules);
177 0 : }
178 :
179 : } // namespace dunedaq::appmodel
|