Project
Loading...
Searching...
No Matches
ClusterPattern.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
22
23#ifndef ALICEO2_ITSMFT_CLUSTERPATTERN_H
24#define ALICEO2_ITSMFT_CLUSTERPATTERN_H
25#include <Rtypes.h>
26#include <array>
27#include <iosfwd>
28#include <gsl/gsl>
30
31namespace o2
32{
33namespace itsmft
34{
35class ClusterTopology;
36class TopologyDictionary;
37class BuildTopologyDictionary;
38
40{
41 public:
42 static constexpr uint8_t MaxRowSpan = 128;
43 static constexpr uint8_t MaxColSpan = 128;
44 static constexpr int MaxPatternBits = MaxRowSpan * MaxColSpan;
45 static constexpr int MaxPatternBytes = MaxPatternBits / 8;
46 static constexpr int SpanMask = 0x7fff;
47 static constexpr int TruncateMask = 0x8000;
48
52 ClusterPattern(int nRow, int nCol, const unsigned char patt[MaxPatternBytes]);
53
54 template <class iterator>
55 void acquirePattern(iterator& pattIt)
56 {
57 mBitmap[0] = *pattIt++;
58 mBitmap[1] = *pattIt++;
59 int nbits = mBitmap[0] * mBitmap[1];
60 int nBytes = nbits / 8;
61 if (((nbits) % 8) != 0) {
62 nBytes++;
63 }
64 memcpy(&mBitmap[2], &(*pattIt), nBytes);
65 pattIt += nBytes;
66 }
67
68 template <class iterator>
69 static void skipPattern(iterator& pattIt)
70 {
71 unsigned char b0 = *pattIt++, b1 = *pattIt++;
72 int nbits = b0 * b1;
73 pattIt += nbits / 8 + (((nbits) % 8) != 0);
74 }
75
77 template <class iterator>
78 ClusterPattern(iterator& pattIt)
79 {
80 acquirePattern(pattIt);
81 }
82
84 static constexpr int kExtendedPatternBytes = MaxPatternBytes + 2;
86 const std::array<unsigned char, kExtendedPatternBytes>& getPattern() const { return mBitmap; }
88 unsigned char getByte(int n) const;
90 int getRowSpan() const { return (int)mBitmap[0]; }
92 int getColumnSpan() const { return (int)mBitmap[1]; }
94 int getUsedBytes() const;
96 int getNPixels() const;
98 friend std::ostream& operator<<(std::ostream& os, const ClusterPattern& top);
99 void print() const;
101 void setPattern(int nRow, int nCol, const unsigned char patt[MaxPatternBytes]);
103 void setPattern(const unsigned char bitmask[kExtendedPatternBytes]);
105 static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float& xCOG, float& zCOG);
107 int getCOG(float& xCOG, float& zCOG) const { return ClusterPattern::getCOG(getRowSpan(), getColumnSpan(), mBitmap.data() + 2, xCOG, zCOG); }
108
109 bool isSet(int row, int col) const
110 {
111 const auto bmap = mBitmap.data() + 2;
112 int pos = row * getColumnSpan() + col;
113 return pos < getColumnSpan() * getRowSpan() && (bmap[pos >> 3] & (0x1 << (7 - (pos % 8))));
114 }
115
116 void resetPixel(int row, int col)
117 {
118 const auto bmap = mBitmap.data() + 2;
119 int pos = row * getColumnSpan() + col;
120 if (pos < getColumnSpan() * getRowSpan()) {
121 bmap[pos >> 3] &= 0xff & ~(0x1 << (7 - (pos % 8)));
122 }
123 }
124
125 void setPixel(int row, int col)
126 {
127 const auto bmap = mBitmap.data() + 2;
128 int pos = row * getColumnSpan() + col;
129 if (pos < getColumnSpan() * getRowSpan()) {
130 bmap[pos >> 3] |= 0x1 << (7 - (pos % 8));
131 }
132 }
133
134 template <typename Processor>
135 void process(Processor procRowCol);
136
140
141 private:
149
150 std::array<unsigned char, kExtendedPatternBytes> mBitmap;
151
152 ClassDefNV(ClusterPattern, 1);
153};
154
155template <typename Processor>
156void ClusterPattern::process(Processor procRowCol)
157{
158 auto cspan = getColumnSpan(), rspan = getRowSpan();
159 uint32_t nBits = cspan * rspan;
160 uint32_t nBytes = (nBits >> 3) + (nBits % 8 != 0);
161 const auto bmap = mBitmap.data() + 2;
162 uint16_t ic = 0, ir = 0;
163 for (unsigned int i = 0; i < nBytes; i++) {
164 int s = 128; // 0b10000000
165 while (s > 0) {
166 if ((bmap[i] & s) != 0) {
167 procRowCol(ir, ic);
168 }
169 ic++;
170 s >>= 1;
171 if (uint32_t(ir + 1) * ic == nBits) {
172 break;
173 }
174 if (ic == cspan) {
175 ic = 0;
176 ir++;
177 }
178 }
179 if (uint32_t(ir + 1) * ic == nBits) {
180 break;
181 }
182 }
183}
184
185} // namespace itsmft
186} // namespace o2
187#endif /* ALICEO2_ITS_CLUSTERPATTERN_H */
Definition of the ITSMFT compact cluster.
int32_t i
const GPUTPCGMMerger::trackCluster & b1
uint16_t pos
Definition RawData.h:3
uint32_t col
Definition RawData.h:4
ClusterPattern(iterator &pattIt)
Constructor from cluster patterns.
int getRowSpan() const
Returns the number of rows.
void acquirePattern(iterator &pattIt)
static constexpr int MaxPatternBytes
int getColumnSpan() const
Returns the number of columns.
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
void setPattern(int nRow, int nCol, const unsigned char patt[MaxPatternBytes])
Sets the pattern.
void resetPixel(int row, int col)
ClusterPattern()
Default constructor.
static constexpr int kExtendedPatternBytes
Maximum number of bytes for the cluster puttern + 2 bytes respectively for the number of rows and col...
static constexpr int SpanMask
unsigned char getByte(int n) const
Returns a specific byte of the pattern.
void process(Processor procRowCol)
static constexpr uint8_t MaxRowSpan
void setPattern(const unsigned char bitmask[kExtendedPatternBytes])
Sets the whole bitmask: the number of rows, the number of columns and the pattern.
int getNPixels() const
Returns the number of fired pixels.
int getCOG(float &xCOG, float &zCOG) const
Compute pattern's COG position. Returns the number of fired pixels.
bool isSet(int row, int col) const
static void skipPattern(iterator &pattIt)
friend std::ostream & operator<<(std::ostream &os, const ClusterPattern &top)
Prints the pattern.
const std::array< unsigned char, kExtendedPatternBytes > & getPattern() const
Returns the pattern.
static constexpr int MaxPatternBits
static constexpr uint8_t MaxColSpan
void setPixel(int row, int col)
int getUsedBytes() const
Returns the number of bytes used for the pattern.
static constexpr int TruncateMask
GLdouble n
Definition glcorearb.h:1982
GLdouble GLdouble GLdouble GLdouble top
Definition glcorearb.h:4077
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
o2::InteractionRecord ir(0, 0)
std::vector< int > row