DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TAProcessor.cpp
Go to the documentation of this file.
1
8#include "trigger/TAProcessor.hpp" // NOLINT(build/include)
9
10//#include "appfwk/DAQModuleHelper.hpp"
11#include "iomanager/Sender.hpp"
12#include "logging/Logging.hpp"
13
18
19//#include "detchannelmaps/TPCChannelMap.hpp"
20
21#include "trigger/TAWrapper.hpp"
23
26
29
32
33// THIS SHOULDN'T BE HERE!!!!! But it is necessary.....
35
36namespace dunedaq {
37namespace trigger {
38
39TAProcessor::TAProcessor(std::unique_ptr<datahandlinglibs::FrameErrorRegistry>& error_registry, bool post_processing_enabled)
40 : datahandlinglibs::TaskRawDataProcessorModel<TAWrapper>(error_registry, post_processing_enabled)
41{
42}
43
46
47void
48TAProcessor::start(const nlohmann::json& args)
49{
50 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Entering start() method";
51
52 // Reset stats
53 m_ta_received_count.store(0);
54 m_tc_made_count.store(0);
55 m_tc_sent_count.store(0);
57
58 m_running_flag.store(true);
59
60 inherited::start(args);
61
62 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Exiting start() method";
63}
64
65void
66TAProcessor::stop(const nlohmann::json& args)
67{
68 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Entering stop() method";
69
70 inherited::stop(args);
71 m_running_flag.store(false);
73
74 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Exiting stop() method";
75}
76
77void
79{
80 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Entering conf() method";
81
82 for (auto output : conf->get_outputs()) {
83 try {
84 if (output->get_data_type() == "TriggerCandidate") {
86 }
87 } catch (const ers::Issue& excpt) {
88 ers::error(datahandlinglibs::ResourceQueueError(ERS_HERE, "tc", "DefaultRequestHandlerModel", excpt));
89 }
90 }
91
92 m_sourceid.id = conf->get_source_id();
94 std::vector<const appmodel::TCAlgorithm*> tc_algorithms;
95 auto dp = conf->get_module_configuration()->get_data_processor();
96 auto proc_conf = dp->cast<appmodel::TADataProcessor>();
97 if (proc_conf != nullptr && m_post_processing_enabled ) {
98 tc_algorithms = proc_conf->get_algorithms();
99 }
100
101 for (auto algo : tc_algorithms) {
102 TLOG() << "Selected TC algorithm: " << algo->UID();
103 std::shared_ptr<triggeralgs::TriggerCandidateMaker> maker = make_tc_maker(algo->class_name());
104 nlohmann::json algo_json = algo->to_json(true);
105 maker->configure(algo_json[algo->UID()]);
106 inherited::add_postprocess_task(std::bind(&TAProcessor::find_tc, this, std::placeholders::_1, maker));
107 m_tcms.push_back(maker);
108 }
109 m_latency_monitoring.store( dp->get_latency_monitoring() );
111
112 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Exiting conf() method";
113}
114
115void
116TAProcessor::scrap(const nlohmann::json& args)
117{
118 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Entering scrap() method";
119 m_tcms.clear();
120 m_tc_sink.reset();
121 inherited::scrap(args);
122 TLOG_DEBUG(TLVL_ENTER_EXIT_METHODS) << "TAProcessor: Exiting scrap() method";
123}
124
125void
127{
129
130 info.set_ta_received_count( m_ta_received_count.load() );
131 info.set_tc_made_count( m_tc_made_count.load() );
132 info.set_tc_sent_count( m_tc_sent_count.load() );
133 info.set_tc_failed_sent_count( m_tc_failed_sent_count.load() );
134
135 this->publish(std::move(info));
136
137 if ( m_latency_monitoring.load() && m_running_flag.load() ) {
138 opmon::TriggerLatency lat_info;
139
142
143 this->publish(std::move(lat_info));
144 }
145}
146
150void
151TAProcessor::find_tc(const TAWrapper* ta, std::shared_ptr<triggeralgs::TriggerCandidateMaker> tca)
152{
153 //time_activity gave 0 :/
156 std::vector<triggeralgs::TriggerCandidate> tcs;
157 tca->operator()(ta->activity, tcs);
158 for (auto tc : tcs) {
160 if (m_latency_monitoring.load()) m_latency_instance.update_latency_out( tc.time_candidate );
161 if(!m_tc_sink->try_send(std::move(tc), iomanager::Sender::s_no_block)) {
162 ers::warning(TCDropped(ERS_HERE, tc.time_start, m_sourceid.id));
164 } else {
166 }
167 }
169 return;
170}
171
172void
174{
175 TLOG() << "TAProcessor opmon counters summary:";
176 TLOG() << "------------------------------";
177 TLOG() << "TAs received: \t\t" << m_ta_received_count;
178 TLOG() << "TCs made: \t\t" << m_tc_made_count;
179 TLOG() << "TCs sent: \t\t" << m_tc_sent_count;
180 TLOG() << "TCs failed to send: \t" << m_tc_failed_sent_count;
181 TLOG();
182}
183
184} // namespace fdreadoutlibs
185} // namespace dunedaq
#define ERS_HERE
#define DUNE_DAQ_TYPESTRING(Type, typestring)
void conf(const appmodel::DataHandlerModule *conf) override
static constexpr timeout_t s_no_block
Definition Sender.hpp:26
void publish(google::protobuf::Message &&, CustomOrigin &&co={}, OpMonLevel l=to_level(EntryOpMonLevel::kDefault)) const noexcept
void update_latency_out(uint64_t latency)
Definition Latency.hpp:43
latency get_latency_in() const
Definition Latency.hpp:48
latency get_latency_out() const
Definition Latency.hpp:53
void update_latency_in(uint64_t latency)
Definition Latency.hpp:38
std::atomic< metric_counter_type > m_ta_received_count
std::atomic< bool > m_running_flag
void generate_opmon_data() override
dunedaq::trigger::Latency m_latency_instance
std::atomic< metric_counter_type > m_tc_failed_sent_count
void find_tc(const TAWrapper *ta, std::shared_ptr< triggeralgs::TriggerCandidateMaker > tcm)
std::vector< std::shared_ptr< triggeralgs::TriggerCandidateMaker > > m_tcms
void start(const nlohmann::json &args) override
Start operation.
daqdataformats::SourceID m_sourceid
std::atomic< metric_counter_type > m_tc_made_count
std::atomic< metric_counter_type > m_tc_sent_count
void scrap(const nlohmann::json &args) override
Unconfigure.
std::atomic< bool > m_latency_monitoring
std::shared_ptr< iomanager::SenderConcept< triggeralgs::TriggerCandidate > > m_tc_sink
void stop(const nlohmann::json &args) override
Stop operation.
void conf(const appmodel::DataHandlerModule *conf) override
Set the emulator mode, if active, timestamps of processed packets are overwritten with new ones.
Base class for any user define issue.
Definition Issue.hpp:69
#define TLVL_ENTER_EXIT_METHODS
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112
#define TLOG(...)
Definition macro.hpp:22
std::unique_ptr< triggeralgs::TriggerCandidateMaker > make_tc_maker(std::string const &plugin_name)
Load a TriggerCandidateMaker plugin and return a unique_ptr to the contained class.
Including Qt Headers.
static std::shared_ptr< iomanager::SenderConcept< Datatype > > get_iom_sender(iomanager::ConnectionId const &id)
void warning(const Issue &issue)
Definition ers.hpp:115
void error(const Issue &issue)
Definition ers.hpp:81
Subsystem subsystem
The general subsystem of the source of the data.
Definition SourceID.hpp:69
ID_t id
Unique identifier of the source of the data.
Definition SourceID.hpp:74
static const constexpr daqdataformats::SourceID::Subsystem subsystem
Definition TAWrapper.hpp:81
triggeralgs::TriggerActivity activity
Definition TAWrapper.hpp:25