DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
AbstractProcessor.hpp
Go to the documentation of this file.
1
8
9#ifndef TPGLIBS_ABSTRACTPROCESSOR_HPP_
10#define TPGLIBS_ABSTRACTPROCESSOR_HPP_
11
12#include <cstdint>
13#include <memory>
14#include <nlohmann/json.hpp>
15
17#ifdef TPGLIBS_ENABLE_STATE_MONITORING
20#endif
21
22namespace tpglibs {
23
28template<class T>
30{
32 std::shared_ptr<AbstractProcessor<T>> m_next_processor;
33
34protected:
35#ifdef TPGLIBS_ENABLE_STATE_MONITORING
36 ProcessorInternalStateBufferManager<T> m_internal_state_buffer_manager;
37 ProcessorInternalStateNameRegistry<T> m_internal_state_name_registry;
38
39 // Sample counting and collection control
40 std::atomic<uint64_t> m_samples{ 0 };
41 bool m_collect_internal_state_flag{ false };
42 uint64_t m_sample_period{ 1 };
43#endif
44
45public:
47 using signal_type_t = T;
48
49 virtual ~AbstractProcessor() = default;
50
51#ifdef TPGLIBS_ENABLE_STATE_MONITORING
52 ProcessorInternalStateBufferManager<T>* _get_internal_state_buffer_manager()
53 {
54 return &m_internal_state_buffer_manager;
55 }
56
57 ProcessorInternalStateNameRegistry<T>* _get_internal_state_name_registry() { return &m_internal_state_name_registry; }
58
68 virtual void configure_internal_state_collection(const nlohmann::json& config)
69 {
70 m_collect_internal_state_flag = config.value("metric_collect_toggle_state", false);
71 m_sample_period = config.value("metric_collect_time_sample_period", 1);
72
73 if (m_collect_internal_state_flag) {
74 if (config.contains("requested_internal_states")) {
75 m_internal_state_name_registry.parse_requested_internal_state_items(config["requested_internal_states"]);
76 } else {
77 m_internal_state_name_registry.parse_requested_internal_state_items("");
78 }
79
80 // Only configure if we actually have states to collect
81 auto num_items = m_internal_state_name_registry.get_number_of_requested_internal_states();
82 if (num_items > 0) {
83 m_internal_state_buffer_manager.configure_from_registry(&m_internal_state_name_registry);
84 }
85 }
86 }
87#else
89 virtual void configure_internal_state_collection(const nlohmann::json& /* config */) {}
90#endif
91
93 virtual void configure(const nlohmann::json& config, const int16_t* plane_numbers) = 0;
94
96 void set_next_processor(std::shared_ptr<AbstractProcessor<T>> next_processor) { m_next_processor = next_processor; }
97
99 std::shared_ptr<AbstractProcessor<T>> get_next_processor() { return m_next_processor; }
100
102 virtual T process(const T& signal)
103 {
104 if (m_next_processor) {
105 return m_next_processor->process(signal);
106 }
107 return signal;
108 }
109
111 virtual std::vector<std::string> get_requested_internal_state_names() const
112 {
113#ifdef TPGLIBS_ENABLE_STATE_MONITORING
114 return m_internal_state_name_registry.get_names_of_requested_internal_states();
115#else
116 return {};
117#endif
118 }
119
121 {
122#ifdef TPGLIBS_ENABLE_STATE_MONITORING
123 return m_internal_state_buffer_manager.switch_buffer_and_read_casted();
124#else
125 return { nullptr, 0 };
126#endif
127 }
128};
129
130} // namespace tpglibs
131
132#endif // TPGLIBS_ABSTRACTPROCESSOR_HPP_
Abstract signal processor.
T signal_type_t
Signal type to process on. General __m256i.
virtual T process(const T &signal)
Simple signal pass-through.
virtual ~AbstractProcessor()=default
virtual ProcessorMetricArray< std::array< int16_t, 16 > > read_internal_states_as_integer_array()
virtual void configure_internal_state_collection(const nlohmann::json &)
No-op: state monitoring disabled at build time.
virtual std::vector< std::string > get_requested_internal_state_names() const
Get the names of requested internal states (delegates to registry).
std::shared_ptr< AbstractProcessor< T > > m_next_processor
Points to next processor in the chain.
virtual void configure(const nlohmann::json &config, const int16_t *plane_numbers)=0
Pure virtual function that will configure the processor using plane numbers.
void set_next_processor(std::shared_ptr< AbstractProcessor< T > > next_processor)
Setter for next processor.
std::shared_ptr< AbstractProcessor< T > > get_next_processor()
Getter for next processor.
Manages the internal state storage buffers for a processor.
void configure_from_registry(ProcessorInternalStateNameRegistry< signal_t > *registry)
Configure and allocate correct buffer storage given the configuration string.
ProcessorMetricArray< std::array< int16_t, 16 > > switch_buffer_and_read_casted()
Read from the inactive buffer and cast to std::array<int16_t, 16>.
std::vector< std::string > get_names_of_requested_internal_states() const
Get the names of the requested internal states.
size_t get_number_of_requested_internal_states()
Get the number of requested internal states.
void parse_requested_internal_state_items(std::string config_string)
Parse the requested internal state items from a configuration string.
Dynamic array of processor metrics, templated on signal type.