From ac10bcbeb4a794fac174a02f8c5164a1e71d08c6 Mon Sep 17 00:00:00 2001 From: Gordon Crone Date: Tue, 10 Sep 2024 12:11:03 +0100 Subject: [PATCH] Add method to Session to get only enabled applications --- pybindsrc/dal_methods.cpp | 14 +++++++++++- schema/confmodel/dunedaq.schema.xml | 3 +++ src/dalMethods.cpp | 34 ++++++++++++++++++++++++----- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/pybindsrc/dal_methods.cpp b/pybindsrc/dal_methods.cpp index 3067b2f..2c51045 100644 --- a/pybindsrc/dal_methods.cpp +++ b/pybindsrc/dal_methods.cpp @@ -44,6 +44,17 @@ namespace dunedaq::confmodel::python { return apps; } + std::vector + session_get_enabled_applications(const Configuration& db, + const std::string& session_name) { + auto session=const_cast(db).get(session_name); + std::vector 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, @@ -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"); diff --git a/schema/confmodel/dunedaq.schema.xml b/schema/confmodel/dunedaq.schema.xml index cb9a38e..3fce14d 100644 --- a/schema/confmodel/dunedaq.schema.xml +++ b/schema/confmodel/dunedaq.schema.xml @@ -348,6 +348,9 @@ + + + diff --git a/src/dalMethods.cpp b/src/dalMethods.cpp index f5945f1..520a38f 100644 --- a/src/dalMethods.cpp +++ b/src/dalMethods.cpp @@ -157,11 +157,27 @@ dunedaq::confmodel::Component::get_parents( // ======================================================================== -static std::vector getSegmentApps(const Segment* segment) { - auto apps = segment->get_applications(); + static std::vector getSegmentApps(const Segment* segment, + const Session* session, + bool enabled_only) { + std::vector apps; + auto segapps = segment->get_applications(); + if (enabled_only) { + for (auto app : segapps) { + auto comp = app->cast(); + 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; } @@ -169,7 +185,15 @@ static std::vector getSegmentApps(const Segment* segment) { std::vector Session::get_all_applications() const { std::vector 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 +Session::get_enabled_applications() const { + std::vector apps; + auto segapps = getSegmentApps(m_segment, this, true); apps.insert(apps.end(), segapps.begin(),segapps.end()); return apps; }