DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigurationHelper.cpp
Go to the documentation of this file.
1
10
22#include "conffwk/Schema.hpp"
27#include "confmodel/Queue.hpp"
28#include "confmodel/Service.hpp"
29#include "confmodel/Session.hpp"
30
31using namespace dunedaq;
32using namespace dunedaq::appmodel;
33
34std::vector<std::pair<std::string, const appmodel::NetworkConnectionDescriptor*>>
35ConfigurationHelper::get_netdescriptors(const std::string& data_type, const std::string& app_class)
36{
37 std::vector<std::pair<std::string, const appmodel::NetworkConnectionDescriptor*>> result;
38 for (auto app : m_session->included_applications()) {
39 if (app_class.empty() || app->castable(app_class)) {
40 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
41 if (smart_app == nullptr) {
42 // Only SmartDaqApplications have network rules
43 continue;
44 }
45 for (auto rule : smart_app->get_network_rules()) {
46 auto desc = rule->get_descriptor();
47 if (desc->get_data_type() == data_type) {
48 result.emplace_back(std::pair{ app->UID(), desc });
49 }
50 }
51 }
52 }
53 return result;
54}
55
56std::vector<const confmodel::Service*>
57ConfigurationHelper::get_services(std::string app_class, std::string data_type)
58{
59 std::vector<const confmodel::Service*> result;
60 for (auto app : m_session->included_applications()) {
61 if (app->castable(app_class)) {
62 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
63 if (smart_app == nullptr) {
64 throw(NotSmart(ERS_HERE, app->full_name()));
65 }
66 for (auto rule : smart_app->get_network_rules()) {
67 if (rule->get_descriptor()->get_data_type() == data_type) {
68 result.push_back(rule->get_descriptor()->get_associated_service());
69 }
70 }
71 }
72 }
73 return result;
74}
75
76std::map<std::string, std::vector<uint32_t>>
78{
79 std::map<std::string, std::vector<uint32_t>> result;
80 for (auto app : m_session->included_applications()) {
81 auto ro_app = app->cast<appmodel::ReadoutApplication>();
82 if (ro_app != nullptr) {
83 std::vector<uint32_t> streams;
84 for (auto res : ro_app->contained_excludable_entities()) {
85 if (!res->is_excluded(*m_session)) {
86 auto d2d = res->cast<confmodel::DetectorToDaqConnection>();
87 if (d2d == nullptr) {
88 throw(BadD2d(ERS_HERE, app->full_name(), res->full_name()));
89 }
90 for (auto stream : d2d->streams()) {
91 if (!stream->is_excluded(*m_session)) {
92 streams.push_back(stream->get_source_id());
93 }
94 }
95 }
96 }
97 result.insert(std::pair{ app->UID(), streams });
98 } else {
99 auto fake_app = app->cast<appmodel::FakeDataApplication>();
100 if (fake_app != nullptr) {
101 std::vector<uint32_t> streams;
102 for (auto res : fake_app->contained_excludable_entities()) {
103 if (!res->is_excluded(*m_session)) {
104 auto fdpc = res->cast<appmodel::FakeDataProdConf>();
105 if (fdpc != nullptr && !fdpc->is_excluded(*m_session)) {
106 streams.push_back(fdpc->get_source_id());
107 }
108 }
109 }
110 result.insert(std::pair(app->UID(), streams));
111 }
112 }
113 }
114 return result;
115}
116
117std::map<std::string, std::vector<const SourceIDConf*>>
119{
120 std::map<std::string, std::vector<const SourceIDConf*>> result;
121 for (auto app : m_session->included_applications()) {
122 auto ro_app = app->cast<appmodel::ReadoutApplication>();
123 if (ro_app != nullptr) {
124 if (ro_app->get_tp_generation_enabled()) {
125 result.insert(std::pair(app->UID(), ro_app->get_tp_source_ids()));
126 } else {
127 result.insert({ app->UID(), std::vector<const SourceIDConf*>() });
128 }
129 }
130 auto replay_app = app->cast<appmodel::TPReplayApplication>();
131 if (replay_app != nullptr) {
132 result.insert(std::pair(app->UID(), replay_app->get_tp_source_ids()));
133 }
134 }
135 return result;
136}
137
138std::vector<std::string>
140{
141 std::vector<std::string> result;
142 for (auto app : m_session->included_applications()) {
143 if (app_class.empty() || app->castable(app_class)) {
144 result.push_back(app->UID());
145 }
146 }
147 return result;
148}
149
150std::map<std::string, const SourceIDConf*>
152{
153 std::map<std::string, const SourceIDConf*> result;
154 for (auto app : m_session->included_applications()) {
155 if (app_class.empty() || app->castable(app_class)) {
156 auto smart_app = app->cast<SmartDaqApplication>();
157 if (smart_app != nullptr && smart_app->get_source_id() != nullptr) {
158 result.insert({ app->UID(), smart_app->get_source_id() });
159 }
160 }
161 }
162 return result;
163}
164
165std::map<std::string, std::map<std::string, const SourceIDConf*>>
167{
168 std::map<std::string, std::map<std::string, const SourceIDConf*>> result;
169 for (auto app : m_session->included_applications()) {
170 if (app_class.empty() || app->castable(app_class)) {
171 auto class_info = app->configuration().get_class_info(app->class_name());
172 auto obj = app->config_object();
173 for (auto rel : class_info.p_relationships) {
174 if (rel.p_type == "SourceIDConf") {
175 if (rel.p_cardinality == dunedaq::conffwk::cardinality_t::zero_or_one ||
176 rel.p_cardinality == dunedaq::conffwk::cardinality_t::only_one) {
178 obj.get(rel.p_name, rel_obj);
179 if (!rel_obj.is_null()) {
180 if (!result.contains(app->UID())) {
181 result.insert({ app->UID(), {} });
182 }
183 const auto srcid = app->configuration().get<SourceIDConf>(rel_obj);
184 result.at(app->UID()).insert({ rel.p_name, srcid });
185 }
186 } // cardinality
187 } // SourceIDConf
188 } // relationships
189 } // class
190 } // apps
191
192 return result;
193}
194
195bool
197{
198 auto res = item->cast<confmodel::ExcludableEntity>();
199 if (res == nullptr) {
200 return false;
201 }
202 return res->is_excluded(*m_session);
203}
#define ERS_HERE
bool is_excluded(const conffwk::DalObject *item)
Check the include/exclude state of the given item.
std::vector< std::string > get_app_uids(std::string app_class="")
Get list of uids of applications that match given type.
std::map< std::string, const SourceIDConf * > get_app_source_ids(std::string app_class="")
Get list of source ids for applications that match given type.
std::map< std::string, std::map< std::string, const SourceIDConf * > > get_all_app_source_ids(std::string app_class="")
Get list of all source ids for applications that match given type. Follows any single value SourceIDC...
std::map< std::string, std::vector< uint32_t > > get_stream_source_ids()
Get the source ids of all DetectorStreams in the Session.
std::map< std::string, std::vector< const SourceIDConf * > > get_tp_source_ids()
Get the source ids of all the TP streams in all ReadoutApplications and TriggerApplications.
std::vector< const confmodel::Service * > get_services(std::string app_class, std::string data_type)
Get the exposed Services of all network connections with given data_type from all smart daq applicati...
std::vector< std::pair< std::string, const appmodel::NetworkConnectionDescriptor * > > get_netdescriptors(const std::string &data_type, const std::string &app_class="")
Get all NetworkConnectionDescriptors with given data_type from all applications of given type.
Represents database objects.
bool is_null() const noexcept
Check if object's implementation points to null.
The base class for any generated DAL object.
Definition DalObject.hpp:51
const TARGET * cast() const noexcept
Casts object to different class.
bool is_excluded(const dunedaq::confmodel::ExcludableEntityTree &session) const
std::vector< const dunedaq::confmodel::Application * > included_applications() const
The DUNE-DAQ namespace.
msgpack::object obj