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