DUNE-DAQ
DUNE Trigger and Data Acquisition software
Toggle main menu visibility
Loading...
Searching...
No Matches
dunedaq
sourcecode
fdreadoutlibs
include
fdreadoutlibs
tpg
TPGInternalStateHarvester.hpp
Go to the documentation of this file.
1
8
#pragma once
9
10
#include <unordered_map>
11
#include <string>
12
#include <vector>
13
#include <memory>
14
#include <array>
15
#include <cstdint>
16
#include <thread>
17
#include <atomic>
18
#include <mutex>
19
#include <condition_variable>
20
#include <chrono>
21
22
23
#include "
tpglibs/AbstractProcessor.hpp
"
24
#include "
trgdataformats/Types.hpp
"
// or the header that defines trgdataformats::channel_t
25
26
namespace
dunedaq
{
27
namespace
fdreadoutlibs
{
28
29
class
TPGInternalStateHarvester
{
30
public
:
31
using
ProcRef
= std::pair<std::shared_ptr<tpglibs::AbstractProcessor<__m256i>>,
int
/*pipeline_id*/
>;
32
33
// Destructor ensures proper thread cleanup
34
~TPGInternalStateHarvester
();
35
36
void
set_processor_references
(std::vector<ProcRef> refs);
37
const
std::vector<ProcRef>&
get_processor_references
()
const
;
38
46
void
update_channel_plane_numbers
(
const
std::vector<std::pair<trgdataformats::channel_t,int16_t>>& channel_plane_numbers,
47
uint8_t num_channels_per_pipeline,
48
uint8_t num_pipelines);
49
55
std::unordered_map<
trgdataformats::channel_t
,
56
std::vector<std::pair<std::string,int16_t>>>
harvest_once
();
57
58
// --- Multi-threaded interface ---
59
64
void
start_collection_thread
();
65
70
void
stop_collection_thread
();
71
76
void
trigger_harvest
();
77
84
std::unordered_map<
trgdataformats::channel_t
,
85
std::vector<std::pair<std::string,int16_t>>>
get_latest_results
()
const
;
86
92
bool
is_collection_thread_running
()
const
;
93
94
private
:
95
96
// --- Original data structures ---
97
std::vector<ProcRef>
m_processor_references
;
98
// index: pipeline_id -> vector of (channel, plane) for its 16 lanes
99
std::vector<std::vector<std::pair<trgdataformats::channel_t,int16_t>>>
m_channel_plane_numbers_per_pipeline
;
100
uint8_t
m_num_channels_per_pipeline
;
101
uint8_t
m_num_pipelines
;
102
103
// --- Preallocation caches (rebuilt when refs/channels change) ---
104
std::vector<std::vector<std::string>>
m_metric_items_per_proc
;
// size == m_processor_references.size()
105
std::vector<size_t>
m_expected_items_per_pipeline
;
// size == m_num_pipelines
106
size_t
m_expected_total_channels
= 0;
// == m_num_channels_per_pipeline * m_num_pipelines
107
108
// --- Multi-threaded data structures ---
109
using
ResultContainer
= std::unordered_map<
trgdataformats::channel_t
,
110
std::vector<std::pair<std::string,int16_t>>>;
111
112
// Single result container with mutex protection
113
mutable
std::mutex
m_results_mutex
;
114
ResultContainer
m_latest_results
;
115
116
// Thread synchronization
117
std::thread
m_collection_thread
;
118
std::atomic<bool>
m_thread_should_stop
{
false
};
119
std::atomic<bool>
m_thread_running
{
false
};
120
std::atomic<bool>
m_harvest_requested
{
false
};
121
122
// Synchronization primitives
123
mutable
std::mutex
m_config_mutex
;
// Protects configuration changes
124
std::mutex
m_collection_mutex
;
// Protects collection process
125
std::condition_variable
m_collection_cv
;
// Signals collection thread
126
127
// Thread management
128
void
collection_thread_worker_
();
129
130
// Rebuild caches after refs or channel layout changes.
131
void
rebuild_prealloc_caches_
();
132
133
};
134
135
}
// namespace fdreadoutlibs
136
}
// namespace dunedaq
AbstractProcessor.hpp
dunedaq::fdreadoutlibs::TPGInternalStateHarvester
Definition
TPGInternalStateHarvester.hpp:29
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_expected_total_channels
size_t m_expected_total_channels
Definition
TPGInternalStateHarvester.hpp:106
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_collection_cv
std::condition_variable m_collection_cv
Definition
TPGInternalStateHarvester.hpp:125
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::stop_collection_thread
void stop_collection_thread()
Stop the background collection thread Blocks until thread is fully stopped.
Definition
TPGInternalStateHarvester.cpp:191
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::is_collection_thread_running
bool is_collection_thread_running() const
Check if collection thread is running.
Definition
TPGInternalStateHarvester.cpp:246
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::start_collection_thread
void start_collection_thread()
Start the background collection thread Must be called before using async collection features.
Definition
TPGInternalStateHarvester.cpp:170
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_channel_plane_numbers_per_pipeline
std::vector< std::vector< std::pair< trgdataformats::channel_t, int16_t > > > m_channel_plane_numbers_per_pipeline
Definition
TPGInternalStateHarvester.hpp:99
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_thread_running
std::atomic< bool > m_thread_running
Definition
TPGInternalStateHarvester.hpp:119
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_num_channels_per_pipeline
uint8_t m_num_channels_per_pipeline
Definition
TPGInternalStateHarvester.hpp:100
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::trigger_harvest
void trigger_harvest()
Signal the collection thread to perform one harvest cycle Non-blocking - returns immediately.
Definition
TPGInternalStateHarvester.cpp:225
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_harvest_requested
std::atomic< bool > m_harvest_requested
Definition
TPGInternalStateHarvester.hpp:120
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_num_pipelines
uint8_t m_num_pipelines
Definition
TPGInternalStateHarvester.hpp:101
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_config_mutex
std::mutex m_config_mutex
Definition
TPGInternalStateHarvester.hpp:123
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::harvest_once
std::unordered_map< trgdataformats::channel_t, std::vector< std::pair< std::string, int16_t > > > harvest_once()
Harvest once, outputs channel -> [(metric_name, value)...].
Definition
TPGInternalStateHarvester.cpp:85
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::get_latest_results
std::unordered_map< trgdataformats::channel_t, std::vector< std::pair< std::string, int16_t > > > get_latest_results() const
Get the latest collected results (thread-safe, non-blocking) Returns a copy of the most recent harves...
Definition
TPGInternalStateHarvester.cpp:241
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::collection_thread_worker_
void collection_thread_worker_()
Definition
TPGInternalStateHarvester.cpp:250
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_expected_items_per_pipeline
std::vector< size_t > m_expected_items_per_pipeline
Definition
TPGInternalStateHarvester.hpp:105
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_processor_references
std::vector< ProcRef > m_processor_references
Definition
TPGInternalStateHarvester.hpp:97
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::ResultContainer
std::unordered_map< trgdataformats::channel_t, std::vector< std::pair< std::string, int16_t > > > ResultContainer
Definition
TPGInternalStateHarvester.hpp:109
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_thread_should_stop
std::atomic< bool > m_thread_should_stop
Definition
TPGInternalStateHarvester.hpp:118
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::set_processor_references
void set_processor_references(std::vector< ProcRef > refs)
Definition
TPGInternalStateHarvester.cpp:25
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_latest_results
ResultContainer m_latest_results
Definition
TPGInternalStateHarvester.hpp:114
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::~TPGInternalStateHarvester
~TPGInternalStateHarvester()
Definition
TPGInternalStateHarvester.cpp:20
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_collection_thread
std::thread m_collection_thread
Definition
TPGInternalStateHarvester.hpp:117
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::ProcRef
std::pair< std::shared_ptr< tpglibs::AbstractProcessor< __m256i > >, int > ProcRef
Definition
TPGInternalStateHarvester.hpp:31
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_results_mutex
std::mutex m_results_mutex
Definition
TPGInternalStateHarvester.hpp:113
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::get_processor_references
const std::vector< ProcRef > & get_processor_references() const
Definition
TPGInternalStateHarvester.cpp:31
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_collection_mutex
std::mutex m_collection_mutex
Definition
TPGInternalStateHarvester.hpp:124
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::m_metric_items_per_proc
std::vector< std::vector< std::string > > m_metric_items_per_proc
Definition
TPGInternalStateHarvester.hpp:104
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::update_channel_plane_numbers
void update_channel_plane_numbers(const std::vector< std::pair< trgdataformats::channel_t, int16_t > > &channel_plane_numbers, uint8_t num_channels_per_pipeline, uint8_t num_pipelines)
Cuts a full list of (channel, plane) into per-pipeline lists of 16 lanes each.
Definition
TPGInternalStateHarvester.cpp:35
dunedaq::fdreadoutlibs::TPGInternalStateHarvester::rebuild_prealloc_caches_
void rebuild_prealloc_caches_()
Definition
TPGInternalStateHarvester.cpp:57
dunedaq::fdreadoutlibs
Definition
CRTBernFrameProcessor.hpp:16
dunedaq::trgdataformats::channel_t
uint32_t channel_t
Definition
Types.hpp:52
dunedaq
Including Qt Headers.
Definition
module.cpp:16
Types.hpp
Generated on
for DUNE-DAQ by
1.17.0