Line data Source code
1 : /**
2 : * @file TriggerApplication.cpp
3 : *
4 : * Implementation of TriggerApplication'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 : #include "appmodel/ConfigurationHelper.hpp"
12 : #include "conffwk/Configuration.hpp"
13 :
14 : #include "confmodel/Connection.hpp"
15 : #include "confmodel/NetworkConnection.hpp"
16 : #include "confmodel/Service.hpp"
17 :
18 : #include "ConfigObjectFactory.hpp"
19 : #include "appmodel/DataReaderConf.hpp"
20 : #include "appmodel/DataRecorderConf.hpp"
21 : #include "appmodel/DataSubscriberModule.hpp"
22 :
23 : #include "appmodel/DataHandlerConf.hpp"
24 : #include "appmodel/DataHandlerModule.hpp"
25 :
26 : #include "appmodel/NetworkConnectionRule.hpp"
27 : #include "appmodel/QueueConnectionRule.hpp"
28 :
29 : #include "appmodel/NetworkConnectionDescriptor.hpp"
30 : #include "appmodel/QueueDescriptor.hpp"
31 :
32 : #include "appmodel/SourceIDConf.hpp"
33 :
34 : #include "appmodel/TriggerApplication.hpp"
35 : #include "appmodel/appmodelIssues.hpp"
36 :
37 : #include "logging/Logging.hpp"
38 :
39 : #include <string>
40 : #include <vector>
41 :
42 : namespace dunedaq {
43 : namespace appmodel {
44 :
45 : /**
46 : * \brief Helper function that gets a network connection config
47 : *
48 : * \param idname Unique ID name of the config object
49 : * \param ntDesc Network connection descriptor object
50 : * \param confdb Global database configuration
51 : * \param dbfile Database file location
52 : *
53 : * \ret OKS configuration object for the network connection
54 : */
55 : conffwk::ConfigObject
56 0 : create_network_connection(std::string uid,
57 : const NetworkConnectionDescriptor* ntDesc,
58 : conffwk::Configuration* confdb,
59 : const std::string& dbfile)
60 : {
61 0 : auto ntServiceObj = ntDesc->get_associated_service()->config_object();
62 0 : conffwk::ConfigObject ntObj;
63 0 : confdb->create(dbfile, "NetworkConnection", uid, ntObj);
64 0 : ntObj.set_by_val<std::string>("data_type", ntDesc->get_data_type());
65 0 : ntObj.set_by_val<std::string>("connection_type", ntDesc->get_connection_type());
66 0 : ntObj.set_obj("associated_service", &ntServiceObj);
67 :
68 0 : return ntObj;
69 0 : }
70 :
71 : void
72 0 : TriggerApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> helper) const
73 : {
74 :
75 0 : std::vector<const confmodel::DaqModule*> modules;
76 :
77 0 : ConfigObjectFactory obj_fac(this);
78 :
79 0 : auto ti_conf = get_trigger_inputs_handler();
80 0 : auto ti_class = ti_conf->get_template_for();
81 0 : std::string handler_name("");
82 : // Process the queue rules looking for inputs to our trigger handler modules
83 0 : const QueueDescriptor* ti_inputq_desc = nullptr;
84 :
85 0 : for (auto rule : get_queue_rules()) {
86 0 : auto destination_class = rule->get_destination_class();
87 0 : auto data_type = rule->get_descriptor()->get_data_type();
88 0 : if (destination_class == "DataHandlerModule" || destination_class == ti_class) {
89 0 : ti_inputq_desc = rule->get_descriptor();
90 : }
91 0 : }
92 : // Process the network rules looking for the TP handler data reuest inputs
93 0 : const NetworkConnectionDescriptor* req_net_desc = nullptr;
94 0 : const NetworkConnectionDescriptor* tin_net_desc = nullptr;
95 0 : const NetworkConnectionDescriptor* tout_net_desc = nullptr;
96 0 : const NetworkConnectionDescriptor* tset_out_net_desc = nullptr;
97 0 : for (auto rule : get_network_rules()) {
98 0 : auto endpoint_class = rule->get_endpoint_class();
99 0 : auto data_type = rule->get_descriptor()->get_data_type();
100 :
101 0 : if (data_type == "DataRequest") {
102 0 : req_net_desc = rule->get_descriptor();
103 0 : } else if (data_type == "TASet" || data_type == "TCSet") {
104 0 : tset_out_net_desc = rule->get_descriptor();
105 0 : } else if (endpoint_class == "DataSubscriberModule") {
106 0 : if (!tin_net_desc) {
107 0 : tin_net_desc = rule->get_descriptor();
108 0 : } else if (rule->get_descriptor()->get_data_type() == tin_net_desc->get_data_type()) {
109 : // For now endpoint_class of DataSubscriberModule for both input and output
110 : // with the same data type is not possible.
111 0 : throw(BadConf(ERS_HERE, "Have two network connections of the same data_type and the same endpoint_class"));
112 0 : } else if (tin_net_desc->get_data_type() == "TriggerActivity" &&
113 0 : rule->get_descriptor()->get_data_type() == "TriggerCandidate") {
114 : // For TA->TC
115 0 : tout_net_desc = rule->get_descriptor();
116 0 : handler_name = "tahandler";
117 0 : } else if (tin_net_desc->get_data_type() == "TriggerCandidate" &&
118 0 : rule->get_descriptor()->get_data_type() == "TriggerActivity") {
119 : // For TA->TC if we saved TC network connection as input first...
120 0 : tout_net_desc = tin_net_desc;
121 0 : tin_net_desc = rule->get_descriptor();
122 0 : handler_name = "tahandler";
123 : } else {
124 0 : throw(BadConf(ERS_HERE, "Unexpected input & output network connection descriptors provided"));
125 : }
126 0 : } else if (data_type == "TriggerActivity" || data_type == "TriggerCandidate") {
127 0 : tout_net_desc = rule->get_descriptor();
128 0 : if (data_type == "TriggerActivity")
129 0 : handler_name = "tphandler";
130 : else
131 0 : handler_name = "tahandler";
132 : }
133 0 : }
134 :
135 : // Process special Network rules!
136 0 : std::vector<conffwk::ConfigObject> fragOutObjs;
137 0 : for (auto [uid, descriptor] : helper->get_netdescriptors("Fragment", "DFApplication")) {
138 0 : fragOutObjs.push_back(obj_fac.create_net_obj(descriptor, uid));
139 0 : }
140 0 : if (req_net_desc == nullptr) {
141 0 : throw(BadConf(ERS_HERE, "No network descriptor given to receive request and send data was set"));
142 : }
143 0 : if (tin_net_desc == nullptr) {
144 0 : throw(BadConf(ERS_HERE, "No network descriptor given to receive trigger objects"));
145 : }
146 0 : if (tout_net_desc == nullptr) {
147 0 : throw(BadConf(ERS_HERE, "No network descriptor given to publish trigger objects"));
148 : }
149 0 : if (ti_inputq_desc == nullptr) {
150 0 : throw(BadConf(ERS_HERE, "No data input queue descriptor given"));
151 : }
152 :
153 0 : auto input_queue_obj = obj_fac.create_queue_obj(ti_inputq_desc);
154 :
155 0 : auto req_net_obj = obj_fac.create_net_obj(req_net_desc, UID());
156 :
157 0 : auto tin_net_obj = obj_fac.create_net_obj(tin_net_desc, ".*");
158 :
159 0 : auto tout_net_obj = obj_fac.create_net_obj(tout_net_desc, UID());
160 0 : conffwk::ConfigObject tset_out_net_obj;
161 0 : if (tset_out_net_desc) {
162 0 : tset_out_net_obj = obj_fac.create_net_obj(tset_out_net_desc, UID());
163 : }
164 :
165 : // build up the full list of outputs
166 0 : std::vector<const conffwk::ConfigObject*> ti_output_objs;
167 0 : for (auto& fNet : fragOutObjs) {
168 0 : ti_output_objs.push_back(&fNet);
169 : }
170 0 : ti_output_objs.push_back(&tout_net_obj);
171 0 : if (tset_out_net_desc != nullptr) {
172 0 : ti_output_objs.push_back(&tset_out_net_obj);
173 : }
174 :
175 0 : if (get_source_id() == nullptr) {
176 0 : throw(BadConf(ERS_HERE, "No source_id associated with this TriggerApplication!"));
177 : }
178 0 : uint32_t source_id = get_source_id()->get_sid();
179 0 : std::string ti_uid(handler_name + "-" + std::to_string(source_id));
180 0 : auto ti_obj = obj_fac.create(ti_class, ti_uid);
181 :
182 0 : ti_obj.set_by_val<uint32_t>("source_id", source_id);
183 0 : ti_obj.set_by_val<uint32_t>("detector_id", 1); // 1 == kDAQ
184 0 : ti_obj.set_by_val<bool>("post_processing_enabled", !get_tx_generation_disabled());
185 :
186 0 : auto ti_conf_obj = ti_conf->config_object();
187 0 : ti_obj.set_obj("module_configuration", &ti_conf_obj);
188 0 : ti_obj.set_objs("inputs", { &input_queue_obj, &req_net_obj });
189 0 : ti_obj.set_objs("outputs", ti_output_objs);
190 : // Add to our list of modules to return
191 0 : modules.push_back(obj_fac.get_dal<DataHandlerModule>(ti_uid));
192 :
193 : // Now create the DataSubscriberModule object
194 0 : auto rdr_conf = get_data_subscriber();
195 0 : if (rdr_conf == nullptr) {
196 : throw(BadConf(ERS_HERE, "No DataReaderModule configuration given"));
197 : }
198 :
199 : // Create a DataReaderModule
200 :
201 0 : std::string reader_uid("data-reader-" + UID());
202 0 : std::string reader_class = rdr_conf->get_template_for();
203 0 : TLOG_DEBUG(7) << "creating OKS configuration object for Data subscriber class " << reader_class;
204 0 : auto reader_obj = obj_fac.create(reader_class, reader_uid);
205 0 : reader_obj.set_objs("inputs", { &tin_net_obj });
206 0 : reader_obj.set_objs("outputs", { &input_queue_obj });
207 0 : reader_obj.set_obj("configuration", &rdr_conf->config_object());
208 :
209 0 : modules.push_back(obj_fac.get_dal<DataSubscriberModule>(reader_uid));
210 :
211 0 : obj_fac.update_modules(modules);
212 0 : }
213 :
214 : } // namespace appmodel
215 : } // namespace dunedaq
|