DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPGenerator.hpp
Go to the documentation of this file.
1
9#ifndef TPGLIBS_TPGENERATOR_HPP_
10#define TPGLIBS_TPGENERATOR_HPP_
11
14
16
17#include <memory>
18#include <utility>
19#include <unordered_map>
20
21
22namespace tpglibs {
23
32 static const uint8_t m_num_channels_per_pipeline = 16; // AVX2 with int16 data samples allows us to process 16 channels.
33 bool m_configured {false};
34 uint8_t m_num_pipelines = 0; // Gets set inside configure.
35 std::vector<AVXPipeline> m_tpg_pipelines;
37 std::vector<uint16_t> m_sot_minima{1,1,1}; // Defaults to 1 for all planes.
38
39 public:
47 void configure(const std::vector<std::pair<std::string, nlohmann::json>>& configs,
48 const std::vector<std::pair<dunedaq::trgdataformats::channel_t, int16_t>> channel_plane_numbers,
49 const float sample_tick_difference);
50
54 void reset();
55
61 void set_sot_minima(const std::vector<uint16_t>& sot_minima);
62
69 std::vector<std::pair<std::shared_ptr<AbstractProcessor<__m256i>>, int>> get_all_processor_references_with_pipeline_index();
70
79 template <typename T>
80 std::vector<dunedaq::trgdataformats::TriggerPrimitive> operator()(const T* frame) {
81 // Max number of TPs for a channel: number of time samples / 2.
82 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tp_aggr;
83 tp_aggr.reserve(T::s_num_channels * T::s_time_samples_per_frame / 2);
84
85 const typename T::word_t (*words_ptr)[T::s_bits_per_adc] = frame->adc_words;
86 const uint64_t timestamp = frame->get_timestamp();
87
88 const int register_alignment = T::s_bits_per_adc * m_num_channels_per_pipeline;
89 // Loop in time.
90 for (int t = 0; t < T::s_time_samples_per_frame; t++) {
91 const typename T::word_t *time_sample = *(words_ptr + t);
92 char* cursor = (char*) time_sample; // Need to walk in terms of bytes/bits.
93
94 // Loop in pipelines.
95 for (int p = 0; p < m_num_pipelines; p++) {
96 if (p == m_num_pipelines - 1)
97 cursor -= 4; // Take a step of 32 bit backwards for the last sub-frame.
98
99 __m256i regi = _mm256_lddqu_si256((__m256i*)cursor);
100
101 if (p == m_num_pipelines - 1) // Permute the row order to use the same operation.
102 regi = _mm256_permutevar8x32_epi32(regi, _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 0));
103
104 __m256i expanded_subframe = expand_frame(regi);
105 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps = m_tpg_pipelines[p].process(expanded_subframe);
106
107 for (auto tp : tps) {
108 tp.time_start = static_cast<int64_t>((t - tp.samples_over_threshold) * m_sample_tick_difference) + timestamp;
109 tp_aggr.push_back(tp);
110 }
111 cursor += register_alignment / 8; // Numerator is in bits. Need bytes.
112 }
113 }
114
115 return tp_aggr;
116 }
117
118 private:
119 __m256i expand_frame(const __m256i& regi);
120 __m256i old_expand_frame(const __m256i& regi);
121};
122
123} // namespace tpglibs
124
125#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