DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPGenerator.hpp
Go to the documentation of this file.
1
8
9#ifndef TPGLIBS_TPGENERATOR_HPP_
10#define TPGLIBS_TPGENERATOR_HPP_
11
14
16
17#include <memory>
18#include <unordered_map>
19#include <utility>
20
21namespace tpglibs {
22
31{
32 static const uint8_t m_num_channels_per_pipeline =
33 16; // AVX2 with int16 data samples allows us to process 16 channels.
34 bool m_configured{ false };
35 uint8_t m_num_pipelines = 0; // Gets set inside configure.
36 std::vector<AVXPipeline> m_tpg_pipelines;
38 std::vector<uint16_t> m_sot_minima{ 1, 1, 1 }; // Defaults to 1 for all planes.
39
40public:
48 void configure(const std::vector<std::pair<std::string, nlohmann::json>>& configs,
49 const std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>> channel_plane_numbers,
50 const float sample_tick_difference);
51
55 void reset();
56
62 void set_sot_minima(const std::vector<uint16_t>& sot_minima);
63
70 std::vector<std::pair<std::shared_ptr<AbstractProcessor<__m256i>>, int>>
72
81 template<typename T>
82 std::vector<dunedaq::trgdataformats::TriggerPrimitive> operator()(const T* frame)
83 {
84 // Max number of TPs for a channel: number of time samples / 2.
85 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tp_aggr;
86 tp_aggr.reserve(T::s_num_channels * T::s_time_samples_per_frame / 2);
87
88 // Flatten the external 2-D C-array to a 1-D base pointer; traversal by row stride.
89 const typename T::word_t* const words_base = &frame->adc_words[0][0];
90 constexpr int row_stride = T::s_bits_per_adc;
91 const uint64_t timestamp = frame->get_timestamp();
92
93 const int register_alignment = T::s_bits_per_adc * m_num_channels_per_pipeline;
94 // Loop in time.
95 for (int t = 0; t < T::s_time_samples_per_frame; t++) {
96 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
97 const typename T::word_t* time_sample = words_base + t * row_stride;
98 const char* cursor = reinterpret_cast<const char*>(time_sample); // Need to walk in terms of bytes/bits.
99
100 // Loop in pipelines.
101 for (int p = 0; p < m_num_pipelines; p++) {
102 if (p == m_num_pipelines - 1) {
103 // Take a step of 32 bit backwards for the last sub-frame.
104 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
105 cursor -= 4;
106 }
107
108 __m256i regi = _mm256_lddqu_si256(reinterpret_cast<const __m256i*>(cursor));
109
110 if (p == m_num_pipelines - 1) // Permute the row order to use the same operation.
111 regi = _mm256_permutevar8x32_epi32(regi, _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 0));
112
113 __m256i expanded_subframe = expand_frame(regi);
114 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps = m_tpg_pipelines[p].process(expanded_subframe);
115
116 for (auto tp : tps) {
117 const auto offset_samples = static_cast<float>(t - tp.samples_over_threshold);
118 tp.time_start = static_cast<int64_t>(offset_samples * m_sample_tick_difference) + timestamp;
119 tp_aggr.push_back(tp);
120 }
121 // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
122 cursor += register_alignment / 8; // Numerator is in bits. Need bytes.
123 }
124 }
125
126 return tp_aggr;
127 }
128
129private:
130 __m256i expand_frame(const __m256i& regi);
131 __m256i old_expand_frame(const __m256i& regi);
132};
133
134} // namespace tpglibs
135
136#endif // TPGLIBS_TPGENERATOR_HPP_
TPG driving class.
std::vector< dunedaq::trgdataformats::TriggerPrimitive > operator()(const T *frame)
Driving function for the TPG.
void reset()
Remove all pipelines and reset member variables to default state.
std::vector< uint16_t > m_sot_minima
void set_sot_minima(const std::vector< uint16_t > &sot_minima)
Set the minimum samples over threshold for a TP according to plane.
void configure(const std::vector< std::pair< std::string, nlohmann::json > > &configs, const std::vector< std::pair< dunedaq::trgdataformats::channel_t, int16_t > > channel_plane_numbers, const float sample_tick_difference)
Setup and configure the AVX pipelines.
__m256i expand_frame(const __m256i &regi)
std::vector< AVXPipeline > m_tpg_pipelines
__m256i old_expand_frame(const __m256i &regi)
Expansion from 14-bit signals to 16-bit.
std::vector< std::pair< std::shared_ptr< AbstractProcessor< __m256i > >, int > > get_all_processor_references_with_pipeline_index()
Return reference to all processors, under all pipelines, where the index of the pipeline is tagged al...
static const uint8_t m_num_channels_per_pipeline