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