DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
dal_methods.cpp
Go to the documentation of this file.
1
8
9#include "pybind11/operators.h"
10#include "pybind11/pybind11.h"
11#include "pybind11/stl.h"
12
21#include "confmodel/Session.hpp"
22
23#include <sstream>
24
25namespace py = pybind11;
26using namespace dunedaq::conffwk;
27
29
31{
32 ObjectLocator(const std::string& id_arg, const std::string& class_name_arg)
33 : id(id_arg)
34 , class_name(class_name_arg)
35 {
36 }
37 const std::string id;
38 const std::string class_name;
39};
40
41std::vector<ObjectLocator>
42session_get_all_applications(Configuration& db, const std::string& session_name)
43{
44 auto session = db.get<Session>(session_name);
45 std::vector<ObjectLocator> apps;
46 for (auto app : session->all_applications()) {
47 apps.push_back({ app->UID(), app->class_name() });
48 }
49 return apps;
50}
51
52std::vector<ObjectLocator>
53session_get_included_applications(Configuration& db, const std::string& session_name)
54{
55 auto session = db.get<Session>(session_name);
56 std::vector<ObjectLocator> apps;
57 for (auto app : session->included_applications()) {
58 apps.push_back({ app->UID(), app->class_name() });
59 }
60 return apps;
61}
62
63void
64exclude_entity(Configuration& db, const std::string& session_id, const std::string& component_id)
65{
66 auto session_ptr = const_cast<dunedaq::confmodel::Session*>(db.get<dunedaq::confmodel::Session>(session_id));
67 auto component_ptr = db.get<dunedaq::confmodel::ExcludableEntity>(component_id);
68 if (session_ptr == nullptr) {
69 throw(std::runtime_error(std::format("Session {} not found", session_id)));
70 }
71 if (component_ptr == nullptr) {
72 throw(std::runtime_error(std::format("Component {} not found", component_id)));
73 }
74 session_ptr->exclude(component_ptr);
75}
76void
77include_entity(Configuration& db, const std::string& session_id, const std::string& component_id)
78{
79 auto session_ptr = const_cast<dunedaq::confmodel::Session*>(db.get<dunedaq::confmodel::Session>(session_id));
80 auto component_ptr = db.get<dunedaq::confmodel::ExcludableEntity>(component_id);
81 if (session_ptr == nullptr) {
82 throw(std::runtime_error(std::format("Session {} not found", session_id)));
83 }
84 if (component_ptr == nullptr) {
85 throw(std::runtime_error(std::format("Component {} not found", component_id)));
86 }
87 session_ptr->include(component_ptr);
88}
89
90bool
91entity_excluded(Configuration& db, const std::string& session_id, const std::string& component_id)
92{
93 const dunedaq::confmodel::Session* session_ptr = db.get<dunedaq::confmodel::Session>(session_id);
94 const dunedaq::confmodel::ExcludableEntity* component_ptr =
96 if (component_ptr == nullptr) {
97 return false;
98 }
99 return component_ptr->is_excluded(*session_ptr);
100}
101
102std::vector<std::vector<ObjectLocator>>
103entity_get_parents(Configuration& db, const std::string& session_id, const std::string& component_id)
104{
105 const dunedaq::confmodel::Session* session_ptr = db.get<dunedaq::confmodel::Session>(session_id);
106 const dunedaq::confmodel::ExcludableEntity* component_ptr =
108
109 std::list<std::vector<const dunedaq::confmodel::ExcludableEntity*>> parents;
110 std::vector<std::vector<ObjectLocator>> parent_ids;
111
112 component_ptr->parents(*session_ptr, parents);
113
114 for (const auto& parent : parents) {
115 std::vector<ObjectLocator> parents_components;
116 for (const auto& ancestor_component_ptr : parent) {
117 parents_components.emplace_back(
118 ObjectLocator(ancestor_component_ptr->UID(), ancestor_component_ptr->class_name()));
119 }
120 parent_ids.emplace_back(parents_components);
121 }
122 return parent_ids;
123}
124
125std::vector<std::string>
127{
128 auto app = db.get<dunedaq::confmodel::DaqApplication>(app_id);
129 std::vector<std::string> resources;
130 for (auto res : app->get_used_host_components()) {
131 resources.push_back(res->UID());
132 }
133 return resources;
134}
135
136std::vector<std::string>
138 const std::string& session_id,
139 const std::string& app_id)
140{
141 const auto* app = db.get<dunedaq::confmodel::DaqApplication>(app_id);
142 const auto* session = db.get<dunedaq::confmodel::Session>(session_id);
143 return app->construct_commandline_parameters(db, session);
144}
145
146std::vector<std::string>
148 const std::string& session_id,
149 const std::string& app_id)
150{
151 const auto* app = db.get<dunedaq::confmodel::RCApplication>(app_id);
152 const auto* session = db.get<dunedaq::confmodel::Session>(session_id);
153 return app->construct_commandline_parameters(db, session);
154}
155
156std::string
157d2d_receiver(Configuration& db, const std::string& d2d_id)
158{
159 const auto* d2d = db.get<dunedaq::confmodel::DetectorToDaqConnection>(d2d_id);
160 if (d2d == nullptr) {
161 return "";
162 }
163 return d2d->receiver()->UID();
164}
165
166std::vector<std::string>
167d2d_senders(Configuration& db, const std::string& d2d_id)
168{
169 std::vector<std::string> senders;
170 const auto* d2d = db.get<dunedaq::confmodel::DetectorToDaqConnection>(d2d_id);
171 if (d2d != nullptr) {
172 for (auto sender : d2d->senders()) {
173 senders.push_back(sender->UID());
174 }
175 }
176 return senders;
177}
178
179std::vector<std::string>
180d2d_streams(Configuration& db, const std::string& d2d_id)
181{
182 std::vector<std::string> streams;
183 const auto* d2d = db.get<dunedaq::confmodel::DetectorToDaqConnection>(d2d_id);
184 if (d2d != nullptr) {
185 for (auto stream : d2d->streams()) {
186 streams.push_back(stream->UID());
187 }
188 }
189 return streams;
190}
191
192std::vector<std::string>
193exclude_entity_set_contains(Configuration& db, const std::string& res_id)
194{
195 std::vector<std::string> resources;
196 auto res_set = db.get<dunedaq::confmodel::ExcludableEntitySet>(res_id);
197 if (res_set != nullptr) {
198 for (auto res : res_set->contained_excludable_entities()) {
199 resources.push_back(res->UID());
200 }
201 }
202 return resources;
203}
204
205void
207{
208 py::class_<ObjectLocator>(m, "ObjectLocator")
209 .def(py::init<const std::string&, const std::string&>())
210 .def_readonly("id", &ObjectLocator::id)
211 .def_readonly("class_name", &ObjectLocator::class_name);
212
213 m.def("session_get_all_applications",
215 "Get list of ALL applications (regardless of included/excluded state) in the requested session");
216 m.def("session_get_included_applications",
218 "Get list of included applications in the requested session");
219
220 m.def("exclude_entity", &exclude_entity, "Exclude a ExcludableEntity-derived object (e.g. a Segment)");
221 m.def("include_entity", &include_entity, "Include a ExcludableEntity-derived object (e.g. a Segment)");
222
223 m.def("entity_excluded",
225 "Determine if a ExcludableEntity-derived object (e.g. a Segment) has been excluded");
226 m.def("entity_get_parents",
228 "Get the ExcludableEntity-derived class instances of the parent(s) of the ExcludableEntity-derived object in "
229 "question");
230 m.def("daqapp_get_used_host_components",
232 "Get list of HostExcludableEntitys used by DAQApplication");
233 m.def("daq_application_construct_commandline_parameters",
235 "Get a version of the command line agruments parsed");
236 m.def("rc_application_construct_commandline_parameters",
238 "Get a version of the command line agruments parsed");
239
240 m.def("d2d_receiver", &d2d_receiver, "Get receiver associated with DetectorToDaqConnection");
241 m.def("d2d_senders", &d2d_senders, "Get senders associated with DetectorToDaqConnection");
242 m.def("d2d_streams", &d2d_streams, "Get streams associated with DetectorToDaqConnection");
243 m.def("exclude_entity_set_contains",
245 "Get contained ExcludableEntitys from ExcludableEntitySet");
246}
247
248} // namespace dunedaq::confmodel::python
Defines base class for cache of template objects.
void get(const std::string &class_name, const std::string &id, ConfigObject &object, unsigned long rlevel=0, const std::vector< std::string > *rclasses=0)
Get object by class name and object id (multi-thread safe).
const std::string & UID() const noexcept
virtual const DetDataReceiver * receiver() const =0
bool is_excluded(const dunedaq::confmodel::ExcludableEntityTree &session) const
void parents(const dunedaq::confmodel::Session &session, std::list< std::vector< const dunedaq::confmodel::ExcludableEntity * > > &parents) const
bool entity_excluded(Configuration &db, const std::string &session_id, const std::string &component_id)
std::vector< std::string > rc_application_construct_commandline_parameters(Configuration &db, const std::string &session_id, const std::string &app_id)
std::vector< std::string > d2d_senders(Configuration &db, const std::string &d2d_id)
std::vector< std::string > d2d_streams(Configuration &db, const std::string &d2d_id)
std::vector< ObjectLocator > session_get_included_applications(Configuration &db, const std::string &session_name)
std::vector< std::string > daq_application_construct_commandline_parameters(Configuration &db, const std::string &session_id, const std::string &app_id)
std::vector< std::string > exclude_entity_set_contains(Configuration &db, const std::string &res_id)
std::vector< std::string > daq_application_get_used_host_components(Configuration &db, const std::string &app_id)
void exclude_entity(Configuration &db, const std::string &session_id, const std::string &component_id)
std::vector< ObjectLocator > session_get_all_applications(Configuration &db, const std::string &session_name)
void register_dal_methods(py::module &m)
std::vector< std::vector< ObjectLocator > > entity_get_parents(Configuration &db, const std::string &session_id, const std::string &component_id)
std::string d2d_receiver(Configuration &db, const std::string &d2d_id)
void include_entity(Configuration &db, const std::string &session_id, const std::string &component_id)
ObjectLocator(const std::string &id_arg, const std::string &class_name_arg)