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