DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
WIECApplication.cpp
Go to the documentation of this file.
1
14#include "logging/Logging.hpp"
15
19#include "confmodel/GeoId.hpp"
20
23
32
33
34#include <string>
35#include <vector>
36#include <iostream>
37#include <fmt/core.h>
38
39namespace dunedaq {
40namespace appmodel {
41
42//-----------------------------------------------------------------------------
43
44std::vector<const confmodel::Resource*>
48
49
50void
51WIECApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
52{
53 ConfigObjectFactory obj_fac(this);
54 conffwk::Configuration* config = &this->configuration();
55 const std::string& dbfile = this->config_object().contained_in();
56
57 std::vector<const confmodel::DaqModule*> modules;
58
59 std::map<std::string, std::vector<const appmodel::HermesDataSender*>> ctrlhost_sender_map;
60
61
62 // uint16_t conn_idx = 0;
63 for (auto d2d_conn : get_detector_connections()) {
64
65 // Are we sure?
66 if (helper->is_disabled(d2d_conn)) {
67 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn->UID();
68 continue;
69 }
70
71 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
72
73 // Is this check necessary?
74 if (d2d_conn->contained_resources().empty()) {
75 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders or receivers"));
76 }
77
78 auto det_senders = d2d_conn->senders();
79 auto det_receiver = d2d_conn->receiver();
80
81 // Ensure that receiver is a nw_receiver
82 const auto* nw_receiver = det_receiver->cast<appmodel::NWDetDataReceiver>();
83
84 if ( !nw_receiver ) {
85 throw(BadConf(ERS_HERE, fmt::format("WEICApplication requires NWDetDataReceiver, found {} of class {}", det_receiver->UID(), det_receiver->class_name())));
86 }
87
88 // Loop over senders
89 for (const auto* sender : det_senders) {
90
91 if (helper->is_disabled(sender)) {
92 TLOG() << "Skipping disabled sender: " << sender->UID();
93 continue;
94 }
95
96 // Check the sender type, must me a HermesSender
97 const auto* hrms_sender = sender->cast<appmodel::HermesDataSender>();
98 if (!hrms_sender ) {
99 throw(BadConf(ERS_HERE, fmt::format("DataSender {} is not a appmodel::HermesDataSender", sender->UID())));
100 }
101
102 ctrlhost_sender_map[hrms_sender->get_control_host()].push_back(hrms_sender);
103 }
104
105
106 for( const auto& [ctrlhost, senders] : ctrlhost_sender_map ) {
107
108 // Create WIBModule
109 if ( this->get_wib_module_conf() ) {
110
111 bool enable_fembs[4] = {false, false, false, false};
112
113 for ( const auto* sender : senders ){
114 for ( const auto* det_stream : sender->get_streams() ) {
115 // Loop over streams for this sender
116 // Retrieve stream_id and calculate the femb_id
117 uint32_t stream_id = det_stream->get_geo_id()->get_stream_id();
118 uint32_t femb_id = (stream_id & 0xf) / 2 + 2*((stream_id >> 6) & 0xf);
119
120 // std::cout << std::format("stream {} -> femb {}", stream_id, femb_id) << std::endl;
121
122 // Enable the femb if any of the associated streams is enabld
123 // Senders in this senders list should be enabled, but better safe than sorry.
124 enable_fembs[femb_id] |= helper->is_enabled(det_stream);
125 }
126 }
127 std::string wib_uid = fmt::format("wib-ctrl-{}-{}", this->UID(), ctrlhost);
128 conffwk::ConfigObject wib_obj = obj_fac.create("WIBModule", wib_uid);
129 wib_obj.set_by_val<std::string>("wib_addr", fmt::format("{}://{}:{}", this->get_wib_module_conf()->get_communication_type(), ctrlhost, this->get_wib_module_conf()->get_communication_port()));
130 wib_obj.set_by_val<bool>("enabled_femb0", enable_fembs[0]);
131 wib_obj.set_by_val<bool>("enabled_femb1", enable_fembs[1]);
132 wib_obj.set_by_val<bool>("enabled_femb2", enable_fembs[2]);
133 wib_obj.set_by_val<bool>("enabled_femb3", enable_fembs[3]);
134 wib_obj.set_obj("conf", &this->get_wib_module_conf()->get_settings()->config_object());
135 modules.push_back(config->get<appmodel::WIBModule>(wib_obj));
136 }
137
138 // Create Hermes Modules
139 if (this->get_hermes_module_conf()) {
140 std::string hermes_uid = fmt::format("hermes-ctrl-{}-{}", this->UID(), ctrlhost);
141 conffwk::ConfigObject hermes_obj = obj_fac.create("HermesModule", hermes_uid);
142 hermes_obj.set_obj("address_table", &this->get_hermes_module_conf()->get_address_table()->config_object());
143 hermes_obj.set_by_val<std::string>("uri", fmt::format("{}://{}:{}", this->get_hermes_module_conf()->get_ipbus_type(), ctrlhost, this->get_hermes_module_conf()->get_ipbus_port()));
144 hermes_obj.set_by_val<uint32_t>("timeout_ms", this->get_hermes_module_conf()->get_ipbus_timeout_ms());
145 hermes_obj.set_obj("destination", &nw_receiver->get_uses()->config_object());
146
147 std::vector< const conffwk::ConfigObject * > links_obj;
148 for ( const auto* sndr : senders ){
149 links_obj.push_back(&sndr->config_object());
150 }
151 hermes_obj.set_objs("links", links_obj);
152
153 modules.push_back(config->get<appmodel::HermesModule>(hermes_obj));
154 }
155
156
157 }
158
159 }
160
161 obj_fac.update_modules(modules);
162}
163
164} // namespace appmodel
165} // namespace dunedaq
#define ERS_HERE
void update_modules(const std::vector< const confmodel::DaqModule * > &modules)
conffwk::ConfigObject create(const std::string &class_name, const std::string &id) const
uint32_t get_ipbus_timeout_ms() const
Get "ipbus_timeout_ms" attribute value.
const dunedaq::appmodel::WIBModuleConf * get_wib_module_conf() const
Get "wib_module_conf" relationship value.
const std::vector< const dunedaq::confmodel::DetectorToDaqConnection * > & get_detector_connections() const
Get "detector_connections" relationship value.
const dunedaq::appmodel::HermesModuleConf * get_hermes_module_conf() const
Get "hermes_module_conf" relationship value.
virtual std::vector< const Resource * > contained_resources() const override
void generate_modules(std::shared_ptr< appmodel::ConfigurationHelper >) const override
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 std::string contained_in() const
Return the name of the database file this object belongs to.
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
Configuration & configuration() const noexcept
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
Including Qt Headers.