DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CIBApplication.cpp
Go to the documentation of this file.
1
12#include "oks/kernel.hpp"
13#include "logging/Logging.hpp"
14
17
22#include "appmodel/CIBConf.hpp"
24
33
34#include <string>
35#include <vector>
36#include <bitset>
37#include <iostream>
38#include <fmt/core.h>
39#include <set>
40
41using namespace dunedaq;
42using namespace dunedaq::appmodel;
43
44std::vector<const confmodel::Resource*>
46 std::vector<const confmodel::Resource*> resources;
47 resources.push_back(dynamic_cast<const confmodel::Resource *>(get_board())); // NOLINT(runtime/rtti)
48 return resources;
49}
50
51
52void
54{
55 std::vector<const confmodel::DaqModule*> modules;
56
57 ConfigObjectFactory obj_fac(this);
58
59 auto dlhConf = get_link_handler();
60 auto dlhClass = dlhConf->get_template_for();
61
62 const QueueDescriptor* dlhInputQDesc = nullptr;
63
64 for (auto rule : get_queue_rules()) {
65 auto destination_class = rule->get_destination_class();
66 if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
67 dlhInputQDesc = rule->get_descriptor();
68 }
69 }
70
71 const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
72 const NetworkConnectionDescriptor* tsNetDesc = nullptr;
73 const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
74
75 for (auto rule : get_network_rules()) {
76 auto endpoint_class = rule->get_endpoint_class();
77 auto data_type = rule->get_descriptor()->get_data_type();
78
79 if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
80 if (data_type == "TimeSync") {
81 tsNetDesc = rule->get_descriptor();
82 }
83 if (data_type == "DataRequest") {
84 dlhReqInputNetDesc = rule->get_descriptor();
85 }
86 }
87 if (data_type == "HSIEvent") {
88 hsiNetDesc = rule->get_descriptor();
89 }
90 }
91
92 auto CIB_conf = get_generator();
93 if (CIB_conf == nullptr) {
94 throw(BadConf(ERS_HERE, "No CIBModule configuration given"));
95 }
96 if (dlhInputQDesc == nullptr) {
97 throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
98 }
99 if (dlhReqInputNetDesc == nullptr) {
100 throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
101 }
102 if (hsiNetDesc == nullptr) {
103 throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
104 }
105
106 // Process special Network rules!
107 // Looking for Fragment rules from DFAppplications in current Session
108 auto sessionApps = session->enabled_applications();
109 std::vector<conffwk::ConfigObject> fragOutObjs;
110 for (auto app : sessionApps) {
111 auto dfapp = app->cast<appmodel::DFApplication>();
112 if (dfapp == nullptr)
113 continue;
114
115 auto dfNRules = dfapp->get_network_rules();
116 for (auto rule : dfNRules) {
117 auto descriptor = rule->get_descriptor();
118 auto data_type = descriptor->get_data_type();
119 if (data_type == "Fragment") {
120 std::string dreqNetUid(descriptor->get_uid_base() + dfapp->UID());
121 conffwk::ConfigObject frag_conn = obj_fac.create_net_obj(descriptor, dreqNetUid);
122 fragOutObjs.push_back(frag_conn);
123 } // If network rule has Fragment type of data
124 } // Loop over Apps network rules
125 } // loop over Session specific Apps
126
127 // start building the list of outputs
128 std::vector<const conffwk::ConfigObject*> fh_output_objs;
129 for (auto& fNet : fragOutObjs) {
130 fh_output_objs.push_back(&fNet);
131 }
132
133 std::vector<conffwk::ConfigObject> CIB_module_outputs;
134 auto source_id = get_source_id();
135
136 int id = static_cast<int>(source_id->get_sid());
137
138 // ----------------------------
139 // create DLH
140 // ----------------------------
141 int det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ // NOLINT(readability/todo)
142 TLOG() << "creating OKS configuration object for CIB Data Link Handler class " << dlhClass << ", id " << id;
143 std::string uid("DLH-CIB");
144 conffwk::ConfigObject dlhObj = obj_fac.create( dlhClass, uid );
145 dlhObj.set_by_val<uint32_t>("source_id", static_cast<uint32_t>(id)); // NOLINT(build/unsigned)
146 dlhObj.set_by_val<uint32_t>("detector_id", static_cast<uint32_t>(det_id)); // NOLINT(build/unsigned)
147 dlhObj.set_by_val<bool>("post_processing_enabled", false);
148 dlhObj.set_obj("module_configuration", &dlhConf->config_object());
149
150 auto net_objc(fh_output_objs);
151
152 conffwk::ConfigObject tsNetObj;
153 // Time Sync network connection
154 if (dlhConf->get_generate_timesync()) {
155 std::string tsStreamUid = tsNetDesc->get_uid_base() + std::to_string(id);
156 tsNetObj = obj_fac.create_net_obj(tsNetDesc, tsStreamUid);
157 net_objc.push_back(&tsNetObj);
158 }
159
160 dlhObj.set_objs("outputs", net_objc);
161
162 // create Queues from CIB to DLH
163 std::string dataQueueUid(dlhInputQDesc->get_uid_base() + std::string("CIB"));
164 conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
165 queueObj.rename(dataQueueUid);
166
167 CIB_module_outputs.push_back(queueObj);
168
169 // Create network connections to DLHs
170 conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID());
171
172 dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
173
174 modules.push_back(obj_fac.get_dal<appmodel::DataHandlerModule>(uid));
175
176 conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
177 CIB_module_outputs.push_back(hsiNetObj);
178
179 auto board = get_board();
180
181 conffwk::ConfigObject module_obj = obj_fac.create( "CIBModule", "CIB-module");
182 module_obj.set_obj("configuration", & CIB_conf -> config_object() );
183 module_obj.set_obj("board", & board -> config_object() );
184
185 std::vector<const conffwk::ConfigObject*> CIB_module_output_ptrs;
186 for ( const auto & o : CIB_module_outputs ) {
187 CIB_module_output_ptrs.push_back( & o );
188 }
189
190 module_obj.set_objs("outputs", CIB_module_output_ptrs);
191
192 auto module = obj_fac.get_dal<appmodel::CIBModule>(module_obj.UID());
193
194 modules.push_back(module);
195
196 obj_fac.update_modules(modules);
197 // return modules;
198} // NOLINT
199
200nlohmann::json CIBoardConf::get_cib_json(const dunedaq::confmodel::Session &session, std::optional<std::string> socket_host, std::optional<uint16_t> socket_port) const
201{
202
203 // shut up compiler!
204 (void)session; // unused parameter
205 nlohmann::json json;
206 json["sockets"] = nlohmann::json::object();
207 if (socket_host.has_value())
208 {
209 json["sockets"]["receiver"] = nlohmann::json::object();
210 json["sockets"]["receiver"]["host"] = socket_host.value();
211 json["sockets"]["receiver"]["port"] = socket_port.value(); // NOLINT(build/unsigned)
212 }
213 else
214 {
215 json["sockets"]["receiver"] = nlohmann::json::object();
216 json["sockets"]["receiver"]["host"] = get_receiver_host();
217 json["sockets"]["receiver"]["port"] = get_receiver_port(); // NOLINT(build/unsigned)
218 }
219
220 TLOG() << "JSON frag : [" << json.dump() << "] " ;
221
222 return json;
223}
#define ERS_HERE
const dunedaq::appmodel::CIBConf * get_generator() const
Get "generator" relationship value.
const dunedaq::appmodel::CIBoardConf * get_board() const
Get "board" relationship value.
void generate_modules(const confmodel::Session *) const override
virtual std::vector< const Resource * > contained_resources() const override
const dunedaq::appmodel::DataHandlerConf * get_link_handler() const
Get "link_handler" relationship value.
uint16_t get_receiver_port() const
Get "receiver_port" attribute value.
nlohmann::json get_cib_json(const dunedaq::confmodel::Session &session, std::optional< std::string > socket_host=std::nullopt, std::optional< uint16_t > socket_port=std::nullopt) const
const std::string & get_receiver_host() const
Get "receiver_host" attribute 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.
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.
void rename(const std::string &new_id)
Rename object.
const ConfigObject & config_object() const
const std::string & UID() const noexcept
conffwk entry point
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.