Line data Source code
1 : /**
2 : * @file generate_modules.cpp
3 : *
4 : * Implementation of ConfigurationHelper class
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 "appmodel/FakeDataApplication.hpp"
13 : #include "appmodel/FakeDataProdConf.hpp"
14 : #include "appmodel/NetworkConnectionDescriptor.hpp"
15 : #include "appmodel/NetworkConnectionRule.hpp"
16 : #include "appmodel/ReadoutApplication.hpp"
17 : #include "appmodel/SmartDaqApplication.hpp"
18 : #include "appmodel/SourceIDConf.hpp"
19 : #include "appmodel/TPReplayApplication.hpp"
20 : #include "appmodel/appmodelIssues.hpp"
21 : #include "conffwk/ConfigObject.hpp"
22 : #include "conffwk/Schema.hpp"
23 : #include "confmodel/DetectorStream.hpp"
24 : #include "confmodel/DetectorToDaqConnection.hpp"
25 : #include "confmodel/ExcludableEntity.hpp"
26 : #include "confmodel/NetworkConnection.hpp"
27 : #include "confmodel/Queue.hpp"
28 : #include "confmodel/Service.hpp"
29 : #include "confmodel/Session.hpp"
30 :
31 : using namespace dunedaq;
32 : using namespace dunedaq::appmodel;
33 :
34 : std::vector<std::pair<std::string, const appmodel::NetworkConnectionDescriptor*>>
35 0 : ConfigurationHelper::get_netdescriptors(const std::string& data_type, const std::string& app_class)
36 : {
37 0 : std::vector<std::pair<std::string, const appmodel::NetworkConnectionDescriptor*>> result;
38 0 : for (auto app : m_session->included_applications()) {
39 0 : if (app_class.empty() || app->castable(app_class)) {
40 0 : auto smart_app = app->cast<appmodel::SmartDaqApplication>();
41 0 : if (smart_app == nullptr) {
42 : // Only SmartDaqApplications have network rules
43 0 : continue;
44 : }
45 0 : for (auto rule : smart_app->get_network_rules()) {
46 0 : auto desc = rule->get_descriptor();
47 0 : if (desc->get_data_type() == data_type) {
48 0 : result.emplace_back(std::pair{ app->UID(), desc });
49 : }
50 : }
51 : }
52 0 : }
53 0 : return result;
54 0 : }
55 :
56 : std::vector<const confmodel::Service*>
57 0 : ConfigurationHelper::get_services(std::string app_class, std::string data_type)
58 : {
59 0 : std::vector<const confmodel::Service*> result;
60 0 : for (auto app : m_session->included_applications()) {
61 0 : if (app->castable(app_class)) {
62 0 : auto smart_app = app->cast<appmodel::SmartDaqApplication>();
63 0 : if (smart_app == nullptr) {
64 0 : throw(NotSmart(ERS_HERE, app->full_name()));
65 : }
66 0 : for (auto rule : smart_app->get_network_rules()) {
67 0 : if (rule->get_descriptor()->get_data_type() == data_type) {
68 0 : result.push_back(rule->get_descriptor()->get_associated_service());
69 : }
70 : }
71 : }
72 0 : }
73 0 : return result;
74 0 : }
75 :
76 : std::map<std::string, std::vector<uint32_t>>
77 0 : ConfigurationHelper::get_stream_source_ids()
78 : {
79 0 : std::map<std::string, std::vector<uint32_t>> result;
80 0 : for (auto app : m_session->included_applications()) {
81 0 : auto ro_app = app->cast<appmodel::ReadoutApplication>();
82 0 : if (ro_app != nullptr) {
83 0 : std::vector<uint32_t> streams;
84 0 : for (auto res : ro_app->contained_excludable_entities()) {
85 0 : if (!res->is_excluded(*m_session)) {
86 0 : auto d2d = res->cast<confmodel::DetectorToDaqConnection>();
87 0 : if (d2d == nullptr) {
88 0 : throw(BadD2d(ERS_HERE, app->full_name(), res->full_name()));
89 : }
90 0 : for (auto stream : d2d->streams()) {
91 0 : if (!stream->is_excluded(*m_session)) {
92 0 : streams.push_back(stream->get_source_id());
93 : }
94 0 : }
95 : }
96 0 : }
97 0 : result.insert(std::pair{ app->UID(), streams });
98 0 : } else {
99 0 : auto fake_app = app->cast<appmodel::FakeDataApplication>();
100 0 : if (fake_app != nullptr) {
101 0 : std::vector<uint32_t> streams;
102 0 : for (auto res : fake_app->contained_excludable_entities()) {
103 0 : if (!res->is_excluded(*m_session)) {
104 0 : auto fdpc = res->cast<appmodel::FakeDataProdConf>();
105 0 : if (fdpc != nullptr && !fdpc->is_excluded(*m_session)) {
106 0 : streams.push_back(fdpc->get_source_id());
107 : }
108 : }
109 0 : }
110 0 : result.insert(std::pair(app->UID(), streams));
111 0 : }
112 : }
113 0 : }
114 0 : return result;
115 0 : }
116 :
117 : std::map<std::string, std::vector<const SourceIDConf*>>
118 0 : ConfigurationHelper::get_tp_source_ids()
119 : {
120 0 : std::map<std::string, std::vector<const SourceIDConf*>> result;
121 0 : for (auto app : m_session->included_applications()) {
122 0 : auto ro_app = app->cast<appmodel::ReadoutApplication>();
123 0 : if (ro_app != nullptr) {
124 0 : if (ro_app->get_tp_generation_enabled()) {
125 0 : result.insert(std::pair(app->UID(), ro_app->get_tp_source_ids()));
126 : } else {
127 0 : result.insert({ app->UID(), std::vector<const SourceIDConf*>() });
128 : }
129 : }
130 0 : auto replay_app = app->cast<appmodel::TPReplayApplication>();
131 0 : if (replay_app != nullptr) {
132 0 : result.insert(std::pair(app->UID(), replay_app->get_tp_source_ids()));
133 : }
134 0 : }
135 0 : return result;
136 0 : }
137 :
138 : std::vector<std::string>
139 0 : ConfigurationHelper::get_app_uids(std::string app_class)
140 : {
141 0 : std::vector<std::string> result;
142 0 : for (auto app : m_session->included_applications()) {
143 0 : if (app_class.empty() || app->castable(app_class)) {
144 0 : result.push_back(app->UID());
145 : }
146 0 : }
147 0 : return result;
148 0 : }
149 :
150 : std::map<std::string, const SourceIDConf*>
151 0 : ConfigurationHelper::get_app_source_ids(std::string app_class)
152 : {
153 0 : std::map<std::string, const SourceIDConf*> result;
154 0 : for (auto app : m_session->included_applications()) {
155 0 : if (app_class.empty() || app->castable(app_class)) {
156 0 : auto smart_app = app->cast<SmartDaqApplication>();
157 0 : if (smart_app != nullptr && smart_app->get_source_id() != nullptr) {
158 0 : result.insert({ app->UID(), smart_app->get_source_id() });
159 : }
160 : }
161 0 : }
162 0 : return result;
163 0 : }
164 :
165 : std::map<std::string, std::map<std::string, const SourceIDConf*>>
166 0 : ConfigurationHelper::get_all_app_source_ids(std::string app_class)
167 : {
168 0 : std::map<std::string, std::map<std::string, const SourceIDConf*>> result;
169 0 : for (auto app : m_session->included_applications()) {
170 0 : if (app_class.empty() || app->castable(app_class)) {
171 0 : auto class_info = app->configuration().get_class_info(app->class_name());
172 0 : auto obj = app->config_object();
173 0 : for (auto rel : class_info.p_relationships) {
174 0 : if (rel.p_type == "SourceIDConf") {
175 0 : if (rel.p_cardinality == dunedaq::conffwk::cardinality_t::zero_or_one ||
176 : rel.p_cardinality == dunedaq::conffwk::cardinality_t::only_one) {
177 0 : dunedaq::conffwk::ConfigObject rel_obj;
178 0 : obj.get(rel.p_name, rel_obj);
179 0 : if (!rel_obj.is_null()) {
180 0 : if (!result.contains(app->UID())) {
181 0 : result.insert({ app->UID(), {} });
182 : }
183 0 : const auto srcid = app->configuration().get<SourceIDConf>(rel_obj);
184 0 : result.at(app->UID()).insert({ rel.p_name, srcid });
185 : }
186 0 : } // cardinality
187 : } // SourceIDConf
188 0 : } // relationships
189 0 : } // class
190 0 : } // apps
191 :
192 0 : return result;
193 0 : }
194 :
195 : bool
196 0 : ConfigurationHelper::is_excluded(const conffwk::DalObject* item)
197 : {
198 0 : auto res = item->cast<confmodel::ExcludableEntity>();
199 0 : if (res == nullptr) {
200 : return false;
201 : }
202 0 : return res->is_excluded(*m_session);
203 : }
|