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
61std::vector<const confmodel::Resource*>
63 std::vector<const confmodel::Resource*> resources;
64 resources.push_back(dynamic_cast<const confmodel::Resource*>(get_board()));
65 return resources;
66}
67
68
69std::vector<const confmodel::DaqModule*>
71{
72 std::vector<const confmodel::DaqModule*> modules;
73
74 ConfigObjectFactory obj_fac(this);
75
76 auto dlhConf = get_link_handler();
77 auto dlhClass = dlhConf->get_template_for();
78
79 const QueueDescriptor* dlhInputQDesc = nullptr;
80
81 for (auto rule : get_queue_rules()) {
82 auto destination_class = rule->get_destination_class();
83 auto data_type = rule->get_descriptor()->get_data_type();
84 if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
85 dlhInputQDesc = rule->get_descriptor();
86 }
87 }
88
89 const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
90 const NetworkConnectionDescriptor* tsNetDesc = nullptr;
91 const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
92
93 for (auto rule : get_network_rules()) {
94 auto endpoint_class = rule->get_endpoint_class();
95 auto data_type = rule->get_descriptor()->get_data_type();
96
97 if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
98 if (data_type == "TimeSync") {
99 tsNetDesc = rule->get_descriptor();
100 }
101 if (data_type == "DataRequest") {
102 dlhReqInputNetDesc = rule->get_descriptor();
103 }
104 }
105 if (data_type == "HSIEvent") {
106 hsiNetDesc = rule->get_descriptor();
107 }
108 }
109
110 auto ctb_conf = get_generator();
111 if (ctb_conf ==nullptr) {
112 throw(BadConf(ERS_HERE, "No CTBModule configuration given"));
113 }
114 if (dlhInputQDesc == nullptr) {
115 throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
116 }
117 if (dlhReqInputNetDesc == nullptr) {
118 throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
119 }
120 if (hsiNetDesc == nullptr) {
121 throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
122 }
123
124 // Process special Network rules!
125 // Looking for Fragment rules from DFAppplications in current Session
126 auto sessionApps = session->enabled_applications();
127 std::vector<conffwk::ConfigObject> fragOutObjs;
128 for (auto app : sessionApps) {
129 auto dfapp = app->cast<appmodel::DFApplication>();
130 if (dfapp == nullptr)
131 continue;
132
133 auto dfNRules = dfapp->get_network_rules();
134 for (auto rule : dfNRules) {
135 auto descriptor = rule->get_descriptor();
136 auto data_type = descriptor->get_data_type();
137 if (data_type == "Fragment") {
138 std::string dreqNetUid(descriptor->get_uid_base() + dfapp->UID());
139 conffwk::ConfigObject frag_conn = obj_fac.create_net_obj(descriptor, dreqNetUid);
140 fragOutObjs.push_back(frag_conn);
141 } // If network rule has TriggerDecision type of data
142 } // Loop over Apps network rules
143 } // loop over Session specific Apps
144
145 // start building the list of outputs
146 std::vector<const conffwk::ConfigObject*> fh_output_objs;
147 for (auto& fNet : fragOutObjs) {
148 fh_output_objs.push_back(&fNet);
149 }
150
151 std::vector<conffwk::ConfigObject> ctb_module_outputs;
152 auto sources = get_sources();
153
154 for ( const auto & s : sources ) {
155 if (s.second == nullptr) {
156 throw(BadConf(ERS_HERE, "No SourceIDConf given for " + s.first));
157 }
158
159 auto id = s.second->get_sid();
160 // ----------------------------
161 // create DLH
162 // ----------------------------
163 auto det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
164 TLOG() << "creating OKS configuration object for " + s.first + " Data Link Handler class " << dlhClass << ", id " << id;
165 std::string uid("DLH-" + s.first);
166 conffwk::ConfigObject dlhObj = obj_fac.create( dlhClass, uid );
167 dlhObj.set_by_val<uint32_t>("source_id", id);
168 dlhObj.set_by_val<uint32_t>("detector_id", det_id);
169 dlhObj.set_by_val<bool>("post_processing_enabled", false);
170 dlhObj.set_obj("module_configuration", &dlhConf->config_object());
171
172 auto net_objc(fh_output_objs);
173
174 // Time Sync network connection
175 if (dlhConf->get_generate_timesync()) {
176 std::string tsStreamUid = tsNetDesc->get_uid_base() + std::to_string(id);
177 conffwk::ConfigObject tsNetObj = obj_fac.create_net_obj(tsNetDesc, tsStreamUid);
178 net_objc.push_back(&tsNetObj);
179 }
180
181 dlhObj.set_objs("outputs", net_objc);
182
183 // create Queues from CTB to DLH
184 std::string dataQueueUid(dlhInputQDesc->get_uid_base() + s.first);
185 conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
186 queueObj.rename(dataQueueUid);
187
188 ctb_module_outputs.push_back(queueObj);
189
190 // Create network connections to DLHs
191 std::string faNetUid = dlhReqInputNetDesc->get_uid_base() + UID() + '_' + s.first;
192 conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, faNetUid);
193
194 dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
195
196 modules.push_back(obj_fac.get_dal<appmodel::DataHandlerModule>(uid));
197
198 } // loop over CTB sources
199
200
201 conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
202 ctb_module_outputs.push_back(hsiNetObj);
203
204 auto board = get_board();
205
206 conffwk::ConfigObject module_obj = obj_fac.create( "CTBModule", "ctb-module");
207 module_obj.set_obj("configuration", & ctb_conf -> config_object() );
208 module_obj.set_obj("board", & board -> config_object() );
209
210 std::vector<const conffwk::ConfigObject*> ctb_module_output_ptrs;
211 for ( const auto & o : ctb_module_outputs ) {
212 ctb_module_output_ptrs.push_back( & o );
213 }
214
215 module_obj.set_objs("outputs", ctb_module_output_ptrs);
216
217 auto module = obj_fac.get_dal<appmodel::CTBModule>(module_obj.UID());
218
219 modules.push_back(module);
220
221 return modules;
222}
223
224
225
226std::vector<const confmodel::Resource*>
228 std::vector<const confmodel::Resource*> resources;
229 resources.push_back(get_misc());
230
231 auto hlts = get_HLTs();
232 resources.insert(resources.end(), hlts.begin(), hlts.end());
233
234 auto crt_llts = get_CRT_LLTs();
235 resources.insert(resources.end(), crt_llts.begin(), crt_llts.end());
236
237 auto llts = get_beam_LLTs();
238 resources.insert(resources.end(), llts.begin(), llts.end());
239
240 return resources;
241}
242
243
244nlohmann::json CTBoardConf::get_ctb_json(const dunedaq::confmodel::Session& session, std::optional<std::string> socket_host) const {
245
246 nlohmann::json json;
247 json["sockets"] = get_sockets() -> get_ctb_json( socket_host );
248 json["misc"] = get_misc()->get_ctb_json(session);
249
250 nlohmann::json hlt;
251
252 // constant block that we don't even want to configure
253 auto & mask = hlt["command_mask"];
254 mask["C"]="0x0";
255 mask["D"]="0x0";
256 mask["E"]="0x0";
257 mask["F"]="0x0";
258
259 auto hlts = get_HLTs();
260
261 std::list<nlohmann::json> json_hlts;
262 for ( const auto & hlt : hlts ) {
263 json_hlts.push_back(hlt->get_ctb_json(session));
264 }
265
266 hlt["trigger"] = nlohmann::json(json_hlts);
267
268 json["HLT"] = hlt;
269
270 // --------------------------
271 // Subsystems
272 // --------------------------
273
274 auto & subsystems = json["subsystems"];
275
276 // ---- Beam ----
277
278 auto & beam_block = subsystems["beam"] = get_beam() -> to_json(false, true);
279 std::list<nlohmann::json> json_beam_llts;
280 auto beam_llts = get_beam_LLTs();
281 for ( const auto & llt : beam_llts ) {
282 json_beam_llts.push_back(llt->get_ctb_json(session));
283 }
284
285 beam_block["triggers"] = nlohmann::json(json_beam_llts);
286
287 // ---- CRT ----
288
289 auto & crt_block = subsystems["crt"] = get_CRT() -> to_json(false, true);
290 std::list<nlohmann::json> json_crt_llts;
291 auto crt_llts = get_CRT_LLTs();
292 for ( const auto & llt : crt_llts ) {
293 json_crt_llts.push_back(llt->get_ctb_json(session));
294 }
295 crt_block["triggers"] = nlohmann::json(json_crt_llts);
296
297 // ---- PDS ----
298
299 subsystems["pds"] = get_pds() -> to_json(false, true);
300
301 nlohmann::json ret;
302 ret["ctb"] = json;
303
304 return ret;
305
306}
307
308std::vector<const confmodel::Resource*> CTBMisc::contained_resources() const {
309 return std::vector<const confmodel::Resource*>{ get_randomtrigger_1(), get_randomtrigger_2() };
310}
311
312
313
315
316 nlohmann::json ret;
317 ret["randomtrigger_1"] = get_randomtrigger_1()->get_ctb_json(session);
318 ret["randomtrigger_2"] = get_randomtrigger_2()->get_ctb_json(session);
319 ret["pulser"] = get_pulser() -> to_json(false, true);
320 ret["timing"] = get_timing() -> to_json(false, true);
321
322 static std::string ch_status_flag = "ch_status";
323 if ( get_ch_status() ) ret[ch_status_flag] = true;
324 else ret[ch_status_flag] = false;
325
326 static std::string standalong_flag = "standalone_enable";
327 ret[standalong_flag] = false;
328
329 return ret;
330
331}
332
333
335
336 auto json = this -> to_json(false, true);
337 static std::string enable_tag = "enable";
338 if ( this -> is_disabled(session) ) {
339 json[enable_tag] = false;
340 }
341 else {
342 json[enable_tag] = true;
343 }
344
345 json["id"] = this -> UID();
346
347 return json;
348
349}
350
351nlohmann::json CTBSockets::get_ctb_json(std::optional<std::string> socket_host) const {
352
353 nlohmann::json json;
354 json["receiver"] = get_receiver() -> get_ctb_json(socket_host);
355 json["monitor"] = get_monitor() -> get_ctb_json(socket_host);
356 json["statistics"] = get_statistics() -> to_json(false, true);
357 return json;
358
359}
360
361nlohmann::json CTBSocket::get_ctb_json(std::optional<std::string> socket_host) const {
362
363 auto json = to_json(false, true);
364 if ( socket_host ) {
365 json["host"] = socket_host.value();
366 }
367 return json;
368
369}
370
371
372
#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
virtual std::vector< const Resource * > contained_resources() const override
virtual std::vector< const Resource * > contained_resources() const override
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:190
bool get_ch_status() const
Get "ch_status" attribute value.
Definition CTBMisc.hpp:115
const dunedaq::appmodel::CTBRandomTrigger * get_randomtrigger_2() const
Get "randomtrigger_2" relationship value.
Definition CTBMisc.hpp:252
const dunedaq::appmodel::CTBRandomTrigger * get_randomtrigger_1() const
Get "randomtrigger_1" relationship value.
Definition CTBMisc.hpp:221
const dunedaq::appmodel::CTBPulser * get_pulser() const
Get "pulser" relationship value.
Definition CTBMisc.hpp:159
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
nlohmann::json get_ctb_json(const dunedaq::confmodel::Session &session, std::optional< std::string > socket_host=std::nullopt) const
const dunedaq::appmodel::CTBMisc * get_misc() const
Get "misc" relationship value.
const std::vector< const dunedaq::appmodel::CTBHLT * > & get_HLTs() const
Get "HLTs" relationship value.
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.
virtual std::vector< const Resource * > contained_resources() const override
const dunedaq::appmodel::CTBPDSSubsystem * get_pds() const
Get "pds" relationship value.
const std::vector< const dunedaq::appmodel::CTBCountLLT * > & get_CRT_LLTs() const
Get "CRT_LLTs" relationship value.
const std::vector< const dunedaq::appmodel::CTBLLT * > & get_beam_LLTs() const
Get "beam_LLTs" relationship value.
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 ConfigObject & config_object() const
const std::string & UID() const noexcept
nlohmann::json to_json(bool direct=false, bool skip_name=false) const
bool is_disabled(const dunedaq::confmodel::ResourceTree &session) const
conffwk entry point
#define TLOG(...)
Definition macro.hpp:22
The DUNE-DAQ namespace.
Definition DataStore.hpp:57