LCOV - code coverage report
Current view: top level - confmodel/pybindsrc - dal_methods.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 97 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 12 0

            Line data    Source code
       1              : /**
       2              :  * @file dal_methods.cpp
       3              :  *
       4              :  * This is part of the DUNE DAQ Software Suite, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "pybind11/operators.h"
      10              : #include "pybind11/pybind11.h"
      11              : #include "pybind11/stl.h"
      12              : 
      13              : #include "confmodel/Application.hpp"
      14              : #include "confmodel/DaqApplication.hpp"
      15              : #include "confmodel/DetectorToDaqConnection.hpp"
      16              : #include "confmodel/DetectorStream.hpp"
      17              : #include "confmodel/DetDataReceiver.hpp"
      18              : #include "confmodel/DetDataSender.hpp"
      19              : #include "confmodel/HostComponent.hpp"
      20              : #include "confmodel/RCApplication.hpp"
      21              : #include "confmodel/Session.hpp"
      22              : 
      23              : 
      24              : #include <sstream>
      25              : 
      26              : namespace py = pybind11;
      27              : using namespace dunedaq::conffwk;
      28              : 
      29              : namespace dunedaq::confmodel::python {
      30              : 
      31              :   struct ObjectLocator {
      32            0 :     ObjectLocator(const std::string& id_arg, const std::string& class_name_arg) :
      33            0 :       id(id_arg), class_name(class_name_arg)
      34            0 :       {}
      35              :     const std::string id;
      36              :     const std::string class_name;
      37              :   };
      38              : 
      39              : 
      40              :   std::vector<ObjectLocator>
      41            0 :   session_get_all_applications(const Configuration& db,
      42              :                                const std::string& session_name) {
      43            0 :     auto session=const_cast<Configuration&>(db).get<Session>(session_name);
      44            0 :     std::vector<ObjectLocator> apps;
      45            0 :     for (auto app : session->all_applications()) {
      46            0 :       apps.push_back({app->UID(),app->class_name()});
      47            0 :     }
      48            0 :     return apps;
      49            0 :   }
      50              : 
      51              :   std::vector<ObjectLocator>
      52            0 :   session_get_enabled_applications(const Configuration& db,
      53              :                                    const std::string& session_name) {
      54            0 :     auto session=const_cast<Configuration&>(db).get<Session>(session_name);
      55            0 :     std::vector<ObjectLocator> apps;
      56            0 :     for (auto app : session->enabled_applications()) {
      57            0 :       apps.push_back({app->UID(),app->class_name()});
      58            0 :     }
      59            0 :     return apps;
      60            0 :   }
      61              : 
      62            0 :   bool component_disabled(const Configuration& db,
      63              :                           const std::string& session_id,
      64              :                           const std::string& component_id) {
      65            0 :     const dunedaq::confmodel::Session* session_ptr = const_cast<Configuration&>(db).get<dunedaq::confmodel::Session>(session_id);
      66            0 :     const dunedaq::confmodel::Resource* component_ptr = const_cast<Configuration&>(db).get<dunedaq::confmodel::Resource>(component_id);
      67            0 :     if (component_ptr == nullptr) {
      68              :       return false;
      69              :     }
      70            0 :     return component_ptr->is_disabled(*session_ptr);
      71              :   }
      72              : 
      73              : 
      74            0 :   std::vector<std::vector<ObjectLocator>> component_get_parents(const Configuration& db,
      75              :                                                                 const std::string& session_id,
      76              :                                                                 const std::string& component_id) {
      77            0 :     const dunedaq::confmodel::Session* session_ptr = const_cast<Configuration&>(db).get<dunedaq::confmodel::Session>(session_id);
      78            0 :     const dunedaq::confmodel::Resource* component_ptr = const_cast<Configuration&>(db).get<dunedaq::confmodel::Resource>(component_id);
      79              : 
      80            0 :     std::list<std::vector<const dunedaq::confmodel::Resource*>> parents;
      81            0 :     std::vector<std::vector<ObjectLocator>> parent_ids;
      82              : 
      83            0 :     component_ptr->parents(*session_ptr, parents);
      84              : 
      85            0 :     for (const auto& parent : parents) {
      86            0 :       std::vector<ObjectLocator> parents_components;
      87            0 :       for (const auto& ancestor_component_ptr : parent) {
      88            0 :         parents_components.emplace_back(
      89            0 :           ObjectLocator(ancestor_component_ptr->UID(),
      90              :                         ancestor_component_ptr->class_name()) );
      91              :       }
      92            0 :       parent_ids.emplace_back(parents_components);
      93            0 :     }
      94            0 :     return parent_ids;
      95            0 :   }
      96              : 
      97            0 :   std::vector<std::string> daq_application_get_used_hostresources(const Configuration& db, const std::string& app_id) {
      98            0 :     auto app = const_cast<Configuration&>(db).get<dunedaq::confmodel::DaqApplication>(app_id);
      99            0 :     std::vector<std::string> resources;
     100            0 :     for (auto res : app->get_used_hostresources()) {
     101            0 :       resources.push_back(res->UID());
     102            0 :     }
     103            0 :     return resources;
     104            0 :   }
     105              : 
     106            0 :   std::vector<std::string> daq_application_construct_commandline_parameters(const Configuration& db,
     107              :                                                                             const std::string& session_id,
     108              :                                                                             const std::string& app_id) {
     109            0 :     const auto* app = const_cast<Configuration&>(db).get<dunedaq::confmodel::DaqApplication>(app_id);
     110            0 :     const auto* session = const_cast<Configuration&>(db).get<dunedaq::confmodel::Session>(session_id);
     111            0 :     return app->construct_commandline_parameters(db, session);
     112              :   }
     113              : 
     114            0 :   std::vector<std::string> rc_application_construct_commandline_parameters(const Configuration& db,
     115              :                                                                            const std::string& session_id,
     116              :                                                                            const std::string& app_id) {
     117            0 :     const auto* app = const_cast<Configuration&>(db).get<dunedaq::confmodel::RCApplication>(app_id);
     118            0 :     const auto* session = const_cast<Configuration&>(db).get<dunedaq::confmodel::Session>(session_id);
     119            0 :     return app->construct_commandline_parameters(db, session);
     120              :   }
     121              : 
     122              : 
     123            0 :   std::string d2d_receiver(const Configuration& db,
     124              :                            const std::string& d2d_id) {
     125            0 :     const auto* d2d = const_cast<Configuration&>(db)
     126            0 :       .get<dunedaq::confmodel::DetectorToDaqConnection>(d2d_id);
     127            0 :     if (d2d == nullptr) {
     128            0 :       return "";
     129              :     }
     130            0 :     return d2d->receiver()->UID();
     131              :   }
     132              : 
     133            0 :   std::vector<std::string> d2d_senders(const Configuration& db,
     134              :                                        const std::string& d2d_id) {
     135            0 :     std::vector<std::string> senders;
     136            0 :     const auto* d2d = const_cast<Configuration&>(db)
     137            0 :       .get<dunedaq::confmodel::DetectorToDaqConnection>(d2d_id);
     138            0 :     if (d2d != nullptr) {
     139            0 :       for (auto sender: d2d->senders()) {
     140            0 :         senders.push_back(sender->UID());
     141            0 :       }
     142              :     }
     143            0 :     return senders;
     144            0 :   }
     145              : 
     146            0 :   std::vector<std::string> d2d_streams(const Configuration& db,
     147              :                                        const std::string& d2d_id) {
     148            0 :     std::vector<std::string> streams;
     149            0 :     const auto* d2d = const_cast<Configuration&>(db)
     150            0 :       .get<dunedaq::confmodel::DetectorToDaqConnection>(d2d_id);
     151            0 :     if (d2d != nullptr) {
     152            0 :       for (auto stream: d2d->streams()) {
     153            0 :         streams.push_back(stream->UID());
     154            0 :       }
     155              :     }
     156            0 :     return streams;
     157            0 :   }
     158              : 
     159              : 
     160              : void
     161            0 : register_dal_methods(py::module& m)
     162              : {
     163            0 :   py::class_<ObjectLocator>(m, "ObjectLocator")
     164            0 :     .def(py::init<const std::string&, const std::string&>())
     165            0 :     .def_readonly("id", &ObjectLocator::id)
     166            0 :     .def_readonly("class_name", &ObjectLocator::class_name)
     167              :     ;
     168              : 
     169            0 :   m.def("session_get_all_applications", &session_get_all_applications, "Get list of ALL applications (regardless of enabled/disabled state) in the requested session");
     170            0 :   m.def("session_get_enabled_applications", &session_get_enabled_applications, "Get list of enabled applications in the requested session");
     171              : 
     172            0 :   m.def("component_disabled", &component_disabled, "Determine if a Resource-derived object (e.g. a Segment) has been disabled");
     173            0 :   m.def("component_get_parents", &component_get_parents, "Get the Resource-derived class instances of the parent(s) of the Resource-derived object in question");
     174            0 :   m.def("daqapp_get_used_resources", &daq_application_get_used_hostresources, "Get list of HostResources used by DAQApplication");
     175            0 :   m.def("daq_application_construct_commandline_parameters", &daq_application_construct_commandline_parameters, "Get a version of the command line agruments parsed");
     176            0 :   m.def("rc_application_construct_commandline_parameters", &rc_application_construct_commandline_parameters, "Get a version of the command line agruments parsed");
     177              : 
     178            0 :   m.def("d2d_receiver", &d2d_receiver, "Get receiver associated with DetectorToDaqConnection");
     179            0 :   m.def("d2d_senders", &d2d_senders, "Get senders associated with DetectorToDaqConnection");
     180            0 :   m.def("d2d_streams", &d2d_streams, "Get streams associated with DetectorToDaqConnection");
     181            0 : }
     182              : 
     183              : } // namespace dunedaq::confmodel::python
        

Generated by: LCOV version 2.0-1