DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
NP02ReadoutApplication.cpp
Go to the documentation of this file.
1
10
18#include "confmodel/Session.hpp"
19
23
26
29
32#include "confmodel/GeoId.hpp"
35#include "confmodel/Service.hpp"
36
43
55
56
58
59#include "logging/Logging.hpp"
60#include <fmt/core.h>
61
62#include <string>
63#include <vector>
64
65// using namespace dunedaq;
66// using namespace dunedaq::appmodel;
67
68namespace dunedaq {
69namespace appmodel {
70
71//-----------------------------------------------------------------------------
72void
73NP02ReadoutApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
74{
75
76 TLOG_DEBUG(6) << "Generating modules for application " << this->UID();
77
78 ConfigObjectFactory obj_fac(this);
79
80 //
81 // Extract basic configuration objects
82 //
83
84 // Data reader
85 auto reader_conf = get_data_reader();
86 if (reader_conf == 0) {
87 throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
88 }
89 std::string reader_class = reader_conf->get_template_for();
90
91 // Link handler
92 auto dlh_conf = get_link_handler();
93 // What is template for?
94 auto dlh_class = dlh_conf->get_template_for();
95
96 auto tph_conf = get_tp_handler();
97 if (tph_conf==nullptr && get_tp_generation_enabled()) {
98 throw(BadConf(ERS_HERE, "TP generation is enabled but there is no TP data handler configuration"));
99 }
100
101 std::string tph_class = "";
102 if (tph_conf != nullptr && get_tp_generation_enabled()) {
103 tph_class = tph_conf->get_template_for();
104 }
105
106 //
107 // Process the queue rules looking for inputs to our DL/TP handler modules
108 //
109 const QueueDescriptor* dlh_reqinput_qdesc = nullptr;
110 const QueueDescriptor* tp_input_qdesc = nullptr;
111 // const QueueDescriptor* tpReqInputQDesc = nullptr;
112 const QueueDescriptor* fa_output_qdesc = nullptr;
113
114 for (auto rule : get_queue_rules()) {
115 auto destination_class = rule->get_destination_class();
116 auto data_type = rule->get_descriptor()->get_data_type();
117 // Why datahander here?
118 if (destination_class == "DataHandlerModule" || destination_class == dlh_class || destination_class == tph_class) {
119 if (data_type == "DataRequest") {
120 dlh_reqinput_qdesc = rule->get_descriptor();
121 } else if ((data_type == "TriggerPrimitive" || data_type == "TriggerPrimitiveVector") && get_tp_generation_enabled()) {
122 tp_input_qdesc = rule->get_descriptor();
123 }
124 } else if (destination_class == "FragmentAggregatorModule") {
125 fa_output_qdesc = rule->get_descriptor();
126 }
127 }
128
129 //
130 // Process the network rules looking for the Fragment Aggregator and TP handler data reuest inputs
131 //
132 const NetworkConnectionDescriptor* fa_net_desc = nullptr;
133 const NetworkConnectionDescriptor* tp_net_desc = nullptr;
134 const NetworkConnectionDescriptor* ta_net_desc = nullptr;
135 const NetworkConnectionDescriptor* ts_net_desc = nullptr;
136 for (auto rule : get_network_rules()) {
137 auto endpoint_class = rule->get_endpoint_class();
138 auto data_type = rule->get_descriptor()->get_data_type();
139
140 if (endpoint_class == "FragmentAggregatorModule") {
141 fa_net_desc = rule->get_descriptor();
142 } else if (data_type == "TPSet") {
143 tp_net_desc = rule->get_descriptor();
144 } else if (data_type == "TriggerActivity") {
145 ta_net_desc = rule->get_descriptor();
146 } else if (data_type == "TimeSync") {
147 ts_net_desc = rule->get_descriptor();
148 }
149 }
150
151 // Create here the Queue on which all data fragments are forwarded to the fragment aggregator
152 // and a container for the queues of data request to TP handler and DLH
153 if (fa_output_qdesc == nullptr) {
154 throw(BadConf(ERS_HERE, "No fragment output queue descriptor given"));
155 }
156 std::vector<const confmodel::Connection*> req_queues;
157 conffwk::ConfigObject frag_queue_obj = obj_fac.create_queue_obj(fa_output_qdesc);
158
159 //
160 // Get the callback descriptor
161 //
162 const DataMoveCallbackDescriptor* raw_data_callback_desc = get_callback_desc();
163
164 if (raw_data_callback_desc == nullptr) {
165 throw(BadConf(ERS_HERE, "No Raw Data Callback descriptor given"));
166 }
167
168 //
169 // Scan Detector 2 DAQ connections to extract sender, receiver and stream information
170 //
171
172 std::vector<const confmodel::DaqModule*> modules;
173
174 // Loop over the detector to daq connections and generate one data reader per connection
175 // and the cooresponding datalink handlers
176
177 // Collect all streams
178 std::vector<std::pair<int16_t, const confmodel::DetectorStream*>> all_enabled_det_streams;
179 std::map<uint32_t, const appmodel::DataMoveCallbackConf*> callback_confs_by_sid;
180
181 std::vector<const conffwk::ConfigObject*> d2d_conn_objs;
182 uint16_t conn_idx = 0;
183
184
185 std::set<int16_t> numas;
186 for (auto d2d_conn : get_detector_connections()) {
187 uint16_t receiver_numa = 0;
188
189 // Are we sure?
190 if (helper->is_disabled(d2d_conn)) {
191 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
192 continue;
193 }
194
195 d2d_conn_objs.push_back(&d2d_conn->config_object());
196
197 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
198 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
199
200 if (d2d_conn->senders().empty()) {
201 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain sebders or receivers"));
202 }
203 if (d2d_conn->receiver() == nullptr) {
204 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain a receiver"));
205 }
206
207 // Loop over detector 2 daq connections to find senders and receivers
208 auto det_senders = d2d_conn->senders();
209 auto det_receiver = d2d_conn->receiver();
210
211 // Here I want to resolve the type of connection (network, felix, or?)
212 // Rules of engagement: if the receiver interface is network or felix, the receivers should be castable to the counterpart
213 bool requires_dpdk = (reader_class == "DPDKReaderModule" || reader_class == "FDFakeReaderModule");
214
215 if (reader_class == "DPDKReaderModule" || reader_class == "SocketReaderModule" || reader_class == "FDFakeReaderModule") {
216 if ((requires_dpdk && !det_receiver->cast<appmodel::DPDKReceiver>()) || // SSB: Note here, we are intrinsically locking FakeCard readout to only emulate DPDK data reception. Given NP02ReadoutApplication is intended for TDE readout at NP02, assuming this is OK.
217 (reader_class == "SocketReaderModule" && !det_receiver->cast<appmodel::SocketReceiver>())) {
218 std::string required_class = requires_dpdk ? "DPDKReceiver" : "SocketReceiver";
219 throw(BadConf(ERS_HERE, fmt::format("{} requires {}, found {} of class {}", reader_class, required_class, det_receiver->UID(), det_receiver->class_name())));
220 }
221
222 // SSB: Note that here you need to include FDFakeCardReader as well, because emulated readout needs some way to map NUMA to streams
223 // Since we require a receiver in the NetworkDetector2DAQConnections this would still work if the receiver type is a DPDKReceiver
224 if (reader_class == "DPDKReaderModule" || reader_class == "FDFakeReaderModule") {
225 auto dpdk_reciever = det_receiver->cast<appmodel::DPDKReceiver>();
226 receiver_numa = (int16_t)dpdk_reciever->get_uses()->get_numa_id();
227 TLOG_DEBUG(7) << "receiver numa: " << receiver_numa;
228 }
229
230 bool all_nw_senders = true;
231 for (auto s : det_senders) {
232 all_nw_senders &= (s->cast<appmodel::NWDetDataSender>() != nullptr);
233 }
234
235 // Ensure that all senders are compatible with receiver
236 if (!all_nw_senders) {
237 throw(BadConf(ERS_HERE, "Non-network DetDataSener found with NWreceiver"));
238 }
239 }
240
241 std::vector<const confmodel::DetectorStream*> enabled_det_streams;
242 // Loop over senders
243 for (auto stream : d2d_conn->streams()) {
244
245 // Are we sure?
246 if (helper->is_disabled(stream)) {
247 TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
248 continue;
249 }
250
251 // loop over streams
252 all_enabled_det_streams.push_back(std::make_pair(receiver_numa, stream));
253 enabled_det_streams.push_back(stream);
254 numas.insert(receiver_numa);
255 }
256
257 }
258
259 //-----------------------------------------------------------------
260 //
261 // Create DataReaderModule object
262 //
263
264 //
265 // Instantiate DataReaderModule of type DPDKReaderModule
266 //
267
268 // Create the Data reader object
269
270 std::string reader_uid(fmt::format("datareader-{}-{}", this->UID(), std::to_string(conn_idx++)));
271 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
272 auto reader_obj = obj_fac.create(reader_class, reader_uid);
273
274 // Populate configuration and interfaces (leave output queues for later)
275 reader_obj.set_obj("configuration", &reader_conf->config_object());
276 reader_obj.set_objs("connections", d2d_conn_objs);
277
278 // Create the raw data callbacks
279 std::vector<const conffwk::ConfigObject*> raw_data_callback_objs;
280
281 // Create data queues
282 for (auto& [numa, ds] : all_enabled_det_streams) {
283 conffwk::ConfigObject callback_obj = obj_fac.create_callback_sid_obj(raw_data_callback_desc, ds->get_source_id());
284 const auto* callback_conf = obj_fac.get_dal<DataMoveCallbackConf>(callback_obj.UID());
285 raw_data_callback_objs.push_back(&callback_conf->config_object());
286 callback_confs_by_sid[ds->get_source_id()] = callback_conf;
287 }
288
289 reader_obj.set_objs("raw_data_callbacks", raw_data_callback_objs);
290
291 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(reader_obj.UID()));
292
293
294
295
296 //-----------------------------------------------------------------
297 //
298 // Prepare the tp handlers and related queues
299 //
300 std::vector<std::pair<uint32_t, const confmodel::Connection*>> tp_queues;
301
303
304 // Create TP handler object
305 auto tph_conf_obj = tph_conf->config_object();
306 auto tpsrc_ids = get_tp_source_ids();
307
308 if ((tpsrc_ids.size() % 3) > 0) {
309 throw(BadConf(ERS_HERE, fmt::format("number of TP source IDs must be a multiple of 3, current amount: {}", tpsrc_ids.size())));
310 }
311
312 for (auto sid : tpsrc_ids) {
313 conffwk::ConfigObject tp_queue_obj;
314 conffwk::ConfigObject tpreq_queue_obj;
315 std::string tp_uid("tphandler-" + std::to_string(sid->get_sid()));
316 auto tph_obj = obj_fac.create(tph_class, tp_uid);
317 tph_obj.set_by_val<uint32_t>("source_id", sid->get_sid());
318 tph_obj.set_by_val<uint32_t>("detector_id", 1); // 1 == kDAQ
319 tph_obj.set_by_val<bool>("post_processing_enabled", get_ta_generation_enabled());
320 tph_obj.set_obj("module_configuration", &tph_conf_obj);
321
322 // Create the TPs aggregator queue (from RawData Handlers to TP handlers)
323 tp_queue_obj = obj_fac.create_queue_sid_obj(tp_input_qdesc, sid->get_sid());
324 tp_queue_obj.set_by_val<uint32_t>("recv_timeout_ms", 50);
325 tp_queue_obj.set_by_val<uint32_t>("send_timeout_ms", 1);
326
327 tp_queues.push_back(std::make_pair(sid->get_sid(), obj_fac.get_dal<confmodel::Connection>(tp_queue_obj.UID())));
328 // Create tp data requests queue from Fragment Aggregator
329 tpreq_queue_obj = obj_fac.create_queue_sid_obj(dlh_reqinput_qdesc, sid->get_sid());
330 req_queues.push_back(obj_fac.get_dal<confmodel::Connection>(tpreq_queue_obj.UID()));
331
332 // Create the tp(set) publishing service
333 conffwk::ConfigObject tp_net_obj = obj_fac.create_net_obj(tp_net_desc, tp_uid);
334
335 // Create the ta(set) publishing service
336 conffwk::ConfigObject ta_net_obj = obj_fac.create_net_obj(ta_net_desc, tp_uid);
337
338 // Register queues with tp handler
339 tph_obj.set_objs("inputs", { &tp_queue_obj, &tpreq_queue_obj });
340 tph_obj.set_objs("outputs", { &tp_net_obj, &ta_net_obj, &frag_queue_obj });
341 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(tph_obj.UID()));
342 }
343 }
344
345 // Add output queueus of tps
346 std::vector<std::pair<uint32_t, const conffwk::ConfigObject*>> tp_queue_objs;
347 for (auto q : tp_queues) {
348 tp_queue_objs.push_back(std::make_pair(q.first, &q.second->config_object()));
349 }
350
351 //-----------------------------------------------------------------
352 //
353 // Create datalink handlers
354 //
355 // Recover the emulation flag
356
357 auto lb_conf = dlh_conf->get_latency_buffer();
358
359 std::map<int16_t, conffwk::ConfigObject> numa_dhlconf_map;
360 for ( int16_t numa : numas ) {
361 auto lb_confobj_numa = obj_fac.create(lb_conf->class_name(), fmt::format("{}-numa{}",lb_conf->UID(), numa));
362 lb_confobj_numa.set_by_val<uint32_t>("size", lb_conf->get_size());
363 lb_confobj_numa.set_by_val<bool>("numa_aware", lb_conf->get_numa_aware());
364 lb_confobj_numa.set_by_val<int16_t>("numa_node", numa);
365 lb_confobj_numa.set_by_val<bool>("intrinsic_allocator", lb_conf->get_intrinsic_allocator());
366 lb_confobj_numa.set_by_val<uint32_t>("alignment_size", lb_conf->get_alignment_size());
367 lb_confobj_numa.set_by_val<bool>("preallocation", lb_conf->get_preallocation());
368
369 auto dhl_confobj_numa = obj_fac.create(dlh_conf->class_name(), fmt::format("{}-numa{}",dlh_conf->UID(), numa));
370 dhl_confobj_numa.set_by_val<std::string>("template_for", dlh_conf->get_template_for());
371 dhl_confobj_numa.set_by_val<std::string>("input_data_type", dlh_conf->get_input_data_type());
372 dhl_confobj_numa.set_by_val<bool>("generate_timesync", dlh_conf->get_generate_timesync());
373 dhl_confobj_numa.set_by_val<uint64_t>("post_processing_delay_ticks", dlh_conf->get_post_processing_delay_ticks());
374 dhl_confobj_numa.set_by_val<std::string>("input_data_type", dlh_conf->get_input_data_type());
375 dhl_confobj_numa.set_obj("request_handler", &dlh_conf->get_request_handler()->config_object());
376 dhl_confobj_numa.set_obj("latency_buffer", &lb_confobj_numa);
377 dhl_confobj_numa.set_obj("data_processor", &dlh_conf->get_data_processor()->config_object());
378
379
380 numa_dhlconf_map[numa] = dhl_confobj_numa;
381
382 }
383
384 auto emulation_mode = reader_conf->get_emulation_mode();
385 for (auto& [numa, ds] : all_enabled_det_streams) {
386 uint32_t sid = ds->get_source_id();
387 TLOG_DEBUG(6) << fmt::format("Processing stream {}, id {}, det id {}", ds->UID(), ds->get_source_id(), ds->get_geo_id()->get_detector_id());
388 std::string uid(fmt::format("DLH-{}", sid));
389 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data Link Handler class {}, if {}", dlh_class, sid);
390 auto dlh_obj = obj_fac.create(dlh_class, uid);
391 dlh_obj.set_by_val<uint32_t>("source_id", sid);
392 dlh_obj.set_by_val<uint32_t>("detector_id", ds->get_geo_id()->get_detector_id());
393 dlh_obj.set_by_val<bool>("post_processing_enabled", get_tp_generation_enabled());
394 dlh_obj.set_by_val<bool>("emulation_mode", emulation_mode);
395 dlh_obj.set_obj("geo_id", &ds->get_geo_id()->config_object());
396 dlh_obj.set_obj("module_configuration", &numa_dhlconf_map[numa]);
397 dlh_obj.set_obj("raw_data_callback", &callback_confs_by_sid[sid]->config_object());
398
399 std::vector<const conffwk::ConfigObject*> dlh_ins, dlh_outs;
400
401 // Create request queue
402 conffwk::ConfigObject req_queue_obj = obj_fac.create_queue_sid_obj(dlh_reqinput_qdesc, ds);
403
404
405 // Add the requessts queue dal pointer to the outputs of the FragmentAggregatorModule
406 req_queues.push_back(obj_fac.get_dal<confmodel::Connection>(req_queue_obj.UID()));
407 dlh_ins.push_back(&req_queue_obj);
408 dlh_outs.push_back(&frag_queue_obj);
409
410
411 // Time Sync network connection
412 if (dlh_conf->get_generate_timesync()) {
413 // Add timestamp endpoint
414 conffwk::ConfigObject ts_net_obj = obj_fac.create_net_obj(ts_net_desc, std::to_string(sid));
415 dlh_outs.push_back(&ts_net_obj);
416 }
417
418 // here, we want to select which tp queues to add to the output, to separate mutiple detector elements
419 for (auto tpq : tp_queue_objs) {
420 if ((sid / 100) == (tpq.first / 10)) {
421 dlh_outs.push_back(tpq.second);
422 }
423 }
424 dlh_obj.set_objs("inputs", dlh_ins);
425 dlh_obj.set_objs("outputs", dlh_outs);
426
427 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(dlh_obj.UID()));
428 }
429
430
431 // Finally create Fragment Aggregator
432 auto aggregator_conf = get_fragment_aggregator();
433 if (aggregator_conf == 0) {
434 throw(BadConf(ERS_HERE, "No FragmentAggregatorModule configuration given"));
435 }
436 std::string faUid("fragmentaggregator-" + UID());
437 // conffwk::ConfigObject frag_aggr;
438 TLOG_DEBUG(7) << "creating OKS configuration object for Fragment Aggregator class ";
439 auto frag_aggr = obj_fac.create("FragmentAggregatorModule", faUid);
440 conffwk::ConfigObject fa_net_obj = obj_fac.create_net_obj(fa_net_desc);
441
442 // Process special Network rules!
443 // Looking for Fragment rules from DFAppplications in current Session
444 std::vector<conffwk::ConfigObject> fragOutObjs;
445 for (auto [uid, descriptor]:
446 helper->get_netdescriptors("Fragment", "DFApplication")) {
447 std::string dreqNetUid(descriptor->get_uid_base() + uid);
448 auto frag_conn = obj_fac.create("NetworkConnection", dreqNetUid);
449
450 frag_conn.set_by_val<std::string>("data_type", descriptor->get_data_type());
451 frag_conn.set_by_val<std::string>("connection_type", descriptor->get_connection_type());
452 // Override capacity, set to 2x expected number of Fragments
453 frag_conn.set_by_val<int>("capacity", all_enabled_det_streams.size() * 2);
454
455 auto serviceObj = descriptor->get_associated_service()->config_object();
456 frag_conn.set_obj("associated_service", &serviceObj);
457 fragOutObjs.push_back(frag_conn);
458 }
459
460 // Add output queueus of data requests and Fragments
461 std::vector<const conffwk::ConfigObject*> fa_output_objs;
462 for (auto& fNet : fragOutObjs) {
463 fa_output_objs.push_back(&fNet);
464 }
465
466 for (auto& q : req_queues) {
467 fa_output_objs.push_back(&q->config_object());
468 }
469
470 frag_aggr.set_obj("configuration", &aggregator_conf->config_object());
471 frag_aggr.set_objs("inputs", { &fa_net_obj, &frag_queue_obj });
472 frag_aggr.set_objs("outputs", fa_output_objs);
473
474 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(frag_aggr.UID()));
475
476 obj_fac.update_modules(modules);
477} // NOLINT
478
479
480} // namespace appmodel
481} // namespace dunedaq
#define ERS_HERE
void update_modules(const std::vector< const confmodel::DaqModule * > &modules)
conffwk::ConfigObject create_queue_sid_obj(const QueueDescriptor *qdesc, uint32_t src_id) const
conffwk::ConfigObject create_callback_sid_obj(const DataMoveCallbackDescriptor *cdesc, uint32_t src_id) const
conffwk::ConfigObject create_net_obj(const NetworkConnectionDescriptor *ndesc, std::string uid) const
Helper function that gets a network connection config.
const T * get_dal(std::string uid) const
conffwk::ConfigObject create_queue_obj(const QueueDescriptor *qdesc, std::string uid="") const
conffwk::ConfigObject create(const std::string &class_name, const std::string &id) const
const dunedaq::confmodel::NetworkDevice * get_uses() const
Get "uses" relationship value.
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
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.
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.
void set_by_val(const std::string &name, T value)
Set attribute value.
void set_objs(const std::string &name, const std::vector< const ConfigObject * > &o, bool skip_non_null_check=false)
Set relationship multi-value.
const std::string & UID() const noexcept
Return object identity.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
const ConfigObject & config_object() const
const std::string & UID() const noexcept
uint8_t get_numa_id() const
Get "numa_id" attribute value.
conffwk entry point
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
The DUNE-DAQ namespace.
Definition access.hpp:13
CTB Buffer std::string descriptor CTB Repeated Word std::string descriptor descriptor