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
57
58void
60{
61 ConfigObjectFactory obj_fac(this);
62
63 std::vector<const confmodel::DaqModule*> modules;
64
65 auto daphne_conf = get_configuration();
66
67 std::map<std::string, const DaphneV2BoardConf*> conf_map;
68 auto confs = daphne_conf->get_boards();
69 for ( const auto & c : confs ) {
70 conf_map[c->get_key()] = c->get_conf();
71 }
72
73 // these maps are all indexed on the board id {detector].{crate}.{slot}
74 std::map<std::string, bool> v3_map;
75 std::map<std::string, const confmodel::NetworkInterface*> interfaces;
76 std::map<std::string, std::string> ctrl_hosts;
77
78 // map from ctrl_host to senders
79 std::map<std::string, std::vector<const appmodel::HermesDataSender*> > hermes_senders;
80
81 for (auto d2d_conn : get_detector_connections()) {
82
83 // 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
84 if (d2d_conn->is_disabled(*session)) {
85 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
86 continue;
87 }
88
89 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
90 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
91
92 // Redundant? Schema forbids 0 connections
93 if (d2d_conn->contained_resources().empty()) {
94 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders or receivers"));
95 }
96
97 auto flx_conn = dynamic_cast<const appmodel::FelixDetectorToDaqConnection *>( d2d_conn ); // NOLINT(runtime/rtti)
98 auto net_conn = dynamic_cast<const appmodel::NetworkDetectorToDaqConnection *>( d2d_conn ); // NOLINT(runtime/rtti)
99
100 if ( ! net_conn && ! flx_conn) {
101 throw BadConf(ERS_HERE, d2d_conn->UID() + " is neither felix or eth connection");
102 }
103
104 if ( flx_conn ) {
105 auto det_senders = flx_conn->get_felix_senders();
106
107 // Loop over senders
108 for (const auto* felix_sender : det_senders) {
109
110 if ( felix_sender->is_disabled(*session) ) {
111 TLOG() << "Skipping disabled sender: " << felix_sender->UID();
112 continue;
113 }
114
115 auto ip = felix_sender -> get_control_host();
116
117 // from the felix sender we get the DetStream and then the GeoID
118
119 auto streams = felix_sender -> get_streams();
120
121 for ( const auto * det_s : streams ) {
122
123 if ( det_s->is_disabled(*session) ) {
124 TLOG() << "Skipping disabled DetStream: " << det_s->UID();
125 continue;
126 }
127
128 auto geo_id = det_s->get_geo_id();
129 auto id = fmt::format("{}.{}.{}", geo_id->get_detector_id(), geo_id->get_crate_id(), geo_id->get_slot_id());
130 if (!v3_map.contains(id)) {
131 v3_map[id] = false;
132 }
133
134 } // loop over DetStreams
135
136 } // loop over det_senders
137 } // if flx connection
138
139 if ( net_conn ) {
140 auto det_senders = net_conn->get_net_senders();
141
142 for ( const auto* nw_sender : det_senders ) {
143 if ( nw_sender->is_disabled(*session) ) {
144 TLOG() << "Skipping disabled sender: " << nw_sender->UID();
145 continue;
146 }
147
148 // Check the sender type, must me a HermesSender
149 const auto* hrms_sender = nw_sender->cast<appmodel::HermesDataSender>();
150 if (!hrms_sender ) {
151 throw(BadConf(ERS_HERE, fmt::format("DataSender {} is not a appmodel::HermesDataSender", nw_sender->UID())));
152 }
153
154 hermes_senders[hrms_sender->get_control_host()].push_back(hrms_sender);
155
156 auto streams = nw_sender -> get_streams();
157 for ( const auto * det_s : streams ) {
158
159 if ( det_s->is_disabled(*session) ) {
160 TLOG() << "Skipping disabled DetStream: " << det_s->UID();
161 continue;
162 }
163
164 auto geo_id = det_s->get_geo_id();
165 auto id = fmt::format("{}.{}.{}", geo_id->get_detector_id(), geo_id->get_crate_id(), geo_id->get_slot_id());
166 if (!v3_map.contains(id)) {
167 v3_map[id] = true;
168 interfaces[id] = net_conn->get_net_receiver()->get_uses();
169 ctrl_hosts[id] = hrms_sender->get_control_host();
170 }
171
172 } // loop over streams
173
174 } // loop over NW senders
175
176 } // if net_connection
177
178 } // loop over det2DAQ Connections
179
180
181
182
183 for ( const auto & [id, v3] : v3_map ) {
184
185 auto conf_it = conf_map.find(id);
186 if ( conf_it == conf_map.end() ) {
187 throw MissingDaphne(ERS_HERE, id);
188 }
189 auto conf = conf_it->second;
190
191 conffwk::ConfigObject module_obj = obj_fac.create( (v3 ? "DaphneV3ControllerModule" : "DaphneV2ControllerModule"), fmt::format("controller-{}", id) );
192 module_obj.set_obj("daphne_conf", & daphne_conf -> config_object() );
193 module_obj.set_obj("board_conf", & conf -> config_object() );
194
195 auto module = obj_fac.get_dal<confmodel::DaqModule>(module_obj);
196 modules.push_back(module);
197
198
199 // Create Hermes Modules
200 if (v3) {
201 std::string hermes_uid = fmt::format("daphne-hermes-ctrl-{}", id);
202 conffwk::ConfigObject hermes_obj = obj_fac.create("HermesModule", hermes_uid);
203 hermes_obj.set_obj("address_table", &this->get_hermes_module_conf()->get_address_table()->config_object());
204 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()));
205 hermes_obj.set_by_val<uint32_t>("timeout_ms", this->get_hermes_module_conf()->get_ipbus_timeout_ms()); // NOLINT
206 hermes_obj.set_obj("destination", & interfaces[id]->config_object());
207
208 std::vector< const conffwk::ConfigObject * > links_obj;
209 const auto & senders = hermes_senders[ctrl_hosts[id]];
210 for ( const auto* sndr : senders ){
211 links_obj.push_back(&sndr->config_object());
212 }
213 hermes_obj.set_objs("links", links_obj);
214
215 modules.push_back(obj_fac.get_dal<appmodel::HermesModule>(hermes_obj));
216
217 }
218
219 } // ips
220
221 obj_fac.update_modules(modules);
222} // NOLINT
223
224
225bool
227
228 for ( auto ch_p : get_active_channels() ) {
229 if ( ch_p->get_channel_id() == ch ) {
230 return true;
231 }
232 }
233
234 return false;
235}
236
237const DaphneV2Channel &
239
240 for ( auto ch_p : get_active_channels() ) {
241 if ( ch_p->get_channel_id() == ch ) {
242 return *ch_p;
243 }
244 }
245
246 return *get_default_channel();
247}
248
249bool
251
252 auto begin = afe*8;
253 auto end = (afe+1)*8;
254 for ( size_t i = begin; i < end; ++i) {
255 if( is_channel_used(i) ) return true;
256 }
257
258 return false;
259}
260
261const DaphneV2AFE &
263
264 if ( ! is_afe_used(ch) ) return *get_default_afe();
265
266 for ( auto afe_p : get_active_afes() ) {
267 if ( afe_p->get_afe_id() == ch ) {
268 return *afe_p;
269 }
270 }
271
272 throw appmodel::MissingAFE(ERS_HERE, UID(), ch);
273}
274
275
276uint16_t
278
279 // ADC, reg 4 has no parsing as it's all made of booleans
280 std::bitset<5> reg4;
281 // bits 0 and 2 are reserved
282 reg4[1] = get_low_resolution();
283 reg4[3] = get_output_offset_binary();
284 reg4[4] = get_MSB_first();
285 return reg4.to_ulong();
286}
287
288uint16_t
290
291 std::bitset<14> reg51(get_lpf_cut_frequency());
292 reg51 <<= 1;
293 reg51[4] = get_integrator_disable();
294 reg51[7] = true; // clamp is always disabled and we are in low noise mode
295 reg51[13] = get_gain();
296
297 return reg51.to_ulong() ;
298}
299
300uint16_t
302
303 std::bitset<16> reg52;
304
305 decltype(reg52) clamp(get_clamp());
306 clamp <<= 6;
307
308 reg52[12] = get_integrator_disable();
309
310 decltype(reg52) gain(get_gain());
311 clamp <<= 13;
312
313 reg52 |= clamp;
314 reg52 |= gain;
315
316 return reg52.to_ulong();
317}
318
319} // 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(const confmodel::Session *) 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