Line data Source code
1 : /**
2 : * @file TCMakerDBSCANAlgorithm.cpp
3 : *
4 : * This is part of the DUNE DAQ Application Framework, copyright 2021.
5 : * Licensing/copyright details are in the COPYING file that you should have
6 : * received with this code.
7 : */
8 :
9 : #include "triggeralgs/dbscan/TCMakerDBSCANAlgorithm.hpp"
10 :
11 : #include "TRACE/trace.h"
12 : #define TRACE_NAME "TCMakerDBSCANAlgorithm"
13 :
14 : namespace triggeralgs {
15 :
16 : void
17 0 : TCMakerDBSCANAlgorithm::set_new_tc(const TriggerActivity& input_ta)
18 : {
19 0 : m_current_tc = TriggerCandidate();
20 0 : m_current_tc.inputs.push_back(input_ta);
21 0 : m_current_tp_count = input_ta.inputs.size();
22 0 : return;
23 : }
24 :
25 : void
26 0 : TCMakerDBSCANAlgorithm::configure(const nlohmann::json& config)
27 : {
28 0 : TriggerCandidateMaker::configure(config);
29 :
30 0 : if (config.contains("max_tp_count"))
31 0 : m_max_tp_count = config["max_tp_count"];
32 0 : return;
33 : }
34 :
35 : void
36 0 : TCMakerDBSCANAlgorithm::set_tc_attributes()
37 : {
38 0 : auto& first_ta = m_current_tc.inputs.front();
39 0 : auto& last_ta = m_current_tc.inputs.back();
40 :
41 0 : m_current_tc.time_start = first_ta.time_start;
42 0 : m_current_tc.time_end = last_ta.time_end;
43 0 : m_current_tc.time_candidate = last_ta.time_start; // Since this is the TA that closed the TC.
44 :
45 0 : m_current_tc.detid = first_ta.detid;
46 0 : m_current_tc.algorithm = TriggerCandidate::Algorithm::kDBSCAN;
47 0 : m_current_tc.type = m_tc_type_out;
48 0 : return;
49 : }
50 :
51 : void
52 0 : TCMakerDBSCANAlgorithm::process(const TriggerActivity& input_ta, std::vector<TriggerCandidate>& output_tcs)
53 : {
54 : // Start a new TC if not already going.
55 0 : if (m_current_tc.inputs.empty()) {
56 0 : set_new_tc(input_ta);
57 0 : return;
58 : }
59 :
60 : // Check to close the TC based on TP contents.
61 0 : if (input_ta.inputs.size() + m_current_tp_count > m_max_tp_count) {
62 0 : set_tc_attributes();
63 0 : output_tcs.push_back(m_current_tc);
64 0 : set_new_tc(input_ta);
65 0 : return;
66 : }
67 :
68 : // Append the new TA and increase the TP count.
69 0 : m_current_tc.inputs.push_back(input_ta);
70 0 : m_current_tp_count += input_ta.inputs.size();
71 0 : return;
72 : }
73 :
74 : // Register algo in TC Factory.
75 12 : REGISTER_TRIGGER_CANDIDATE_MAKER(TRACE_NAME, TCMakerDBSCANAlgorithm)
76 :
77 : } // namespace triggeralgs
|