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