DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TCProcessor.hpp
Go to the documentation of this file.
1
8#ifndef TRIGGER_SRC_TRIGGER_TCPROCESSOR_HPP_
9#define TRIGGER_SRC_TRIGGER_TCPROCESSOR_HPP_
10
12#include "iomanager/Sender.hpp"
13#include "logging/Logging.hpp"
14
21
23
24#include "trigger/Issues.hpp"
25#include "trigger/TCWrapper.hpp"
26#include "trigger/Latency.hpp"
29
32
36
37namespace dunedaq {
38namespace trigger {
39
41{
42
43public:
45 using tcptr = TCWrapper*;
46 using consttcptr = const TCWrapper*;
48 using TDBitset = std::bitset<64>;
49
50 explicit TCProcessor(std::unique_ptr<datahandlinglibs::FrameErrorRegistry>& error_registry, bool post_processing_enabled);
51
53
54 void start(const nlohmann::json& args) override;
55
56 void stop(const nlohmann::json& args) override;
57
58 void conf(const appmodel::DataHandlerModule* conf) override;
59
60 void scrap(const nlohmann::json& args) override;
61
62 void generate_opmon_data() override;
63
64protected:
65
66 void make_td(const TCWrapper* tc);
67
68private:
71
72 // TD requests
73 std::vector<daqdataformats::SourceID> m_mandatory_links;
74 std::map<int, std::vector<daqdataformats::SourceID>> m_group_links;
75 nlohmann::json m_group_links_data;
77 void parse_group_links(const nlohmann::json& data);
78 void print_group_links();
79
83 std::vector<dfmessages::ComponentRequest> create_all_decision_requests(std::vector<daqdataformats::SourceID> links,
87 std::vector<dfmessages::ComponentRequest> requests);
88
89 // ROI
91 struct roi_group
92 {
94 float prob;
96 std::string mode;
97 };
98 std::map<int, roi_group> m_roi_conf;
99 std::vector<const appmodel::ROIGroupConf*> m_roi_conf_data;
100 void parse_roi_conf(const std::vector<const appmodel::ROIGroupConf*>& data);
101 void print_roi_conf(std::map<int, roi_group> roi_conf);
102 std::vector<int> m_roi_conf_ids;
103 std::vector<float> m_roi_conf_probs;
104 std::vector<float> m_roi_conf_probs_c;
105 float get_random_num_float(float limit);
106 int get_random_num_int();
109
111 std::atomic<bool> m_tc_merging;
112
115
117
119
120 std::atomic<bool> m_running_flag{ false };
121
122 // New buffering
130 std::vector<PendingTD> m_pending_tds;
132 std::condition_variable m_cv;
133
136 void call_tc_decision(const PendingTD& pending_td);
137 bool check_overlap(const triggeralgs::TriggerCandidate& tc, const PendingTD& pending_td);
138 //bool check_overlap_td(const PendingTD& pending_td);
140 void clear_td_vectors();
141 std::vector<PendingTD> get_ready_tds(std::vector<PendingTD>& pending_tds);
144 std::atomic<bool> m_send_timed_out_tds;
146 int get_earliest_tc_index(const PendingTD& pending_td);
147
148 // Bitwords logic
150 std::vector<TDBitset> m_trigger_bitwords;
151 TDBitset get_TD_bitword(const PendingTD& ready_td) const;
153 bool check_trigger_bitwords(const TDBitset& td_bitword) const;
154 void set_trigger_bitwords(const std::vector<const appmodel::TriggerBitword*>& _bitwords);
155
156 // Readout map config
158 std::vector<const appmodel::TCReadoutMap*> m_readout_window_map_data;
159 std::map<TCType, std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>>
161 void parse_readout_map(const std::vector<const appmodel::TCReadoutMap*>& data);
162 void print_readout_map(std::map<TCType,
163 std::pair<triggeralgs::timestamp_t, triggeralgs::timestamp_t>> map);
164
165 // Create the next trigger decision
168
169 // Optional list of TC types to ignore
170 std::vector<unsigned int> m_ignored_tc_types;
172 bool check_trigger_type_ignore(unsigned int tc_type);
173
174
175 // output queue for TDs
176 std::shared_ptr<iomanager::SenderConcept<dfmessages::TriggerDecision>> m_td_sink;
177
178 // opmon
179 using metric_counter_type = uint64_t;
180 std::atomic<metric_counter_type> m_tds_created_count{ 0 }; // NOLINT(build/unsigned)
181 std::atomic<metric_counter_type> m_tds_sent_count{ 0 };
182 std::atomic<metric_counter_type> m_tds_dropped_count{ 0 };
183 std::atomic<metric_counter_type> m_tds_failed_bitword_count{ 0 };
184 std::atomic<metric_counter_type> m_tds_cleared_count{ 0 };
185
186 // opmon: per TC
187 std::atomic<metric_counter_type> m_tc_received_count{ 0 };
188 std::atomic<metric_counter_type> m_tds_created_tc_count{ 0 };
189 std::atomic<metric_counter_type> m_tds_sent_tc_count{ 0 };
190 std::atomic<metric_counter_type> m_tds_dropped_tc_count{ 0 };
191 std::atomic<metric_counter_type> m_tds_failed_bitword_tc_count{ 0 };
192 std::atomic<metric_counter_type> m_tds_cleared_tc_count{ 0 };
193 std::atomic<metric_counter_type> m_tc_ignored_count{ 0 };
194
195 // latency
196 std::atomic<bool> m_latency_monitoring{ false };
198 std::atomic<metric_counter_type> m_latency_in{ 0 };
199 std::atomic<metric_counter_type> m_latency_out{ 0 };
200
201 void print_opmon_stats();
202};
203
204} // namespace trigger
205} // namespace dunedaq
206
207#endif // TRIGGER_SRC_TRIGGER_TCPROCESSOR_HPP_
std::vector< const appmodel::TCReadoutMap * > m_readout_window_map_data
std::atomic< metric_counter_type > m_tc_ignored_count
std::atomic< metric_counter_type > m_tds_dropped_count
void stop(const nlohmann::json &args) override
Stop operation.
bool check_trigger_type_ignore(unsigned int tc_type)
void call_tc_decision(const PendingTD &pending_td)
TCProcessor(std::unique_ptr< datahandlinglibs::FrameErrorRegistry > &error_registry, bool post_processing_enabled)
dunedaq::trigger::Latency m_latency_instance
std::vector< unsigned int > m_ignored_tc_types
std::map< int, std::vector< daqdataformats::SourceID > > m_group_links
std::atomic< metric_counter_type > m_latency_in
void print_roi_conf(std::map< int, roi_group > roi_conf)
TDBitset get_TD_bitword(const PendingTD &ready_td) const
void parse_roi_conf(const std::vector< const appmodel::ROIGroupConf * > &data)
std::thread m_send_trigger_decisions_thread
dfmessages::trigger_number_t m_last_trigger_number
void scrap(const nlohmann::json &args) override
Unconfigure.
std::atomic< metric_counter_type > m_tds_failed_bitword_tc_count
void add_requests_to_decision(dfmessages::TriggerDecision &decision, std::vector< dfmessages::ComponentRequest > requests)
std::shared_ptr< iomanager::SenderConcept< dfmessages::TriggerDecision > > m_td_sink
dfmessages::TriggerDecision create_decision(const PendingTD &pending_td)
std::vector< dfmessages::ComponentRequest > create_all_decision_requests(std::vector< daqdataformats::SourceID > links, triggeralgs::timestamp_t start, triggeralgs::timestamp_t end)
std::atomic< metric_counter_type > m_tds_cleared_count
std::atomic< metric_counter_type > m_latency_out
void conf(const appmodel::DataHandlerModule *conf) override
Set the emulator mode, if active, timestamps of processed packets are overwritten with new ones.
std::atomic< bool > m_tc_merging
bool check_trigger_bitwords(const TDBitset &td_bitword) const
void roi_readout_make_requests(dfmessages::TriggerDecision &decision)
std::map< int, roi_group > m_roi_conf
std::atomic< metric_counter_type > m_tds_sent_tc_count
void print_readout_map(std::map< TCType, std::pair< triggeralgs::timestamp_t, triggeralgs::timestamp_t > > map)
void make_td(const TCWrapper *tc)
void generate_opmon_data() override
std::atomic< metric_counter_type > m_tds_cleared_tc_count
void set_trigger_bitwords(const std::vector< const appmodel::TriggerBitword * > &_bitwords)
bool check_td_readout_length(const PendingTD &)
std::atomic< metric_counter_type > m_tds_dropped_tc_count
std::atomic< metric_counter_type > m_tds_failed_bitword_count
dfmessages::run_number_t m_run_number
std::vector< int > m_roi_conf_ids
std::vector< PendingTD > get_ready_tds(std::vector< PendingTD > &pending_tds)
std::vector< float > m_roi_conf_probs_c
std::vector< PendingTD > m_pending_tds
std::atomic< metric_counter_type > m_tc_received_count
dfmessages::trigger_type_t m_trigger_type_shifted
std::atomic< metric_counter_type > m_tds_created_tc_count
void start(const nlohmann::json &args) override
Start operation.
bool m_ignore_tc_pileup
Ignore TCs that overlap with already made TD.
dfmessages::ComponentRequest create_request_for_link(daqdataformats::SourceID link, triggeralgs::timestamp_t start, triggeralgs::timestamp_t end)
std::vector< const appmodel::ROIGroupConf * > m_roi_conf_data
std::atomic< bool > m_running_flag
void parse_readout_map(const std::vector< const appmodel::TCReadoutMap * > &data)
std::condition_variable m_cv
void add_tc(const triggeralgs::TriggerCandidate tc)
std::atomic< metric_counter_type > m_tds_sent_count
std::vector< float > m_roi_conf_probs
std::atomic< bool > m_latency_monitoring
bool check_overlap(const triggeralgs::TriggerCandidate &tc, const PendingTD &pending_td)
void parse_group_links(const nlohmann::json &data)
std::atomic< metric_counter_type > m_tds_created_count
float get_random_num_float(float limit)
std::vector< TDBitset > m_trigger_bitwords
void add_tc_ignored(const triggeralgs::TriggerCandidate tc)
std::atomic< bool > m_send_timed_out_tds
std::vector< daqdataformats::SourceID > m_mandatory_links
int get_earliest_tc_index(const PendingTD &pending_td)
std::map< TCType, std::pair< triggeralgs::timestamp_t, triggeralgs::timestamp_t > > m_readout_window_map
daqdataformats::run_number_t run_number_t
Copy daqdataformats::run_number_t.
Definition Types.hpp:34
daqdataformats::trigger_type_t trigger_type_t
Copy daqdataformats::trigger_type_t.
Definition Types.hpp:45
daqdataformats::trigger_number_t trigger_number_t
Copy daqdataformats::trigger_number_t.
Definition Types.hpp:35
Including Qt Headers.
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
A request sent to a Component, including the SourceID of the component and the window offset and widt...
SourceID is a generalized representation of the source of a piece of data in the DAQ....
Definition SourceID.hpp:32
A message containing information about a Trigger from Data Selection (or a TriggerDecisionEmulator)
std::vector< triggeralgs::TriggerCandidate > contributing_tcs