LCOV - code coverage report
Current view: top level - trigger/plugins - FixedTimeTCMakerModule.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 0.0 % 67 0
Test Date: 2025-12-21 13:07:08 Functions: 0.0 % 8 0

            Line data    Source code
       1              : /**
       2              :  * @file FixedTimeTCMakerModule.cpp Implementation of the Fixed-Time TC Maker
       3              :  *
       4              :  * This is part of the DUNE DAQ , copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "FixedTimeTCMakerModule.hpp"
      10              : 
      11              : #include "appmodel/FixedTimeTCMakerModule.hpp"
      12              : #include "appmodel/FixedTimeTCMakerModuleConf.hpp"
      13              : #include "appmodel/FixedTimeTCConf.hpp"
      14              : #include "appmodel/SourceIDConf.hpp"
      15              : #include "trigger/opmon/latency_info.pb.h"
      16              : #include "trigger/opmon/randomtcmaker_info.pb.h"
      17              : #include "trigger/TriggerCandidate_serialization.hpp"
      18              : 
      19              : namespace dunedaq::trigger {
      20            0 : FixedTimeTCMakerModule::FixedTimeTCMakerModule(const std::string& module_name)
      21              :   : appfwk::DAQModule(module_name)
      22            0 :   , m_send_trigger_candidates_thread(
      23            0 :       std::bind(&FixedTimeTCMakerModule::send_trigger_candidates, this, std::placeholders::_1))
      24              : {
      25            0 :   register_command("enable_triggers", &FixedTimeTCMakerModule::do_enable_triggers);
      26            0 : }
      27              : 
      28              : void
      29            0 : FixedTimeTCMakerModule::init(std::shared_ptr<appfwk::ConfigurationManager> cfg)
      30              : {
      31            0 :   auto mdal = cfg->get_dal<appmodel::FixedTimeTCMakerModule>(get_name());
      32              : 
      33            0 :   if (!mdal) {
      34            0 :     throw appfwk::CommandFailed(ERS_HERE, "init", get_name(), "Unable to retrieve configuration object");
      35              :   }
      36              : 
      37            0 :   auto iom = iomanager::IOManager::get();
      38            0 :   for (auto con : mdal->get_outputs()) {
      39            0 :     if (con->get_data_type() == datatype_to_string<triggeralgs::TriggerCandidate>()) {
      40            0 :       m_trigger_sender = iom->get_sender<triggeralgs::TriggerCandidate>(con->UID());
      41              :     }
      42              :   }
      43              : 
      44            0 :   if (m_trigger_sender == nullptr) {
      45            0 :     throw appfwk::MissingConnection(ERS_HERE, get_name(), "TriggerCandidate", "output");
      46              :   }
      47              : 
      48            0 :   m_conf = mdal->get_configuration();
      49              : 
      50            0 :   m_latency_monitoring.store(m_conf->get_latency_monitoring());
      51            0 :   m_wait_time = std::chrono::milliseconds(m_conf->get_wait_time_ms());
      52            0 :   m_tcout_type =
      53            0 :     static_cast<TCType>(dunedaq::trgdataformats::string_to_trigger_candidate_type(m_conf->get_tc_type_name()));
      54            0 : }
      55              : 
      56              : void
      57            0 : FixedTimeTCMakerModule::generate_opmon_data()
      58              : {
      59            0 :   opmon::RandomTCMakerInfo info;
      60              : 
      61            0 :   info.set_tc_made_count(m_tc_made_count.load());
      62            0 :   info.set_tc_sent_count(m_tc_sent_count.load());
      63            0 :   info.set_tc_failed_sent_count(m_tc_failed_sent_count.load());
      64              : 
      65            0 :   this->publish(std::move(info));
      66              : 
      67            0 :   if (m_latency_monitoring.load()) {
      68            0 :     opmon::TriggerLatencyStandalone lat_info;
      69              : 
      70            0 :     lat_info.set_latency_out(m_latency_instance.get_latency_out());
      71              : 
      72            0 :     this->publish(std::move(lat_info));
      73            0 :   }
      74            0 : }
      75              : 
      76              : void
      77            0 : FixedTimeTCMakerModule::do_enable_triggers(const CommandData_t& /*cmd*/)
      78              : {
      79            0 :   m_send_trigger_candidates_thread.start_working_thread("PCTRIG");
      80            0 : }
      81              : void
      82            0 : FixedTimeTCMakerModule::do_disable_triggers(const CommandData_t& /*cmd*/)
      83              : {
      84            0 :   m_send_trigger_candidates_thread.stop_working_thread();
      85            0 : }
      86              : 
      87              : 
      88              : 
      89              : triggeralgs::TriggerCandidate
      90            0 : FixedTimeTCMakerModule::create_candidate(dfmessages::timestamp_t time_start, dfmessages::timestamp_t time_end)
      91              : {
      92            0 :   triggeralgs::TriggerCandidate candidate;
      93            0 :   candidate.time_start = time_start;
      94            0 :   candidate.time_end = time_end;
      95            0 :   candidate.time_candidate = time_start;
      96            0 :   candidate.detid = { 0 };
      97            0 :   candidate.type = m_tcout_type;
      98              : 
      99              :   // TODO: Originally kHSIEventToTriggerCandidate
     100            0 :   candidate.algorithm = triggeralgs::TriggerCandidate::Algorithm::kCustom;
     101              : 
     102            0 :   return candidate;
     103              : }
     104              : 
     105              : void
     106            0 : FixedTimeTCMakerModule::send_trigger_candidates(std::atomic<bool>& running_flag)
     107              : {
     108            0 :   auto triggers = m_conf->get_triggers();
     109            0 :   for (auto& trigger : triggers) {
     110            0 :     if (!running_flag.load())
     111              :       break;
     112              : 
     113            0 :     auto candidate = create_candidate(trigger->get_timestamp_start(), trigger->get_timestamp_end());
     114              : 
     115            0 :     m_tc_made_count++;
     116              : 
     117            0 :     if (m_latency_monitoring.load())
     118            0 :       m_latency_instance.update_latency_out(candidate.time_candidate);
     119              :     
     120            0 :     try {
     121            0 :       m_trigger_sender->send(std::move(candidate), std::chrono::milliseconds(10));
     122            0 :       m_tc_sent_count++;
     123            0 :     } catch (const ers::Issue& e) {
     124            0 :       ers::error(e);
     125            0 :       m_tc_failed_sent_count++;
     126            0 :     }
     127              : 
     128            0 :     std::this_thread::sleep_for(m_wait_time);
     129            0 :   }
     130            0 : }
     131              : 
     132              : } // namespace dunedaq::trigger
     133              : 
     134            0 : DEFINE_DUNE_DAQ_MODULE(dunedaq::trigger::FixedTimeTCMakerModule)
        

Generated by: LCOV version 2.0-1