Line data Source code
1 : /**
2 : * @file DFO.cpp
3 : *
4 : * Implementation of Dune Timing System HSIApplication'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 "appmodel/ConfigurationHelper.hpp"
13 : #include "ConfigObjectFactory.hpp"
14 : #include "appmodel/DTSHSIApplication.hpp"
15 : #include "appmodel/NetworkConnectionDescriptor.hpp"
16 : #include "appmodel/NetworkConnectionRule.hpp"
17 : #include "appmodel/QueueConnectionRule.hpp"
18 : #include "appmodel/QueueDescriptor.hpp"
19 : #include "appmodel/DataHandlerModule.hpp"
20 : #include "appmodel/DataHandlerConf.hpp"
21 : #include "appmodel/SourceIDConf.hpp"
22 : #include "appmodel/HSIReadout.hpp"
23 : #include "appmodel/HSIReadoutConf.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 "conffwk/Configuration.hpp"
30 :
31 : #include <iostream>
32 : #include <string>
33 : #include <vector>
34 :
35 : namespace dunedaq {
36 : namespace appmodel {
37 :
38 :
39 : void
40 0 : DTSHSIApplication::generate_modules(std::shared_ptr<appmodel::ConfigurationHelper> /*helper*/) const
41 : {
42 0 : ConfigObjectFactory obj_fac(this);
43 :
44 0 : std::vector<const confmodel::DaqModule*> modules;
45 :
46 0 : auto dlhConf = get_link_handler();
47 0 : auto dlhClass = dlhConf->get_template_for();
48 :
49 0 : const QueueDescriptor* dlhInputQDesc = nullptr;
50 :
51 0 : for (auto rule : get_queue_rules()) {
52 0 : auto destination_class = rule->get_destination_class();
53 0 : auto data_type = rule->get_descriptor()->get_data_type();
54 0 : if (destination_class == "DataHandlerModule" || destination_class == dlhClass) {
55 0 : dlhInputQDesc = rule->get_descriptor();
56 : }
57 0 : }
58 :
59 0 : const NetworkConnectionDescriptor* dlhReqInputNetDesc = nullptr;
60 0 : const NetworkConnectionDescriptor* tsNetDesc = nullptr;
61 0 : const NetworkConnectionDescriptor* hsiNetDesc = nullptr;
62 :
63 0 : for (auto rule : get_network_rules()) {
64 0 : auto endpoint_class = rule->get_endpoint_class();
65 0 : auto data_type = rule->get_descriptor()->get_data_type();
66 :
67 0 : if (endpoint_class == "DataHandlerModule" || endpoint_class == dlhClass) {
68 0 : if (data_type == "TimeSync") {
69 0 : tsNetDesc = rule->get_descriptor();
70 : }
71 0 : if (data_type == "DataRequest") {
72 0 : dlhReqInputNetDesc = rule->get_descriptor();
73 : }
74 : }
75 0 : if (data_type == "HSIEvent") {
76 0 : hsiNetDesc = rule->get_descriptor();
77 : }
78 0 : }
79 :
80 0 : auto rdrConf = get_generator();
81 0 : if (rdrConf == 0) {
82 : throw(BadConf(ERS_HERE, "No HSIEventGeneratorModule configuration given"));
83 : }
84 0 : if (dlhInputQDesc == nullptr) {
85 0 : throw(BadConf(ERS_HERE, "No DLH data input queue descriptor given"));
86 : }
87 0 : if (dlhReqInputNetDesc == nullptr) {
88 0 : throw(BadConf(ERS_HERE, "No DLH request input network descriptor given"));
89 : }
90 0 : if (hsiNetDesc == nullptr) {
91 0 : throw(BadConf(ERS_HERE, "No HSIEvent output network descriptor given"));
92 : }
93 :
94 0 : auto idconf = get_source_id();
95 0 : if (idconf == nullptr) {
96 0 : throw(BadConf(ERS_HERE, "No SourceIDConf given"));
97 : }
98 0 : auto id = idconf->get_sid();
99 :
100 0 : auto det_id = 1; // TODO Eric Flumerfelt <eflumerf@fnal.gov>, 08-Feb-2024: This is a magic number corresponding to kDAQ
101 0 : std::string uid("DLH-" + std::to_string(id));
102 0 : TLOG_DEBUG(7) << "creating OKS configuration object for Data Link Handler class " << dlhClass << ", id " << id;
103 0 : conffwk::ConfigObject dlhObj = obj_fac.create(dlhClass, uid);
104 0 : dlhObj.set_by_val<uint32_t>("source_id", id);
105 0 : dlhObj.set_by_val<uint32_t>("detector_id", det_id);
106 0 : dlhObj.set_by_val<bool>("post_processing_enabled", false);
107 0 : dlhObj.set_obj("module_configuration", &dlhConf->config_object());
108 :
109 : // Time Sync network connection
110 0 : if (dlhConf->get_generate_timesync()) {
111 0 : auto tsServiceObj = tsNetDesc->get_associated_service()->config_object();
112 0 : auto tsNetObj = obj_fac.create_net_obj(tsNetDesc, std::to_string(id));
113 :
114 0 : dlhObj.set_objs("outputs", { &tsNetObj });
115 0 : } else {
116 0 : dlhObj.set_objs("outputs", {});
117 : }
118 0 : conffwk::ConfigObject queueObj = obj_fac.create_queue_sid_obj(dlhInputQDesc,id);
119 0 : conffwk::ConfigObject faNetObj = obj_fac.create_net_obj(dlhReqInputNetDesc, UID());
120 0 : dlhObj.set_objs("inputs", { &queueObj, &faNetObj });
121 :
122 0 : modules.push_back(obj_fac.get_dal<DataHandlerModule>(uid));
123 :
124 0 : auto hsiServiceObj = hsiNetDesc->get_associated_service()->config_object();
125 0 : conffwk::ConfigObject hsiNetObj = obj_fac.create_net_obj(hsiNetDesc, "");
126 :
127 0 : std::string genuid("HSI-" + std::to_string(id));
128 0 : conffwk::ConfigObject hsiObj = obj_fac.create("HSIReadout", genuid);
129 0 : hsiObj.set_obj("configuration", &rdrConf->config_object());
130 0 : hsiObj.set_objs("outputs", { &queueObj, &hsiNetObj });
131 :
132 0 : modules.push_back(obj_fac.get_dal<HSIReadout>(genuid));
133 :
134 0 : obj_fac.update_modules(modules);
135 0 : }
136 :
137 : } // namespace appmodel
138 : } // namespace dunedaq
|