DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPGPipeline.hpp
Go to the documentation of this file.
1
8
9#ifndef TPGLIBS_TPGPIPELINE_HPP_
10#define TPGLIBS_TPGPIPELINE_HPP_
11
14
17
18#include <array>
19#include <nlohmann/json.hpp>
20#include <vector>
21
22namespace tpglibs {
23
29template<typename T, typename U>
31{
32public:
34 using processor_t = T;
36 using signal_t = U;
37
38 virtual ~TPGPipeline() = default;
39
46 virtual void configure(
47 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 {
50 std::shared_ptr<processor_t> prev_processor = nullptr;
51
52 for (int i = 0; i < 16; i++) {
53 m_channels.at(i) = channel_plane_numbers[i].first;
54 m_plane_numbers.at(i) = channel_plane_numbers[i].second;
55 }
56
57 for (const auto& name_config : configs) {
58 // Get the requested processor.
59 std::shared_ptr<processor_t> processor = m_factory->create_processor(name_config.first);
60
61 // Configure it.
62 processor->configure(name_config.second, m_plane_numbers.data());
63
64 // If it's the first one, make it the head.
65 if (!prev_processor) {
66 m_processor_head = processor;
67 prev_processor = processor;
68 continue;
69 }
70
71 // Otherwise, start linking the chain.
72 prev_processor->set_next_processor(processor);
73 prev_processor = processor;
74 }
75 }
76
80 virtual std::vector<dunedaq::trgdataformats::TriggerPrimitive> process(const signal_t& signal)
81 {
82 signal_t tp_mask = save_state(m_processor_head->process(signal));
83
84 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps;
85 if (check_for_tps(tp_mask))
86 tps = generate_tps(tp_mask);
87
88 return tps;
89 }
90
92 virtual bool check_for_tps(const signal_t& tp_mask) = 0;
93
95 virtual signal_t save_state(const signal_t& processed_signal) = 0;
96
98 virtual std::vector<dunedaq::trgdataformats::TriggerPrimitive> generate_tps(const signal_t& tp_mask) = 0;
99
105 virtual std::vector<std::shared_ptr<AbstractProcessor<signal_t>>> get_all_processor_references()
106 {
107 std::vector<std::shared_ptr<AbstractProcessor<signal_t>>> processor_references;
108 if (m_processor_head == nullptr)
109 return processor_references;
110
111 auto current_processor = std::static_pointer_cast<AbstractProcessor<signal_t>>(m_processor_head);
112 while (current_processor != nullptr) {
113 processor_references.push_back(current_processor);
114 current_processor = current_processor->get_next_processor();
115 }
116 return processor_references;
117 }
118
120 virtual void set_sot_minima(const std::vector<uint16_t>& sot_minima)
121 {
122 int idx = 0;
123 for (auto sot_minimum : sot_minima) {
124 m_sot_minima.at(idx++) = sot_minimum;
125 }
126 }
127
128protected:
139 std::array<dunedaq::trgdataformats::channel_t, 16> m_channels;
141 std::array<int16_t, 16> m_plane_numbers;
143 std::array<uint16_t, 3> m_sot_minima;
145 std::shared_ptr<AbstractFactory<processor_t>> m_factory = AbstractFactory<processor_t>::get_instance();
147 std::shared_ptr<processor_t> m_processor_head;
148};
149
150} // namespace tpglibs
151
152#endif // TPGLIBS_TPGPIPELINE_HPP_
static std::shared_ptr< AbstractFactory< T > > get_instance()
Singleton get instance function.
Abstract class for the TPG pipeline.
virtual ~TPGPipeline()=default
std::array< int16_t, 16 > m_plane_numbers
Detector plane numbers for the 16 channels that are being processed.
std::array< dunedaq::trgdataformats::channel_t, 16 > m_channels
Detector channel numbers for the 16 channels that are being processed.
std::shared_ptr< processor_t > m_processor_head
Processor head to start from.
signal_t m_adc_peak
The ADC peak for channels that are considered active.
std::shared_ptr< AbstractFactory< processor_t > > m_factory
Processor factory singleton.
signal_t m_adc_integral_lo
The on-going ADC integral for channels that are considered active.
virtual void set_sot_minima(const std::vector< uint16_t > &sot_minima)
Set the samples over threshold minimum values.
signal_t m_samples_over_threshold
The samples over threshold for channels that are considered active.
T processor_t
Processor type to use. Generally AVX.
virtual bool check_for_tps(const signal_t &tp_mask)=0
Pure virtual function that will check if any TPs can be generated.
std::array< uint16_t, 3 > m_sot_minima
The samples over threshold minimum that a TP from plane i must have.
virtual 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)
Configure the pieces to the pipeline.
virtual std::vector< std::shared_ptr< AbstractProcessor< signal_t > > > get_all_processor_references()
Return reference to all processors in this pipeline.
U signal_t
Signal type to use. Generally __m256i.
virtual std::vector< dunedaq::trgdataformats::TriggerPrimitive > process(const signal_t &signal)
Process a signal through the pipeline.
signal_t m_samples_to_peak
The number of samples from time_start to the ADC peak.
virtual std::vector< dunedaq::trgdataformats::TriggerPrimitive > generate_tps(const signal_t &tp_mask)=0
Pure virtual function that will generate TPs given a mask to draw from.
virtual signal_t save_state(const signal_t &processed_signal)=0
Pure virtual function that will save the state of the generation.