DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CTBApplication.cpp
Go to the documentation of this file.
1
12#include "oks/kernel.hpp"
13#include "logging/Logging.hpp"
14
17
22#include "appmodel/CTBConf.hpp"
26#include "appmodel/CTBMisc.hpp"
30#include "appmodel/CTBHLT.hpp"
31#include "appmodel/CTBLLT.hpp"
40
41
50
51#include <string>
52#include <vector>
53#include <bitset>
54#include <iostream>
55#include <fmt/core.h>
56#include <set>
57
58using namespace dunedaq;
59using namespace dunedaq::appmodel;
60
61
62std::vector<const confmodel::DaqModule*>
64{
65 std::vector<const confmodel::DaqModule*> modules;
66
67 ConfigObjectFactory obj_fac(this);
68
69 auto dlhConf = get_link_handler();
70 auto dlhClass = dlhConf->get_template_for();
71
72 const QueueDescriptor* dlhInputQDesc = nullptr;
73
74 for (auto rule : get_queue_rules()) {
75 auto destination_class = rule->get_destination_class();
76 auto data_type = rule->get_descriptor()->get_data_type();
77 if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
78 dlhInputQDesc = rule->get_descriptor();
79 }
80 }
81
82 const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
83 const NetworkConnectionDescriptor* tsNetDesc = nullptr;
84 const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
85
86 for (auto rule : get_network_rules()) {
87 auto endpoint_class = rule->get_endpoint_class();
88 auto data_type = rule->get_descriptor()->get_data_type();
89
90 if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
91 if (data_type == "TimeSync") {
92 tsNetDesc = rule->get_descriptor();
93 }
94 if (data_type == "DataRequest") {
95 dlhReqInputNetDesc = rule->get_descriptor();
96 }
97 }
98 if (data_type == "HSIEvent") {
99 hsiNetDesc = rule->get_descriptor();
100 }
101 }
102
103 auto ctb_conf = get_generator();
104 if (ctb_conf ==nullptr) {
105 throw(BadConf(ERS_HERE, "No CTBModule configuration given"));
106 }
107 if (dlhInputQDesc == nullptr) {
108 throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
109 }
110 if (dlhReqInputNetDesc == nullptr) {
111 throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
112 }
113 if (hsiNetDesc == nullptr) {
114 throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
115 }
116
117 // Process special Network rules!
118 // Looking for Fragment rules from DFAppplications in current Session
119 auto sessionApps = session->get_enabled_applications();
120 std::vector<conffwk::ConfigObject> fragOutObjs;
121 for (auto app : sessionApps) {
122 auto dfapp = app->cast<appmodel::DFApplication>();
123 if (dfapp == nullptr)
124 continue;
125
126 auto dfNRules = dfapp->get_network_rules();
127 for (auto rule : dfNRules) {
128 auto descriptor = rule->get_descriptor();
129 auto data_type = descriptor->get_data_type();
130 if (data_type == "Fragment") {
131 std::string dreqNetUid(descriptor->get_uid_base() + dfapp->UID());
132 conffwk::ConfigObject frag_conn = obj_fac.create_net_obj(descriptor, dreqNetUid);
133 fragOutObjs.push_back(frag_conn);
134 } // If network rule has TriggerDecision type of data
135 } // Loop over Apps network rules
136 } // loop over Session specific Apps
137
138 // start building the list of outputs
139 std::vector<const conffwk::ConfigObject*> fh_output_objs;
140 for (auto& fNet : fragOutObjs) {
141 fh_output_objs.push_back(&fNet);
142 }
143
144 std::vector<conffwk::ConfigObject> ctb_module_outputs;
145 auto sources = get_sources();
146
147 for ( const auto & s : sources ) {
148 if (s.second == nullptr) {
149 throw(BadConf(ERS_HERE, "No SourceIDConf given for " + s.first));
150 }
151
152 auto id = s.second->get_sid();
153 // ----------------------------
154 // create DLH
155 // ----------------------------
156 auto det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
157 TLOG() << "creating OKS configuration object for " + s.first + " Data Link Handler class " << dlhClass << ", id " << id;
158 std::string uid("DLH-" + s.first);
159 conffwk::ConfigObject dlhObj = obj_fac.create( dlhClass, uid );
160 dlhObj.set_by_val<uint32_t>("source_id", id);
161 dlhObj.set_by_val<uint32_t>("detector_id", det_id);
162 dlhObj.set_by_val<bool>("post_processing_enabled", false);
163 dlhObj.set_obj("module_configuration", &dlhConf->config_object());
164
165 auto net_objc(fh_output_objs);
166
167 // Time Sync network connection
168 if (dlhConf->get_generate_timesync()) {
169 std::string tsStreamUid = tsNetDesc->get_uid_base() + std::to_string(id);
170 conffwk::ConfigObject tsNetObj = obj_fac.create_net_obj(tsNetDesc, tsStreamUid);
171 net_objc.push_back(&tsNetObj);
172 }
173
174 dlhObj.set_objs("outputs", net_objc);
175
176 // create Queues from CTB to DLH
177 std::string dataQueueUid(dlhInputQDesc->get_uid_base() + s.first);
178 conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
179 queueObj.rename(dataQueueUid);
180
181 ctb_module_outputs.push_back(queueObj);
182
183 // Create network connections to DLHs
184 std::string faNetUid = dlhReqInputNetDesc->get_uid_base() + UID() + '_' + s.first;
185 conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, faNetUid);
186
187 dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
188
189 modules.push_back(obj_fac.get_dal<appmodel::DataHandlerModule>(uid));
190
191 } // loop over CTB sources
192
193
194 conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
195 ctb_module_outputs.push_back(hsiNetObj);
196
197 auto board = get_board();
198
199 conffwk::ConfigObject module_obj = obj_fac.create( "CTBModule", "ctb-module");
200 module_obj.set_obj("configuration", & ctb_conf -> config_object() );
201 module_obj.set_obj("board", & board -> config_object() );
202
203 std::vector<const conffwk::ConfigObject*> ctb_module_output_ptrs;
204 for ( const auto & o : ctb_module_outputs ) {
205 ctb_module_output_ptrs.push_back( & o );
206 }
207
208 module_obj.set_objs("outputs", ctb_module_output_ptrs);
209
210 auto module = obj_fac.get_dal<appmodel::CTBModule>(module_obj.UID());
211
212 modules.push_back(module);
213
214 return modules;
215}
216
217
219
220 auto vec = get_contains();
221 for ( auto & t : vec) {
222 auto misc = t->cast<CTBMisc>();
223 if ( misc ) {
224 return *misc;
225 }
226 }
227
228 throw BadConf(ERS_HERE, "Missing Misc");
229
230}
231
232
233std::vector<const CTBHLT*> CTBoardConf::get_HLTs() const {
234
235 std::vector<const CTBHLT*> ret;
236
237 auto vec = get_contains();
238
239 for ( auto & t : vec ) {
240 auto hlt = t->cast<CTBHLT>();
241 if ( hlt ) {
242 ret.push_back(hlt);
243 }
244 }
245
246 return ret;
247}
248
249
250std::vector<const CTBCountLLT*> CTBoardConf::get_CRT_LLTs() const {
251
252 std::vector<const CTBCountLLT*> ret;
253
254 auto vec = get_contains();
255
256 for ( auto & t : vec ) {
257 auto llt = t->cast<CTBCountLLT>();
258 if ( llt ) {
259 ret.push_back(llt);
260 }
261 }
262
263 return ret;
264}
265
266
267std::vector<const CTBLLT*> CTBoardConf::get_beam_LLTs() const {
268
269 std::vector<const CTBLLT*> ret;
270
271 auto vec = get_contains();
272
273 for ( auto & t : vec ) {
274 auto llt = t->cast<CTBLLT>();
275 auto count_llt = t->cast<CTBCountLLT>();
276 if ( (!count_llt) && (llt) ) {
277 ret.push_back(llt);
278 }
279 }
280
281 return ret;
282}
283
284
285nlohmann::json CTBoardConf::get_ctb_json(const dunedaq::confmodel::Session& session, std::optional<std::string> socket_host) const {
286
287 nlohmann::json json;
288 json["sockets"] = get_sockets() -> get_ctb_json( socket_host );
289 json["misc"] = get_misc().get_ctb_json(session);
290
291 nlohmann::json hlt;
292
293 // constant block that we don't even want to configure
294 auto & mask = hlt["command_mask"];
295 mask["C"]="0x0";
296 mask["D"]="0x0";
297 mask["E"]="0x0";
298 mask["F"]="0x0";
299
300 auto hlts = get_HLTs();
301
302 std::list<nlohmann::json> json_hlts;
303 for ( const auto & hlt : hlts ) {
304 json_hlts.push_back(hlt->get_ctb_json(session));
305 }
306
307 hlt["trigger"] = nlohmann::json(json_hlts);
308
309 json["HLT"] = hlt;
310
311 // --------------------------
312 // Subsystems
313 // --------------------------
314
315 auto & subsystems = json["subsystems"];
316
317 // ---- Beam ----
318
319 auto & beam_block = subsystems["beam"] = get_beam() -> to_json(false, true);
320 std::list<nlohmann::json> json_beam_llts;
321 auto beam_llts = get_beam_LLTs();
322 for ( const auto & llt : beam_llts ) {
323 json_beam_llts.push_back(llt->get_ctb_json(session));
324 }
325
326 beam_block["triggers"] = nlohmann::json(json_beam_llts);
327
328 // ---- CRT ----
329
330 auto & crt_block = subsystems["crt"] = get_CRT() -> to_json(false, true);
331 std::list<nlohmann::json> json_crt_llts;
332 auto crt_llts = get_CRT_LLTs();
333 for ( const auto & llt : crt_llts ) {
334 json_crt_llts.push_back(llt->get_ctb_json(session));
335 }
336 crt_block["triggers"] = nlohmann::json(json_crt_llts);
337
338 // ---- PDS ----
339
340 subsystems["pds"] = get_pds() -> to_json(false, true);
341
342 nlohmann::json ret;
343 ret["ctb"] = json;
344
345 return ret;
346
347}
348
349
351
352 auto vec = get_contains();
353 for ( auto & t : vec) {
354 if ( t->UID().find("HLT") != std::string::npos ) {
355 auto ret = t->cast<CTBRandomTrigger>();
356 return *ret;
357 }
358 }
359
360 throw BadConf(ERS_HERE, "Missing HLT_0");
361}
362
364
365 auto vec = get_contains();
366 for ( auto & t : vec) {
367 if ( t->UID().find("LLT") != std::string::npos ) {
368 auto ret = t->cast<CTBRandomTrigger>();
369 return *ret;
370 }
371 }
372
373 throw BadConf(ERS_HERE, "Missing LLT_0");
374}
375
376
377
378
380
381 nlohmann::json ret;
382 ret["randomtrigger_1"] = get_randomtrigger_1().get_ctb_json(session);
383 ret["randomtrigger_2"] = get_randomtrigger_2().get_ctb_json(session);
384 ret["pulser"] = get_pulser() -> to_json(false, true);
385 ret["timing"] = get_timing() -> to_json(false, true);
386
387 static std::string ch_status_flag = "ch_status";
388 if ( get_ch_status() ) ret[ch_status_flag] = true;
389 else ret[ch_status_flag] = false;
390
391 static std::string standalong_flag = "standalone_enable";
392 ret[standalong_flag] = false;
393
394 return ret;
395
396}
397
398
400
401 auto json = this -> to_json(false, true);
402 static std::string enable_tag = "enable";
403 if ( this -> disabled(session) ) {
404 json[enable_tag] = false;
405 }
406 else {
407 json[enable_tag] = true;
408 }
409
410 json["id"] = this -> UID();
411
412 return json;
413
414}
415
416nlohmann::json CTBSockets::get_ctb_json(std::optional<std::string> socket_host) const {
417
418 nlohmann::json json;
419 json["receiver"] = get_receiver() -> get_ctb_json(socket_host);
420 json["monitor"] = get_monitor() -> get_ctb_json(socket_host);
421 json["statistics"] = get_statistics() -> to_json(false, true);
422 return json;
423
424}
425
426nlohmann::json CTBSocket::get_ctb_json(std::optional<std::string> socket_host) const {
427
428 auto json = to_json(false, true);
429 if ( socket_host ) {
430 json["host"] = socket_host.value();
431 }
432 return json;
433
434}
435
436
437
#define ERS_HERE
const dunedaq::appmodel::CTBConf * get_generator() const
Get "generator" relationship value.
std::vector< std::pair< std::string, const appmodel::SourceIDConf * > > get_sources() const
const dunedaq::appmodel::CTBoardConf * get_board() const
Get "board" relationship value.
const dunedaq::appmodel::DataHandlerConf * get_link_handler() const
Get "link_handler" relationship value.
std::vector< const dunedaq::confmodel::DaqModule * > generate_modules(const confmodel::Session *) const override
const CTBRandomTrigger & get_randomtrigger_1() const
const CTBRandomTrigger & get_randomtrigger_2() const
nlohmann::json get_ctb_json(const dunedaq::confmodel::Session &session) const
const dunedaq::appmodel::CTBTiming * get_timing() const
Get "timing" relationship value.
Definition CTBMisc.hpp:184
bool get_ch_status() const
Get "ch_status" attribute value.
Definition CTBMisc.hpp:113
const dunedaq::appmodel::CTBPulser * get_pulser() const
Get "pulser" relationship value.
Definition CTBMisc.hpp:153
nlohmann::json get_ctb_json(std::optional< std::string > socket_host=std::nullopt) const
const dunedaq::appmodel::CTBReceiverSocket * get_receiver() const
Get "receiver" relationship value.
const dunedaq::appmodel::CTBStatisticsSocket * get_statistics() const
Get "statistics" relationship value.
const dunedaq::appmodel::CTBMonitorSocket * get_monitor() const
Get "monitor" relationship value.
nlohmann::json get_ctb_json(std::optional< std::string > socket_host=std::nullopt) const
nlohmann::json get_ctb_json(const dunedaq::confmodel::Session &session) const
std::vector< const CTBLLT * > get_beam_LLTs() const
nlohmann::json get_ctb_json(const dunedaq::confmodel::Session &session, std::optional< std::string > socket_host=std::nullopt) const
const dunedaq::appmodel::CTBSubsystem * get_beam() const
Get "beam" relationship value.
const dunedaq::appmodel::CTBCRTSubsystem * get_CRT() const
Get "CRT" relationship value.
const dunedaq::appmodel::CTBSockets * get_sockets() const
Get "sockets" relationship value.
std::vector< const CTBCountLLT * > get_CRT_LLTs() const
std::vector< const CTBHLT * > get_HLTs() const
const dunedaq::appmodel::CTBPDSSubsystem * get_pds() const
Get "pds" relationship value.
const CTBMisc & get_misc() const
conffwk::ConfigObject create_queue_sid_obj(const QueueDescriptor *qdesc, 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(const std::string &class_name, const std::string &id) const
const std::string & get_uid_base() const
Get "uid_base" attribute value. Base for UID string. To be combined with a source id.
const std::string & get_uid_base() const
Get "uid_base" attribute value. Base for UID string. May be combined with a source id.
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.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
void rename(const std::string &new_id)
Rename object.
const TARGET * cast() const noexcept
Casts object to different class.
const ConfigObject & config_object() const
const std::string & UID() const noexcept
bool disabled(const dunedaq::confmodel::Session &session) const
nlohmann::json to_json(bool direct=false, bool skip_name=false) const
const std::vector< const dunedaq::confmodel::ResourceBase * > & get_contains() const
Get "contains" relationship value. A resource set is a container of resources to easily implement gro...
conffwk entry point
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.