Line data Source code
1 : /**
2 : * @file TAMakerBundleNAlgorithm.cpp
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2020.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "triggeralgs/BundleN/TAMakerBundleNAlgorithm.hpp"
10 :
11 : #include "TRACE/trace.h"
12 : #define TRACE_NAME "TAMakerBundleNAlgorithm"
13 :
14 : namespace triggeralgs {
15 :
16 : using Logging::TLVL_IMPORTANT;
17 : using Logging::TLVL_DEBUG_HIGH;
18 :
19 0 : void TAMakerBundleNAlgorithm::set_ta_attributes() {
20 : // Using the first TA as reference.
21 0 : TriggerPrimitive first_tp = m_current_ta.inputs.front();
22 0 : TriggerPrimitive last_tp = m_current_ta.inputs.back();
23 :
24 0 : m_current_ta.channel_start = first_tp.channel;
25 0 : m_current_ta.channel_end = last_tp.channel;
26 :
27 0 : m_current_ta.time_start = first_tp.time_start;
28 0 : m_current_ta.time_end = last_tp.time_start;
29 :
30 0 : m_current_ta.detid = first_tp.detid;
31 :
32 0 : m_current_ta.algorithm = TriggerActivity::Algorithm::kBundle;
33 0 : m_current_ta.type = TriggerActivity::Type::kTPC;
34 :
35 0 : m_current_ta.adc_peak = 0;
36 0 : for (const TriggerPrimitive& tp : m_current_ta.inputs) {
37 0 : m_current_ta.adc_integral += tp.adc_integral;
38 0 : if (tp.adc_peak <= m_current_ta.adc_peak) continue;
39 0 : m_current_ta.adc_peak = tp.adc_peak;
40 0 : m_current_ta.channel_peak = tp.channel;
41 0 : m_current_ta.time_peak = tp.samples_to_peak * 32 + tp.time_start; // FIXME: Replace STP to `time_peak` conversion.
42 : }
43 0 : m_current_ta.time_activity = m_current_ta.time_peak;
44 0 : return;
45 : }
46 :
47 0 : bool TAMakerBundleNAlgorithm::bundle_condition() {
48 0 : return m_current_ta.inputs.size() == m_bundle_size;
49 : }
50 :
51 : void
52 0 : TAMakerBundleNAlgorithm::process(const TriggerPrimitive& input_tp, std::vector<TriggerActivity>& output_tas)
53 : {
54 : // Expect that TPs are inherently time ordered.
55 0 : m_current_ta.inputs.push_back(input_tp);
56 :
57 0 : if (bundle_condition()) {
58 0 : TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TA:BN] Emitting BundleN TA with " << m_current_ta.inputs.size() << " TPs.";
59 0 : set_ta_attributes();
60 0 : output_tas.push_back(m_current_ta);
61 :
62 : // Reset the current.
63 0 : m_current_ta = TriggerActivity();
64 : }
65 :
66 : // Should never reach this step. In this case, send it out.
67 0 : if (m_current_ta.inputs.size() > m_bundle_size) {
68 0 : TLOG_DEBUG(TLVL_IMPORTANT) << "[TA:BN] Emitting large BundleN TriggerActivity with " << m_current_ta.inputs.size() << " TPs.";
69 0 : set_ta_attributes();
70 0 : output_tas.push_back(m_current_ta);
71 :
72 : // Reset the current.
73 0 : m_current_ta = TriggerActivity();
74 : }
75 0 : }
76 :
77 : void
78 0 : TAMakerBundleNAlgorithm::configure(const nlohmann::json& config)
79 : {
80 0 : if (config.is_object() && config.contains("bundle_size")) {
81 0 : m_bundle_size = config["bundle_size"];
82 : }
83 0 : }
84 :
85 12 : REGISTER_TRIGGER_ACTIVITY_MAKER(TRACE_NAME, TAMakerBundleNAlgorithm)
86 : } // namespace triggeralgs
87 :
|