DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TPGPipeline.hpp
Go to the documentation of this file.
1
9#ifndef TPGLIBS_TPGPIPELINE_HPP_
10#define TPGLIBS_TPGPIPELINE_HPP_
11
14
17
18#include <nlohmann/json.hpp>
19#include <vector>
20
21namespace tpglibs {
22
28template <typename T, typename U>
30 public:
32 using processor_t = T;
34 using signal_t = U;
35
36 virtual ~TPGPipeline() = default;
37
44 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) {
45 std::shared_ptr<processor_t> prev_processor = nullptr;
46
47 for (int i = 0; i < 16; i++) {
48 m_channels[i] = channel_plane_numbers[i].first;
49 m_plane_numbers[i] = channel_plane_numbers[i].second;
50 }
51
52 for (const auto& name_config : configs) {
53 // Get the requested processor.
54 std::shared_ptr<processor_t> processor = m_factory->create_processor(name_config.first);
55
56 // Configure it.
57 processor->configure(name_config.second, m_plane_numbers);
58
59 // If it's the first one, make it the head.
60 if (!prev_processor) {
61 m_processor_head = processor;
62 prev_processor = processor;
63 continue;
64 }
65
66 // Otherwise, start linking the chain.
67 prev_processor->set_next_processor(processor);
68 prev_processor = processor;
69 }
70 }
71
75 virtual std::vector<dunedaq::trgdataformats::TriggerPrimitive> process(const signal_t& signal) {
76 signal_t tp_mask = save_state(m_processor_head->process(signal));
77
78 std::vector<dunedaq::trgdataformats::TriggerPrimitive> tps;
79 if (check_for_tps(tp_mask))
80 tps = generate_tps(tp_mask);
81
82 return tps;
83 }
84
86 virtual bool check_for_tps(const signal_t& tp_mask) = 0;
87
89 virtual signal_t save_state(const signal_t& processed_signal) = 0;
90
92 virtual std::vector<dunedaq::trgdataformats::TriggerPrimitive> generate_tps(const signal_t& tp_mask) = 0;
93
95 virtual void set_sot_minima(const std::vector<uint16_t>& sot_minima) {
96 int idx = 0;
97 for (auto sot_minimum : sot_minima) {
98 m_sot_minima[idx++] = sot_minimum;
99 }
100 }
101
103 virtual void attach_to_metric_collector(ProcessorMetricCollector<signal_t>& collector, size_t pipeline_id) {
104 if (m_processor_head == nullptr) return;
105
106 m_processor_head->attach_to_metric_collector(collector, pipeline_id);
107 }
108
109 protected:
122 int16_t m_plane_numbers[16];
124 uint16_t m_sot_minima[3];
126 std::shared_ptr<AbstractFactory<processor_t>> m_factory = AbstractFactory<processor_t>::get_instance();
128 std::shared_ptr<processor_t> m_processor_head;
129};
130
131} // namespace tpglibs
132
133#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
int16_t m_plane_numbers[16]
Detector plane 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.
dunedaq::trgdataformats::channel_t m_channels[16]
Detector channel numbers for the 16 channels that are being processed.
T processor_t
Processor type to use. Generally AVX.
uint16_t m_sot_minima[3]
The samples over threshold minimum that a TP from plane i must have.
virtual bool check_for_tps(const signal_t &tp_mask)=0
Pure virtual function that will check if any TPs can be generated.
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.
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.
virtual void attach_to_metric_collector(ProcessorMetricCollector< signal_t > &collector, size_t pipeline_id)
Register all processors in this pipeline with the metric collector.
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.