DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPReplayApplication.cpp
Go to the documentation of this file.
1
12
14
17#include "confmodel/Service.hpp"
18
34
35#include "logging/Logging.hpp"
36
37#include <iomanip>
38#include <set>
39#include <string>
40#include <vector>
41
42namespace dunedaq {
43namespace appmodel {
44
45void
46TPReplayApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> /*helper*/) const
47{
48
49 std::vector<const confmodel::DaqModule*> modules;
50
51 ConfigObjectFactory obj_fac(this);
52
53 /**************************************************************
54 * Instantiate the Trigger Primitive Maker Module module
55 **************************************************************/
56
57 auto tprm_conf = get_tprm_conf();
58
59 if (!tprm_conf) {
60 throw(BadConf(ERS_HERE, "No TPPM configuration in TPReplayApplication given"));
61 }
62
63 const std::string tprm_uid(tprm_conf->UID());
64 const std::string tprm_class = tprm_conf->get_template_for();
65 auto tpm_obj = obj_fac.create(tprm_class, tprm_uid);
66 tpm_obj.set_obj("configuration", &(tprm_conf->config_object()));
67
68 /**************************************************************
69 * Get total planes from config
70 **************************************************************/
71 const int total_planes = tprm_conf->get_total_planes();
72
73 /**************************************************************
74 * Extract # of filtered planes
75 **************************************************************/
76 const auto plane_filtering = tprm_conf->get_filter_out_plane();
77 if (plane_filtering.size() >= 3) {
78 throw(BadConf(ERS_HERE,
79 "TPReplayApplication: too many planes configured for filtering! At most 2 planes can be filtered!"));
80 }
81
82 /**************************************************************
83 * Instantiate the TP Handler (TA Maker) module(s)
84 **************************************************************/
85 auto tph_conf = get_tp_handler();
86 if (!tph_conf) {
87 throw(BadConf(ERS_HERE, "TP handler configuration object is missing"));
88 }
89 std::string tph_class = "";
90 if (tph_conf != nullptr) {
91 tph_class = tph_conf->get_template_for();
92 }
93
94 // For now, have X (X=total_planes) identical config TP Handlers
95 std::vector<conffwk::ConfigObject> TPHs;
96 std::vector<std::string> TPHs_uids;
97
98 // Source IDs
99 auto tpsrc_ids = get_tp_source_ids();
100 if (tpsrc_ids.size() < static_cast<size_t>(total_planes)) {
101 throw(BadConf(ERS_HERE, "Not enough TP source IDs provided"));
102 }
103
104 const auto tph_conf_obj = tph_conf->config_object();
105 for (int i = 0; i < total_planes; i++) {
106 std::string tp_uid = "tphandler-tpreplay-" + std::to_string(i + 1);
107 TPHs_uids.push_back(tp_uid);
108 auto tph_obj = obj_fac.create(tph_class, tp_uid);
109 tph_obj.set_by_val<uint32_t>("source_id", tpsrc_ids[i]->get_sid());
110 tph_obj.set_by_val<uint32_t>("detector_id", 1); // 1 == kDAQ
111 tph_obj.set_by_val<bool>("post_processing_enabled", true);
112 tph_obj.set_obj("module_configuration", &tph_conf_obj);
113 TPHs.push_back(tph_obj);
114 }
115
116 /**************************************************************
117 * Deal with queues
118 **************************************************************/
119 // Load queue configurations
120 const QueueDescriptor* tp_inputq_desc = nullptr;
121
122 for (const auto& rule : get_queue_rules()) {
123 auto destination_class = rule->get_destination_class();
124 auto data_type = rule->get_descriptor()->get_data_type();
125 if (destination_class == "TriggerDataHandlerModule" && data_type == "TriggerPrimitiveVector") {
126 tp_inputq_desc = rule->get_descriptor();
127 }
128 }
129 if (!tp_inputq_desc) {
130 throw(BadConf(ERS_HERE, "No matching queue descriptor found for TP input"));
131 }
132
133 // Same as above (ROUs * planes queues), later dynamically
134 std::vector<conffwk::ConfigObject> TP_queues;
135 for (int i = 0; i < total_planes; i++) {
136 std::string tp_q_uid = "tpinput-" + std::to_string(i + 1);
137 auto tp_q_obj = obj_fac.create_queue_obj(tp_inputq_desc, tp_q_uid);
138 TP_queues.push_back(tp_q_obj);
139 }
140
141 /**************************************************************
142 * Deal with network connections
143 **************************************************************/
144 const NetworkConnectionDescriptor* ta_net_desc = nullptr;
145 const NetworkConnectionDescriptor* dr_net_desc = nullptr;
146
147 for (const auto& rule : get_network_rules()) {
148 auto endpoint_class = rule->get_endpoint_class();
149 auto data_type = rule->get_descriptor()->get_data_type();
150 if (data_type == "TriggerActivity") {
151 ta_net_desc = rule->get_descriptor();
152 } else if (data_type == "DataRequest") {
153 dr_net_desc = rule->get_descriptor();
154 }
155 }
156 if (!ta_net_desc || !dr_net_desc) {
157 throw(BadConf(ERS_HERE, "Missing network descriptors for TA or DR"));
158 }
159
160 // Create vectors for network connections
161 std::vector<conffwk::ConfigObject> ta_net_objects;
162 std::vector<conffwk::ConfigObject> dr_net_objects;
163
164 // Outputs for each handler
165 for (int i = 0; i < total_planes; i++) {
166 const auto ta_service_obj = ta_net_desc->get_associated_service()->config_object();
167 const std::string ta_stream_uid = ta_net_desc->get_uid_base() + UID() + "-" + std::to_string(i + 1);
168 auto ta_net_obj = obj_fac.create_net_obj(ta_net_desc, ta_stream_uid);
169 ta_net_obj.set_obj("associated_service", &ta_service_obj);
170 ta_net_objects.push_back(ta_net_obj);
171 }
172
173 // Data requests
174 for (int i = 0; i < total_planes; i++) {
175 const auto dr_service_obj = dr_net_desc->get_associated_service()->config_object();
176 // Format the integer with leading zeros to maintain consistent length
177 std::ostringstream oss;
178 oss << UID() << "-1000" << std::setfill('0') << std::setw(2) // Ensures at least 2 digits (e.g., 01, 10)
179 << (i + 1);
180 const std::string dr_stream_uid = oss.str();
181 auto dr_net_obj = obj_fac.create_net_obj(dr_net_desc, dr_stream_uid);
182 dr_net_obj.set_obj("associated_service", &dr_service_obj);
183 dr_net_objects.push_back(dr_net_obj);
184 }
185
186 /**************************************************************
187 * Finally set inputs & outputs
188 **************************************************************/
189 // Convert TP_queues to a vector of raw pointers
190 std::vector<const conffwk::ConfigObject*> raw_tp_queues;
191 for (const auto& tp_queue : TP_queues) {
192 raw_tp_queues.push_back(&tp_queue);
193 }
194 tpm_obj.set_objs("outputs", raw_tp_queues);
195
196 for (int i = 0; i < total_planes; i++) {
197 // Convert network objects to raw pointers
198 const std::vector<const conffwk::ConfigObject*> temp_inputs = { &TP_queues[i], &dr_net_objects[i] };
199 const std::vector<const conffwk::ConfigObject*> temp_outputs = { &ta_net_objects[i] };
200 TPHs[i].set_objs("inputs", temp_inputs);
201 TPHs[i].set_objs("outputs", temp_outputs);
202 }
203
204 // Store modules
205 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(tprm_conf->UID()));
206 for (int i = 0; i < total_planes; i++) {
207 modules.push_back(obj_fac.get_dal<confmodel::DaqModule>(TPHs_uids[i]));
208 }
209
210 obj_fac.update_modules(modules);
211}
212
213} // namespace appmodel
214} // namespace dunedaq
#define ERS_HERE
void update_modules(const std::vector< const confmodel::DaqModule * > &modules)
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_queue_obj(const QueueDescriptor *qdesc, 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 dunedaq::confmodel::Service * get_associated_service() const
Get "associated_service" relationship value. Service provided by this connection.
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.
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
const std::vector< const dunedaq::appmodel::SourceIDConf * > & get_tp_source_ids() const
Get "tp_source_ids" relationship value.
const dunedaq::appmodel::DataHandlerConf * get_tp_handler() const
Get "tp_handler" relationship value.
const dunedaq::appmodel::TPReplayModuleConf * get_tprm_conf() const
Get "tprm_conf" relationship value.
void set_by_val(const std::string &name, T value)
Set attribute value.
void set_obj(const std::string &name, const ConfigObject *o, bool skip_non_null_check=false)
Set relationship single-value.
const ConfigObject & config_object() const
const std::string & UID() const noexcept
conffwk entry point
Including Qt Headers.