LCOV - code coverage report
Current view: top level - tpglibs/src - NaiveRunSumProcessor.cpp (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 31 31
Test Date: 2025-12-21 13:07:08 Functions: 75.0 % 4 3

            Line data    Source code
       1              : /**
       2              :  * @file NaiveRunSumProcessor.cpp
       3              :  *
       4              :  * @copyright 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 "tpglibs/NaiveRunSumProcessor.hpp"
      10              : 
      11              : namespace tpglibs {
      12              : 
      13           15 : REGISTER_NAIVEPROCESSOR_CREATOR("NaiveRunSumProcessor", NaiveRunSumProcessor)
      14              : 
      15           10 : void NaiveRunSumProcessor::configure(const nlohmann::json& config, const int16_t* plane_numbers) {
      16              :   // Configure common metric collection parameters
      17              :   // Register pointers to the ACTUAL member variables, not copies
      18              :   // Use shared_ptr with no-op deleter to avoid double-free
      19           10 :   m_internal_state_name_registry.register_internal_state("r", 
      20           20 :     std::shared_ptr<naive_array_t>(&m_memory_factor, [](auto*){}));
      21           10 :   m_internal_state_name_registry.register_internal_state("s", 
      22           20 :     std::shared_ptr<naive_array_t>(&m_scale_factor, [](auto*){}));
      23           10 :   m_internal_state_name_registry.register_internal_state("rs", 
      24           20 :     std::shared_ptr<naive_array_t>(&m_running_sum, [](auto*){}));
      25              :     
      26           10 :   configure_internal_state_collection(config);
      27              : 
      28           10 :   int16_t config_memory[3] = {config["memory_factor_plane0"],
      29           10 :                               config["memory_factor_plane1"],
      30           10 :                               config["memory_factor_plane2"]};
      31           10 :   int16_t config_scale[3]  = {config["scale_factor_plane0"],
      32           10 :                               config["scale_factor_plane1"],
      33           10 :                               config["scale_factor_plane2"]};
      34              : 
      35          170 :   for (int i = 0; i < 16; i++) {
      36          160 :     m_memory_factor[i] = config_memory[plane_numbers[i]];
      37          160 :     m_scale_factor[i] = config_scale[plane_numbers[i]];
      38              :   }
      39           10 : }
      40              : 
      41            4 : NaiveRunSumProcessor::naive_array_t NaiveRunSumProcessor::process(const naive_array_t& signal) {
      42              :   // Update sample counter and write internal states to buffer for harvesting
      43            4 :   m_samples++;
      44            4 :   if (m_collect_internal_state_flag && (m_samples % m_sample_period == 0)) {
      45            4 :     m_internal_state_buffer_manager.write_to_active_buffer();
      46              :   }
      47              : 
      48           68 :   for (int i = 0; i < 16; i++) {
      49           64 :     int32_t scaled_rs = _naive_div_int16(m_running_sum[i], 10);
      50           64 :     scaled_rs *= m_memory_factor[i];
      51              : 
      52           64 :     int32_t scaled_signal = _naive_div_int16(signal[i], 10);
      53           64 :     scaled_signal *= m_scale_factor[i];
      54              : 
      55           64 :     int32_t intermediate = scaled_signal + scaled_rs;
      56           64 :     m_running_sum[i] = std::min(intermediate, INT16_MAX);
      57              :   }
      58            4 :   return NaiveProcessor::process(m_running_sum);
      59              : }
      60              : 
      61              : } // namespace tpglibs
        

Generated by: LCOV version 2.0-1