Line data Source code
1 : /**
2 : * @file TDECrateApplication.cpp
3 : *
4 : * Implementation of TDECrateApplication's generate_modules dal method
5 : *
6 : * This is part of the DUNE DAQ Software Suite, copyright 2023.
7 : * Licensing/copyright details are in the COPYING file that you should have
8 : * received with this code.
9 : */
10 : #include "conffwk/Configuration.hpp"
11 : #include "logging/Logging.hpp"
12 : #include "oks/kernel.hpp"
13 :
14 : #include "appmodel/NWDetDataReceiver.hpp"
15 : #include "confmodel/DetectorStream.hpp"
16 : #include "confmodel/DetectorToDaqConnection.hpp"
17 : #include "confmodel/GeoId.hpp"
18 : #include "confmodel/NetworkInterface.hpp"
19 :
20 : #include "ConfigObjectFactory.hpp"
21 : #include "appmodel/TDEAMCModule.hpp"
22 : #include "appmodel/TDEAMCModuleConf.hpp"
23 : #include "appmodel/TDECrateApplication.hpp"
24 : #include "appmodel/TdeAmcDetDataSender.hpp"
25 : #include "appmodel/appmodelIssues.hpp"
26 :
27 : #include <fmt/core.h>
28 : #include <iostream>
29 : #include <string>
30 : #include <vector>
31 :
32 : namespace dunedaq {
33 : namespace appmodel {
34 :
35 : std::vector<const confmodel::ExcludableEntity*>
36 0 : TDECrateApplication::contained_excludable_entities() const
37 : {
38 0 : return to_resources(get_detector_connections());
39 : }
40 :
41 : void
42 0 : TDECrateApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
43 : {
44 0 : ConfigObjectFactory obj_fac(this);
45 :
46 0 : std::vector<const confmodel::DaqModule*> modules;
47 :
48 0 : std::map<std::string, std::vector<const appmodel::TdeAmcDetDataSender*>> ctrlhost_sender_map;
49 :
50 0 : for (auto d2d_conn : get_detector_connections()) {
51 : // Are we sure?
52 0 : if (helper->is_excluded(d2d_conn)) {
53 0 : TLOG_DEBUG(7) << "Ignoring excluded DetectorToDaqConnection " << d2d_conn->UID();
54 0 : continue;
55 0 : }
56 :
57 0 : TLOG_DEBUG(6) << "Processing DetectorToDaqConnection " << d2d_conn->UID();
58 : // get the readout groups and the interfaces and streams therein; 1 reaout group corresponds to 1 data reader module
59 :
60 0 : auto det_senders = d2d_conn->senders();
61 : // Should not be necessary, schema doesn't allow 0 senders
62 0 : if (det_senders.empty()) {
63 0 : throw(BadConf(ERS_HERE, "DetectorToDaqConnection does not contain senders"));
64 : }
65 :
66 : // Loop over senders
67 0 : for (const auto* sender : det_senders) {
68 :
69 0 : if (helper->is_excluded(sender)) {
70 0 : TLOG() << "Skipping excluded sender: " << sender->UID();
71 0 : continue;
72 0 : }
73 :
74 : // Check the sender type, must me a TdeAmcDetDataSender
75 0 : const auto* tde_sender = sender->cast<appmodel::TdeAmcDetDataSender>();
76 0 : if (!tde_sender) {
77 0 : throw(BadConf(ERS_HERE, fmt::format("DataSender {} is not a appmodel::TdeAmcDetDataSender", sender->UID())));
78 : }
79 :
80 0 : ctrlhost_sender_map[tde_sender->get_control_host()].push_back(tde_sender);
81 : }
82 0 : }
83 :
84 0 : for (const auto& [ctrlhost, senders] : ctrlhost_sender_map) {
85 :
86 : // std::cout << "this->UID()='" << this->UID() << "' ctrlhost='" << ctrlhost << "'" << std::endl;
87 0 : if (this->get_tde_amc_module_conf()) {
88 0 : conffwk::ConfigObject tde_obj =
89 0 : obj_fac.create("TDEAMCModule", fmt::format("tde-ctrl-{}-{}", this->UID(), ctrlhost));
90 : // std::string tde_uid = fmt::format("tde-ctrl-{}-{}", this->UID(), ctrlhost);
91 : // config->create(dbfile, "TDEAMCModule", tde_uid, tde_obj);
92 0 : tde_obj.set_obj("amc", &(senders[0]->config_object())); // for now just allow one AMC per module
93 0 : modules.push_back(obj_fac.get_dal<appmodel::TDEAMCModule>(tde_obj));
94 0 : }
95 : }
96 0 : obj_fac.update_modules(modules);
97 0 : }
98 :
99 : } // namespace appmodel
100 : } // namespace dunedaq
|