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
41std::vector<const confmodel::DaqModule*>
43{
44
45 TLOG_DEBUG(6) << "Generating modules for application " << this->UID();
46
47 std::vector<const confmodel::DaqModule*> modules;
48
49 const 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?
77 if (destination_class == "FDDataHandlerModule") {
78 if (data_type != "DataRequest") {
79 dlh_input_qdesc = rule->get_descriptor();
80 }
81 }
82 }
83
84 //
85 // Scan Detector 2 DAQ connections to extract sender, receiver and stream information
86 //
87
88 // Loop over the detector to daq connections and generate one data reader per connection
89
90 // Collect all streams
91 std::map<uint32_t, const confmodel::Connection*> data_queues_by_sid;
92
93 uint16_t conn_idx = 0;
94
95 for (auto d2d_conn : get_detector_connections()) {
96
97 // Are we sure?
98 if (d2d_conn->is_disabled(*session)) {
99 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
100 continue;
101 }
102
103 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
104 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
105
106 std::vector<const confmodel::DetectorStream*> enabled_det_streams;
107 // Loop over streams
108 for (auto stream : d2d_conn->streams()) {
109
110 // Are we sure?
111 if (stream->is_disabled(*session)) {
112 TLOG_DEBUG(7) << "Ignoring disabled DetectorStream " << stream->UID();
113 continue;
114 }
115
116 enabled_det_streams.push_back(stream);
117 }
118
119 // Create the raw data queues
120 std::vector<const conffwk::ConfigObject*> data_queue_objs;
121 // keep a map for convenience
122
123 // Create data queues
124 for (auto ds : enabled_det_streams) {
125 conffwk::ConfigObject queue_obj = obj_fac.create_queue_sid_obj(dlh_input_qdesc, ds);
126 const auto* data_queue = obj_fac.get_dal<confmodel::Connection>(queue_obj.UID());
127 data_queue_objs.push_back(&data_queue->config_object());
128 data_queues_by_sid[ds->get_source_id()] = data_queue;
129 }
130
131 //-----------------------------------------------------------------
132 //
133 // Create DataReaderModule object
134 //
135
136 //
137 // Instantiate DataReaderModule of type CRTBernReaderModule/CRTGrenobleReaderModule
138 //
139
140 // Create the Data reader object
141
142 std::string reader_uid(fmt::format("crtdatareader-{}-{}", this->UID(), std::to_string(conn_idx++)));
143 TLOG_DEBUG(6) << fmt::format("creating OKS configuration object for Data reader class {} with id {}", reader_class, reader_uid);
144 auto reader_obj = obj_fac.create(reader_class, reader_uid);
145
146 // Populate configuration and interfaces (leave output queues for later)
147 reader_obj.set_obj("configuration", &reader_conf->config_object());
148 reader_obj.set_objs("connections", {&d2d_conn->config_object()});
149 reader_obj.set_objs("outputs", data_queue_objs);
150
151 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(reader_obj.UID()));
152
153 //-----------------------------------------------------------------
154 //
155 // Create DataWriterModule objects
156 //
157
158 //
159 // Instantiate DataWriterModule of type SocketWriterModule
160 //
161
162 // Create the SocketWriterModule objects
163
164 conn_idx = 0;
165
166 for (const auto writer_conf : writer_confs) {
167
168 const std::string writer_class = writer_conf->get_template_for();
169
170 std::string writer_uid(fmt::format("socketdatawriter-{}-{}", this->UID(), std::to_string(conn_idx++)));
171 TLOG_DEBUG(6) << fmt::format(
172 "Creating OKS configuration object for socket data writer class {} with id {}", writer_class, writer_uid);
173 auto writer_obj = obj_fac.create(writer_class, writer_uid);
174
175 // Populate configuration and interfaces
176 writer_obj.set_obj("configuration", &writer_conf->config_object());
177 writer_obj.set_objs("connections", {&d2d_conn->config_object()});
178 writer_obj.set_objs("inputs", data_queue_objs);
179
180 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(writer_obj.UID()));
181 }
182
183 }
184
185 return modules;
186}
187
188} // 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.
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.
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