LCOV - code coverage report
Current view: top level - tpglibs/unittest - avx_generator_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 51 51
Test Date: 2026-10-11 15:05:20 Functions: 100.0 % 5 5

            Line data    Source code
       1              : /**
       2              :  * @file avx_generator_test.cxx
       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              : #define BOOST_TEST_MODULE boost_test_macro_overview
      10              : 
      11              : #include "tpglibs/TPGenerator.hpp"
      12              : 
      13              : #include "fddetdataformats/TDEEthFrame.hpp"
      14              : #include "fddetdataformats/WIBEthFrame.hpp"
      15              : #include "trgdataformats/Types.hpp"
      16              : 
      17              : #include <boost/test/unit_test.hpp>
      18              : #include <fmt/core.h>
      19              : #include <fmt/ranges.h>
      20              : 
      21              : namespace tpglibs {
      22              : 
      23              : /* Helper function to build a test frame to send through a TPGenerator. */
      24              : dunedaq::fddetdataformats::WIBEthFrame
      25            2 : create_test_frame()
      26              : {
      27            2 :   dunedaq::fddetdataformats::WIBEthFrame frame;
      28              : 
      29            2 :   const int num_time_samples_per_frame = dunedaq::fddetdataformats::WIBEthFrame::s_time_samples_per_frame;
      30              : 
      31          130 :   for (int t_sample = 0; t_sample < num_time_samples_per_frame; t_sample++) {
      32         8320 :     for (int chan = 0; chan < 64; chan++) {
      33         8192 :       frame.set_adc(chan, t_sample, (t_sample * 100 + chan) % 500);
      34              :     }
      35              :   }
      36              :   /* Naively, this looks like:
      37              :    *   uint14_t adcs[i][j] = (100*i + j) % 500;
      38              :    * */
      39            2 :   return frame;
      40              : }
      41              : 
      42            2 : BOOST_AUTO_TEST_CASE(test_macro_overview)
      43              : {
      44            1 :   dunedaq::fddetdataformats::WIBEthFrame frame = create_test_frame();
      45              : 
      46              :   // Lazy with the channel-plane assignments.
      47            1 :   std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>> channel_plane_numbers = {
      48              :     { 0, 0 },  { 1, 0 },  { 2, 0 },  { 3, 0 },  { 4, 0 },  { 5, 0 },  { 6, 0 },  { 7, 0 },  { 8, 0 },  { 9, 0 },
      49              :     { 10, 0 }, { 11, 0 }, { 12, 0 }, { 13, 0 }, { 14, 0 }, { 15, 0 }, { 16, 1 }, { 17, 1 }, { 18, 1 }, { 19, 1 },
      50              :     { 20, 1 }, { 21, 1 }, { 22, 1 }, { 23, 1 }, { 24, 1 }, { 25, 1 }, { 26, 1 }, { 27, 1 }, { 28, 1 }, { 29, 1 },
      51              :     { 30, 1 }, { 31, 1 }, { 32, 2 }, { 33, 2 }, { 34, 2 }, { 35, 2 }, { 36, 2 }, { 37, 2 }, { 38, 2 }, { 39, 2 },
      52              :     { 40, 2 }, { 41, 2 }, { 42, 2 }, { 43, 2 }, { 44, 2 }, { 45, 2 }, { 46, 2 }, { 47, 2 }, { 48, 0 }, { 49, 0 },
      53              :     { 50, 0 }, { 51, 0 }, { 52, 0 }, { 53, 1 }, { 54, 1 }, { 55, 1 }, { 56, 1 }, { 57, 1 }, { 58, 2 }, { 59, 2 },
      54              :     { 60, 2 }, { 61, 2 }, { 62, 2 }, { 63, 2 }
      55            1 :   };
      56              : 
      57              :   // Just using the thresholding for simplicity.
      58            1 :   std::vector<std::pair<std::string, nlohmann::json>> configs = {
      59            6 :     { "AVXThresholdProcessor", { { "plane0", 200 }, { "plane1", 300 }, { "plane2", 445 } } }
      60           14 :   };
      61              : 
      62            1 :   TPGenerator tpg;
      63            1 :   constexpr int sample_tick_difference = 1; // Arbitrary choice for this test. Live has been 32 (2024-08-15).
      64            1 :   tpg.configure(configs, channel_plane_numbers, sample_tick_difference);
      65              : 
      66            1 :   std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps = tpg(&frame);
      67              : 
      68            1 :   int16_t min_peak = INT16_MAX;
      69            1 :   size_t tp_count = tps.size();
      70              : 
      71          601 :   for (auto tp : tps) {
      72          600 :     if (tp.adc_peak < min_peak)
      73            1 :       min_peak = tp.adc_peak;
      74              :   }
      75              : 
      76            1 :   BOOST_TEST(tp_count == 600);
      77            1 :   BOOST_TEST(min_peak > 200); // Truly it should depend on the plane, so this is naive.
      78           10 : }
      79              : 
      80            2 : BOOST_AUTO_TEST_CASE(test_tpg_resetting)
      81              : {
      82            1 :   dunedaq::fddetdataformats::WIBEthFrame frame = create_test_frame();
      83              : 
      84            1 :   std::vector<std::pair<std::string, nlohmann::json>> configs = {
      85            6 :     { "AVXThresholdProcessor", { { "plane0", 200 }, { "plane1", 300 }, { "plane2", 445 } } }
      86           14 :   };
      87              : 
      88            1 :   TPGenerator tpg;
      89            1 :   constexpr int sample_tick_difference = 1;
      90              : 
      91            1 :   std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>> channel_plane_numbers = {
      92              :     { 0, 0 },  { 1, 0 },  { 2, 0 },  { 3, 0 },  { 4, 0 },  { 5, 0 },  { 6, 0 },  { 7, 0 },  { 8, 0 },  { 9, 0 },
      93              :     { 10, 0 }, { 11, 0 }, { 12, 0 }, { 13, 0 }, { 14, 0 }, { 15, 0 }, { 16, 1 }, { 17, 1 }, { 18, 1 }, { 19, 1 },
      94              :     { 20, 1 }, { 21, 1 }, { 22, 1 }, { 23, 1 }, { 24, 1 }, { 25, 1 }, { 26, 1 }, { 27, 1 }, { 28, 1 }, { 29, 1 },
      95              :     { 30, 1 }, { 31, 1 }, { 32, 2 }, { 33, 2 }, { 34, 2 }, { 35, 2 }, { 36, 2 }, { 37, 2 }, { 38, 2 }, { 39, 2 },
      96              :     { 40, 2 }, { 41, 2 }, { 42, 2 }, { 43, 2 }, { 44, 2 }, { 45, 2 }, { 46, 2 }, { 47, 2 }, { 48, 0 }, { 49, 0 },
      97              :     { 50, 0 }, { 51, 0 }, { 52, 0 }, { 53, 1 }, { 54, 1 }, { 55, 1 }, { 56, 1 }, { 57, 1 }, { 58, 2 }, { 59, 2 },
      98              :     { 60, 2 }, { 61, 2 }, { 62, 2 }, { 63, 2 }
      99            1 :   };
     100              : 
     101            1 :   tpg.configure(configs, channel_plane_numbers, sample_tick_difference);
     102              : 
     103            1 :   std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps = tpg(&frame);
     104            1 :   BOOST_TEST(tps.size() == 600);
     105              : 
     106            1 :   tps.clear();
     107            1 :   tpg.reset();
     108              : 
     109            1 :   configs[0].second["plane0"] = 64;
     110            1 :   configs[0].second["plane1"] = 64;
     111            1 :   configs[0].second["plane2"] = 64;
     112              : 
     113            1 :   tpg.configure(configs, channel_plane_numbers, sample_tick_difference);
     114              : 
     115            1 :   tps = tpg(&frame);
     116            1 :   BOOST_TEST(tps.size() == 768);
     117              : 
     118            1 :   tpg.reset();
     119            1 :   tps.clear();
     120            1 :   tps = tpg(&frame);
     121            1 :   BOOST_TEST(tps.size() == 0);
     122           10 : }
     123              : 
     124              : } // namespace tpglibs
        

Generated by: LCOV version 2.0-1