DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CTBApplication.cpp
Go to the documentation of this file.
1
10
12#include "logging/Logging.hpp"
13#include "oks/kernel.hpp"
14
17
21#include "appmodel/CTBConf.hpp"
23#include "appmodel/CTBHLT.hpp"
24#include "appmodel/CTBLLT.hpp"
25#include "appmodel/CTBMisc.hpp"
40
48
49#include <bitset>
50#include <fmt/core.h>
51#include <iostream>
52#include <set>
53#include <string>
54#include <vector>
55
56using namespace dunedaq;
57using namespace dunedaq::appmodel;
58
59std::vector<const confmodel::ExcludableEntity*>
61{
62 std::vector<const confmodel::ExcludableEntity*> resources;
63 resources.push_back(dynamic_cast<const confmodel::ExcludableEntity*>(get_board()));
64 return resources;
65}
66
67void
68CTBApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
69{
70 std::vector<const confmodel::DaqModule*> modules;
71
72 ConfigObjectFactory obj_fac(this);
73
74 auto dlhConf = get_link_handler();
75 auto dlhClass = dlhConf->get_template_for();
76
77 const QueueDescriptor* dlhInputQDesc = 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 == "DataHandlerModule" || destination_class == dlhClass) {
83 dlhInputQDesc = rule->get_descriptor();
84 }
85 }
86
87 const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
88 const NetworkConnectionDescriptor* tsNetDesc = nullptr;
89 const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
90
91 for (auto rule : get_network_rules()) {
92 auto endpoint_class = rule->get_endpoint_class();
93 auto data_type = rule->get_descriptor()->get_data_type();
94
95 if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
96 if (data_type == "TimeSync") {
97 tsNetDesc = rule->get_descriptor();
98 }
99 if (data_type == "DataRequest") {
100 dlhReqInputNetDesc = rule->get_descriptor();
101 }
102 }
103 if (data_type == "HSIEvent") {
104 hsiNetDesc = rule->get_descriptor();
105 }
106 }
107
108 auto ctb_conf = get_generator();
109 if (ctb_conf == nullptr) {
110 throw(BadConf(ERS_HERE, "No CTBModule configuration given"));
111 }
112 if (dlhInputQDesc == nullptr) {
113 throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
114 }
115 if (dlhReqInputNetDesc == nullptr) {
116 throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
117 }
118 if (hsiNetDesc == nullptr) {
119 throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
120 }
121
122 // Process special Network rules!
123 // Looking for Fragment rules from DFAppplications in current Session
124 std::vector<conffwk::ConfigObject> fragOutObjs;
125 for (auto [uid, descriptor] : helper->get_netdescriptors("Fragment", "DFApplication")) {
126 fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
127 }
128
129 // start building the list of outputs
130 std::vector<const conffwk::ConfigObject*> fh_output_objs;
131 for (auto& fNet : fragOutObjs) {
132 fh_output_objs.push_back(&fNet);
133 }
134
135 std::vector<conffwk::ConfigObject> ctb_module_outputs;
136 auto sources = get_sources();
137
138 for (const auto& s : sources) {
139 if (s.second == nullptr) {
140 throw(BadConf(ERS_HERE, "No SourceIDConf given for " + s.first));
141 }
142
143 auto id = s.second->get_sid();
144 // ----------------------------
145 // create DLH
146 // ----------------------------
147 auto det_id =
148 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
149 TLOG() << "creating OKS configuration object for " + s.first + " Data Link Handler class " << dlhClass << ", id "
150 << 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 conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
186 ctb_module_outputs.push_back(hsiNetObj);
187
188 auto board = get_board();
189
190 conffwk::ConfigObject module_obj = obj_fac.create("CTBModule", "ctb-module");
191 module_obj.set_obj("configuration", &ctb_conf->config_object());
192 module_obj.set_obj("board", &board->config_object());
193
194 std::vector<const conffwk::ConfigObject*> ctb_module_output_ptrs;
195 for (const auto& o : ctb_module_outputs) {
196 ctb_module_output_ptrs.push_back(&o);
197 }
198
199 module_obj.set_objs("outputs", ctb_module_output_ptrs);
200
201 auto module = obj_fac.get_dal<appmodel::CTBModule>(module_obj.UID());
202
203 modules.push_back(module);
204
205 obj_fac.update_modules(modules);
206}
207
208std::vector<const confmodel::ExcludableEntity*>
210{
211 std::vector<const confmodel::ExcludableEntity*> resources;
212 resources.push_back(get_misc());
213
214 auto hlts = get_HLTs();
215 resources.insert(resources.end(), hlts.begin(), hlts.end());
216
217 auto crt_llts = get_CRT_LLTs();
218 resources.insert(resources.end(), crt_llts.begin(), crt_llts.end());
219
220 auto llts = get_beam_LLTs();
221 resources.insert(resources.end(), llts.begin(), llts.end());
222
223 return resources;
224}
225
226nlohmann::json
227CTBoardConf::get_ctb_json(const dunedaq::confmodel::Session& session, std::optional<std::string> socket_host) const
228{
229
230 nlohmann::json json;
231 json["sockets"] = get_sockets()->get_ctb_json(socket_host);
232 json["misc"] = get_misc()->get_ctb_json(session);
233
234 nlohmann::json hlt;
235
236 // constant block that we don't even want to configure
237 auto& mask = hlt["command_mask"];
238 mask["C"] = "0x0";
239 mask["D"] = "0x0";
240 mask["E"] = "0x0";
241 mask["F"] = "0x0";
242
243 auto hlts = get_HLTs();
244
245 std::list<nlohmann::json> json_hlts;
246 for (const auto& hlt : hlts) {
247 json_hlts.push_back(hlt->get_ctb_json(session));
248 }
249
250 hlt["trigger"] = nlohmann::json(json_hlts);
251
252 json["HLT"] = hlt;
253
254 // --------------------------
255 // Subsystems
256 // --------------------------
257
258 auto& subsystems = json["subsystems"];
259
260 // ---- Beam ----
261
262 auto& beam_block = subsystems["beam"] = get_beam()->to_json(false, true);
263 std::list<nlohmann::json> json_beam_llts;
264 auto beam_llts = get_beam_LLTs();
265 for (const auto& llt : beam_llts) {
266 json_beam_llts.push_back(llt->get_ctb_json(session));
267 }
268
269 beam_block["triggers"] = nlohmann::json(json_beam_llts);
270
271 // ---- CRT ----
272
273 auto& crt_block = subsystems["crt"] = get_CRT()->to_json(false, true);
274 std::list<nlohmann::json> json_crt_llts;
275 auto crt_llts = get_CRT_LLTs();
276 for (const auto& llt : crt_llts) {
277 json_crt_llts.push_back(llt->get_ctb_json(session));
278 }
279 crt_block["triggers"] = nlohmann::json(json_crt_llts);
280
281 // ---- PDS ----
282
283 subsystems["pds"] = get_pds()->to_json(false, true);
284
285 nlohmann::json ret;
286 ret["ctb"] = json;
287
288 return ret;
289}
290
291std::vector<const confmodel::ExcludableEntity*>
293{
294 return std::vector<const confmodel::ExcludableEntity*>{ get_randomtrigger_1(), get_randomtrigger_2() };
295}
296
297nlohmann::json
299{
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())
309 ret[ch_status_flag] = true;
310 else
311 ret[ch_status_flag] = false;
312
313 static std::string standalong_flag = "standalone_enable";
314 ret[standalong_flag] = false;
315
316 return ret;
317}
318
319nlohmann::json
321{
322
323 auto json = this->to_json(false, true);
324 static std::string enable_tag = "enable";
325 if (this->is_excluded(session)) {
326 json[enable_tag] = false;
327 } else {
328 json[enable_tag] = true;
329 }
330
331 json["id"] = this->UID();
332
333 return json;
334}
335
336nlohmann::json
337CTBSockets::get_ctb_json(std::optional<std::string> socket_host) const
338{
339
340 nlohmann::json json;
341 json["receiver"] = get_receiver()->get_ctb_json(socket_host);
342 json["monitor"] = get_monitor()->get_ctb_json(socket_host);
343 json["statistics"] = get_statistics()->to_json(false, true);
344 return json;
345}
346
347nlohmann::json
348CTBSocket::get_ctb_json(std::optional<std::string> socket_host) const
349{
350
351 auto json = to_json(false, true);
352 if (socket_host) {
353 json["host"] = socket_host.value();
354 }
355 return json;
356}
#define ERS_HERE
virtual std::vector< const ExcludableEntity * > contained_excludable_entities() const override
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
nlohmann::json get_ctb_json(const dunedaq::confmodel::Session &session) const
virtual std::vector< const ExcludableEntity * > contained_excludable_entities() const override
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 ExcludableEntity * > contained_excludable_entities() 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 std::string & UID() const noexcept
bool is_excluded(const dunedaq::confmodel::ExcludableEntityTree &session) const
nlohmann::json to_json(bool direct=false, bool skip_name=false) const
conffwk entry point
#define TLOG(...)
Definition macro.hpp:21
The DUNE-DAQ namespace.
CIB Buffer std::string descriptor Message from std::string descriptor CIB process std::string descriptor descriptor