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::DaqModule*>
38{
39
40 TLOG_DEBUG(6) << "Generating modules for application " << this->UID();
41
42 std::vector<const confmodel::DaqModule*> modules;
43
44 const ConfigObjectFactory obj_fac(this);
45
46 //
47 // Extract basic configuration objects
48 //
49
50 // Data reader
51 const auto reader_conf = get_data_reader();
52 if (reader_conf == 0) {
53 throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
54 }
55 const std::string reader_class = reader_conf->get_template_for();
56
57 // Data writers
58 const auto writer_confs = get_data_writers();
59 if (writer_confs.size() == 0) {
60 throw(BadConf(ERS_HERE, "No DataWriterModule configuration given"));
61 }
62
63 //
64 // Process the queue rules looking for inputs to our DL/TP handler modules
65 //
66 const QueueDescriptor* dlh_input_qdesc = nullptr;
67
68 for (auto rule : get_queue_rules()) {
69 auto destination_class = rule->get_destination_class();
70 auto data_type = rule->get_descriptor()->get_data_type();
71 // Why datahander here?
72 if (destination_class == "FDDataHandlerModule") {
73 if (data_type != "DataRequest") {
74 dlh_input_qdesc = rule->get_descriptor();
75 }
76 }
77 }
78
79 //
80 // Scan Detector 2 DAQ connections to extract sender, receiver and stream information
81 //
82
83 // Loop over the detector to daq connections and generate one data reader per connection
84
85 // Collect all streams
86 std::map<uint32_t, const confmodel::Connection*> data_queues_by_sid;
87
88 uint16_t conn_idx = 0;
89
90 for (auto d2d_conn_res : get_contains()) {
91
92 // Are we sure?
93 if (d2d_conn_res->disabled(*session)) {
94 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn_res->UID();
95 continue;
96 }
97
98 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn_res->UID();
99 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
100 auto d2d_conn = d2d_conn_res->cast<confmodel::DetectorToDaqConnection>();
101
102 if (!d2d_conn) {
103 throw(BadConf(ERS_HERE, "CRTReaderApplication contains something other than DetectorToDaqConnection"));
104 }
105
106 if (d2d_conn->get_contains().empty()) {
107 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders or receivers"));
108 }
109
110 std::vector<const confmodel::DetectorStream*> enabled_det_streams;
111 // Loop over streams
112 for (auto stream : d2d_conn->get_streams()) {
113
114 // Are we sure?
115 if (stream->disabled(*session)) {
116 TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
117 continue;
118 }
119
120 enabled_det_streams.push_back(stream);
121 }
122
123 // Create the raw data queues
124 std::vector<const conffwk::ConfigObject*> data_queue_objs;
125 // keep a map for convenience
126
127 // Create data queues
128 for (auto ds : enabled_det_streams) {
129 conffwk::ConfigObject queue_obj = obj_fac.create_queue_sid_obj(dlh_input_qdesc, ds);
130 const auto* data_queue = obj_fac.get_dal<confmodel::Connection>(queue_obj.UID());
131 data_queue_objs.push_back(&data_queue->config_object());
132 data_queues_by_sid[ds->get_source_id()] = data_queue;
133 }
134
135 //-----------------------------------------------------------------
136 //
137 // Create DataReaderModule object
138 //
139
140 //
141 // Instantiate DataReaderModule of type CRTBernReaderModule/CRTGrenobleReaderModule
142 //
143
144 // Create the Data reader object
145
146 std::string reader_uid(fmt::format("crtdatareader-{}-{}", this->UID(), std::to_string(conn_idx++)));
147 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
148 auto reader_obj = obj_fac.create(reader_class, reader_uid);
149
150 // Populate configuration and interfaces (leave output queues for later)
151 reader_obj.set_obj("configuration", &reader_conf->config_object());
152 reader_obj.set_objs("connections", {&d2d_conn_res->config_object()});
153 reader_obj.set_objs("outputs", data_queue_objs);
154
155 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(reader_obj.UID()));
156
157 //-----------------------------------------------------------------
158 //
159 // Create DataWriterModule objects
160 //
161
162 //
163 // Instantiate DataWriterModule of type SocketWriterModule
164 //
165
166 // Create the SocketWriterModule objects
167
168 conn_idx = 0;
169
170 for (const auto writer_conf : writer_confs) {
171
172 const std::string writer_class = writer_conf->get_template_for();
173
174 std::string writer_uid(fmt::format("socketdatawriter-{}-{}", this->UID(), std::to_string(conn_idx++)));
175 TLOG_DEBUG(6) << fmt::format(
176 "Creating OKS configuration object for socket data writer class {} with id {}", writer_class, writer_uid);
177 auto writer_obj = obj_fac.create(writer_class, writer_uid);
178
179 // Populate configuration and interfaces
180 writer_obj.set_obj("configuration", &writer_conf->config_object());
181 writer_obj.set_objs("connections", {&d2d_conn_res->config_object()});
182 writer_obj.set_objs("inputs", data_queue_objs);
183
184 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(writer_obj.UID()));
185 }
186
187 }
188
189 return modules;
190}
191
192} // namespace dunedaq::appmodel
#define ERS_HERE
const dunedaq::appmodel::DataReaderConf * get_data_reader() const
Get "data_reader" relationship value.
std::vector< const dunedaq::confmodel::DaqModule * > generate_modules(const confmodel::Session *) const override
const std::vector< const dunedaq::appmodel::SocketDataWriterConf * > & get_data_writers() const
Get "data_writers" relationship value.
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
const std::vector< const dunedaq::confmodel::ResourceBase * > & get_contains() const
Get "contains" relationship value. A resource set is a container of resources to easily implement gro...
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112