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
12#include <memory>
15
17
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 uint8_t m_num_pipelines = 0; // Gets set inside configure.
34 std::vector<AVXPipeline> m_tpg_pipelines;
36 std::vector<uint16_t> m_sot_minima{1,1,1}; // Defaults to 1 for all planes.
37 std::shared_ptr<ProcessorMetricCollector<__m256i>> m_processor_metric_collector_ptr {nullptr};
39
40 public:
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 int sample_tick_difference);
51
57 void set_sot_minima(const std::vector<uint16_t>& sot_minima);
58
69
70 std::shared_ptr<ProcessorMetricCollector<__m256i>> get_processor_metric_collector_ptr();
71
75
79
81
82 std::unordered_map<dunedaq::trgdataformats::channel_t, std::vector<std::pair<std::string, int16_t>>> get_processor_metrics();
83
91
100 template <typename T>
101 std::vector<dunedaq::trgdataformats::TriggerPrimitive> operator()(const T* frame) {
102 // Max number of TPs for a channel: number of time samples / 2.
103 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tp_aggr;
104 tp_aggr.reserve(T::s_num_channels * T::s_time_samples_per_frame / 2);
105
106 const typename T::word_t (*words_ptr)[T::s_bits_per_adc] = frame->adc_words;
107 const uint64_t timestamp = frame->get_timestamp();
108
109 const int register_alignment = T::s_bits_per_adc * m_num_channels_per_pipeline;
110 // Loop in time.
111 for (int t = 0; t < T::s_time_samples_per_frame; t++) {
112 const typename T::word_t *time_sample = *(words_ptr + t);
113 char* cursor = (char*) time_sample; // Need to walk in terms of bytes/bits.
114
115 // Loop in pipelines.
116 for (int p = 0; p < m_num_pipelines; p++) {
117 if (p == m_num_pipelines - 1)
118 cursor -= 4; // Take a step of 32 bit backwards for the last sub-frame.
119
120 __m256i regi = _mm256_lddqu_si256((__m256i*)cursor);
121
122 if (p == m_num_pipelines - 1) // Permute the row order to use the same operation.
123 regi = _mm256_permutevar8x32_epi32(regi, _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 0));
124
125 __m256i expanded_subframe = expand_frame(regi);
126 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps = m_tpg_pipelines[p].process(expanded_subframe);
127
128 for (auto tp : tps) {
129 tp.time_start = (t - tp.samples_over_threshold) * m_sample_tick_difference + timestamp;
130 tp_aggr.push_back(tp);
131 }
132 cursor += register_alignment / 8; // Numerator is in bits. Need bytes.
133 }
134 }
135
136 return tp_aggr;
137 }
138
139 private:
140 __m256i expand_frame(const __m256i& regi);
141 __m256i old_expand_frame(const __m256i& regi);
142};
143
144} // namespace tpglibs
145
146#endif // TPGLIBS_TPGENERATOR_HPP_
TPG driving class.
std::vector< dunedaq::trgdataformats::TriggerPrimitive > operator()(const T *frame)
Driving function for the TPG.
void set_metric_collector_enable_state(bool state)
std::shared_ptr< ProcessorMetricCollector< __m256i > > get_processor_metric_collector_ptr()
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.
bool get_metric_collector_enable_state()
std::unordered_map< dunedaq::trgdataformats::channel_t, std::vector< std::pair< std::string, int16_t > > > get_processor_metrics()
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 int sample_tick_difference)
Setup and configure the AVX pipelines.
void * get_processor_metric_collector()
Lazily initialize and return the processor metric collector.
__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.
static const uint8_t m_num_channels_per_pipeline
std::shared_ptr< ProcessorMetricCollector< __m256i > > m_processor_metric_collector_ptr