DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
tpglibs
include
tpglibs
TPGenerator.hpp
Go to the documentation of this file.
1
8
9
#ifndef TPGLIBS_TPGENERATOR_HPP_
10
#define TPGLIBS_TPGENERATOR_HPP_
11
12
#include "
tpglibs/AVXPipeline.hpp
"
13
#include "
tpglibs/AbstractProcessor.hpp
"
14
15
#include "
trgdataformats/Types.hpp
"
16
17
#include <memory>
18
#include <utility>
19
#include <unordered_map>
20
21
22
namespace
tpglibs
{
23
31
class
TPGenerator
{
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
;
36
float
m_sample_tick_difference
= 0;
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
// Flatten the external 2-D C-array to a 1-D base pointer; traversal by row stride.
86
const
typename
T::word_t*
const
words_base = &frame->adc_words[0][0];
87
constexpr
int
row_stride = T::s_bits_per_adc;
88
const
uint64_t timestamp = frame->get_timestamp();
89
90
const
int
register_alignment = T::s_bits_per_adc *
m_num_channels_per_pipeline
;
91
// Loop in time.
92
for
(
int
t = 0; t < T::s_time_samples_per_frame; t++) {
93
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
94
const
typename
T::word_t *time_sample = words_base + t * row_stride;
95
const
char
* cursor =
reinterpret_cast<
const
char
*
>
(time_sample);
// Need to walk in terms of bytes/bits.
96
97
// Loop in pipelines.
98
for
(
int
p = 0; p <
m_num_pipelines
; p++) {
99
if
(p ==
m_num_pipelines
- 1) {
100
// Take a step of 32 bit backwards for the last sub-frame.
101
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
102
cursor -= 4;
103
}
104
105
__m256i regi = _mm256_lddqu_si256(
reinterpret_cast<
const
__m256i*
>
(cursor));
106
107
if
(p ==
m_num_pipelines
- 1)
// Permute the row order to use the same operation.
108
regi = _mm256_permutevar8x32_epi32(regi, _mm256_setr_epi32(1, 2, 3, 4, 5, 6, 7, 0));
109
110
__m256i expanded_subframe =
expand_frame
(regi);
111
std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps =
m_tpg_pipelines
[p].process(expanded_subframe);
112
113
for
(
auto
tp : tps) {
114
const
auto
offset_samples =
static_cast<
float
>
(t - tp.samples_over_threshold);
115
tp.time_start =
116
static_cast<
int64_t
>
(offset_samples *
m_sample_tick_difference
) + timestamp;
117
tp_aggr.push_back(tp);
118
}
119
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
120
cursor += register_alignment / 8;
// Numerator is in bits. Need bytes.
121
}
122
}
123
124
return
tp_aggr;
125
}
126
127
private
:
128
__m256i
expand_frame
(
const
__m256i& regi);
129
__m256i
old_expand_frame
(
const
__m256i& regi);
130
};
131
132
}
// namespace tpglibs
133
134
#endif
// TPGLIBS_TPGENERATOR_HPP_
AVXPipeline.hpp
AbstractProcessor.hpp
tpglibs::TPGenerator
TPG driving class.
Definition
TPGenerator.hpp:31
tpglibs::TPGenerator::m_sample_tick_difference
float m_sample_tick_difference
Definition
TPGenerator.hpp:36
tpglibs::TPGenerator::operator()
std::vector< dunedaq::trgdataformats::TriggerPrimitive > operator()(const T *frame)
Driving function for the TPG.
Definition
TPGenerator.hpp:80
tpglibs::TPGenerator::reset
void reset()
Remove all pipelines and reset member variables to default state.
Definition
TPGenerator.cpp:48
tpglibs::TPGenerator::m_sot_minima
std::vector< uint16_t > m_sot_minima
Definition
TPGenerator.hpp:37
tpglibs::TPGenerator::set_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.
Definition
TPGenerator.cpp:57
tpglibs::TPGenerator::configure
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.
Definition
TPGenerator.cpp:14
tpglibs::TPGenerator::m_configured
bool m_configured
Definition
TPGenerator.hpp:33
tpglibs::TPGenerator::expand_frame
__m256i expand_frame(const __m256i ®i)
Definition
TPGenerator.cpp:63
tpglibs::TPGenerator::m_tpg_pipelines
std::vector< AVXPipeline > m_tpg_pipelines
Definition
TPGenerator.hpp:35
tpglibs::TPGenerator::old_expand_frame
__m256i old_expand_frame(const __m256i ®i)
Expansion from 14-bit signals to 16-bit.
Definition
TPGenerator.cpp:83
tpglibs::TPGenerator::get_all_processor_references_with_pipeline_index
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...
Definition
TPGenerator.cpp:36
tpglibs::TPGenerator::m_num_pipelines
uint8_t m_num_pipelines
Definition
TPGenerator.hpp:34
tpglibs::TPGenerator::m_num_channels_per_pipeline
static const uint8_t m_num_channels_per_pipeline
Definition
TPGenerator.hpp:32
tpglibs
Definition
AbstractFactory.hpp:20
Types.hpp
Generated on
for DUNE-DAQ by
1.17.0