DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ReadoutApplication.cpp
Go to the documentation of this file.
1
10
11
12
21#include "confmodel/Session.hpp"
22
26
29
32
34#include "confmodel/GeoId.hpp"
37#include "confmodel/Service.hpp"
38
45
55
56
57
59
60#include "logging/Logging.hpp"
61#include <fmt/core.h>
62
63#include <string>
64#include <vector>
65
66// using namespace dunedaq;
67// using namespace dunedaq::appmodel;
68
69namespace dunedaq {
70namespace appmodel {
71
72//-----------------------------------------------------------------------------
73
74std::vector<const confmodel::Resource*>
78
79void
80ReadoutApplication::generate_modules(std::shared_ptr<ConfigurationHelper> helper) const {
81
82 TLOG_DEBUG(6) << "Generating modules for application " << this->UID();
83
84 ConfigObjectFactory obj_fac(this);
85 // conffwk::Configuration& confdb = this->configuration();
86
87 //
88 // Extract basic configuration objects
89 //
90
91 // Data reader
92 auto reader_conf = get_data_reader();
93 if (reader_conf == 0) {
94 throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
95 }
96 std::string reader_class = reader_conf->get_template_for();
97
98 // Link handler
99 auto dlh_conf = get_link_handler();
100 // What is template for?
101 auto dlh_class = dlh_conf->get_template_for();
102
103 auto tph_conf = get_tp_handler();
104 if (tph_conf==nullptr && get_tp_generation_enabled()) {
105 throw(BadConf(ERS_HERE, "TP generation is enabled but there is no TP data handler configuration"));
106 }
107
108 std::string tph_class = "";
109 if (tph_conf != nullptr && get_tp_generation_enabled()) {
110 tph_class = tph_conf->get_template_for();
111 }
112
113 //
114 // Process the queue rules looking for inputs to our DL/TP handler modules
115 //
116 const QueueDescriptor* dlh_reqinput_qdesc = nullptr;
117 const QueueDescriptor* tp_input_qdesc = nullptr;
118 // const QueueDescriptor* tpReqInputQDesc = nullptr;
119 const QueueDescriptor* fa_output_qdesc = nullptr;
120
121 for (auto rule : get_queue_rules()) {
122 auto destination_class = rule->get_destination_class();
123 auto data_type = rule->get_descriptor()->get_data_type();
124 // Why datahander here? It is the base class for several DataHandler types (e.g. FDDataHandlerModule, SNBDataHandlerModule)
125 if (destination_class == "DataHandlerModule" || destination_class == dlh_class || destination_class == tph_class) {
126 if (data_type == "DataRequest") {
127 dlh_reqinput_qdesc = rule->get_descriptor();
128 } else if ((data_type == "TriggerPrimitive" || data_type == "TriggerPrimitiveVector") && get_tp_generation_enabled()) {
129 tp_input_qdesc = rule->get_descriptor();
130 }
131 } else if (destination_class == "FragmentAggregatorModule") {
132 fa_output_qdesc = rule->get_descriptor();
133 }
134 }
135
136 if (dlh_reqinput_qdesc == nullptr) {
137 throw(BadConf(ERS_HERE, "No data link handler request input queue descriptor given"));
138 }
139
140 //
141 // Process the network rules looking for the Fragment Aggregator and TP handler data reuest inputs
142 //
143 const NetworkConnectionDescriptor* fa_net_desc = nullptr;
144 const NetworkConnectionDescriptor* tp_net_desc = nullptr;
145 const NetworkConnectionDescriptor* ta_net_desc = nullptr;
146 const NetworkConnectionDescriptor* ts_net_desc = nullptr;
147 for (auto rule : get_network_rules()) {
148 auto endpoint_class = rule->get_endpoint_class();
149 auto data_type = rule->get_descriptor()->get_data_type();
150
151 if (endpoint_class == "FragmentAggregatorModule") {
152 fa_net_desc = rule->get_descriptor();
153 } else if (data_type == "TPSet") {
154 tp_net_desc = rule->get_descriptor();
155 } else if (data_type == "TriggerActivity") {
156 ta_net_desc = rule->get_descriptor();
157 } else if (data_type == "TimeSync") {
158 ts_net_desc = rule->get_descriptor();
159 }
160 }
161
162 if (fa_net_desc == nullptr) {
163 throw(BadConf(ERS_HERE, "No Fragment Aggregator network descriptor given"));
164 }
165 if (ts_net_desc == nullptr && dlh_conf->get_generate_timesync()) {
166 throw(BadConf(ERS_HERE, "No Time Sync network descriptor given but time sync generation is enabled"));
167 }
168
169 //
170 // Get the callback descriptor
171 //
172 const DataMoveCallbackDescriptor* raw_data_callback_desc = get_callback_desc();
173
174 if (raw_data_callback_desc == nullptr) {
175 throw(BadConf(ERS_HERE, "No Raw Data Callback descriptor given"));
176 }
177
178 // Create here the Queue on which all data fragments are forwarded to the fragment aggregator
179 // and a container for the queues of data request to TP handler and DLH
180 if (fa_output_qdesc == nullptr) {
181 throw(BadConf(ERS_HERE, "No fragment output queue descriptor given"));
182 }
183 std::vector<const confmodel::Connection*> req_queues;
184 conffwk::ConfigObject frag_queue_obj = obj_fac.create_queue_obj(fa_output_qdesc);
185
186 //
187 // Scan Detector 2 DAQ connections to extract sender, receiver and stream information
188 //
189
190 std::vector<const confmodel::DaqModule*> modules;
191
192 // Loop over the detector to daq connections and generate one data reader per connection
193 // and the cooresponding datalink handlers
194
195 // Collect all streams
196 std::vector<const confmodel::DetectorStream*> all_enabled_det_streams;
197 std::map<uint32_t, const appmodel::DataMoveCallbackConf*> callback_confs_by_sid;
198
199 // std::vector<const conffwk::ConfigObject*> d2d_conn_objs;
200 uint16_t conn_idx = 0;
201
202 for (auto d2d_conn : get_detector_connections()) {
203 if (helper->is_disabled(d2d_conn)) {
204 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
205 continue;
206 }
207
208 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
209
210 // Are these tests necessary? Schema does not allow 0 cardinality
211 // for these relationships!! TODO
212 if (d2d_conn->senders().empty()) {
213 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders"));
214 }
215 if (d2d_conn->receiver() == nullptr) {
216 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain a receiver"));
217 }
218
219 // Find senders and receiver
220 auto det_senders = d2d_conn->senders();
221 auto det_receiver = d2d_conn->receiver();
222
223 std::vector<const confmodel::DetectorStream*> enabled_det_streams;
224 // Loop over streams
225 for (auto stream : d2d_conn->streams()) {
226
227 // Are we sure?
228 if (helper->is_disabled(stream)) {
229 TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
230 continue;
231 }
232
233 all_enabled_det_streams.push_back(stream);
234 enabled_det_streams.push_back(stream);
235 }
236
237
238 // Here I want to resolve the type of connection (network, felix, or?)
239 // Rules of engagement: if the receiver interface is network or felix, the receivers should be castable to the counterpart
240 if (reader_class == "DPDKReaderModule") {
241 if (!d2d_conn->castable("NetworkDetectorToDaqConnection")) {
242 throw(BadConf(ERS_HERE, fmt::format("{} requires NetworkDetectorToDaqConnection, found {} of class {}", reader_class, d2d_conn->UID(), d2d_conn->class_name())));
243 }
244 if (!det_receiver->cast<appmodel::DPDKReceiver>()) {
245 throw(BadConf(ERS_HERE, fmt::format("{} requires NWDetDataReceiver, found {} of class {}", reader_class, det_receiver->UID(), det_receiver->class_name())));
246 }
247 }
248 else if (reader_class == "SocketReaderModule") {
249 if (!d2d_conn->castable("SocketDetectorToDaqConnection")) {
250 throw(BadConf(ERS_HERE, fmt::format("{} requires SocketDetectorToDaqConnection, found {} of class {}", reader_class, d2d_conn->UID(), d2d_conn->class_name())));
251 }
252 if (!det_receiver->cast<appmodel::SocketReceiver>()) {
253 throw(BadConf(ERS_HERE, fmt::format("{} requires SocketReceiver, found {} of class {}", reader_class, det_receiver->UID(), det_receiver->class_name())));
254 }
255 }
256 else if (reader_class == "FelixReaderModule") {
257 if (!d2d_conn->castable("FelixDetectorToDaqConnection")) {
258 throw(BadConf(ERS_HERE, fmt::format("{} requires FelixDetectorToDaqConnection, found {} of class {}", reader_class, d2d_conn->UID(), d2d_conn->class_name())));
259 }
260 if (!det_receiver->cast<appmodel::FelixDataReceiver>()) {
261 throw(BadConf(ERS_HERE, fmt::format("FelixReaderModule requires FelixDataReceiver, found {} of class {}", det_receiver->UID(), det_receiver->class_name())));
262 }
263 }
264 // }
265
266 //-----------------------------------------------------------------
267 //
268 // Create DataReaderModule object
269 //
270
271 //
272 // Instantiate DataReaderModule of type DPDKReaderModule
273 //
274
275 // Create the Data reader object
276
277 std::string reader_uid(fmt::format("datareader-{}-{}", this->UID(), std::to_string(conn_idx++)));
278 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
279 auto reader_obj = obj_fac.create(reader_class, reader_uid);
280
281 // Populate configuration and interfaces (leave output queues for later)
282 reader_obj.set_obj("configuration", &reader_conf->config_object());
283 reader_obj.set_objs("connections", {&d2d_conn->config_object()});
284
285 // Create the raw data callbacks
286 std::vector<const conffwk::ConfigObject*> raw_data_callback_objs;
287
288 // Create data queues
289 for (auto ds : enabled_det_streams) {
290 conffwk::ConfigObject callback_obj = obj_fac.create_callback_sid_obj(raw_data_callback_desc, ds->get_source_id());
291 const auto* callback_conf = obj_fac.get_dal<DataMoveCallbackConf>(callback_obj.UID());
292 raw_data_callback_objs.push_back(&callback_conf->config_object());
293 callback_confs_by_sid[ds->get_source_id()] = callback_conf;
294 }
295
296 reader_obj.set_objs("raw_data_callbacks", raw_data_callback_objs);
297
298 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(reader_obj.UID()));
299 }
300
301
302 //-----------------------------------------------------------------
303 //
304 // Prepare the tp handlers and related queues
305 //
306 std::vector<const confmodel::Connection*> tp_queues;
308 if (tp_input_qdesc == nullptr) {
309 throw(BadConf(ERS_HERE, "TP generation is enabled but no TP input queue descriptor given"));
310 }
311 if (tp_net_desc == nullptr) {
312 throw(BadConf(ERS_HERE, "TP generation is enabled but no TPSet network descriptor given"));
313 }
314 if (ta_net_desc == nullptr) {
315 throw(BadConf(ERS_HERE, "TP generation is enabled but no TriggerActivity network descriptor given"));
316 }
317 // Create TP handler object
318 auto tph_conf_obj = tph_conf->config_object();
319 auto tpsrc_ids = get_tp_source_ids();
320
321 for (auto sid : tpsrc_ids) {
322 conffwk::ConfigObject tp_queue_obj;
323 conffwk::ConfigObject tpreq_queue_obj;
324 std::string tp_uid("tphandler-" + std::to_string(sid->get_sid()));
325 auto tph_obj = obj_fac.create(tph_class, tp_uid);
326 tph_obj.set_by_val<uint32_t>("source_id", sid->get_sid());
327 tph_obj.set_by_val<uint32_t>("detector_id", 1); // 1 == kDAQ
328 tph_obj.set_by_val<bool>("post_processing_enabled", get_ta_generation_enabled());
329 tph_obj.set_obj("module_configuration", &tph_conf_obj);
330
331 // Create the TPs aggregator queue (from RawData Handlers to TP handlers)
332 tp_queue_obj = obj_fac.create_queue_sid_obj(tp_input_qdesc, sid->get_sid());
333 tp_queue_obj.set_by_val<uint32_t>("recv_timeout_ms", 50);
334 tp_queue_obj.set_by_val<uint32_t>("send_timeout_ms", 1);
335
336 tp_queues.push_back(obj_fac.get_dal<confmodel::Connection>(tp_queue_obj.UID()));
337 // Create tp data requests queue from Fragment Aggregator
338 tpreq_queue_obj = obj_fac.create_queue_sid_obj(dlh_reqinput_qdesc, sid->get_sid());
339 req_queues.push_back(obj_fac.get_dal<confmodel::Connection>(tpreq_queue_obj.UID()));
340
341 // Create the tp(set) publishing service
342 conffwk::ConfigObject tp_net_obj = obj_fac.create_net_obj(tp_net_desc, tp_uid);
343
344 // Create the ta(set) publishing service
345 conffwk::ConfigObject ta_net_obj = obj_fac.create_net_obj(ta_net_desc, tp_uid);
346
347 // Register queues with tp hankder
348 tph_obj.set_objs("inputs", { &tp_queue_obj, &tpreq_queue_obj });
349 tph_obj.set_objs("outputs", { &tp_net_obj, &ta_net_obj, &frag_queue_obj });
350
351 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(tph_obj.UID()));
352 }
353 }
354
355 // Add output queueus of tps
356 std::vector<const conffwk::ConfigObject*> tp_queue_objs;
357 for (auto q : tp_queues) {
358 tp_queue_objs.push_back(&q->config_object());
359 }
360
361 //-----------------------------------------------------------------
362 //
363 // Create datalink handlers
364 //
365 // Recover the emulation flag
366 auto emulation_mode = reader_conf->get_emulation_mode();
367 for (auto ds : all_enabled_det_streams) {
368
369 uint32_t sid = ds->get_source_id();
370 TLOG_DEBUG(6) << fmt::format("Processing stream {}, id {}, det id {}", ds->UID(), ds->get_source_id(), ds->get_geo_id()->get_detector_id());
371 std::string uid(fmt::format("DLH-{}", sid));
372 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data Link Handler class {}, if {}", dlh_class, sid);
373 auto dlh_obj = obj_fac.create(dlh_class, uid);
374 dlh_obj.set_by_val<uint32_t>("source_id", sid);
375 dlh_obj.set_by_val<uint32_t>("detector_id", ds->get_geo_id()->get_detector_id());
376 dlh_obj.set_by_val<bool>("post_processing_enabled", get_tp_generation_enabled());
377 dlh_obj.set_by_val<bool>("emulation_mode", emulation_mode);
378 dlh_obj.set_obj("geo_id", &ds->get_geo_id()->config_object());
379 dlh_obj.set_obj("module_configuration", &dlh_conf->config_object());
380 dlh_obj.set_obj("raw_data_callback", &callback_confs_by_sid[sid]->config_object());
381
382 std::vector<const conffwk::ConfigObject*> dlh_ins, dlh_outs;
383
384 // Create request queue
385 conffwk::ConfigObject req_queue_obj = obj_fac.create_queue_sid_obj(dlh_reqinput_qdesc, ds);
386
387
388 // Add the requessts queue dal pointer to the outputs of the FragmentAggregatorModule
389 req_queues.push_back(obj_fac.get_dal<confmodel::Connection>(req_queue_obj.UID()));
390 dlh_ins.push_back(&req_queue_obj);
391 dlh_outs.push_back(&frag_queue_obj);
392
393
394 // Time Sync network connection
395 if (dlh_conf->get_generate_timesync()) {
396 // Add timestamp endpoint
397 conffwk::ConfigObject ts_net_obj = obj_fac.create_net_obj(ts_net_desc, std::to_string(sid));
398 dlh_outs.push_back(&ts_net_obj);
399 }
400
401 for (auto tpq : tp_queue_objs) {
402 dlh_outs.push_back(tpq);
403 }
404 dlh_obj.set_objs("inputs", dlh_ins);
405 dlh_obj.set_objs("outputs", dlh_outs);
406
407 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(dlh_obj.UID()));
408 }
409
410 // Finally create Fragment Aggregator
411 auto aggregator_conf = get_fragment_aggregator();
412 if (aggregator_conf == 0) {
413 throw(BadConf(ERS_HERE, "No FragmentAggregatorModule configuration given"));
414 }
415 std::string faUid("fragmentaggregator-" + UID());
416 // conffwk::ConfigObject frag_aggr;
417 TLOG_DEBUG(7) << "creating OKS configuration object for Fragment Aggregator class ";
418 auto frag_aggr = obj_fac.create("FragmentAggregatorModule", faUid);
419 conffwk::ConfigObject fa_net_obj = obj_fac.create_net_obj(fa_net_desc);
420
421 // Process special Network rules!
422 // Looking for Fragment rules from DFAppplications in current Session
423 std::vector<conffwk::ConfigObject> fragOutObjs;
424 for (auto [uid, descriptor]:
425 helper->get_netdescriptors("Fragment", "DFApplication")) {
426 std::string dreqNetUid(descriptor->get_uid_base() + uid);
427 auto frag_conn = obj_fac.create("NetworkConnection", dreqNetUid);
428
429 frag_conn.set_by_val<std::string>("data_type", descriptor->get_data_type());
430 frag_conn.set_by_val<std::string>("connection_type", descriptor->get_connection_type());
431 // Override capacity, set to 2x expected number of Fragments
432 frag_conn.set_by_val<int>("capacity", all_enabled_det_streams.size() * 2);
433
434 auto serviceObj = descriptor->get_associated_service()->config_object();
435 frag_conn.set_obj("associated_service", &serviceObj);
436 fragOutObjs.push_back(frag_conn);
437 }
438
439 // Add output queueus of data requests and Fragments
440 std::vector<const conffwk::ConfigObject*> fa_output_objs;
441 for (auto& fNet : fragOutObjs) {
442 fa_output_objs.push_back(&fNet);
443 }
444
445 for (auto& q : req_queues) {
446 fa_output_objs.push_back(&q->config_object());
447 }
448
449 frag_aggr.set_obj("configuration", &aggregator_conf->config_object());
450 frag_aggr.set_objs("inputs", { &fa_net_obj, &frag_queue_obj });
451 frag_aggr.set_objs("outputs", fa_output_objs);
452 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(frag_aggr.UID()));
453
454 obj_fac.update_modules(modules);
455}
456
457} // namespace appmodel
458} // namespace dunedaq
#define ERS_HERE
const dunedaq::appmodel::DataHandlerConf * get_tp_handler() const
Get "tp_handler" relationship value.
const std::vector< const dunedaq::confmodel::DetectorToDaqConnection * > & get_detector_connections() const
Get "detector_connections" relationship value. The list of detector channels to be read out by this r...
bool get_ta_generation_enabled() const
Get "ta_generation_enabled" attribute value.
const dunedaq::appmodel::FragmentAggregatorConf * get_fragment_aggregator() const
Get "fragment_aggregator" relationship value.
const std::vector< const dunedaq::appmodel::SourceIDConf * > & get_tp_source_ids() const
Get "tp_source_ids" relationship value.
const dunedaq::appmodel::DataHandlerConf * get_link_handler() const
Get "link_handler" relationship value.
const dunedaq::appmodel::DataMoveCallbackDescriptor * get_callback_desc() const
Get "callback_desc" relationship value.
const dunedaq::appmodel::DataReaderConf * get_data_reader() const
Get "data_reader" relationship value.
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
virtual std::vector< const Resource * > contained_resources() const override
bool get_tp_generation_enabled() const
Get "tp_generation_enabled" attribute value.
const std::vector< const dunedaq::appmodel::NetworkConnectionRule * > & get_network_rules() const
Get "network_rules" relationship value.
const std::vector< const dunedaq::appmodel::QueueConnectionRule * > & get_queue_rules() const
Get "queue_rules" relationship value.
const ConfigObject & config_object() const
const std::string & UID() const noexcept
conffwk entry point
std::vector< const dunedaq::confmodel::Resource * > to_resources(const std::vector< T * > &vector_of_children)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
Including Qt Headers.
Definition module.cpp:16
CIB Buffer std::string descriptor Message from std::string descriptor CIB process std::string descriptor descriptor