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 <unordered_map>
19
#include <utility>
20
21
namespace
tpglibs
{
22
30
class
TPGenerator
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
;
37
float
m_sample_tick_difference
= 0;
38
std::vector<uint16_t>
m_sot_minima
{ 1, 1, 1 };
// Defaults to 1 for all planes.
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
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
>>
71
get_all_processor_references_with_pipeline_index
();
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
129
private
:
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_
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:37
tpglibs::TPGenerator::operator()
std::vector< dunedaq::trgdataformats::TriggerPrimitive > operator()(const T *frame)
Driving function for the TPG.
Definition
TPGenerator.hpp:82
tpglibs::TPGenerator::reset
void reset()
Remove all pipelines and reset member variables to default state.
Definition
TPGenerator.cpp:53
tpglibs::TPGenerator::m_sot_minima
std::vector< uint16_t > m_sot_minima
Definition
TPGenerator.hpp:38
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:63
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:34
tpglibs::TPGenerator::expand_frame
__m256i expand_frame(const __m256i ®i)
Definition
TPGenerator.cpp:69
tpglibs::TPGenerator::m_tpg_pipelines
std::vector< AVXPipeline > m_tpg_pipelines
Definition
TPGenerator.hpp:36
tpglibs::TPGenerator::old_expand_frame
__m256i old_expand_frame(const __m256i ®i)
Expansion from 14-bit signals to 16-bit.
Definition
TPGenerator.cpp:90
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:40
tpglibs::TPGenerator::m_num_pipelines
uint8_t m_num_pipelines
Definition
TPGenerator.hpp:35
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.18.0