DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
ConfigurationHelper.cpp
Go to the documentation of this file.
1
22#include "conffwk/Schema.hpp"
26#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*>>
36 const std::string& data_type,
37 const std::string& app_class) {
38 std::vector<std::pair<std::string, const appmodel::NetworkConnectionDescriptor*>>
39 result;
40 for (auto app: m_session->enabled_applications()) {
41 if (app_class.empty() || app->castable(app_class)) {
42 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
43 if (smart_app == nullptr) {
44 // Only SmartDaqApplications have network rules
45 continue;
46 }
47 for (auto rule: smart_app->get_network_rules()) {
48 auto desc = rule->get_descriptor();
49 if (desc->get_data_type() == data_type) {
50 result.emplace_back(std::pair{app->UID(), desc});
51 }
52 }
53 }
54 }
55 return result;
56}
57
58
59std::vector<const confmodel::Service*> ConfigurationHelper::get_services(
60 std::string app_class,
61 std::string data_type)
62{
63 std::vector<const confmodel::Service*> result;
64 for (auto app: m_session->enabled_applications()) {
65 if (app->castable(app_class)) {
66 auto smart_app = app->cast<appmodel::SmartDaqApplication>();
67 if (smart_app == nullptr) {
68 throw (NotSmart(ERS_HERE, app->full_name()));
69 }
70 for (auto rule: smart_app->get_network_rules()) {
71 if (rule->get_descriptor()->get_data_type() == data_type) {
72 result.push_back(rule->get_descriptor()->get_associated_service());
73 }
74 }
75 }
76 }
77 return result;
78}
79
80
81std::map<std::string,std::vector<uint32_t>> ConfigurationHelper::get_stream_source_ids() {
82 std::map<std::string,std::vector<uint32_t>> result;
83 for (auto app: m_session->enabled_applications()) {
84 auto ro_app = app->cast<appmodel::ReadoutApplication>();
85 if (ro_app != nullptr) {
86 std::vector<uint32_t> streams;
87 for (auto res: ro_app->contained_resources()) {
88 if (!res->is_disabled(*m_session)) {
89 auto d2d = res->cast<confmodel::DetectorToDaqConnection>();
90 if (d2d == nullptr) {
91 throw (BadD2d(ERS_HERE, app->full_name(), res->full_name()));
92 }
93 for (auto stream: d2d->streams()) {
94 if (!stream->is_disabled(*m_session)) {
95 streams.push_back(stream->get_source_id());
96 }
97 }
98 }
99 }
100 result.insert(std::pair{app->UID(), streams});
101 }
102 else {
103 auto fake_app = app->cast<appmodel::FakeDataApplication>();
104 if (fake_app != nullptr) {
105 std::vector<uint32_t> streams;
106 for (auto res: fake_app->contained_resources()) {
107 if (!res->is_disabled(*m_session)) {
108 auto fdpc = res->cast<appmodel::FakeDataProdConf>();
109 if (fdpc != nullptr && !fdpc->is_disabled(*m_session)) {
110 streams.push_back(fdpc->get_source_id());
111 }
112 }
113 }
114 result.insert(std::pair(app->UID(), streams));
115 }
116 }
117 }
118 return result;
119}
120
121std::map<std::string, std::vector<const SourceIDConf*>>
123 std::map<std::string, std::vector<const SourceIDConf*>> result;
124 for (auto app: m_session->enabled_applications()) {
125 auto ro_app = app->cast<appmodel::ReadoutApplication>();
126 if (ro_app != nullptr) {
127 if (ro_app->get_tp_generation_enabled()) {
128 result.insert(std::pair(app->UID(), ro_app->get_tp_source_ids()));
129 }
130 else {
131 result.insert({app->UID(), std::vector<const SourceIDConf*>()});
132 }
133 }
134 auto replay_app = app->cast<appmodel::TPReplayApplication>();
135 if (replay_app != nullptr) {
136 result.insert(std::pair(app->UID(), replay_app->get_tp_source_ids()));
137 }
138 }
139 return result;
140}
141
142std::vector<std::string> ConfigurationHelper::get_app_uids(
143 std::string app_class){
144 std::vector<std::string> result;
145 for (auto app: m_session->enabled_applications()) {
146 if (app_class.empty() || app->castable(app_class)) {
147 result.push_back(app->UID());
148 }
149 }
150 return result;
151}
152
153std::map<std::string, const SourceIDConf*>
155 std::map<std::string, const SourceIDConf*> result;
156 for (auto app: m_session->enabled_applications()) {
157 if (app_class.empty() || app->castable(app_class)) {
158 auto smart_app = app->cast<SmartDaqApplication>();
159 if (smart_app != nullptr && smart_app->get_source_id() != nullptr) {
160 result.insert({app->UID(), smart_app->get_source_id()});
161 }
162 }
163 }
164 return result;
165}
166
167
168std::map<std::string, std::map<std::string, const SourceIDConf*>>
170 std::map<std::string, std::map<std::string, const SourceIDConf*>> result;
171 for (auto app: m_session->enabled_applications()) {
172 if (app_class.empty() || app->castable(app_class)) {
173 auto class_info = app->configuration().get_class_info(app->class_name());
174 auto obj = app->config_object();
175 for (auto rel: class_info.p_relationships) {
176 if (rel.p_type == "SourceIDConf") {
177 if (rel.p_cardinality == dunedaq::conffwk::cardinality_t::zero_or_one ||
178 rel.p_cardinality == dunedaq::conffwk::cardinality_t::only_one) {
180 obj.get(rel.p_name, rel_obj);
181 if (!rel_obj.is_null()) {
182 if (!result.contains(app->UID())) {
183 result.insert({app->UID(), {}});
184 }
185 const auto srcid = app->configuration().get<SourceIDConf>(rel_obj);
186 result.at(app->UID()).insert({rel.p_name, srcid});
187 }
188 } // cardinality
189 } // SourceIDConf
190 } // relationships
191 } // class
192 } // apps
193
194 return result;
195}
196
198 auto res = item->cast<confmodel::Resource>();
199 if (res == nullptr) {
200 return false;
201 }
202 return res->is_disabled(*m_session);
203}
#define ERS_HERE
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...
bool is_disabled(const conffwk::DalObject *item)
Check the enabled state of the given item.
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.
void get(const std::string &name, T &value)
Get value of object's attribute or relationship.
bool is_null() const noexcept
Check if object's implementation points to null.
The base class for any generated DAL object.
Definition DalObject.hpp:45
const TARGET * cast() const noexcept
Casts object to different class.
bool is_disabled(const dunedaq::confmodel::ResourceTree &session) const
std::vector< const dunedaq::confmodel::Application * > enabled_applications() const
Including Qt Headers.
msgpack::object obj