Line data Source code
1 : /**
2 : * @file FakeHSIApplication.cpp
3 : *
4 : * Implementation of FakeHSIApplication'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 :
11 :
12 : #include "ConfigObjectFactory.hpp"
13 : #include "appmodel/ConfigurationHelper.hpp"
14 : #include "appmodel/FakeHSIApplication.hpp"
15 : #include "appmodel/FakeHSIEventGeneratorModule.hpp"
16 : #include "appmodel/FakeHSIEventGeneratorConf.hpp"
17 : #include "appmodel/NetworkConnectionDescriptor.hpp"
18 : #include "appmodel/NetworkConnectionRule.hpp"
19 : #include "appmodel/QueueConnectionRule.hpp"
20 : #include "appmodel/QueueDescriptor.hpp"
21 : #include "appmodel/DataHandlerModule.hpp"
22 : #include "appmodel/DataHandlerConf.hpp"
23 : #include "appmodel/SourceIDConf.hpp"
24 : #include "appmodel/appmodelIssues.hpp"
25 : #include "confmodel/Connection.hpp"
26 : #include "confmodel/NetworkConnection.hpp"
27 : #include "confmodel/Service.hpp"
28 : #include "logging/Logging.hpp"
29 : #include "oks/kernel.hpp"
30 : #include "conffwk/Configuration.hpp"
31 :
32 : #include <iostream>
33 : #include <string>
34 : #include <vector>
35 :
36 : namespace dunedaq {
37 : namespace appmodel {
38 :
39 : void
40 0 : FakeHSIApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
41 : {
42 0 : std::vector<const confmodel::DaqModule*> modules;
43 :
44 0 : ConfigObjectFactory obj_fac(this);
45 :
46 :
47 0 : auto dlhConf = get_link_handler();
48 0 : auto dlhClass = dlhConf->get_template_for();
49 :
50 : // 23-Sep-2025, KAB et al: prevent a mis-configuration of the system in which the
51 : // FakeHSI DLH is told to generate TimeSync messages. (TimeSync messages should only
52 : // be sent from Readout DLH modules so that we don't get confusing system behavior.)
53 0 : if (dlhConf->get_generate_timesync()) {
54 0 : throw(BadConf(ERS_HERE, "TimeSync generation is enabled for a FakeHSIApplication and this is not allowed"));
55 : }
56 :
57 0 : const QueueDescriptor* dlhInputQDesc = nullptr;
58 :
59 0 : for (auto rule : get_queue_rules()) {
60 0 : auto destination_class = rule->get_destination_class();
61 0 : auto data_type = rule->get_descriptor()->get_data_type();
62 0 : if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
63 0 : dlhInputQDesc = rule->get_descriptor();
64 : }
65 0 : }
66 :
67 0 : const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
68 0 : const NetworkConnectionDescriptor* tsNetDesc = nullptr;
69 0 : const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
70 :
71 0 : for (auto rule : get_network_rules()) {
72 0 : auto endpoint_class = rule->get_endpoint_class();
73 0 : auto data_type = rule->get_descriptor()->get_data_type();
74 :
75 0 : if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
76 0 : if (data_type == "TimeSync") {
77 0 : tsNetDesc = rule->get_descriptor();
78 : }
79 0 : if (data_type == "DataRequest") {
80 0 : dlhReqInputNetDesc = rule->get_descriptor();
81 : }
82 : }
83 0 : if (data_type == "HSIEvent") {
84 0 : hsiNetDesc = rule->get_descriptor();
85 : }
86 0 : }
87 :
88 0 : auto rdrConf = get_generator();
89 0 : if (rdrConf == 0) {
90 : throw(BadConf(ERS_HERE, "No FakeHSIEventGeneratorModule configuration given"));
91 : }
92 0 : if (dlhInputQDesc == nullptr) {
93 0 : throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
94 : }
95 0 : if (dlhReqInputNetDesc == nullptr) {
96 0 : throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
97 : }
98 0 : if (hsiNetDesc == nullptr) {
99 0 : throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
100 : }
101 :
102 0 : auto idconf = get_source_id();
103 0 : if (idconf == nullptr) {
104 0 : throw(BadConf(ERS_HERE, "No SourceIDConf given"));
105 : }
106 0 : auto id = idconf->get_sid();
107 :
108 0 : auto det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
109 0 : std::string uid("DLH-" + std::to_string(id));
110 0 : TLOG_DEBUG(7) << "creating OKS configuration object for Data Link Handler class " << dlhClass << ", id " << id;
111 0 : conffwk::ConfigObject dlhObj = obj_fac.create(dlhClass, uid);
112 0 : dlhObj.set_by_val<uint32_t>("source_id", id);
113 0 : dlhObj.set_by_val<uint32_t>("detector_id", det_id);
114 0 : dlhObj.set_by_val<bool>("post_processing_enabled", false);
115 0 : dlhObj.set_obj("module_configuration", &dlhConf->config_object());
116 :
117 : // Process special Network rules!
118 : // Looking for Fragment rules from DFAppplications in current Session
119 0 : std::vector<conffwk::ConfigObject> fragOutObjs;
120 0 : for (auto [uid, descriptor]:
121 0 : helper->get_netdescriptors("Fragment", "DFApplication")) {
122 0 : fragOutObjs.emplace_back(obj_fac.create_net_obj(descriptor, uid));
123 0 : }
124 :
125 : // start building the list of outputs
126 0 : std::vector<const conffwk::ConfigObject*> fh_output_objs;
127 0 : for (auto& fNet : fragOutObjs) {
128 0 : fh_output_objs.push_back(&fNet);
129 : }
130 :
131 : // Time Sync network connection
132 0 : if (dlhConf->get_generate_timesync()) {
133 0 : conffwk::ConfigObject tsNetObj = obj_fac.create_net_obj(tsNetDesc, std::to_string(id));
134 0 : fh_output_objs.push_back(&tsNetObj);
135 0 : }
136 0 : dlhObj.set_objs("outputs", fh_output_objs);
137 :
138 0 : conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc, id);
139 0 : conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID());
140 :
141 0 : dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
142 :
143 0 : modules.push_back(obj_fac.get_dal<DataHandlerModule>(uid));
144 :
145 0 : auto hsiServiceObj = hsiNetDesc->get_associated_service()->config_object();
146 0 : conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
147 :
148 0 : std::string genuid("FakeHSI-" + std::to_string(id));
149 0 : conffwk::ConfigObject fakehsiObj =
150 0 : obj_fac.create("FakeHSIEventGeneratorModule", genuid);
151 0 : fakehsiObj.set_obj("configuration", &rdrConf->config_object());
152 0 : fakehsiObj.set_objs("outputs", { &queueObj, &hsiNetObj });
153 0 : if (tsNetDesc != nullptr) {
154 0 : conffwk::ConfigObject tsNetObjIn = obj_fac.create_net_obj(tsNetDesc, ".*");
155 0 : fakehsiObj.set_objs("inputs", { &tsNetObjIn });
156 0 : }
157 :
158 0 : modules.push_back(obj_fac.get_dal<FakeHSIEventGeneratorModule>(genuid));
159 :
160 0 : obj_fac.update_modules(modules);
161 0 : }
162 :
163 : } // namespace appmodel
164 : } // namespace dunedaq
|