DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AVXFrugalPedestalSubtractProcessor.cpp
Go to the documentation of this file.
1
10
11namespace tpglibs {
12
13REGISTER_AVXPROCESSOR_CREATOR("AVXFrugalPedestalSubtractProcessor", AVXFrugalPedestalSubtractProcessor)
14
15void AVXFrugalPedestalSubtractProcessor::configure(const nlohmann::json& config, const int16_t* /* plane_numbers */) {
16 // Configure common metric collection parameters
17 // Register pointers to the ACTUAL member variables, not copies
18 // Use shared_ptr with no-op deleter to avoid double-free
19 m_internal_state_name_registry.register_internal_state("pedestal",
20 std::shared_ptr<__m256i>(&m_pedestal, [](auto*){}));
21 m_internal_state_name_registry.register_internal_state("accum",
22 std::shared_ptr<__m256i>(&m_accum, [](auto*){}));
23
24 configure_internal_state_collection(config);
25
26 m_accum_limit = config["accum_limit"];
27}
28
29__m256i AVXFrugalPedestalSubtractProcessor::process(const __m256i& signal) {
30 // Update sample counter and write internal states to buffer for harvesting
31 m_samples++;
34 }
35
36 // Find the channels that are above or below the pedestal.
37 __m256i is_gt = _mm256_cmpgt_epi16(signal, m_pedestal);
38 __m256i is_lt = _mm256_cmpgt_epi16(m_pedestal, signal);
39
40 // Update m_accum.
41 __m256i to_add = _mm256_setzero_si256(); // Assumes equal to pedestal.
42 to_add = _mm256_blendv_epi8(to_add, _mm256_set1_epi16(1), is_gt); // Set the above pedestal case.
43 to_add = _mm256_blendv_epi8(to_add, _mm256_set1_epi16(-1), is_lt); // Set the below pedestal case.
44
45 m_accum = _mm256_add_epi16(m_accum, to_add);
46
47 // Check the accum limit condition.
48 is_gt = _mm256_cmpgt_epi16(m_accum, _mm256_set1_epi16(m_accum_limit)); // m_accum > +limit.
49 is_lt = _mm256_cmpgt_epi16(_mm256_set1_epi16(-1*m_accum_limit), m_accum); // m_accum < -limit = -limit > m_accum.
50
51 to_add = _mm256_setzero_si256();
52 to_add = _mm256_blendv_epi8(to_add, _mm256_set1_epi16(1), is_gt);
53 to_add = _mm256_blendv_epi8(to_add, _mm256_set1_epi16(-1), is_lt);
54
55 // Update pedestal.
56 m_pedestal = _mm256_adds_epi16(m_pedestal, to_add);
57
58 // Reset too high/low m_accum channels.
59 __m256i need_reset = _mm256_or_si256(is_lt, is_gt);
60 m_accum = _mm256_blendv_epi8(m_accum, _mm256_setzero_si256(), need_reset);
61
62 return AVXProcessor::process(_mm256_sub_epi16(signal, m_pedestal));
63}
64
65} // namespace tpglibs
#define REGISTER_AVXPROCESSOR_CREATOR(processor_name, processor_class)
Factory registration macro.
AVX signal processor: Estimates the pedestal and subtracts.
__m256i process(const __m256i &signal) override
Estimate the pedestal using the given signal and subtract.
__m256i m_pedestal
Vector of estimated pedestals for each channel.
int16_t m_accum_limit
Count limit before committing to a pedestal shift.
__m256i m_accum
Vector of counts that a channel's signal was above or below m_pedestal.
virtual __m256i process(const __m256i &signal) override
Simple signal pass-through on __m256i type.
ProcessorInternalStateBufferManager< __m256i > m_internal_state_buffer_manager