DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
tpglibs
include
tpglibs
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
16
#include "
tpglibs/ProcessorMetricArray.hpp
"
17
#ifdef TPGLIBS_ENABLE_STATE_MONITORING
18
#include "
tpglibs/ProcessorInternalStateBufferManager.hpp
"
19
#include "
tpglibs/ProcessorInternalStateNameRegistry.hpp
"
20
#endif
21
22
namespace
tpglibs
{
23
28
template
<
class
T>
29
class
AbstractProcessor
30
{
32
std::shared_ptr<AbstractProcessor<T>>
m_next_processor
;
33
34
protected
:
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
45
public
:
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
120
virtual
ProcessorMetricArray<std::array<int16_t, 16>
>
read_internal_states_as_integer_array
()
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_
ProcessorInternalStateBufferManager.hpp
ProcessorInternalStateNameRegistry.hpp
ProcessorMetricArray.hpp
tpglibs::AbstractProcessor
Abstract signal processor.
Definition
AbstractProcessor.hpp:30
tpglibs::AbstractProcessor::signal_type_t
T signal_type_t
Signal type to process on. General __m256i.
Definition
AbstractProcessor.hpp:47
tpglibs::AbstractProcessor::process
virtual T process(const T &signal)
Simple signal pass-through.
Definition
AbstractProcessor.hpp:102
tpglibs::AbstractProcessor::~AbstractProcessor
virtual ~AbstractProcessor()=default
tpglibs::AbstractProcessor::read_internal_states_as_integer_array
virtual ProcessorMetricArray< std::array< int16_t, 16 > > read_internal_states_as_integer_array()
Definition
AbstractProcessor.hpp:120
tpglibs::AbstractProcessor::configure_internal_state_collection
virtual void configure_internal_state_collection(const nlohmann::json &)
No-op: state monitoring disabled at build time.
Definition
AbstractProcessor.hpp:89
tpglibs::AbstractProcessor::get_requested_internal_state_names
virtual std::vector< std::string > get_requested_internal_state_names() const
Get the names of requested internal states (delegates to registry).
Definition
AbstractProcessor.hpp:111
tpglibs::AbstractProcessor::m_next_processor
std::shared_ptr< AbstractProcessor< T > > m_next_processor
Points to next processor in the chain.
Definition
AbstractProcessor.hpp:32
tpglibs::AbstractProcessor::configure
virtual void configure(const nlohmann::json &config, const int16_t *plane_numbers)=0
Pure virtual function that will configure the processor using plane numbers.
tpglibs::AbstractProcessor::set_next_processor
void set_next_processor(std::shared_ptr< AbstractProcessor< T > > next_processor)
Setter for next processor.
Definition
AbstractProcessor.hpp:96
tpglibs::AbstractProcessor::get_next_processor
std::shared_ptr< AbstractProcessor< T > > get_next_processor()
Getter for next processor.
Definition
AbstractProcessor.hpp:99
tpglibs::ProcessorInternalStateBufferManager
Manages the internal state storage buffers for a processor.
Definition
ProcessorInternalStateBufferManager.hpp:33
tpglibs::ProcessorInternalStateBufferManager::configure_from_registry
void configure_from_registry(ProcessorInternalStateNameRegistry< signal_t > *registry)
Configure and allocate correct buffer storage given the configuration string.
Definition
ProcessorInternalStateBufferManager.hpp:132
tpglibs::ProcessorInternalStateBufferManager::switch_buffer_and_read_casted
ProcessorMetricArray< std::array< int16_t, 16 > > switch_buffer_and_read_casted()
Read from the inactive buffer and cast to std::array<int16_t, 16>.
tpglibs::ProcessorInternalStateNameRegistry
Registry of internal state names.
Definition
ProcessorInternalStateNameRegistry.hpp:28
tpglibs::ProcessorInternalStateNameRegistry::get_names_of_requested_internal_states
std::vector< std::string > get_names_of_requested_internal_states() const
Get the names of the requested internal states.
Definition
ProcessorInternalStateNameRegistry.hpp:145
tpglibs::ProcessorInternalStateNameRegistry::get_number_of_requested_internal_states
size_t get_number_of_requested_internal_states()
Get the number of requested internal states.
Definition
ProcessorInternalStateNameRegistry.hpp:138
tpglibs::ProcessorInternalStateNameRegistry::parse_requested_internal_state_items
void parse_requested_internal_state_items(std::string config_string)
Parse the requested internal state items from a configuration string.
Definition
ProcessorInternalStateNameRegistry.hpp:178
tpglibs
Definition
AbstractFactory.hpp:20
tpglibs::ProcessorMetricArray
Dynamic array of processor metrics, templated on signal type.
Definition
ProcessorMetricArray.hpp:20
Generated on
for DUNE-DAQ by
1.18.0