DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
MLTApplication.cpp
Go to the documentation of this file.
1
13
16
19
30#include "appmodel/MLTConf.hpp"
43
44#include "logging/Logging.hpp"
45
46#include <string>
47#include <vector>
48
49namespace dunedaq {
50namespace appmodel {
51
52
53void
54MLTApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
55{
56 std::vector<const confmodel::DaqModule*> modules;
57
58 ConfigObjectFactory obj_fac(this);
59
60 // auto mlt_conf = get_mlt_conf();
61 // auto mlt_class = mlt_conf->get_template_for();
62
63 auto tch_conf = get_trigger_inputs_handler();
64 auto tch_class = tch_conf->get_template_for();
65
66 auto mlt_conf = get_mlt_conf();
67 auto mlt_class = mlt_conf->get_template_for();
68 std::string handler_name(tch_conf->UID());
69
70 if (!mlt_conf) {
71 throw(BadConf(ERS_HERE, "No MLT configuration in MLTApplication given"));
72 }
73
74 // Queue descriptors
75 // Process the queue rules looking for inputs to our trigger handler modules
76 const QueueDescriptor* tc_inputq_desc = nullptr;
77 const QueueDescriptor* td_outputq_desc = nullptr;
78
79 for (auto rule : get_queue_rules()) {
80 auto destination_class = rule->get_destination_class();
81 auto data_type = rule->get_descriptor()->get_data_type();
82 if (destination_class == tch_class) {
83 tc_inputq_desc = rule->get_descriptor();
84 } else if (destination_class == mlt_class) {
85 td_outputq_desc = rule->get_descriptor();
86 }
87 }
88
89 if (tc_inputq_desc == nullptr) {
90 throw(BadConf(ERS_HERE, "No TC input queue descriptor given"));
91 }
92 if (td_outputq_desc == nullptr) {
93 throw(BadConf(ERS_HERE, "No TD output-input queue descriptor given"));
94 }
95
96 // Create queues
97 auto input_queue_obj = obj_fac.create_queue_obj(tc_inputq_desc);
98 auto output_queue_obj = obj_fac.create_queue_obj(td_outputq_desc);
99
100 // Net descriptors
101 const NetworkConnectionDescriptor* req_net_desc = nullptr;
102 const NetworkConnectionDescriptor* tc_net_desc = nullptr;
103 const NetworkConnectionDescriptor* ti_net_desc = nullptr;
104 const NetworkConnectionDescriptor* td_net_desc = nullptr;
105 const NetworkConnectionDescriptor* timesync_net_desc = nullptr;
106
107 for (auto rule : get_network_rules()) {
108 std::string data_type = rule->get_descriptor()->get_data_type();
109
110 // Network connections for the MLT
111 if (data_type == "TriggerInhibit") {
112 ti_net_desc = rule->get_descriptor();
113 }
114 if (data_type == "TriggerDecision") {
115 td_net_desc = rule->get_descriptor();
116 }
117 if (data_type == "TriggerCandidate") {
118 tc_net_desc = rule->get_descriptor();
119 }
120 if (data_type == "TimeSync") {
121 timesync_net_desc = rule->get_descriptor();
122 }
123 if (data_type == "DataRequest") {
124 req_net_desc = rule->get_descriptor();
125 }
126
127 TLOG_DEBUG(3) << "Endpoint class (currently not used in for networkconnections): data_type: " << data_type;
128 }
129
130 if (!td_net_desc) {
131 throw(BadConf(ERS_HERE, "No MLT network connection for the output TriggerDecision given"));
132 }
133 if (!ti_net_desc) {
134 throw(BadConf(ERS_HERE, "No MLT network connection for the output TriggerInhibit given"));
135 }
136 if (!tc_net_desc) {
137 throw(BadConf(ERS_HERE, "No MLT network connection for the Input of TriggerCandidates given"));
138 }
139 if (!req_net_desc) {
140 throw(BadConf(ERS_HERE, "No MLT network connection for the Input of DataRequests given"));
141 }
142 // Network connection for input TriggerInhibit, input TCs
143
144 conffwk::ConfigObject ti_net_obj =
145 obj_fac.create_net_obj(ti_net_desc, "");
146
147 conffwk::ConfigObject tc_net_obj =
148 obj_fac.create_net_obj(tc_net_desc, ".*");
149
150 // Network connection for output TriggerDecision
151 conffwk::ConfigObject td_net_obj =
152 obj_fac.create_net_obj(td_net_desc, "");
153
154 // Network conection for the input Data Requests
155 conffwk::ConfigObject dr_net_obj =
156 obj_fac.create_net_obj(req_net_desc, UID());
157
158 conffwk::ConfigObject timesync_net_obj;
159 if (timesync_net_desc != nullptr) {
160 timesync_net_obj =
161 obj_fac.create_net_obj(timesync_net_desc, ".*");
162 }
163
164 /**************************************************************
165 * Instantiate standalone TC generator modules (e.g. random TC generator)
166 **************************************************************/
167
168 auto standalone_TC_maker_confs = get_standalone_candidate_maker_confs();
169 std::vector<conffwk::ConfigObject> generated_tc_conns;
170 generated_tc_conns.reserve(standalone_TC_maker_confs.size());
171 for (auto gen_conf : standalone_TC_maker_confs) {
172 conffwk::ConfigObject gen_obj = obj_fac.create(gen_conf->get_template_for(),
173 gen_conf->UID());
174 gen_obj.set_obj("configuration", &(gen_conf->config_object()));
175 if (gen_conf->get_timestamp_method() == "kTimeSync" && !timesync_net_obj.is_null()) {
176 gen_obj.set_objs("inputs", { &timesync_net_obj });
177 }
178
179 auto tc_net_gen = obj_fac.create_net_obj(tc_net_desc, gen_conf->UID());
180 generated_tc_conns.push_back(tc_net_gen);
181
182 gen_obj.set_objs("outputs", { &generated_tc_conns.back() });
183 modules.push_back(obj_fac.get_dal<StandaloneTCMakerModule>(gen_conf->UID()));
184 }
185
186 /**************************************************************
187 * Create the Data Reader
188 **************************************************************/
189 auto rdr_conf = get_data_subscriber();
190 if (rdr_conf == nullptr) {
191 throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
192 }
193
194 std::string reader_uid("data-reader-" + UID());
195 std::string reader_class = rdr_conf->get_template_for();
196 TLOG_DEBUG(7) << "creating OKS configuration object for Data subscriber class " << reader_class;
197 conffwk::ConfigObject reader_obj = obj_fac.create(reader_class, reader_uid);
198 reader_obj.set_objs("inputs", { &tc_net_obj });
199 reader_obj.set_objs("outputs", { &input_queue_obj });
200 reader_obj.set_obj("configuration", &rdr_conf->config_object());
201
202 modules.push_back(obj_fac.get_dal<DataSubscriberModule>(reader_uid));
203
204 /**************************************************************
205 * Create the readout map
206 **************************************************************/
207
208 std::vector<const conffwk::ConfigObject*> sourceIds;
209 for (auto [uid, source_ids]: helper->get_stream_source_ids()) {
210 for (auto src_id: source_ids) {
211 // Create SourceIDConf object for the MLT
212 std::string sourceIdConfUID = "dro-mlt-stream-config-" +
213 std::to_string(src_id);
215 obj_fac.create("SourceIDConf", sourceIdConfUID));
216 sourceIdConf->set_by_val<uint32_t>("sid", src_id);
217 // https://github.com/DUNE-DAQ/daqdataformats/blob/5b99506675a586c8a09123900e224f2371d96df9/include/daqdataformats/detail/SourceID.hxx#L108
218 sourceIdConf->set_by_val<std::string>("subsystem", "Detector_Readout");
219 sourceIds.push_back(sourceIdConf);
220 }
221 }
222 for (auto [uid, source_ids]: helper->get_tp_source_ids()) {
223 for (auto src_id: source_ids) {
224 sourceIds.push_back(&(src_id->config_object()));
225 }
226 }
227
228 // set the CTB sources
229 for (const auto & [uid, sources]: helper->get_all_app_source_ids("CTBApplication")) {
230 for (const auto & [source_name, source_conf] : sources ) {
231 auto final_name = uid;
232 final_name += source_name.find("LLT")!=std::string::npos ? "_LLT" : "_HLT";
233 auto tcSourceIdConf = new conffwk::ConfigObject(
234 obj_fac.create("SourceIDConf", final_name));
235 tcSourceIdConf->set_by_val<uint32_t>("sid", source_conf->get_sid());
236 tcSourceIdConf->set_by_val<std::string>("subsystem", source_conf->get_subsystem());
237 sourceIds.push_back(tcSourceIdConf);
238 }
239 }
240
241 for (auto app_class: {"TriggerApplication", "FakeHSIApplication",
242 "DTSHSIApplication", "CIBApplication"}) {
243 for (auto [uid, src_id]: helper->get_app_source_ids(app_class)) {
244 auto tcSourceIdConf = new conffwk::ConfigObject(
245 obj_fac.create("SourceIDConf",
246 uid + "-" + std::to_string(src_id->get_sid())
247 ));
248 tcSourceIdConf->set_by_val<uint32_t>("sid", src_id->get_sid());
249 tcSourceIdConf->set_by_val<std::string>("subsystem", src_id->get_subsystem());
250 sourceIds.push_back(tcSourceIdConf);
251
252 }
253 }
254
255 // Get mandatory links
256 std::vector<const conffwk::ConfigObject*> mandatory_sids;
257 const TCDataProcessor* tc_dp = tch_conf->get_data_processor()->cast<TCDataProcessor>();
258 if (tc_dp != nullptr) {
259 for (auto m : tc_dp->get_mandatory_links()) {
260 mandatory_sids.push_back(&m->config_object());
261 }
262 }
263
264 /**************************************************************
265 * Create the TC handler
266 **************************************************************/
267
268 // Process special Network rules!
269 // Looking for Fragment rules from DFAppplications in current Session
270
271 // auto sessionApps = session->get_enabled_applications();
272 // std::vector<conffwk::ConfigObject> fragOutObjs;
273 // for (auto app : sessionApps) {
274 // auto dfapp = app->cast<appmodel::DFApplication>();
275 // if (dfapp == nullptr)
276 // continue;
277
278 // auto dfNRules = dfapp->get_network_rules();
279 // for (auto rule : dfNRules) {
280 // auto descriptor = rule->get_descriptor();
281 // auto data_type = descriptor->get_data_type();
282 // if (data_type == "Fragment") {
283 // std::string dreqNetUid(descriptor->get_uid_base() + dfapp->UID());
284 // conffwk::ConfigObject frag_conn;
285 // confdb->create(dbfile, "NetworkConnection", dreqNetUid, frag_conn);
286
287 // frag_conn.set_by_val<std::string>("data_type", descriptor->get_data_type());
288 // frag_conn.set_by_val<std::string>("connection_type", descriptor->get_connection_type());
289
290 // auto serviceObj = descriptor->get_associated_service()->config_object();
291 // frag_conn.set_obj("associated_service", &serviceObj);
292 // fragOutObjs.push_back(frag_conn);
293 // } // If network rule has TriggerDecision type of data
294 // } // Loop over Apps network rules
295 // } // loop over Session specific Apps
296
297 std::vector<conffwk::ConfigObject> fragOutObjs;
298 for (auto [uid, descriptor]:
299 helper->get_netdescriptors("Fragment", "DFApplication")) {
300 fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
301 }
302
303 // build up the full list of outputs
304 std::vector<const conffwk::ConfigObject*> ti_output_objs;
305 for (auto& fNet : fragOutObjs) {
306 ti_output_objs.push_back(&fNet);
307 }
308 ti_output_objs.push_back(&output_queue_obj);
309
310 auto tch_conf_obj = tch_conf->config_object();
311 if (get_source_id() == nullptr) {
312 throw(BadConf(ERS_HERE, "No source_id associated with this TriggerApplication!"));
313 }
314 uint32_t source_id = get_source_id()->get_sid();
315 std::string ti_uid(handler_name + "-" + std::to_string(source_id));
316 conffwk::ConfigObject ti_obj = obj_fac.create(tch_class, ti_uid);
317 ti_obj.set_by_val<uint32_t>("source_id", source_id);
318 ti_obj.set_by_val<uint32_t>("detector_id", 1); // 1 == kDAQ
319 ti_obj.set_obj("module_configuration", &tch_conf_obj);
320 ti_obj.set_objs("enabled_source_ids", sourceIds);
321 ti_obj.set_objs("mandatory_source_ids", mandatory_sids);
322 ti_obj.set_objs("inputs", { &input_queue_obj, &dr_net_obj });
323 ti_obj.set_objs("outputs", ti_output_objs);
324
325 // Add to our list of modules to return
326 modules.push_back(obj_fac.get_dal<DataHandlerModule>(ti_uid));
327
328 /**************************************************************
329 * Instantiate the MLTModule module
330 **************************************************************/
331
332 conffwk::ConfigObject mlt_obj = obj_fac.create(mlt_conf->get_template_for(),
333 mlt_conf->UID());
334 mlt_obj.set_obj("configuration", &(mlt_conf->config_object()));
335 mlt_obj.set_objs("inputs", { &output_queue_obj, &ti_net_obj });
336 mlt_obj.set_objs("outputs", { &td_net_obj });
337 modules.push_back(obj_fac.get_dal<MLTModule>(mlt_conf->UID()));
338
339 obj_fac.update_modules(modules);
340}
341
342} // namespace appmodel
343} // 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
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
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.
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 ConfigObject & config_object() const
const std::string & UID() const noexcept
conffwk entry point
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
Including Qt Headers.