DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
CRTReaderApplication.cpp
Go to the documentation of this file.
1
12
14
20
22
26
27#include "logging/Logging.hpp"
28
29#include <fmt/core.h>
30
31#include <string>
32#include <vector>
33
34namespace dunedaq::appmodel {
35
36std::vector<const confmodel::Resource*>
40
41void
43{
44
45 TLOG_DEBUG(6) << "Generating modules for application " << this->UID();
46
47 std::vector<const confmodel::DaqModule*> modules;
48
49 ConfigObjectFactory obj_fac(this);
50
51 //
52 // Extract basic configuration objects
53 //
54
55 // Data reader
56 const auto reader_conf = get_data_reader();
57 if (reader_conf == 0) {
58 throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
59 }
60 const std::string reader_class = reader_conf->get_template_for();
61
62 // Data writers
63 const auto writer_confs = get_data_writers();
64 if (writer_confs.size() == 0) {
65 throw(BadConf(ERS_HERE, "No DataWriterModule configuration given"));
66 }
67
68 //
69 // Process the queue rules looking for inputs to our DL/TP handler modules
70 //
71 const QueueDescriptor* dlh_input_qdesc = nullptr;
72
73 for (auto rule : get_queue_rules()) {
74 auto destination_class = rule->get_destination_class();
75 auto data_type = rule->get_descriptor()->get_data_type();
76 // Why datahander here? It is the base class for several DataHandler types (e.g. FDDataHandlerModule,
77 // SNBDataHandlerModule)
78 if (destination_class == "DataHandlerModule") {
79 if (data_type != "DataRequest") {
80 dlh_input_qdesc = rule->get_descriptor();
81 }
82 }
83 }
84
85 if (dlh_input_qdesc == nullptr) {
86 throw(BadConf(ERS_HERE, "No data link handler input queue descriptor given"));
87 }
88
89 //
90 // Scan Detector 2 DAQ connections to extract sender, receiver and stream information
91 //
92
93 // Loop over the detector to daq connections and generate one data reader per connection
94
95 // Collect all streams
96 std::map<uint32_t, const confmodel::Connection*> data_queues_by_sid;
97
98 uint16_t conn_idx = 0;
99
100 for (auto d2d_conn : get_detector_connections()) {
101
102 // Are we sure?
103 if (d2d_conn->is_disabled(*session)) {
104 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
105 continue;
106 }
107
108 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
109 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
110
111 std::vector<const confmodel::DetectorStream*> enabled_det_streams;
112 // Loop over streams
113 for (auto stream : d2d_conn->streams()) {
114
115 // Are we sure?
116 if (stream->is_disabled(*session)) {
117 TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
118 continue;
119 }
120
121 enabled_det_streams.push_back(stream);
122 }
123
124 // Create the raw data queues
125 std::vector<const conffwk::ConfigObject*> data_queue_objs;
126 // keep a map for convenience
127
128 // Create data queues
129 for (auto ds : enabled_det_streams) {
130 conffwk::ConfigObject queue_obj = obj_fac.create_queue_sid_obj(dlh_input_qdesc, ds);
131 const auto* data_queue = obj_fac.get_dal<confmodel::Connection>(queue_obj.UID());
132 data_queue_objs.push_back(&data_queue->config_object());
133 data_queues_by_sid[ds->get_source_id()] = data_queue;
134 }
135
136 //-----------------------------------------------------------------
137 //
138 // Create DataReaderModule object
139 //
140
141 //
142 // Instantiate DataReaderModule of type CRTBernReaderModule/CRTGrenobleReaderModule
143 //
144
145 // Create the Data reader object
146
147 std::string reader_uid(fmt::format("crtdatareader-{}-{}", this->UID(), std::to_string(conn_idx++)));
148 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
149 auto reader_obj = obj_fac.create(reader_class, reader_uid);
150
151 // Populate configuration and interfaces (leave output queues for later)
152 reader_obj.set_obj("configuration", &reader_conf->config_object());
153 reader_obj.set_objs("connections", {&d2d_conn->config_object()});
154 reader_obj.set_objs("outputs", data_queue_objs);
155
156 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(reader_obj.UID()));
157
158 //-----------------------------------------------------------------
159 //
160 // Create DataWriterModule objects
161 //
162
163 //
164 // Instantiate DataWriterModule of type SocketWriterModule
165 //
166
167 // Create the SocketWriterModule objects
168
169 conn_idx = 0;
170
171 for (const auto writer_conf : writer_confs) {
172
173 const std::string writer_class = writer_conf->get_template_for();
174
175 std::string writer_uid(fmt::format("socketdatawriter-{}-{}", this->UID(), std::to_string(conn_idx++)));
176 TLOG_DEBUG(6) << fmt::format(
177 "Creating OKS configuration object for socket data writer class {} with id {}", writer_class, writer_uid);
178 auto writer_obj = obj_fac.create(writer_class, writer_uid);
179
180 // Populate configuration and interfaces
181 writer_obj.set_obj("configuration", &writer_conf->config_object());
182 writer_obj.set_objs("connections", {&d2d_conn->config_object()});
183 writer_obj.set_objs("inputs", data_queue_objs);
184
185 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(writer_obj.UID()));
186 }
187 }
188
189 obj_fac.update_modules(modules);
190}
191
192} // namespace dunedaq::appmodel
#define ERS_HERE
const dunedaq::appmodel::DataReaderConf * get_data_reader() const
Get "data_reader" relationship value.
void generate_modules(const confmodel::Session *) const override
const std::vector< const dunedaq::appmodel::SocketDataWriterConf * > & get_data_writers() const
Get "data_writers" relationship value.
virtual std::vector< const Resource * > contained_resources() const override
const std::vector< const dunedaq::confmodel::DetectorToDaqConnection * > & get_detector_connections() const
Get "detector_connections" 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
const T * get_dal(std::string uid) const
conffwk::ConfigObject create(const std::string &class_name, const std::string &id) const
const std::vector< const dunedaq::appmodel::QueueConnectionRule * > & get_queue_rules() const
Get "queue_rules" relationship value.
const std::string & UID() const noexcept
Return object identity.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
const std::string & UID() const noexcept
std::vector< const dunedaq::confmodel::Resource * > to_resources(const std::vector< T * > &vector_of_children)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112