DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TriggerActivityMaker.hpp
Go to the documentation of this file.
1
9#ifndef TRIGGERALGS_INCLUDE_TRIGGERALGS_TRIGGERACTIVITYMAKER_HPP_
10#define TRIGGERALGS_INCLUDE_TRIGGERALGS_TRIGGERACTIVITYMAKER_HPP_
11
16#include "triggeralgs/Types.hpp"
17
18#include <atomic>
19#include <chrono>
20#include <nlohmann/json.hpp>
21#include <vector>
22
23// TRACE_NAME to be defined in the derived TAMs
24#include "TRACE/trace.h"
25
26namespace triggeralgs {
27
29{
30public:
31 virtual ~TriggerActivityMaker() = default;
32 void operator()(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta)
33 {
34 // Apply TP filtering
35 if (!preprocess(input_tp)) {
36 return;
37 }
38
39 // Process TP, to implement per alg triggeralgs
40 process(input_tp, output_ta);
41
42 // Postprocess TA, e.g. prescaling
43 postprocess(output_ta);
44 }
45
52 virtual void process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_ta) = 0;
53
66 virtual bool preprocess(const TriggerPrimitive& input_tp)
67 {
69 return false;
70 }
71
72 return true;
73 }
74
85 virtual void postprocess(std::vector<TriggerActivity>& output_ta)
86 {
87 // Don't post-process TAs if there's no TAs made.
88 if (output_ta.size() == 0) {
89 return;
90 }
91
92 // Apply prescale by erasing TAs
93 if (m_prescale > 1) {
94 for (std::vector<TriggerActivity>::iterator iter = output_ta.begin(); iter != output_ta.end();) {
95 m_ta_count++;
96
97 if (m_ta_count % m_prescale != 0) {
98 iter = output_ta.erase(iter);
99 continue;
100 }
101
102 TLOG_DEBUG(TLVL_DEBUG_MEDIUM) << "Emitting prescaled TriggerActivity " << (m_ta_count-1)
103 << " with time start/end/activity: " << iter->time_start
104 << " " << iter->time_end << " " << iter->time_activity;
105 ++iter;
106 }
107 }
108 }
109
110 virtual void flush(timestamp_t /* until */, std::vector<TriggerActivity>&) {}
111 virtual void configure(const nlohmann::json& config)
112 {
113 // Don't do anyting if the config does not exist
114 if (!config.is_object()) {
115 return;
116 }
117
118 if (config.contains("prescale"))
119 m_prescale = config["prescale"];
120 if (config.contains("max_samples_over_threshold"))
121 m_max_samples_over_threshold = config["max_samples_over_threshold"];
122
123 TLOG() << "[TAM]: max sot : " << m_max_samples_over_threshold;
124 TLOG() << "[TAM]: prescale : " << m_prescale;
125 }
126
127 std::atomic<uint64_t> m_data_vs_system_time = 0;
128 std::atomic<uint64_t> m_initial_offset = 0;
129
131 uint64_t m_prescale = 1;
133 uint64_t m_ta_count = 0;
134
136 uint32_t m_max_samples_over_threshold = std::numeric_limits<uint32_t>::max();
137};
138
139} // namespace triggeralgs
140
141#endif // TRIGGERALGS_INCLUDE_TRIGGERALGS_TRIGGERACTIVITYMAKER_HPP_
virtual void flush(timestamp_t, std::vector< TriggerActivity > &)
std::atomic< uint64_t > m_data_vs_system_time
virtual void configure(const nlohmann::json &config)
uint64_t m_ta_count
TA made count for prescaling.
virtual ~TriggerActivityMaker()=default
virtual void process(const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)=0
TP processing function that creates & fills TAs.
virtual void postprocess(std::vector< TriggerActivity > &output_ta)
Post-processing/filtering of the TAs, e.g. prescale.
uint32_t m_max_samples_over_threshold
Time-over-threshold TP filtering.
virtual bool preprocess(const TriggerPrimitive &input_tp)
TP pre-processing/filtering.
uint64_t m_prescale
Configurable prescale factor.
void operator()(const TriggerPrimitive &input_tp, std::vector< TriggerActivity > &output_ta)
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
A single energy deposition on a TPC or PDS channel.