DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
DaphneApplication.cpp
Go to the documentation of this file.
1
12#include "oks/kernel.hpp"
13#include "logging/Logging.hpp"
14
15#include "confmodel/GeoId.hpp"
18
41
42#include <string>
43#include <vector>
44#include <bitset>
45#include <iostream>
46#include <fmt/core.h>
47#include <set>
48#include <map>
49
50namespace dunedaq::appmodel {
51
52std::vector<const confmodel::Resource*>
56
57void
58DaphneApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
59{
60 ConfigObjectFactory obj_fac(this);
61
62 std::vector<const confmodel::DaqModule*> modules;
63
64 auto daphne_conf = get_configuration();
65
66 std::map<std::string, const DaphneV2BoardConf*> conf_map;
67 auto confs = daphne_conf->get_boards();
68 for ( const auto & c : confs ) {
69 conf_map[c->get_key()] = c->get_conf();
70 }
71
72 // these maps are all indexed on the board id {detector].{crate}.{slot}
73 std::map<std::string, bool> v3_map;
74 std::map<std::string, const confmodel::NetworkInterface*> interfaces;
75 std::map<std::string, std::string> ctrl_hosts;
76
77 // map from ctrl_host to senders
78 std::map<std::string, std::vector<const appmodel::HermesDataSender*> > hermes_senders;
79
80 for (auto d2d_conn : get_detector_connections()) {
81
82 // A Resource can be disabled and still its application can be enabled because the application can have multile resources, so we need to check which resources are enabled
83 if (helper->is_disabled(d2d_conn)) {
84 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
85 continue;
86 }
87
88 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
89 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
90
91 // Redundant? Schema forbids 0 connections
92 if (d2d_conn->contained_resources().empty()) {
93 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders or receivers"));
94 }
95
96 auto flx_conn = dynamic_cast<const appmodel::FelixDetectorToDaqConnection *>( d2d_conn ); // NOLINT(runtime/rtti)
97 auto net_conn = dynamic_cast<const appmodel::NetworkDetectorToDaqConnection *>( d2d_conn ); // NOLINT(runtime/rtti)
98
99 if ( ! net_conn && ! flx_conn) {
100 throw BadConf(ERS_HERE, d2d_conn->UID() + " is neither felix or eth connection");
101 }
102
103 if ( flx_conn ) {
104 auto det_senders = flx_conn->get_felix_senders();
105
106 // Loop over senders
107 for (const auto* felix_sender : det_senders) {
108
109 if ( helper->is_disabled(felix_sender) ) {
110 TLOG() << "Skipping disabled sender: " << felix_sender->UID();
111 continue;
112 }
113
114 auto ip = felix_sender -> get_control_host();
115
116 // from the felix sender we get the DetStream and then the GeoID
117
118 auto streams = felix_sender -> get_streams();
119
120 for ( const auto * det_s : streams ) {
121
122 if ( helper->is_disabled(det_s) ) {
123 TLOG() << "Skipping disabled DetStream: " << det_s->UID();
124 continue;
125 }
126
127 auto geo_id = det_s->get_geo_id();
128 auto id = fmt::format("{}.{}.{}", geo_id->get_detector_id(), geo_id->get_crate_id(), geo_id->get_slot_id());
129 if (!v3_map.contains(id)) {
130 v3_map[id] = false;
131 }
132
133 } // loop over DetStreams
134
135 } // loop over det_senders
136 } // if flx connection
137
138 if ( net_conn ) {
139 auto det_senders = net_conn->get_net_senders();
140
141 for ( const auto* nw_sender : det_senders ) {
142 if ( helper->is_disabled(nw_sender) ) {
143 TLOG() << "Skipping disabled sender: " << nw_sender->UID();
144 continue;
145 }
146
147 // Check the sender type, must me a HermesSender
148 const auto* hrms_sender = nw_sender->cast<appmodel::HermesDataSender>();
149 if (!hrms_sender ) {
150 throw(BadConf(ERS_HERE, fmt::format("DataSender {} is not a appmodel::HermesDataSender", nw_sender->UID())));
151 }
152
153 hermes_senders[hrms_sender->get_control_host()].push_back(hrms_sender);
154
155 auto streams = nw_sender -> get_streams();
156 for ( const auto * det_s : streams ) {
157
158 if ( helper->is_disabled(det_s) ) {
159 TLOG() << "Skipping disabled DetStream: " << det_s->UID();
160 continue;
161 }
162
163 auto geo_id = det_s->get_geo_id();
164 auto id = fmt::format("{}.{}.{}", geo_id->get_detector_id(), geo_id->get_crate_id(), geo_id->get_slot_id());
165 if (!v3_map.contains(id)) {
166 v3_map[id] = true;
167 interfaces[id] = net_conn->get_net_receiver()->get_uses();
168 ctrl_hosts[id] = hrms_sender->get_control_host();
169 }
170
171 } // loop over streams
172
173 } // loop over NW senders
174
175 } // if net_connection
176
177 } // loop over det2DAQ Connections
178
179
180
181
182 for ( const auto & [id, v3] : v3_map ) {
183
184 auto conf_it = conf_map.find(id);
185 if ( conf_it == conf_map.end() ) {
186 throw MissingDaphne(ERS_HERE, id);
187 }
188 auto conf = conf_it->second;
189
190 conffwk::ConfigObject module_obj = obj_fac.create( (v3 ? "DaphneV3ControllerModule" : "DaphneV2ControllerModule"), fmt::format("controller-{}", id) );
191 module_obj.set_obj("daphne_conf", & daphne_conf -> config_object() );
192 module_obj.set_obj("board_conf", & conf -> config_object() );
193
194 auto module = obj_fac.get_dal<confmodel::DaqModule>(module_obj);
195 modules.push_back(module);
196
197
198 // Create Hermes Modules
199 if (v3) {
200 std::string hermes_uid = fmt::format("daphne-hermes-ctrl-{}", id);
201 conffwk::ConfigObject hermes_obj = obj_fac.create("HermesModule", hermes_uid);
202 hermes_obj.set_obj("address_table", &this->get_hermes_module_conf()->get_address_table()->config_object());
203 hermes_obj.set_by_val<std::string>("uri", fmt::format("{}://{}:{}", this->get_hermes_module_conf()->get_ipbus_type(), ctrl_hosts[id], this->get_hermes_module_conf()->get_ipbus_port()));
204 hermes_obj.set_by_val<uint32_t>("timeout_ms", this->get_hermes_module_conf()->get_ipbus_timeout_ms()); // NOLINT
205 hermes_obj.set_obj("destination", & interfaces[id]->config_object());
206
207 std::vector< const conffwk::ConfigObject * > links_obj;
208 const auto & senders = hermes_senders[ctrl_hosts[id]];
209 for ( const auto* sndr : senders ){
210 links_obj.push_back(&sndr->config_object());
211 }
212 hermes_obj.set_objs("links", links_obj);
213
214 modules.push_back(obj_fac.get_dal<appmodel::HermesModule>(hermes_obj));
215
216 }
217
218 } // ips
219
220 obj_fac.update_modules(modules);
221} // NOLINT
222
223
224bool
226
227 for ( auto ch_p : get_active_channels() ) {
228 if ( ch_p->get_channel_id() == ch ) {
229 return true;
230 }
231 }
232
233 return false;
234}
235
236const DaphneV2Channel &
238
239 for ( auto ch_p : get_active_channels() ) {
240 if ( ch_p->get_channel_id() == ch ) {
241 return *ch_p;
242 }
243 }
244
245 return *get_default_channel();
246}
247
248bool
250
251 auto begin = afe*8;
252 auto end = (afe+1)*8;
253 for ( size_t i = begin; i < end; ++i) {
254 if( is_channel_used(i) ) return true;
255 }
256
257 return false;
258}
259
260const DaphneV2AFE &
262
263 if ( ! is_afe_used(ch) ) return *get_default_afe();
264
265 for ( auto afe_p : get_active_afes() ) {
266 if ( afe_p->get_afe_id() == ch ) {
267 return *afe_p;
268 }
269 }
270
271 throw appmodel::MissingAFE(ERS_HERE, UID(), ch);
272}
273
274
275uint16_t
277
278 // ADC, reg 4 has no parsing as it's all made of booleans
279 std::bitset<5> reg4;
280 // bits 0 and 2 are reserved
281 reg4[1] = get_low_resolution();
282 reg4[3] = get_output_offset_binary();
283 reg4[4] = get_MSB_first();
284 return reg4.to_ulong();
285}
286
287uint16_t
289
290 std::bitset<14> reg51(get_lpf_cut_frequency());
291 reg51 <<= 1;
292 reg51[4] = get_integrator_disable();
293 reg51[7] = true; // clamp is always disabled and we are in low noise mode
294 reg51[13] = get_gain();
295
296 return reg51.to_ulong() ;
297}
298
299uint16_t
301
302 std::bitset<16> reg52;
303
304 decltype(reg52) clamp(get_clamp());
305 clamp <<= 6;
306
307 reg52[12] = get_integrator_disable();
308
309 decltype(reg52) gain(get_gain());
310 clamp <<= 13;
311
312 reg52 |= clamp;
313 reg52 |= gain;
314
315 return reg52.to_ulong();
316}
317
318} // namespace dunedaq::appmodel
#define ERS_HERE
void update_modules(const std::vector< const confmodel::DaqModule * > &modules)
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::confmodel::DetectorToDaqConnection * > & get_detector_connections() const
Get "detector_connections" relationship value. List of detector components controlled by this applica...
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
virtual std::vector< const Resource * > contained_resources() const override
const dunedaq::appmodel::HermesModuleConf * get_hermes_module_conf() const
Get "hermes_module_conf" relationship value.
const dunedaq::appmodel::DaphneConf * get_configuration() const
Get "configuration" relationship value.
bool get_MSB_first() const
Get "MSB_first" attribute value. Which Significant bit comes first, true=MSB, false=LSB.
bool get_low_resolution() const
Get "low_resolution" attribute value. true=12bit, false=14bit.
bool get_output_offset_binary() const
Get "output_offset_binary" attribute value. true=Offset Binary, false=2s complement.
const std::vector< const dunedaq::appmodel::DaphneV2AFE * > & get_active_afes() const
Get "active_afes" relationship value.
const DaphneV2AFE & get_afe(size_t id) const
const DaphneV2Channel & get_channel(size_t ch) const
const dunedaq::appmodel::DaphneV2Channel * get_default_channel() const
Get "default_channel" relationship value.
const std::vector< const dunedaq::appmodel::DaphneV2Channel * > & get_active_channels() const
Get "active_channels" relationship value.
const dunedaq::appmodel::DaphneV2AFE * get_default_afe() const
Get "default_afe" relationship value.
bool get_integrator_disable() const
Get "integrator_disable" attribute value.
uint8_t get_clamp() const
Get "clamp" attribute value. 0=auto setting, 1=1.5 Vpp, 2=1.15 Vpp, 3=0.6 Vpp.
uint8_t get_gain() const
Get "gain" attribute value. 0=18 dB, 1=24 dB, 2=12 dB.
bool get_integrator_disable() const
Get "integrator_disable" attribute value.
uint8_t get_lpf_cut_frequency() const
Get "lpf_cut_frequency" attribute value. cut frequency, only 4 values acceptable. 0=15MHz,...
bool get_gain() const
Get "gain" attribute value. rue=30 dB, false=24 dB.
uint32_t get_ipbus_timeout_ms() const
Get "ipbus_timeout_ms" attribute value.
void set_by_val(const std::string &name, T value)
Set attribute value.
void set_objs(const std::string &name, const std::vector< const ConfigObject * > &o, bool skip_non_null_check=false)
Set relationship multi-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
std::vector< const dunedaq::confmodel::Resource * > to_resources(const std::vector< T * > &vector_of_children)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22