Skip to content

Commit

Permalink
Merge pull request #42 from DUNE-DAQ/gcrone/get_enabled_apps
Browse files Browse the repository at this point in the history
Add method to Session to get only enabled applications
  • Loading branch information
gcrone authored Sep 11, 2024
2 parents d71cc4d + ac10bcb commit 62de473
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
14 changes: 13 additions & 1 deletion pybindsrc/dal_methods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ namespace dunedaq::confmodel::python {
return apps;
}

std::vector<ObjectLocator>
session_get_enabled_applications(const Configuration& db,
const std::string& session_name) {
auto session=const_cast<Configuration&>(db).get<Session>(session_name);
std::vector<ObjectLocator> apps;
for (auto app : session->get_enabled_applications()) {
apps.push_back({app->UID(),app->class_name()});
}
return apps;
}

void
session_set_disabled(const Configuration& db,
const std::string& session_name,
Expand Down Expand Up @@ -128,7 +139,8 @@ register_dal_methods(py::module& m)
.def_readonly("class_name", &ObjectLocator::class_name)
;

m.def("session_get_all_applications", &session_get_all_applications, "Get list of applications in the requested session");
m.def("session_get_all_applications", &session_get_all_applications, "Get list of ALL applications (regardless of enabled/disabled state) in the requested session");
m.def("session_get_enabled_applications", &session_get_enabled_applications, "Get list of enabled applications in the requested session");
m.def("session_set_disabled", &session_set_disabled, "Temporarily disable Components in the requested session");

m.def("component_disabled", &component_disabled, "Determine if a Component-derived object (e.g. a Segment) has been disabled");
Expand Down
3 changes: 3 additions & 0 deletions schema/confmodel/dunedaq.schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@
<method name="get_all_applications" description="Returns applications defined in the Session and all of its Segments.">
<method-implementation language="c++" prototype="std::vector&lt;const dunedaq::confmodel::Application *&gt; get_all_applications() const" body=""/>
</method>
<method name="get_enabled_applications" description="Returns all enabled applications defined in the Session and all of its Segments.">
<method-implementation language="c++" prototype="std::vector&lt;const dunedaq::confmodel::Application *&gt; get_enabled_applications() const" body=""/>
</method>
<method name="set_disabled" description="In addition to persistently disabled components, dynamically disable these components. It will be taken into account by disabled() algorithm of Component class. This information is not committed to the database and will be overwritten by next set_disabled() call or erased by any config action (DB load, unload, reload).">
<method-implementation language="c++" prototype="void set_disabled(const std::set&lt;const dunedaq::confmodel::Component *&gt;&amp; objs) const" body="BEGIN_PRIVATE_SECTION&#xA;friend class DisabledComponents;&#xA;friend class Component;&#xA;mutable dunedaq::confmodel::DisabledComponents m_disabled_components; &#xA;END_PRIVATE_SECTION&#xA;BEGIN_MEMBER_INITIALIZER_LIST&#xA;m_disabled_components(p_db,this)&#xA;END_MEMBER_INITIALIZER_LIST&#xA;BEGIN_HEADER_PROLOGUE&#xA;#include &quot;confmodel/disabled-components.hpp&quot;&#xA;END_HEADER_PROLOGUE"/>
</method>
Expand Down
34 changes: 29 additions & 5 deletions src/dalMethods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,43 @@ dunedaq::confmodel::Component::get_parents(

// ========================================================================

static std::vector<const Application*> getSegmentApps(const Segment* segment) {
auto apps = segment->get_applications();
static std::vector<const Application*> getSegmentApps(const Segment* segment,
const Session* session,
bool enabled_only) {
std::vector<const Application*> apps;
auto segapps = segment->get_applications();
if (enabled_only) {
for (auto app : segapps) {
auto comp = app->cast<Component>();
if (comp == nullptr || !comp->disabled(*session)) {
apps.insert(apps.end(), app);
}
}
}
else {
apps.swap(segapps);
}
for (auto seg : segment->get_segments()) {
auto segapps = getSegmentApps(seg);
apps.insert(apps.end(), segapps.begin(),segapps.end());
if (!enabled_only || !seg->disabled(*session)) {
auto segapps = getSegmentApps(seg, session, enabled_only);
apps.insert(apps.end(), segapps.begin(),segapps.end());
}
}
return apps;
}

std::vector<const Application*>
Session::get_all_applications() const {
std::vector<const Application*> apps;
auto segapps = getSegmentApps(m_segment);
auto segapps = getSegmentApps(m_segment, this, false);
apps.insert(apps.end(), segapps.begin(),segapps.end());
return apps;
}

std::vector<const Application*>
Session::get_enabled_applications() const {
std::vector<const Application*> apps;
auto segapps = getSegmentApps(m_segment, this, true);
apps.insert(apps.end(), segapps.begin(),segapps.end());
return apps;
}
Expand Down

0 comments on commit 62de473

Please sign in to comment.