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

            Line data    Source code
       1              : /**
       2              :  * @file DAQModuleManager.hpp Loads and distributes commands to DAQModules
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #ifndef APPFWK_SRC_DAQMODULEMANAGER_HPP_
      10              : #define APPFWK_SRC_DAQMODULEMANAGER_HPP_
      11              : 
      12              : #include "ers/Issue.hpp"
      13              : #include "nlohmann/json.hpp"
      14              : 
      15              : #include "appfwk/ConfigurationManager.hpp"
      16              : #include "appfwk/DAQModule.hpp"
      17              : #include "appfwk/ValidationReport.hpp"
      18              : #include "conffwk/Configuration.hpp"
      19              : #include "confmodel/DaqModule.hpp"
      20              : 
      21              : #include "cmdlib/cmd/Structs.hpp"
      22              : #include "logging/Logging.hpp" // NOTE: if ISSUES ARE DECLARED BEFORE include logging/Logging.hpp, TLOG_DEBUG<<issue wont work.
      23              : #include "opmonlib/OpMonManager.hpp"
      24              : 
      25              : #include <map>
      26              : #include <memory>
      27              : #include <string>
      28              : #include <vector>
      29              : 
      30              : namespace dunedaq {
      31              : 
      32              : // Disable coverage collection LCOV_EXCL_START
      33              : ERS_DECLARE_ISSUE(appfwk,
      34              :                   DAQModuleManagerNotInitialized,
      35              :                   "Command " << cmdid << " received before initialization",
      36              :                   ((std::string)cmdid))
      37              : 
      38              : ERS_DECLARE_ISSUE(appfwk,
      39              :                   DAQModuleManagerAlreadyInitialized,
      40              :                   "\"init\" Command received when already initialized",
      41              :                   ERS_EMPTY)
      42              : 
      43              : ERS_DECLARE_ISSUE(appfwk,
      44              :                   CommandDispatchingFailed,
      45              :                   "Command " << cmdid << " was not executed correctly by: " << modules,
      46              :                   ((std::string)cmdid)((std::string)modules))
      47              : 
      48              : ERS_DECLARE_ISSUE(appfwk,
      49              :                   ConflictingCommandMatching,
      50              :                   "Command " << cmdid << " matches multiple times modules: " << modules,
      51              :                   ((std::string)cmdid)((std::string)modules))
      52              : 
      53              : ERS_DECLARE_ISSUE(appfwk, FailedInfoGathering, "Info gathering failed for module: " << module, ((std::string)module))
      54              : 
      55              : ERS_DECLARE_ISSUE_BASE(appfwk,
      56              :                        ExceptionWhileInfoGathering,
      57              :                        FailedInfoGathering,
      58              :                        module << " threw exception while info gathering: " << message,
      59              :                        ((std::string)module),
      60              :                        ((std::string)message))
      61              : 
      62              : ERS_DECLARE_ISSUE(appfwk,
      63              :                   ActionPlanNotFound,
      64              :                   "No action plan found for command " << cmd << ", taking the following action: " << message,
      65              :                   ((std::string)cmd)((std::string)message))
      66              : 
      67              : // Re-enable coverage collection LCOV_EXCL_STOP
      68              : 
      69              : namespace appfwk {
      70              : 
      71              : constexpr int ACTION_PLANS_REQUIRED = 0;
      72              : constexpr int ACTION_PLANS_REQUIRED_WARNING = 0;
      73              : 
      74              : class DAQModuleManager
      75              : {
      76              : public:
      77              :   explicit DAQModuleManager(const std::string& session_name);
      78              : 
      79              :   void initialize(std::shared_ptr<ConfigurationManager> mgr, opmonlib::OpMonManager&);
      80           24 :   bool initialized() const { return m_initialized; }
      81              :   void cleanup();
      82              : 
      83              :   // Execute a properly structured command
      84              :   void execute(const std::string& cmd, const DAQModule::CommandData_t& cmd_data);
      85              : 
      86              :   // Used during ActionPlan validation
      87           19 :   void set_config_mgr(std::shared_ptr<ConfigurationManager> mgr) { m_configuration_mgr = mgr; }
      88              :   void construct_modules(const std::vector<const dunedaq::confmodel::DaqModule*>& modules);
      89              :   std::vector<ValidationReport> validate_action_plans(bool throw_on_fatal = true);
      90              : 
      91              : private:
      92              :   typedef std::map<std::string, std::shared_ptr<DAQModule>> DAQModuleMap_t; ///< DAQModules indexed by name
      93              : 
      94              :   void init_modules(const std::vector<const dunedaq::confmodel::DaqModule*>& modules, opmonlib::OpMonManager&);
      95              : 
      96              :   void check_command_data(const std::string& id, const DAQModule::CommandData_t& cmd_data);
      97              :   DAQModule::CommandData_t get_command_data_for_module(const std::string& mod_name,
      98              :                                                        const DAQModule::CommandData_t& cmd_data);
      99              :   bool execute_action(const std::string& mod_name, const std::string& action, const DAQModule::CommandData_t& data_obj);
     100              :   void execute_action_plan_step(const std::string& cmd,
     101              :                                 const confmodel::DaqModulesGroup* step,
     102              :                                 const DAQModule::CommandData_t& cmd_data,
     103              :                                 bool execution_mode_is_serial);
     104              : 
     105              :   std::optional<ValidationReport> check_mod_has_cmd(const std::string& cmd,
     106              :                                                   const std::string& mod_class,
     107              :                                                   bool is_optional,
     108              :                                                   const std::string& mod_id,
     109              :                                                   bool throw_on_fatal);
     110              : 
     111              :   std::vector<std::string> get_modnames_by_cmdid(cmdlib::cmd::CmdId id);
     112              :   std::shared_ptr<ConfigurationManager> m_configuration_mgr;
     113              : 
     114              :   std::string m_session_name;
     115              :   bool m_initialized;
     116              : 
     117              :   DAQModuleMap_t m_module_map;
     118              :   std::map<std::string, std::vector<std::string>> m_modules_by_type;
     119              : };
     120              : 
     121              : } // namespace appfwk
     122              : } // namespace dunedaq
     123              : 
     124              : #endif // APPFWK_SRC_DAQMODULEMANAGER_HPP_
        

Generated by: LCOV version 2.0-1