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