DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
FakeHSIApplication.cpp
Go to the documentation of this file.
1
27#include "confmodel/Service.hpp"
28#include "logging/Logging.hpp"
29#include "oks/kernel.hpp"
31
32#include <iostream>
33#include <string>
34#include <vector>
35
36namespace dunedaq {
37namespace appmodel {
38
39void
40FakeHSIApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
41{
42 std::vector<const confmodel::DaqModule*> modules;
43
44 ConfigObjectFactory obj_fac(this);
45
46
47 auto dlhConf = get_link_handler();
48 auto dlhClass = dlhConf->get_template_for();
49
50 // 23-Sep-2025, KAB et al: prevent a mis-configuration of the system in which the
51 // FakeHSI DLH is told to generate TimeSync messages. (TimeSync messages should only
52 // be sent from Readout DLH modules so that we don't get confusing system behavior.)
53 if (dlhConf->get_generate_timesync()) {
54 throw(BadConf(ERS_HERE, "TimeSync generation is enabled for a FakeHSIApplication and this is not allowed"));
55 }
56
57 const QueueDescriptor* dlhInputQDesc = nullptr;
58
59 for (auto rule : get_queue_rules()) {
60 auto destination_class = rule->get_destination_class();
61 auto data_type = rule->get_descriptor()->get_data_type();
62 if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
63 dlhInputQDesc = rule->get_descriptor();
64 }
65 }
66
67 const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
68 const NetworkConnectionDescriptor* tsNetDesc = nullptr;
69 const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
70
71 for (auto rule : get_network_rules()) {
72 auto endpoint_class = rule->get_endpoint_class();
73 auto data_type = rule->get_descriptor()->get_data_type();
74
75 if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
76 if (data_type == "TimeSync") {
77 tsNetDesc = rule->get_descriptor();
78 }
79 if (data_type == "DataRequest") {
80 dlhReqInputNetDesc = rule->get_descriptor();
81 }
82 }
83 if (data_type == "HSIEvent") {
84 hsiNetDesc = rule->get_descriptor();
85 }
86 }
87
88 auto rdrConf = get_generator();
89 if (rdrConf == 0) {
90 throw(BadConf(ERS_HERE, "No FakeHSIEventGeneratorModule configuration given"));
91 }
92 if (dlhInputQDesc == nullptr) {
93 throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
94 }
95 if (dlhReqInputNetDesc == nullptr) {
96 throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
97 }
98 if (hsiNetDesc == nullptr) {
99 throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
100 }
101
102 auto idconf = get_source_id();
103 if (idconf == nullptr) {
104 throw(BadConf(ERS_HERE, "No SourceIDConf given"));
105 }
106 auto id = idconf->get_sid();
107
108 auto det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
109 std::string uid("DLH-" + std::to_string(id));
110 TLOG_DEBUG(7) << "creating OKS configuration object for Data Link Handler class " << dlhClass << ", id " << id;
111 conffwk::ConfigObject dlhObj = obj_fac.create(dlhClass, uid);
112 dlhObj.set_by_val<uint32_t>("source_id", id);
113 dlhObj.set_by_val<uint32_t>("detector_id", det_id);
114 dlhObj.set_by_val<bool>("post_processing_enabled", false);
115 dlhObj.set_obj("module_configuration", &dlhConf->config_object());
116
117 // Process special Network rules!
118 // Looking for Fragment rules from DFAppplications in current Session
119 std::vector<conffwk::ConfigObject> fragOutObjs;
120 for (auto [uid, descriptor]:
121 helper->get_netdescriptors("Fragment", "DFApplication")) {
122 fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
123 }
124
125 // start building the list of outputs
126 std::vector<const conffwk::ConfigObject*> fh_output_objs;
127 for (auto& fNet : fragOutObjs) {
128 fh_output_objs.push_back(&fNet);
129 }
130
131 // Time Sync network connection
132 if (dlhConf->get_generate_timesync()) {
133 conffwk::ConfigObject tsNetObj = obj_fac.create_net_obj(tsNetDesc, std::to_string(id));
134 fh_output_objs.push_back(&tsNetObj);
135 }
136 dlhObj.set_objs("outputs", fh_output_objs);
137
138 conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
139 conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID());
140
141 dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
142
143 modules.push_back(obj_fac.get_dal<DataHandlerModule>(uid));
144
145 auto hsiServiceObj = hsiNetDesc->get_associated_service()->config_object();
146 conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
147
148 std::string genuid("FakeHSI-" + std::to_string(id));
149 conffwk::ConfigObject fakehsiObj =
150 obj_fac.create("FakeHSIEventGeneratorModule", genuid);
151 fakehsiObj.set_obj("configuration", &rdrConf->config_object());
152 fakehsiObj.set_objs("outputs", { &queueObj, &hsiNetObj });
153 if (tsNetDesc != nullptr) {
154 conffwk::ConfigObject tsNetObjIn = obj_fac.create_net_obj(tsNetDesc, ".*");
155 fakehsiObj.set_objs("inputs", { &tsNetObjIn });
156 }
157
158 modules.push_back(obj_fac.get_dal<FakeHSIEventGeneratorModule>(genuid));
159
160 obj_fac.update_modules(modules);
161}
162
163} // namespace appmodel
164} // namespace dunedaq
#define ERS_HERE
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 dunedaq::appmodel::DataHandlerConf * get_link_handler() const
Get "link_handler" relationship value.
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
const dunedaq::appmodel::FakeHSIEventGeneratorConf * get_generator() const
Get "generator" relationship value.
const dunedaq::confmodel::Service * get_associated_service() const
Get "associated_service" relationship value. Service provided by this connection.
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.
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.
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.