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
53CIBApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
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 std::vector<conffwk::ConfigObject> fragOutObjs;
109 for (auto [uid, descriptor]:
110 helper->get_netdescriptors("Fragment", "DFApplication")) {
111 fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
112 }
113
114 // start building the list of outputs
115 std::vector<const conffwk::ConfigObject*> fh_output_objs;
116 for (auto& fNet : fragOutObjs) {
117 fh_output_objs.push_back(&fNet);
118 }
119
120 std::vector<conffwk::ConfigObject> CIB_module_outputs;
121 auto source_id = get_source_id();
122
123 int id = static_cast<int>(source_id->get_sid());
124
125 // ----------------------------
126 // create DLH
127 // ----------------------------
128 int det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ // NOLINT(readability/todo)
129 TLOG() << "creating OKS configuration object for CIB Data Link Handler class " << dlhClass << ", id " << id;
130 std::string uid("DLH-CIB");
131 conffwk::ConfigObject dlhObj = obj_fac.create( dlhClass, uid );
132 dlhObj.set_by_val<uint32_t>("source_id", static_cast<uint32_t>(id)); // NOLINT(build/unsigned)
133 dlhObj.set_by_val<uint32_t>("detector_id", static_cast<uint32_t>(det_id)); // NOLINT(build/unsigned)
134 dlhObj.set_by_val<bool>("post_processing_enabled", false);
135 dlhObj.set_obj("module_configuration", &dlhConf->config_object());
136
137 auto net_objc(fh_output_objs);
138
139 conffwk::ConfigObject tsNetObj;
140 // Time Sync network connection
141 if (dlhConf->get_generate_timesync()) {
142 std::string tsStreamUid = tsNetDesc->get_uid_base() + std::to_string(id);
143 tsNetObj = obj_fac.create_net_obj(tsNetDesc, tsStreamUid);
144 net_objc.push_back(&tsNetObj);
145 }
146
147 dlhObj.set_objs("outputs", net_objc);
148
149 // create Queues from CIB to DLH
150 std::string dataQueueUid(dlhInputQDesc->get_uid_base() + std::string("CIB"));
151 conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
152 queueObj.rename(dataQueueUid);
153
154 CIB_module_outputs.push_back(queueObj);
155
156 // Create network connections to DLHs
157 conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID());
158
159 dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
160
161 modules.push_back(obj_fac.get_dal<appmodel::DataHandlerModule>(uid));
162
163 conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
164 CIB_module_outputs.push_back(hsiNetObj);
165
166 auto board = get_board();
167
168 conffwk::ConfigObject module_obj = obj_fac.create( "CIBModule", "CIB-module");
169 module_obj.set_obj("configuration", & CIB_conf -> config_object() );
170 module_obj.set_obj("board", & board -> config_object() );
171
172 std::vector<const conffwk::ConfigObject*> CIB_module_output_ptrs;
173 for ( const auto & o : CIB_module_outputs ) {
174 CIB_module_output_ptrs.push_back( & o );
175 }
176
177 module_obj.set_objs("outputs", CIB_module_output_ptrs);
178
179 auto module = obj_fac.get_dal<appmodel::CIBModule>(module_obj.UID());
180
181 modules.push_back(module);
182
183 obj_fac.update_modules(modules);
184 // return modules;
185} // NOLINT
186
187nlohmann::json CIBoardConf::get_cib_json(const dunedaq::confmodel::Session &session, std::optional<std::string> socket_host, std::optional<uint16_t> socket_port) const
188{
189
190 // shut up compiler!
191 (void)session; // unused parameter
192 nlohmann::json json;
193 json["sockets"] = nlohmann::json::object();
194 if (socket_host.has_value())
195 {
196 json["sockets"]["receiver"] = nlohmann::json::object();
197 json["sockets"]["receiver"]["host"] = socket_host.value();
198 json["sockets"]["receiver"]["port"] = socket_port.value(); // NOLINT(build/unsigned)
199 }
200 else
201 {
202 json["sockets"]["receiver"] = nlohmann::json::object();
203 json["sockets"]["receiver"]["host"] = get_receiver_host();
204 json["sockets"]["receiver"]["port"] = get_receiver_port(); // NOLINT(build/unsigned)
205 }
206
207 TLOG() << "JSON frag : [" << json.dump() << "] " ;
208
209 return json;
210}
#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(std::shared_ptr< appmodel::ConfigurationHelper >) 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.