Project
Loading...
Searching...
No Matches
PixelData.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#ifndef ALICEO2_ITSMFT_PIXELDATA_H
15#define ALICEO2_ITSMFT_PIXELDATA_H
16
20
21#include <string>
22#include <vector>
23#include <utility>
24#include <cstdint>
25
26namespace o2
27{
28namespace itsmft
29{
30
33{
34
35 public:
36 PixelData(const Digit* dig) : mRow(dig->getRow()), mCol(dig->getColumn()) {}
37 PixelData(uint16_t r = 0, uint16_t c = 0) : mRow(r), mCol(c) {}
38 uint16_t getRow() const { return mRow & RowMask; }
39 uint16_t getCol() const { return mCol; }
40 bool isMasked() const { return mRow & MaskBit; }
41 void setMask() { mRow |= MaskBit; }
42 void unsetMask() { mRow &= RowMask; }
43
45 uint16_t getRowDirect() const { return mRow; }
46
47 bool operator==(const PixelData& dt) const
48 {
50 return (getCol() == dt.getCol()) && (getRow() == dt.getRow());
51 }
52
53 bool operator>(const PixelData& dt) const
54 {
56 if (getCol() == dt.getCol()) {
57 return getRow() > dt.getRow();
58 }
59 return getCol() > dt.getCol();
60 }
61
62 bool operator<(const PixelData& dt) const
63 {
65 if (getCol() == dt.getCol()) {
66 return getRow() < dt.getRow();
67 }
68 return getCol() < dt.getCol();
69 }
70
71 bool isNeighbour(const PixelData& dt, int maxDist) const
72 {
74 return (std::abs(static_cast<int>(getCol()) - static_cast<int>(dt.getCol())) <= maxDist &&
75 std::abs(static_cast<int>(getRow()) - static_cast<int>(dt.getRow())) <= maxDist);
76 }
77
78 int compare(const PixelData& dt) const
79 {
81 return operator==(dt) ? 0 : (operator>(dt) ? 1 : -1);
82 }
83
84 static constexpr uint32_t DummyROF = 0xffffffff;
85 static constexpr uint32_t DummyChipID = 0xffff;
86
87 private:
88 void sanityCheck() const;
89 static constexpr int RowMask = 0x7FFF;
90 static constexpr int MaskBit = 0x8000;
91 uint16_t mRow = 0;
92 uint16_t mCol = 0;
93
94 ClassDefNV(PixelData, 1);
95};
96
100{
101
102 public:
103 // total number of raw data bytes to save in case of error and number of bytes (if any) after problematic one
104 static constexpr size_t MAXDATAERRBYTES = 16, MAXDATAERRBYTES_AFTER = 2;
105 ChipPixelData() = default;
106 ~ChipPixelData() = default;
107 uint8_t getROFlags() const { return mROFlags; }
108 uint16_t getChipID() const { return mChipID; }
109 uint32_t getROFrame() const { return mROFrame; }
110 uint32_t getStartID() const { return mStartID; }
111 uint32_t getFirstUnmasked() const { return mFirstUnmasked; }
112 uint32_t getTrigger() const { return mTrigger; }
113 const o2::InteractionRecord& getInteractionRecord() const { return mInteractionRecord; }
114 void setInteractionRecord(const o2::InteractionRecord& r) { mInteractionRecord = r; }
115 const std::vector<PixelData>& getData() const { return mPixels; }
116 std::vector<PixelData>& getData() { return (std::vector<PixelData>&)mPixels; }
117
118 void setROFlags(uint8_t f = 0) { mROFlags = f; }
119 void setChipID(uint16_t id) { mChipID = id; }
120 void setROFrame(uint32_t r) { mROFrame = r; }
121 void setStartID(uint32_t id) { mStartID = id; }
122 void setFirstUnmasked(uint32_t n) { mFirstUnmasked = n; }
123 void setTrigger(uint32_t t) { mTrigger = t; }
124
125 void setError(ChipStat::DecErrors i) { mErrors |= 0x1UL << i; }
126 void addErrorInfo(uint64_t b) { mErrorInfo |= b; }
127 void setErrorInfo(uint64_t b) { mErrorInfo = b; }
128 void setErrorFlags(uint64_t f) { mErrors |= f; }
129 bool isErrorSet(ChipStat::DecErrors i) const { return mErrors & (0x1UL << i); }
130 bool isErrorSet() const { return mErrors != 0; }
131 auto getErrorFlags() const { return mErrors; }
132 auto getErrorInfo() const { return mErrorInfo; }
133 auto getNBytesInRawBuff() const { return int(mErrorInfo >> 32) & 0xff; }
134 void setNBytesInRawBuff(int n) { mErrorInfo |= (uint64_t(n & 0xff)) << 32; }
135 auto& getRawErrBuff() { return mRawBuff; }
136 auto& getRawErrBuff() const { return mRawBuff; }
137 std::string getErrorDetails(int pos) const;
138
140 {
141 mChipID = -1;
142 }
143
144 void clear()
145 {
146 resetChipID();
147 mPixels.clear();
148 mROFlags = 0;
149 mFirstUnmasked = 0;
150 mErrors = 0;
151 mErrorInfo = 0;
152 mPixIds.clear();
153 mPixelsOrder.clear();
154 }
155
157 {
158 // swap content of two objects
159 std::swap(mROFlags, other.mROFlags);
160 std::swap(mChipID, other.mChipID);
161 std::swap(mROFrame, other.mROFrame);
162 std::swap(mFirstUnmasked, other.mFirstUnmasked); // strictly speaking, not needed
163 std::swap(mStartID, other.mStartID); // strictly speaking, not needed
164 std::swap(mTrigger, other.mTrigger);
165 std::swap(mErrors, other.mErrors);
166 std::swap(mInteractionRecord, other.mInteractionRecord);
167 mPixels.swap(other.mPixels);
168 }
169
171 {
173 const auto& pixelsS = sample.getData();
174 uint32_t nC = mPixels.size();
175 if (!nC) {
176 return;
177 }
178 uint32_t nS = pixelsS.size();
179 if (!nS) {
180 return;
181 }
182 uint32_t itC = 0, itS = 0;
183 while (itC < nC && itS < nS) {
184 auto& pix0 = mPixels[itC];
185 const auto& pixC = pixelsS[itS];
186 if (pix0 == pixC) { // same
187 pix0.setMask();
188 if (mFirstUnmasked == itC++) { // mFirstUnmasked should flag 1st unmasked pixel entry
189 mFirstUnmasked = itC;
190 }
191 itS++;
192 } else if (pix0 < pixC) {
193 itC++;
194 } else {
195 itS++;
196 }
197 }
198 }
199
200 void maskFiredInSample(const ChipPixelData& sample, int maxDist)
201 {
203 const auto& pixelsS = sample.getData();
204 int nC = mPixels.size();
205 if (!nC) {
206 return;
207 }
208 int nS = pixelsS.size();
209 if (!nS) {
210 return;
211 }
212 for (int itC = 0, itS = 0; itC < nC; itC++) {
213 auto& pix0 = mPixels[itC];
214
215 // seek to itS which is inferior than itC - maxDist
216 auto mincol = pix0.getCol() > maxDist ? pix0.getCol() - maxDist : 0;
217 auto minrow = pix0.getRowDirect() > maxDist ? pix0.getRowDirect() - maxDist : 0;
218 if (itS == nS) { // in case itS lool below reached the end
219 itS--;
220 }
221 while ((pixelsS[itS].getCol() > mincol || pixelsS[itS].getRow() > minrow) && itS > 0) {
222 itS--;
223 }
224 for (; itS < nS; itS++) {
225 const auto& pixC = pixelsS[itS];
226
227 auto drow = static_cast<int>(pixC.getRow()) - static_cast<int>(pix0.getRowDirect());
228 auto dcol = static_cast<int>(pixC.getCol()) - static_cast<int>(pix0.getCol());
229
230 if (dcol > maxDist || (dcol == maxDist && drow > maxDist)) {
231 break; // all higher itS will not match to this itC also
232 }
233 if (dcol < -maxDist || (drow > maxDist || drow < -maxDist)) {
234 continue;
235 } else {
236 pix0.setMask();
237 if (int(mFirstUnmasked) == itC) { // mFirstUnmasked should flag 1st unmasked pixel entry
238 mFirstUnmasked = itC + 1;
239 }
240 break;
241 }
242 }
243 }
244 }
245
246 template <typename Func>
247 void forEachSetError(Func f) const
248 {
249 auto outer = [&](int errIdx) {
250 if (getErrorFlags() && (getErrorFlags() & (0x1UL << errIdx))) {
251 f(errIdx);
252 }
253 };
255 }
256
257 std::string reportErrors() const
258 {
259 std::string res;
260 bool first = true;
261 auto inner = [&](int errIdx) {
262 if (!first) {
263 res += ", ";
264 }
265 res += ChipStat::ErrNames[errIdx];
266 first = false;
267 };
268 forEachSetError(inner);
269 return res;
270 }
271
272 void print() const;
273 std::vector<uint32_t>& getPixIds() { return mPixIds; }
274 std::vector<int>& getPixelsOrder() { return mPixelsOrder; }
275 uint32_t getOrderedPixId(int pos) const { return mPixIds[mPixelsOrder[pos]]; }
276
277 private:
278 uint8_t mROFlags = 0; // readout flags from the chip trailer
279 uint16_t mChipID = 0; // chip id within the detector
280 uint32_t mROFrame = 0; // readout frame ID
281 uint32_t mFirstUnmasked = 0; // first unmasked entry in the mPixels
282 uint32_t mStartID = 0; // entry of the 1st pixel data in the whole detector data, for MCtruth access
283 uint32_t mTrigger = 0; // trigger pattern
284 uint64_t mErrors = 0; // errors set during decoding
285 uint64_t mErrorInfo = 0; // optional extra info on the error
286 std::array<uint8_t, MAXDATAERRBYTES> mRawBuff{}; // buffer for raw data showing an error
287 o2::InteractionRecord mInteractionRecord = {}; // interaction record
288 std::vector<PixelData> mPixels; // vector of pixels
289 std::vector<uint32_t> mPixIds; // vector of label indices in case of squashing+Monte Carlo
290 std::vector<int> mPixelsOrder; // vector to get ordered access to pixel ids
291
292 ClassDefNV(ChipPixelData, 2);
293};
294} // namespace itsmft
295} // namespace o2
296
297#endif // ALICEO2_ITSMFT_PIXELDATA_H
Definition of the ITSMFT digit.
Alpide Chip and GBT link decoding statistics.
unsigned short int uint16_t
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
uint16_t pos
Definition RawData.h:3
uint32_t res
Definition RawData.h:0
uint32_t c
Definition RawData.h:2
o2::mid::ColumnData & getColumn(std::vector< o2::mid::ColumnData > &patterns, uint8_t icolumn, uint8_t deId)
uint32_t getOrderedPixId(int pos) const
Definition PixelData.h:275
std::string reportErrors() const
Definition PixelData.h:257
auto getNBytesInRawBuff() const
Definition PixelData.h:133
uint32_t getStartID() const
Definition PixelData.h:110
static constexpr size_t MAXDATAERRBYTES
Definition PixelData.h:104
uint8_t getROFlags() const
Definition PixelData.h:107
void setError(ChipStat::DecErrors i)
Definition PixelData.h:125
void setErrorFlags(uint64_t f)
Definition PixelData.h:128
void setInteractionRecord(const o2::InteractionRecord &r)
Definition PixelData.h:114
uint32_t getFirstUnmasked() const
Definition PixelData.h:111
std::vector< uint32_t > & getPixIds()
Definition PixelData.h:273
void setErrorInfo(uint64_t b)
Definition PixelData.h:127
void setROFrame(uint32_t r)
Definition PixelData.h:120
void setStartID(uint32_t id)
Definition PixelData.h:121
void setNBytesInRawBuff(int n)
Definition PixelData.h:134
std::vector< int > & getPixelsOrder()
Definition PixelData.h:274
auto & getRawErrBuff() const
Definition PixelData.h:136
auto getErrorInfo() const
Definition PixelData.h:132
void setChipID(uint16_t id)
Definition PixelData.h:119
void swap(ChipPixelData &other)
Definition PixelData.h:156
void setROFlags(uint8_t f=0)
Definition PixelData.h:118
void setFirstUnmasked(uint32_t n)
Definition PixelData.h:122
uint32_t getROFrame() const
Definition PixelData.h:109
bool isErrorSet(ChipStat::DecErrors i) const
Definition PixelData.h:129
const o2::InteractionRecord & getInteractionRecord() const
Definition PixelData.h:113
void addErrorInfo(uint64_t b)
Definition PixelData.h:126
void setTrigger(uint32_t t)
Definition PixelData.h:123
static constexpr size_t MAXDATAERRBYTES_AFTER
Definition PixelData.h:104
auto getErrorFlags() const
Definition PixelData.h:131
uint32_t getTrigger() const
Definition PixelData.h:112
std::vector< PixelData > & getData()
Definition PixelData.h:116
std::string getErrorDetails(int pos) const
Definition PixelData.cxx:42
uint16_t getChipID() const
Definition PixelData.h:108
const std::vector< PixelData > & getData() const
Definition PixelData.h:115
void forEachSetError(Func f) const
Definition PixelData.h:247
void maskFiredInSample(const ChipPixelData &sample)
Definition PixelData.h:170
void maskFiredInSample(const ChipPixelData &sample, int maxDist)
Definition PixelData.h:200
Digit class for the ITS.
Definition Digit.h:30
< single pixel datum, with possibility to set a flag of pixel being masked out
Definition PixelData.h:33
uint16_t getRowDirect() const
for faster access when the pixel is guaranteed to not be masked
Definition PixelData.h:45
PixelData(const Digit *dig)
Definition PixelData.h:36
static constexpr uint32_t DummyChipID
Definition PixelData.h:85
uint16_t getCol() const
Definition PixelData.h:39
static constexpr uint32_t DummyROF
Definition PixelData.h:84
int compare(const PixelData &dt) const
Definition PixelData.h:78
bool operator>(const PixelData &dt) const
Definition PixelData.h:53
bool operator==(const PixelData &dt) const
Definition PixelData.h:47
bool isNeighbour(const PixelData &dt, int maxDist) const
Definition PixelData.h:71
bool isMasked() const
Definition PixelData.h:40
PixelData(uint16_t r=0, uint16_t c=0)
Definition PixelData.h:37
uint16_t getRow() const
Definition PixelData.h:38
bool operator<(const PixelData &dt) const
Definition PixelData.h:62
GLdouble n
Definition glcorearb.h:1982
GLint first
Definition glcorearb.h:399
GLdouble f
Definition glcorearb.h:310
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLboolean r
Definition glcorearb.h:1233
GLuint id
Definition glcorearb.h:650
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static constexpr std::array< std::string_view, NErrorsDefined > ErrNames
static void forEachError(Func f)
VectorOfTObjectPtrs other