DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
WIECApplication.cpp
Go to the documentation of this file.
1
13#include "logging/Logging.hpp"
14
18#include "confmodel/GeoId.hpp"
19
23
32
33
34#include <string>
35#include <vector>
36#include <iostream>
37#include <fmt/core.h>
38
39namespace dunedaq {
40namespace appmodel {
41
42std::vector<const confmodel::DaqModule*>
44{
45 ConfigObjectFactory obj_fac(this);
46 conffwk::Configuration* config = &this->configuration();
47 const std::string& dbfile = this->config_object().contained_in();
48
49 std::vector<const confmodel::DaqModule*> modules;
50
51 std::map<std::string, std::vector<const appmodel::HermesDataSender*>> ctrlhost_sender_map;
52
53
54 // uint16_t conn_idx = 0;
55 for (auto d2d_conn_res : get_contains()) {
56
57 // Are we sure?
58 if (d2d_conn_res->disabled(*session)) {
59 TLOG_DEBUG(7) << "Ignoring disabled DetectorToDaqConnection " << d2d_conn_res->UID();
60 continue;
61 }
62
63 TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn_res->UID();
64 // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
65 auto d2d_conn = d2d_conn_res->cast<confmodel::DetectorToDaqConnection>();
66
67 if (!d2d_conn) {
68 throw(BadConf(ERS_HERE, "ReadoutApplication contains something other than DetectorToDaqConnection"));
69 }
70
71 if (d2d_conn->get_contains().empty()) {
72 throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders or receivers"));
73 }
74
75 auto det_senders = d2d_conn->get_senders();
76 auto det_receiver = d2d_conn->get_receiver();
77
78 // Ensure that receiver is a nw_receiver
79 const auto* nw_receiver = det_receiver->cast<appmodel::NWDetDataReceiver>();
80
81 if ( !nw_receiver ) {
82 throw(BadConf(ERS_HERE, fmt::format("WEICApplication requires NWDetDataReceiver, found {} of class {}", det_receiver->UID(), det_receiver->class_name())));
83 }
84
85 // Loop over senders
86 for (const auto* sender : det_senders) {
87
88 if ( sender->disabled(*session) ) {
89 TLOG() << "Skipping disabled sender: " << sender->UID();
90 continue;
91 }
92
93 // Check the sender type, must me a HermesSender
94 const auto* hrms_sender = sender->cast<appmodel::HermesDataSender>();
95 if (!hrms_sender ) {
96 throw(BadConf(ERS_HERE, fmt::format("DataSender {} is not a appmodel::HermesDataSender", sender->UID())));
97 }
98
99 ctrlhost_sender_map[hrms_sender->get_control_host()].push_back(hrms_sender);
100 }
101
102
103 for( const auto& [ctrlhost, senders] : ctrlhost_sender_map ) {
104
105 // Create WIBModule
106 if ( this->get_wib_module_conf() ) {
107
108 bool enable_fembs[4] = {false, false, false, false};
109
110 for ( const auto* sender : senders ){
111 for ( const auto* res : sender->get_contains() ) {
112 // Loop over streams for this sender
113 const auto* det_stream = res->cast<confmodel::DetectorStream>();
114 // Retrieve stream_id and calculate the femb_id
115 uint32_t stream_id = det_stream->get_geo_id()->get_stream_id();
116 uint32_t femb_id = (stream_id & 0xf) / 2 + 2*((stream_id >> 6) & 0xf);
117
118 // std::cout << std::format("stream {} -> femb {}", stream_id, femb_id) << std::endl;
119
120 // Enable the femb if any of the associated streams is enabld
121 // Senders in this senders list should be enabled, but better safe than sorry.
122 enable_fembs[femb_id] |= !det_stream->disabled(*session);
123 }
124 }
125 conffwk::ConfigObject wib_obj;
126 std::string wib_uid = fmt::format("wib-ctrl-{}-{}", this->UID(), ctrlhost);
127 config->create(dbfile, "WIBModule", wib_uid, wib_obj);
128 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()));
129 wib_obj.set_by_val<bool>("enabled_femb0", enable_fembs[0]);
130 wib_obj.set_by_val<bool>("enabled_femb1", enable_fembs[1]);
131 wib_obj.set_by_val<bool>("enabled_femb2", enable_fembs[2]);
132 wib_obj.set_by_val<bool>("enabled_femb3", enable_fembs[3]);
133 wib_obj.set_obj("conf", &this->get_wib_module_conf()->get_settings()->config_object());
134 modules.push_back(config->get<appmodel::WIBModule>(wib_obj));
135 }
136
137 // Create Hermes Modules
138 if (this->get_hermes_module_conf()) {
139 conffwk::ConfigObject hermes_obj;
140 std::string hermes_uid = fmt::format("hermes-ctrl-{}-{}", this->UID(), ctrlhost);
141 config->create(dbfile, "HermesModule", hermes_uid, hermes_obj);
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 return modules;
162}
163
164} // namespace appmodel
165} // namespace dunedaq
#define ERS_HERE
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 dunedaq::appmodel::HermesModuleConf * get_hermes_module_conf() const
Get "hermes_module_conf" relationship 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 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).
void create(const std::string &at, const std::string &class_name, const std::string &id, ConfigObject &object)
Create new object by class name and object id.
Configuration & configuration() const noexcept
const ConfigObject & config_object() const
const std::string & UID() const noexcept
const dunedaq::confmodel::GeoId * get_geo_id() const
Get "geo_id" relationship value.
std::vector< const confmodel::DetDataSender * > get_senders() const
uint32_t get_stream_id() const
Get "stream_id" attribute value.
Definition GeoId.hpp:196
const std::vector< const dunedaq::confmodel::ResourceBase * > & get_contains() const
Get "contains" relationship value. A resource set is a container of resources to easily implement gro...
conffwk entry point
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
Including Qt Headers.