DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TriggerCandidateMaker.hpp
Go to the documentation of this file.
1
9#ifndef TRIGGERALGS_INCLUDE_TRIGGERALGS_TRIGGERCANDIDATEMAKER_HPP_
10#define TRIGGERALGS_INCLUDE_TRIGGERALGS_TRIGGERCANDIDATEMAKER_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 ~TriggerCandidateMaker() = default;
32 void operator()(const TriggerActivity& input_ta, std::vector<TriggerCandidate>& output_tc)
33 {
34 // Apply TP filtering
35 if (!preprocess(input_ta)) {
36 return;
37 }
38
39 // Process TP, to implement per alg triggeralgs
40 process(input_ta, output_tc);
41
42 // Postprocess TA, e.g. prescaling
43 postprocess(output_tc);
44 }
45
52 virtual void process(const TriggerActivity& input_ta, std::vector<TriggerCandidate>& output_tc) = 0;
53
63 virtual bool preprocess(const TriggerActivity&)
64 {
65 return true;
66 }
67
78 virtual void postprocess(std::vector<TriggerCandidate>& output_tc)
79 {
80 // Don't post-process TCs if there's no TCs made.
81 if (output_tc.size() == 0) {
82 return;
83 }
84
85 // Apply prescale by erasing TCs
86 if (m_prescale > 1) {
87 for (std::vector<TriggerCandidate>::iterator iter = output_tc.begin(); iter != output_tc.end();) {
88 m_tc_count++;
89
90 if (m_tc_count % m_prescale != 0) {
91 iter = output_tc.erase(iter);
92 continue;
93 }
94
95 TLOG_DEBUG(TLVL_DEBUG_10) << "Emitting prescaled TriggerCandidate " << (m_tc_count-1);
96 ++iter;
97 }
98 }
99 }
100 virtual void flush(timestamp_t /* until */, std::vector<TriggerCandidate>& /* output_tc */) {}
101 virtual void configure(const nlohmann::json& config)
102 {
103 // Don't do anyting if the config does not exist
104 if (!config.is_object()) {
105 return;
106 }
107
108 if (config.contains("prescale")) {
109 m_prescale = config["prescale"];
110 }
111
112 if (config.contains("tc_type_name")) {
115 }
116
118 // 27-Feb-2025, KAB: moified the following statement to check whether the configuration
119 // contains the tc_type_name parameter before trying to add it do the exception message.
120 throw(InvalidConfiguration(ERS_HERE, "Provided an unknown output TC type: " +
121 (config.contains("tc_type_name") ?
122 std::string(config["tc_type_name"]) : "null")));
123 }
124
125 TLOG() << "[TCM]: prescale : " << m_prescale;
126 TLOG() << "[TCM]: TC type out: " << config["tc_type_name"];
127 }
128
129 std::atomic<uint64_t> m_data_vs_system_time = 0;
130 std::atomic<uint64_t> m_initial_offset = 0;
131
133 uint64_t m_prescale = 1;
135 uint64_t m_tc_count = 0;
136
139
140};
141
142} // namespace triggeralgs
143
144#endif // TRIGGERALGS_INCLUDE_TRIGGERALGS_TRIGGERCANDIDATEMAKER_HPP_
#define ERS_HERE
uint64_t m_tc_count
TC made count for prescaling.
TriggerCandidate::Type m_tc_type_out
Configurable TC type output.
virtual void configure(const nlohmann::json &config)
virtual ~TriggerCandidateMaker()=default
virtual void process(const TriggerActivity &input_ta, std::vector< TriggerCandidate > &output_tc)=0
TA processing function that creates & fills TCs.
void operator()(const TriggerActivity &input_ta, std::vector< TriggerCandidate > &output_tc)
virtual void flush(timestamp_t, std::vector< TriggerCandidate > &)
uint64_t m_prescale
Configurable prescale factor.
virtual void postprocess(std::vector< TriggerCandidate > &output_tc)
Post-processing/filtering of the TCs, e.g. prescale.
virtual bool preprocess(const TriggerActivity &)
TA pre-processing/filtering.
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
int string_to_trigger_candidate_type(const std::string &name)
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
Factory couldn t std::string alg_name InvalidConfiguration
Definition Issues.hpp:33