DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MLTApplication.cpp
Go to the documentation of this file.
1
13
15
18// #include "confmodel/ReadoutGroup.hpp"
19// #include "confmodel/ReadoutInterface.hpp"
20// #include "confmodel/DetectorStream.hpp"
24#include "confmodel/Service.hpp"
25#include "confmodel/Session.hpp"
26
40#include "appmodel/MLTConf.hpp"
56
57#include "logging/Logging.hpp"
58
59#include <string>
60#include <vector>
61
62namespace dunedaq {
63namespace appmodel {
64
65
66void
68{
69
70 std::vector<const confmodel::DaqModule*> modules;
71
72 ConfigObjectFactory obj_fac(this);
73
74 // auto mlt_conf = get_mlt_conf();
75 // auto mlt_class = mlt_conf->get_template_for();
76
77 auto tch_conf = get_trigger_inputs_handler();
78 auto tch_class = tch_conf->get_template_for();
79
80 auto mlt_conf = get_mlt_conf();
81 auto mlt_class = mlt_conf->get_template_for();
82 std::string handler_name(tch_conf->UID());
83
84 if (!mlt_conf) {
85 throw(BadConf(ERS_HERE, "No MLT configuration in MLTApplication given"));
86 }
87
88 // Queue descriptors
89 // Process the queue rules looking for inputs to our trigger handler modules
90 const QueueDescriptor* tc_inputq_desc = nullptr;
91 const QueueDescriptor* td_outputq_desc = nullptr;
92
93 for (auto rule : get_queue_rules()) {
94 auto destination_class = rule->get_destination_class();
95 auto data_type = rule->get_descriptor()->get_data_type();
96 if (destination_class == tch_class) {
97 tc_inputq_desc = rule->get_descriptor();
98 } else if (destination_class == mlt_class) {
99 td_outputq_desc = rule->get_descriptor();
100 }
101 }
102
103 if (tc_inputq_desc == nullptr) {
104 throw(BadConf(ERS_HERE, "No TC input queue descriptor given"));
105 }
106 if (td_outputq_desc == nullptr) {
107 throw(BadConf(ERS_HERE, "No TD output-input queue descriptor given"));
108 }
109
110 // Create queues
111 auto input_queue_obj = obj_fac.create_queue_obj(tc_inputq_desc);
112 auto output_queue_obj = obj_fac.create_queue_obj(td_outputq_desc);
113
114 // Net descriptors
115 const NetworkConnectionDescriptor* req_net_desc = nullptr;
116 const NetworkConnectionDescriptor* tc_net_desc = nullptr;
117 const NetworkConnectionDescriptor* ti_net_desc = nullptr;
118 const NetworkConnectionDescriptor* td_net_desc = nullptr;
119 const NetworkConnectionDescriptor* timesync_net_desc = nullptr;
120
121 for (auto rule : get_network_rules()) {
122 std::string data_type = rule->get_descriptor()->get_data_type();
123
124 // Network connections for the MLT
125 if (data_type == "TriggerInhibit") {
126 ti_net_desc = rule->get_descriptor();
127 }
128 if (data_type == "TriggerDecision") {
129 td_net_desc = rule->get_descriptor();
130 }
131 if (data_type == "TriggerCandidate") {
132 tc_net_desc = rule->get_descriptor();
133 }
134 if (data_type == "TimeSync") {
135 timesync_net_desc = rule->get_descriptor();
136 }
137 if (data_type == "DataRequest") {
138 req_net_desc = rule->get_descriptor();
139 }
140
141 TLOG_DEBUG(3) << "Endpoint class (currently not used in for networkconnections): data_type: " << data_type;
142 }
143
144 if (!td_net_desc) {
145 throw(BadConf(ERS_HERE, "No MLT network connection for the output TriggerDecision given"));
146 }
147 if (!ti_net_desc) {
148 throw(BadConf(ERS_HERE, "No MLT network connection for the output TriggerInhibit given"));
149 }
150 if (!tc_net_desc) {
151 throw(BadConf(ERS_HERE, "No MLT network connection for the Input of TriggerCandidates given"));
152 }
153 if (!req_net_desc) {
154 throw(BadConf(ERS_HERE, "No MLT network connection for the Input of DataRequests given"));
155 }
156 // Network connection for input TriggerInhibit, input TCs
157
158 conffwk::ConfigObject ti_net_obj =
159 obj_fac.create_net_obj(ti_net_desc, "");
160
161 conffwk::ConfigObject tc_net_obj =
162 obj_fac.create_net_obj(tc_net_desc, ".*");
163
164 // Network connection for output TriggerDecision
165 conffwk::ConfigObject td_net_obj =
166 obj_fac.create_net_obj(td_net_desc, "");
167
168 // Network conection for the input Data Requests
169 conffwk::ConfigObject dr_net_obj =
170 obj_fac.create_net_obj(req_net_desc, UID());
171
172 conffwk::ConfigObject timesync_net_obj;
173 if (timesync_net_desc != nullptr) {
174 timesync_net_obj =
175 obj_fac.create_net_obj(timesync_net_desc, ".*");
176 }
177
178 /**************************************************************
179 * Instantiate standalone TC generator modules (e.g. random TC generator)
180 **************************************************************/
181
182 auto standalone_TC_maker_confs = get_standalone_candidate_maker_confs();
183 std::vector<conffwk::ConfigObject> generated_tc_conns;
184 generated_tc_conns.reserve(standalone_TC_maker_confs.size());
185 for (auto gen_conf : standalone_TC_maker_confs) {
186 conffwk::ConfigObject gen_obj = obj_fac.create(gen_conf->get_template_for(),
187 gen_conf->UID());
188 gen_obj.set_obj("configuration", &(gen_conf->config_object()));
189 if (gen_conf->get_timestamp_method() == "kTimeSync" && !timesync_net_obj.is_null()) {
190 gen_obj.set_objs("inputs", { &timesync_net_obj });
191 }
192
193 auto tc_net_gen = obj_fac.create_net_obj(tc_net_desc, gen_conf->UID());
194 generated_tc_conns.push_back(tc_net_gen);
195
196 gen_obj.set_objs("outputs", { &generated_tc_conns.back() });
197 modules.push_back(obj_fac.get_dal<StandaloneTCMakerModule>(gen_conf->UID()));
198 }
199
200 /**************************************************************
201 * Create the Data Reader
202 **************************************************************/
203 auto rdr_conf = get_data_subscriber();
204 if (rdr_conf == nullptr) {
205 throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
206 }
207
208 std::string reader_uid("data-reader-" + UID());
209 std::string reader_class = rdr_conf->get_template_for();
210 TLOG_DEBUG(7) << "creating OKS configuration object for Data subscriber class " << reader_class;
211 conffwk::ConfigObject reader_obj = obj_fac.create(reader_class, reader_uid);
212 reader_obj.set_objs("inputs", { &tc_net_obj });
213 reader_obj.set_objs("outputs", { &input_queue_obj });
214 reader_obj.set_obj("configuration", &rdr_conf->config_object());
215
216 modules.push_back(obj_fac.get_dal<DataSubscriberModule>(reader_uid));
217
218 /**************************************************************
219 * Create the readout map
220 **************************************************************/
221
222 std::vector<const dunedaq::confmodel::Application*> apps = session->enabled_applications();
223
224 std::vector<const conffwk::ConfigObject*> sourceIds;
225
226 for (auto app : apps) {
227 auto ro_app = app->cast<appmodel::ReadoutApplication>();
228 if (ro_app != nullptr) {
229 auto connections = ro_app->get_detector_connections();
230 // Interate over all the readout groups
231 for (auto d2d_conn : connections) {
232 if (d2d_conn->is_disabled(*session)) {
233 TLOG_DEBUG(7) << "Ignoring disabled Detector2DaqConnection " << d2d_conn->UID();
234 continue;
235 }
236
237 if (d2d_conn->contained_resources().empty()) {
238 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain interfaces"));
239 }
240
241 // Interate over all the streams
242 for (auto stream : d2d_conn->streams()) {
243 if (stream == nullptr) {
244 throw(BadConf(ERS_HERE, "ReadoutInterface contains something other than DetectorStream"));
245 }
246 if (stream->is_disabled(*session)) {
247 TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
248 continue;
249 }
250
251 // Create SourceIDConf object for the MLT
252 auto id = stream->get_source_id();
253 std::string sourceIdConfUID = "dro-mlt-stream-config-" + std::to_string(id);
255 obj_fac.create("SourceIDConf", sourceIdConfUID));
256 sourceIdConf->set_by_val<uint32_t>("sid", id);
257 // https://github.com/DUNE-DAQ/daqdataformats/blob/5b99506675a586c8a09123900e224f2371d96df9/include/daqdataformats/detail/SourceID.hxx#L108
258 sourceIdConf->set_by_val<std::string>("subsystem", "Detector_Readout");
259 sourceIds.push_back(sourceIdConf);
260 }
261 }
262 if (ro_app->get_tp_generation_enabled()) {
263 for (auto sid : ro_app->get_tp_source_ids()) {
264 sourceIds.push_back(&(sid->config_object()));
265 }
266 // conffwk::ConfigObject* tpSourceIdConf = new conffwk::ConfigObject();
267 // confdb->create(dbfile, "SourceIDConf", ro_app->UID()+"-"+ std::to_string(ro_app->get_tp_source_id()),
268 // *tpSourceIdConf); tpSourceIdConf->set_by_val<uint32_t>("sid", ro_app->get_tp_source_id());
269 // tpSourceIdConf->set_by_val<std::string>("subsystem", "Trigger");
270 // sourceIds.push_back(tpSourceIdConf);
271 }
272 }
273
274 auto tpreplay_app = app->cast<appmodel::TPReplayApplication>();
275 if (tpreplay_app != nullptr) {
276 for (auto sid : tpreplay_app->get_tp_source_ids()) {
277 sourceIds.push_back(&(sid->config_object()));
278 }
279 }
280
281 auto fd_app = app->cast<appmodel::FakeDataApplication>();
282 if (fd_app != nullptr) {
283
284 auto producers = fd_app->get_producers();
285 // Interate over all the FakeDataProd modules
286 for (auto stream : producers) {
287
288 if (stream->is_disabled(*session)) {
289 TLOG_DEBUG(7) << "Ignoring disabled FakeDataProdConf " << stream->UID();
290 continue;
291 }
292
293 // Create SourceIDConf object for the MLT
294 auto id = stream->get_source_id();
295 std::string sourceIdConfUID = "dro-mlt-stream-config-" + std::to_string(id);
297 obj_fac.create("SourceIDConf", sourceIdConfUID));
298 sourceIdConf->set_by_val<uint32_t>("sid", id);
299 // https://github.com/DUNE-DAQ/daqdataformats/blob/5b99506675a586c8a09123900e224f2371d96df9/include/daqdataformats/detail/SourceID.hxx#L108
300 sourceIdConf->set_by_val<std::string>("subsystem", "Detector_Readout");
301 sourceIds.push_back(sourceIdConf);
302 }
303 }
304
305 // SmartDaqApplication now has source_id member, might want to use that but make sure that it's actually a data
306 // source somehow...
307 auto trg_app = app->cast<appmodel::TriggerApplication>();
308 if (trg_app != nullptr && trg_app->get_source_id() != nullptr) {
309 conffwk::ConfigObject* tcSourceIdConf = new conffwk::ConfigObject(
310 obj_fac.create(
311 "SourceIDConf",
312 trg_app->UID() + "-" + std::to_string(trg_app->get_source_id()->get_sid())
313 ));
314 tcSourceIdConf->set_by_val<uint32_t>("sid", trg_app->get_source_id()->get_sid());
315 tcSourceIdConf->set_by_val<std::string>("subsystem", trg_app->get_source_id()->get_subsystem());
316 sourceIds.push_back(tcSourceIdConf);
317 }
318
319 // FIXME: add here same logics for HSI application(s)
320 //
321 auto hsi_app = app->cast<appmodel::FakeHSIApplication>();
322 if (hsi_app != nullptr && hsi_app->get_source_id() != nullptr) {
323 conffwk::ConfigObject* hsEventSourceIdConf = new conffwk::ConfigObject(
324 obj_fac.create(
325 "SourceIDConf",
326 hsi_app->UID() + "-" + std::to_string(hsi_app->get_source_id()->get_sid())));
327 hsEventSourceIdConf->set_by_val<uint32_t>("sid", hsi_app->get_source_id()->get_sid());
328 hsEventSourceIdConf->set_by_val<std::string>("subsystem", hsi_app->get_source_id()->get_subsystem());
329 sourceIds.push_back(hsEventSourceIdConf);
330 }
331
332 auto dts_hsi_app = app->cast<appmodel::DTSHSIApplication>();
333 if (dts_hsi_app != nullptr && dts_hsi_app->get_source_id() != nullptr) {
334 conffwk::ConfigObject* hsEventSourceIdConf = new conffwk::ConfigObject(
335 obj_fac.create(
336 "SourceIDConf",
337 dts_hsi_app->UID() + "-" + std::to_string(dts_hsi_app->get_source_id()->get_sid())
338 )
339 );
340 hsEventSourceIdConf->set_by_val<uint32_t>("sid", dts_hsi_app->get_source_id()->get_sid());
341 hsEventSourceIdConf->set_by_val<std::string>("subsystem", dts_hsi_app->get_source_id()->get_subsystem());
342 sourceIds.push_back(hsEventSourceIdConf);
343 }
344
345 auto ctb_app = app->cast<appmodel::CTBApplication>();
346 if (ctb_app) {
347 auto sources = ctb_app->get_sources();
348 for ( const auto & s : sources ) {
349 auto src_id_conf_ptr = new conffwk::ConfigObject( obj_fac.create("SourceIDConf",
350 ctb_app->UID() + "-" + s.first ) );
351 src_id_conf_ptr->set_by_val<uint32_t>("sid", s.second->get_sid());
352 src_id_conf_ptr->set_by_val<std::string>("subsystem", s.second->get_subsystem());
353 sourceIds.push_back(src_id_conf_ptr);
354 } // loop over CTB sources
355 } // CTB app
356
357 auto cib_app = app->cast<appmodel::CIBApplication>();
358 if (cib_app) {
359 conffwk::ConfigObject* hsEventSourceIdConf = new conffwk::ConfigObject(
360 obj_fac.create(
361 "SourceIDConf",
362 cib_app->UID() + "-" + std::to_string(cib_app->get_source_id()->get_sid())
363 )
364 );
365 hsEventSourceIdConf->set_by_val<uint32_t>("sid", cib_app->get_source_id()->get_sid());
366 hsEventSourceIdConf->set_by_val<std::string>("subsystem", cib_app->get_source_id()->get_subsystem());
367 sourceIds.push_back(hsEventSourceIdConf);
368 } // CIB app
369
370 } // loop over applications
371
372 // Get mandatory links
373 std::vector<const conffwk::ConfigObject*> mandatory_sids;
374 const TCDataProcessor* tc_dp = tch_conf->get_data_processor()->cast<TCDataProcessor>();
375 if (tc_dp != nullptr) {
376 for (auto m : tc_dp->get_mandatory_links()) {
377 mandatory_sids.push_back(&m->config_object());
378 }
379 }
380
381 /**************************************************************
382 * Create the TC handler
383 **************************************************************/
384
385 // Process special Network rules!
386 // Looking for Fragment rules from DFAppplications in current Session
387 auto sessionApps = session->enabled_applications();
388 std::vector<conffwk::ConfigObject> fragOutObjs;
389 for (auto app : sessionApps) {
390 auto dfapp = app->cast<appmodel::DFApplication>();
391 if (dfapp == nullptr)
392 continue;
393
394 auto dfNRules = dfapp->get_network_rules();
395 for (auto rule : dfNRules) {
396 auto descriptor = rule->get_descriptor();
397 auto data_type = descriptor->get_data_type();
398 if (data_type == "Fragment") {
399 fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, dfapp->UID()));
400 } // If network rule has TriggerDecision type of data
401 } // Loop over Apps network rules
402 } // loop over Session specific Apps
403
404 // build up the full list of outputs
405 std::vector<const conffwk::ConfigObject*> ti_output_objs;
406 for (auto& fNet : fragOutObjs) {
407 ti_output_objs.push_back(&fNet);
408 }
409 ti_output_objs.push_back(&output_queue_obj);
410
411 auto tch_conf_obj = tch_conf->config_object();
412 if (get_source_id() == nullptr) {
413 throw(BadConf(ERS_HERE, "No source_id associated with this TriggerApplication!"));
414 }
415 uint32_t source_id = get_source_id()->get_sid();
416 std::string ti_uid(handler_name + "-" + std::to_string(source_id));
417 conffwk::ConfigObject ti_obj = obj_fac.create(tch_class, ti_uid);
418 ti_obj.set_by_val<uint32_t>("source_id", source_id);
419 ti_obj.set_by_val<uint32_t>("detector_id", 1); // 1 == kDAQ
420 ti_obj.set_obj("module_configuration", &tch_conf_obj);
421 ti_obj.set_objs("enabled_source_ids", sourceIds);
422 ti_obj.set_objs("mandatory_source_ids", mandatory_sids);
423 ti_obj.set_objs("inputs", { &input_queue_obj, &dr_net_obj });
424 ti_obj.set_objs("outputs", ti_output_objs);
425
426 // Add to our list of modules to return
427 modules.push_back(obj_fac.get_dal<DataHandlerModule>(ti_uid));
428
429 /**************************************************************
430 * Instantiate the MLTModule module
431 **************************************************************/
432
433 conffwk::ConfigObject mlt_obj = obj_fac.create(mlt_conf->get_template_for(),
434 mlt_conf->UID());
435 mlt_obj.set_obj("configuration", &(mlt_conf->config_object()));
436 mlt_obj.set_objs("inputs", { &output_queue_obj, &ti_net_obj });
437 mlt_obj.set_objs("outputs", { &td_net_obj });
438 modules.push_back(obj_fac.get_dal<MLTModule>(mlt_conf->UID()));
439
440 obj_fac.update_modules(modules);
441}
442
443} // namespace appmodel
444} // namespace dunedaq
#define ERS_HERE
void update_modules(const std::vector< const confmodel::DaqModule * > &modules)
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 std::vector< const dunedaq::appmodel::StandaloneTCMakerConf * > & get_standalone_candidate_maker_confs() const
Get "standalone_candidate_maker_confs" relationship value.
const dunedaq::appmodel::MLTConf * get_mlt_conf() const
Get "mlt_conf" relationship value.
void generate_modules(const confmodel::Session *) const override
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 dunedaq::appmodel::SourceIDConf * get_source_id() const
Get "source_id" relationship value.
uint32_t get_sid() const
Get "sid" attribute value.
const std::vector< const dunedaq::appmodel::SourceIDConf * > & get_mandatory_links() const
Get "mandatory_links" relationship value. Source Ids that will always be included in a trigger decisi...
const dunedaq::appmodel::DataHandlerConf * get_trigger_inputs_handler() const
Get "trigger_inputs_handler" relationship value.
const dunedaq::appmodel::DataReaderConf * get_data_subscriber() const
Get "data_subscriber" 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.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
bool is_null() const noexcept
Check if object's implementation points to null.
const TARGET * cast() const noexcept
Casts object to different class.
const std::string & UID() const noexcept
conffwk entry point
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
Including Qt Headers.