-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathWindowFiller.h
More file actions
180 lines (138 loc) · 6.04 KB
/
WindowFiller.h
File metadata and controls
180 lines (138 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef ALICEO2_TOF_WINDOWFILLER_H_
#define ALICEO2_TOF_WINDOWFILLER_H_
#include "TOFBase/Geo.h"
#include "TOFBase/Digit.h"
#include "TOFBase/Strip.h"
#include "CommonDataFormat/InteractionRecord.h"
#include "DataFormatsTOF/Diagnostic.h"
#include "TOFBase/Utils.h"
namespace o2
{
namespace tof
{
class WindowFiller
{
public:
struct PatternData {
uint32_t pattern;
int icrate;
unsigned long row;
PatternData(uint32_t patt = 0, int icr = 0, unsigned long rw = 0) : pattern(patt), icrate(icr), row(rw) {}
};
struct CrateHeaderData {
int32_t bc[Geo::kNCrate] = {-1};
uint32_t eventCounter[Geo::kNCrate] = {0};
CrateHeaderData() { memset(bc, -1, Geo::kNCrate * 4); }
};
WindowFiller() { initObj(); };
~WindowFiller() = default;
void initObj();
void reset();
uint64_t getCurrentReadoutWindow() const { return mReadoutWindowCurrent; }
void setCurrentReadoutWindow(uint64_t value) { mReadoutWindowCurrent = value; }
void setEventTime(InteractionTimeRecord value)
{
mEventTime = value;
}
std::vector<Digit>* getDigitPerTimeFrame() { return &mDigitsPerTimeFrame; }
std::vector<ReadoutWindowData>* getReadoutWindowData() { return &mReadoutWindowData; }
std::vector<ReadoutWindowData>* getReadoutWindowDataFiltered() { return &mReadoutWindowDataFiltered; }
DigitHeader& getDigitHeader() { return mDigitHeader; }
template <typename VROF, typename VPAT>
void setReadoutWindowData(const VROF& row, const VPAT& pattern)
{
// copy rowdata info needed to call fillDiagonsticFrequency when reading frm file (digits/ctf). Not needed when digitizing or decoding
mPatterns.clear();
mReadoutWindowData.clear();
for (const auto crow : row) {
mReadoutWindowData.push_back(crow);
}
for (const auto dia : pattern) {
mPatterns.push_back(dia);
}
}
void setNOrbitInTF(uint32_t norb) { o2::tof::Utils::setNOrbitInTF(norb); }
void fillOutputContainer(std::vector<Digit>& digits);
void flushOutputContainer(std::vector<Digit>& digits); // flush all residual buffered data
void setContinuous(bool value = true) { mContinuous = value; }
bool isContinuous() const { return mContinuous; }
void fillDiagnosticFrequency();
void resizeVectorFutureDigit(int size) { mFutureDigits.resize(size); }
void setFirstIR(const o2::InteractionRecord& ir) { mFirstIR = ir; }
void maskNoiseRate(int val) { mMaskNoiseRate = val; }
void clearCounts()
{
memset(mChannelCounts, 0, o2::tof::Geo::NCHANNELS * sizeof(mChannelCounts[0]));
}
std::vector<uint8_t>& getPatterns() { return mPatterns; }
void addPattern(const uint32_t val, int icrate, int orbit, int bc) { mCratePatterns.emplace_back(val, icrate, ((unsigned long)orbit) * 3 + (bc + 100) / Geo::BC_IN_WINDOW); }
void addCrateHeaderData(unsigned long orbit, int crate, int32_t bc, uint32_t eventCounter);
Diagnostic& getDiagnosticFrequency() { return mDiagnosticFrequency; }
void addCount(int channel) { mChannelCounts[channel]++; }
protected:
// info TOF timewindow
uint64_t mReadoutWindowCurrent = 0; // keeps track of current readout window
InteractionRecord mFirstIR{0, 0}; // reference IR (1st IR of the timeframe)
InteractionTimeRecord mEventTime;
bool mContinuous = true;
bool mFutureToBeSorted = false;
// only needed from Decoder
int mMaskNoiseRate = -11;
int mChannelCounts[o2::tof::Geo::NCHANNELS]; // count of channel hits in the current TF (if MaskNoiseRate enabled)
// digit info
//std::vector<Digit>* mDigits;
static const int MAXWINDOWS = 2; // how many readout windows we can buffer
std::vector<Digit> mDigitsPerTimeFrame;
std::vector<ReadoutWindowData> mReadoutWindowData;
std::vector<ReadoutWindowData> mReadoutWindowDataFiltered;
int mIcurrentReadoutWindow = 0;
// array of strips to store the digits per strip (one for the current readout window, one for the next one)
std::vector<Strip> mStrips[MAXWINDOWS];
std::vector<Strip>* mStripsCurrent = &(mStrips[0]);
std::vector<Strip>* mStripsNext[MAXWINDOWS - 1];
// arrays with digit and MCLabels out of the current readout windows (stored to fill future readout window)
std::vector<Digit> mFutureDigits;
std::vector<uint8_t> mPatterns;
std::vector<uint64_t> mErrors;
Diagnostic mDiagnosticFrequency;
std::vector<PatternData> mCratePatterns;
std::vector<CrateHeaderData> mCrateHeaderData;
DigitHeader mDigitHeader;
void fillDigitsInStrip(std::vector<Strip>* strips, int channel, int tdc, int tot, uint64_t nbc, UInt_t istrip, uint32_t triggerorbit = 0, uint16_t triggerbunch = 0);
// void fillDigitsInStrip(std::vector<Strip>* strips, o2::dataformats::MCTruthContainer<o2::tof::MCLabel>* mcTruthContainer, int channel, int tdc, int tot, int nbc, UInt_t istrip, Int_t trackID, Int_t eventID, Int_t sourceID);
void checkIfReuseFutureDigits();
void checkIfReuseFutureDigitsRO();
void insertDigitInFuture(Int_t channel, Int_t tdc, Int_t tot, uint64_t bc, Int_t label = 0, uint32_t triggerorbit = 0, uint16_t triggerbunch = 0)
{
mFutureDigits.emplace_back(channel, tdc, tot, bc, label, triggerorbit, triggerbunch);
mFutureToBeSorted = true;
}
bool isMergable(Digit digit1, Digit digit2)
{
if (digit1.getChannel() != digit2.getChannel()) {
return false;
}
if (digit1.getBC() != digit2.getBC()) {
return false;
}
// Check if the difference is larger than the TDC dead time
if (std::abs(digit1.getTDC() - digit2.getTDC()) > Geo::DEADTIMETDC) {
return false;
}
return true;
}
ClassDefNV(WindowFiller, 2);
};
} // namespace tof
} // namespace o2
#endif