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