LCOV - code coverage report
Current view: top level - appfwk/src - ConfigurationManager.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 93.9 % 66 62
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 12 12

            Line data    Source code
       1              : /**
       2              :  * @file ConfigurationManager.cpp ConfigurationManager class
       3              :  * implementation
       4              :  *
       5              :  * This is part of the DUNE DAQ Software Suite, copyright 2023.
       6              :  * Licensing/copyright details are in the COPYING file that you should have
       7              :  * received with this code.
       8              :  */
       9              : 
      10              : #include "appfwk/ConfigurationManager.hpp"
      11              : 
      12              : #include "appmodel/SmartDaqApplication.hpp"
      13              : #include "conffwk/Configuration.hpp"
      14              : #include "confmodel/DaqApplication.hpp"
      15              : #include "confmodel/DaqModule.hpp"
      16              : #include "confmodel/DaqModulesGroupByType.hpp"
      17              : #include "confmodel/FSMCommand.hpp"
      18              : #include "confmodel/NetworkConnection.hpp"
      19              : #include "confmodel/Queue.hpp"
      20              : #include "confmodel/ResourceSet.hpp"
      21              : #include "confmodel/Service.hpp"
      22              : #include "confmodel/Session.hpp"
      23              : 
      24              : #include <set>
      25              : #include <string>
      26              : 
      27              : using namespace dunedaq::appfwk;
      28              : 
      29              : enum
      30              : {
      31              :   TLVL_SESSION = 5,
      32              :   TLVL_APP = 6,
      33              :   TLVL_MODULE = 7,
      34              :   TLVL_QUEUE = 8,
      35              :   TLVL_ACTION_PLAN = 9,
      36              : 
      37              : };
      38              : 
      39           44 : ConfigurationManager::ConfigurationManager(std::string const& config_spec,
      40              :                                            std::string const& app_name,
      41           44 :                                            std::string const& session_name)
      42           44 :   : m_confdb(new conffwk::Configuration(config_spec))
      43           44 :   , m_app_name(app_name)
      44           44 :   , m_session_name(session_name)
      45              : {
      46           88 :   TLOG() << "configSpec <" << config_spec << "> session name " << session_name << " application name " << app_name;
      47              : 
      48           44 :   TLOG_DBG(TLVL_SESSION) << "getting session " << session_name;
      49           44 :   m_session = m_confdb->get<confmodel::Session>(session_name);
      50           44 :   if (m_session == nullptr) {
      51            2 :     TLOG() << "Failed to get session " << session_name;
      52            1 :     throw MissingComponent(ERS_HERE, "Session " + session_name);
      53              :   }
      54           50 : }
      55              : 
      56              : std::vector<ValidationReport>
      57          149 : ConfigurationManager::initialize(bool throw_on_fatal)
      58              : {
      59          149 :   std::vector<ValidationReport> reports;
      60          149 :   if (m_initialized) {
      61              :     return reports;
      62              :   }
      63           38 :   TLOG_DBG(TLVL_APP) << "getting app " << m_app_name;
      64           38 :   m_application = m_confdb->get<confmodel::DaqApplication>(m_app_name);
      65           38 :   if (m_application == nullptr) {
      66            2 :     TLOG() << "Failed to get app " << m_app_name;
      67            1 :     throw MissingComponent(ERS_HERE, "Application " + m_app_name);
      68              :   }
      69              : 
      70           37 :   TLOG_DBG(TLVL_APP) << "getting modules for app " << m_app_name;
      71           37 :   auto smart_daq_app = m_application->cast<appmodel::SmartDaqApplication>();
      72           37 :   auto daq_app = m_application->cast<confmodel::DaqApplication>();
      73           37 :   if(!daq_app && !smart_daq_app) {
      74            0 :     throw(NotADaqApplication(ERS_HERE, m_application->UID()));    
      75              :   }
      76              : 
      77           37 :   if (smart_daq_app) {
      78            0 :     smart_daq_app->generate_modules(m_session);
      79              :   }
      80              :  
      81           37 :   m_modules = m_application->get_modules();
      82              :    
      83           73 :   for (auto& plan : m_application->get_action_plans()) {
      84           37 :     auto cmd = plan->get_command()->get_cmd();
      85           37 :     TLOG_DBG(TLVL_ACTION_PLAN) << "Registering action plan " << plan->UID() << " for cmd " << cmd;
      86           37 :     if (m_action_plans.count(cmd)) {
      87            1 :       reports.emplace_back(ValidationReport::Severity::Fatal,
      88              :                            m_app_name,
      89              :                            "N/A",
      90              :                            cmd,
      91            2 :                            "Multiple ActionPlans registered for cmd, conflicting plan is " + plan->UID());
      92            1 :       if (throw_on_fatal)
      93            1 :         throw ActionPlanValidationFailed(
      94            1 :           ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message());
      95              :       else
      96            0 :         ers::error(ActionPlanValidationFailed(
      97            0 :           ERS_HERE, reports.back().get_command(), reports.back().get_module(), reports.back().get_message()));
      98              :     }
      99           36 :     m_action_plans[cmd] = plan;
     100           37 :   }
     101              : 
     102           36 :   m_connsvc_config = m_session->get_connectivity_service();
     103              : 
     104           36 :   std::set<std::string> connectionsAdded;
     105           93 :   for (auto mod : m_modules) {
     106           57 :     TLOG_DBG(TLVL_MODULE) << "initialising " << mod->class_name() << " module " << mod->UID();
     107           57 :     auto connections = mod->get_inputs();
     108           57 :     auto outputs = mod->get_outputs();
     109           57 :     connections.insert(connections.end(), outputs.begin(), outputs.end());
     110          171 :     for (auto con : connections) {
     111          114 :       auto [c, inserted] = connectionsAdded.insert(con->UID());
     112          114 :       if (!inserted) {
     113              :         // Already handled this connection, don't add it again
     114           45 :         continue;
     115              :       }
     116           69 :       auto queue = m_confdb->cast<confmodel::Queue>(con);
     117           69 :       if (queue) {
     118           45 :         TLOG_DBG(TLVL_QUEUE) << "Adding queue " << queue->UID();
     119           45 :         m_queues.emplace_back(queue);
     120              :       }
     121           69 :       auto net_con = m_confdb->cast<confmodel::NetworkConnection>(con);
     122           69 :       if (net_con) {
     123           24 :         m_networkconnections.emplace_back(net_con);
     124              :       }
     125              :     }
     126           57 :   }
     127              : 
     128           36 :   m_initialized = true;
     129           36 :   return reports;
     130           38 : }
     131              : 
     132              : const dunedaq::confmodel::ActionPlan*
     133           15 : ConfigurationManager::get_action_plan(std::string cmd) const
     134              : {
     135           15 :   if (m_action_plans.count(cmd)) {
     136           12 :     return m_action_plans.at(cmd);
     137              :   }
     138              :   return nullptr;
     139              : }
        

Generated by: LCOV version 2.0-1