DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
TAWindow.cpp
Go to the documentation of this file.
2
3#include <vector>
4
5#include <chrono>
6#include <map>
7#include <memory>
8#include <string>
9#include <unordered_set>
10#include <utility>
11
12namespace triggeralgs {
13
14//---
15void
17{
18
19 adc_integral += input_ta.adc_integral;
20 for (TriggerPrimitive tp : input_ta.inputs) {
22 }
23 // Perform binary search based on time_start.
24 uint16_t insert_at = 0;
25 for (auto ta : inputs) {
26 if (input_ta.time_start < ta.time_start)
27 break;
28 insert_at++;
29 }
30 inputs.insert(inputs.begin() + insert_at, input_ta);
31}
32
33//---
34void
36{
37 inputs.clear();
38 channel_states.clear();
39 time_start = 0;
40 adc_integral = 0;
41};
42
43//---
44void
45TAWindow::move(TriggerActivity const& input_ta, timestamp_t const& window_length)
46{
47 uint32_t n_tas_to_erase = 0;
48 for (auto ta : inputs) {
49 if (!(input_ta.time_start - ta.time_start < window_length)) {
50 n_tas_to_erase++;
51 adc_integral -= ta.adc_integral;
52 for (TriggerPrimitive tp : ta.inputs) {
54 // If a TA being removed from the window results in a channel no longer having
55 // any hits, remove from the states map so map.size() can be used for number
56 // channel hits.
57 if (channel_states[tp.channel] == 0)
58 channel_states.erase(tp.channel);
59 }
60 } else
61 break;
62 }
63 // Erase the TAs from the window.
64 inputs.erase(inputs.begin(), inputs.begin() + n_tas_to_erase);
65 // Make the window start time the start time of what is now the
66 // first TA.
67 if (inputs.size() != 0) {
68 time_start = inputs.front().time_start;
69 add(input_ta);
70 } else {
71 reset(input_ta);
72 }
73 // add(input_ta);
74 // time_start = inputs.front().time_start;
75}
76
77//---
78void
80{
81 // Empty the channel and TA lists.
82 channel_states.clear();
83 inputs.clear();
84 // Set the start time of the window to be the start time of the
85 // input_ta.
86 time_start = input_ta.time_start;
87 // Start the total ADC integral.
88 adc_integral = input_ta.adc_integral;
89 // Start hit count for the hit channels.
90 for (TriggerPrimitive tp : input_ta.inputs) {
92 }
93 // Add the input TA to the TA list.
94 inputs.push_back(input_ta);
95}
96
97std::ostream&
98operator<<(std::ostream& os, const TAWindow& window)
99{
100 if (window.is_empty())
101 os << "Window is empty!\n";
102 else {
103 os << "Window start: " << window.time_start << ", end: " << window.inputs.back().time_start;
104 os << ". Total of: " << window.adc_integral << " ADC counts with " << window.inputs.size() << " TPs.\n";
105 os << window.channel_states.size() << " independent channels have hits.\n";
106 }
107 return os;
108};
109
110//---
111//---
112//---
113//---
114//---
115//---
116
117} // namespace triggeralgs
timestamp_t time_start
Definition TAWindow.hpp:52
void clear()
Clear all inputs.
Definition TAWindow.cpp:35
void add(const TriggerActivity &input_ta)
Add the input TA's contribution to the total ADC, increase the hit count of all of the channels which...
Definition TAWindow.cpp:16
std::vector< TriggerActivity > inputs
Definition TAWindow.hpp:55
std::unordered_map< channel_t, uint16_t > channel_states
Definition TAWindow.hpp:54
bool is_empty() const
Definition TAWindow.hpp:22
void reset(TriggerActivity const &input_ta)
Reset window content on the input.
Definition TAWindow.cpp:79
void move(TriggerActivity const &input_ta, timestamp_t const &window_length)
Find all of the TAs in the window that need to be removed if the input_ta is to be added and the size...
Definition TAWindow.cpp:45
dunedaq::trgdataformats::timestamp_t timestamp_t
Definition Types.hpp:16
std::ostream & operator<<(std::ostream &os, const TAWindow &window)
Definition TAWindow.cpp:98
A single energy deposition on a TPC or PDS channel.
std::vector< TriggerPrimitive > inputs