Line data Source code
1 : /**
2 : * @file TCMakerBundleNAlgorithm.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/TCMakerBundleNAlgorithm.hpp"
10 :
11 : #include "TRACE/trace.h"
12 : #define TRACE_NAME "TCMakerBundleNAlgorithm"
13 :
14 : namespace triggeralgs {
15 :
16 : using Logging::TLVL_IMPORTANT;
17 : using Logging::TLVL_DEBUG_HIGH;
18 :
19 0 : void TCMakerBundleNAlgorithm::set_tc_attributes() {
20 : // Using the first TA as reference.
21 0 : dunedaq::trgdataformats::TriggerActivityData front_ta = m_current_tc.inputs.front();
22 :
23 0 : m_current_tc.time_start = front_ta.time_start;
24 0 : m_current_tc.time_end = m_current_tc.inputs.back().time_end;
25 0 : m_current_tc.time_candidate = front_ta.time_start; // TODO: Conforming. Do we change this?
26 0 : m_current_tc.detid = front_ta.detid;
27 0 : m_current_tc.type = m_tc_type_out;
28 0 : m_current_tc.algorithm = TriggerCandidate::Algorithm::kBundle;
29 0 : return;
30 : }
31 :
32 0 : bool TCMakerBundleNAlgorithm::bundle_condition() {
33 0 : return m_current_tc.inputs.size() == m_bundle_size;
34 : }
35 :
36 : void
37 0 : TCMakerBundleNAlgorithm::process(const TriggerActivity& input_ta, std::vector<TriggerCandidate>& output_tcs)
38 : {
39 : // Expect that TAs are inherently time ordered.
40 0 : m_current_tc.inputs.push_back(input_ta);
41 :
42 0 : if (bundle_condition()) {
43 0 : TLOG_DEBUG(TLVL_DEBUG_HIGH) << "[TC:BN] Emitting BundleN TriggerCandidate with " << m_current_tc.inputs.size() << " TAs.";
44 0 : set_tc_attributes();
45 0 : output_tcs.push_back(m_current_tc);
46 :
47 : // Reset the current.
48 0 : m_current_tc = TriggerCandidate();
49 : }
50 :
51 : // Should never reach this step. In this case, send it out.
52 0 : if (m_current_tc.inputs.size() > m_bundle_size) {
53 0 : TLOG_DEBUG(TLVL_IMPORTANT) << "[TC:BN] Emitting large BundleN TriggerCandidate with " << m_current_tc.inputs.size() << " TAs.";
54 0 : set_tc_attributes();
55 0 : output_tcs.push_back(m_current_tc);
56 :
57 : // Reset the current.
58 0 : m_current_tc = TriggerCandidate();
59 : }
60 0 : }
61 :
62 : void
63 0 : TCMakerBundleNAlgorithm::configure(const nlohmann::json& config)
64 : {
65 0 : TriggerCandidateMaker::configure(config);
66 0 : if (config.is_object() && config.contains("bundle_size")) {
67 0 : m_bundle_size = config["bundle_size"];
68 : }
69 0 : }
70 :
71 12 : REGISTER_TRIGGER_CANDIDATE_MAKER(TRACE_NAME, TCMakerBundleNAlgorithm)
72 : } // namespace triggeralgs
73 :
|