Project
Loading...
Searching...
No Matches
AlpideCoder.cxx
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
16
17using namespace o2::itsmft;
18
19const NoiseMap* AlpideCoder::mNoisyPixels = nullptr;
20
21//_____________________________________
23{
24 for (auto id : mFirstInRow) {
25 auto link = mPix2Encode[id];
26 printf("r%3d | c%4d", link.row, link.col);
27 while (link.nextInRow != -1) {
28 link = mPix2Encode[link.nextInRow];
29 printf(" %3d", link.col);
30 }
31 printf("\n");
32 }
33}
34
35//_____________________________________
37{
38 // reset before processing next chip
39 mFirstInRow.clear();
40 mPix2Encode.clear();
41}
42
43//_____________________________________
45 uint16_t chipInModule, uint16_t bc, uint16_t roflags)
46{
47 // Encode chip data into provided buffer. Data must be provided sorted in row/col, no check is done
48 int nfound = 0;
49 auto pixels = chipData.getData();
50 if (pixels.size()) { // non-empty chip
51 for (const auto& pix : pixels) {
52 addPixel(pix.getRow(), pix.getCol());
53 }
54 buffer.addFast(makeChipHeader(chipInModule, bc)); // chip header
55 for (int ir = 0; ir < NRegions; ir++) {
56 // For each region, we encode a REGION HEADER flag immediately
57 // to ensure its uniqueness.
58 buffer.addFast(makeRegion(ir));
59 int nfoundInRegion = procRegion(buffer, ir);
60 nfound += nfoundInRegion;
61 // If the region was unpopulated, we remove REGION HEADER flag.
62 if (!nfoundInRegion) {
63 buffer.erase(1);
64 }
65 }
66 buffer.addFast(makeChipTrailer(roflags));
67 resetMap();
68 } else {
69 buffer.addFast(makeChipEmpty(chipInModule, bc));
70 }
71 //
72 return nfound;
73}
74
75//_____________________________________
76int AlpideCoder::procDoubleCol(PayLoadCont& buffer, short reg, short dcol)
77{
78 // process double column: encoding
79 std::array<short, 2 * NRows> hits;
80 int nHits = 0, nData = 0;
81 //
82 int nr = mFirstInRow.size();
83 short col0 = ((reg * NDColInReg + dcol) << 1), col1 = col0 + 1; // 1st,2nd column of double column
84 int prevRow = -1;
85 for (int ir = 0; ir < nr; ir++) {
86 int linkID = mFirstInRow[ir];
87 if (linkID == -1) { // no pixels left on this row
88 continue;
89 }
90 if (mPix2Encode[linkID].col > col1) { // all following hits will have higher columns
91 break;
92 }
93 short rowID = mPix2Encode[linkID].row;
94 // process fired pixels
95 bool left = 0, right = 0;
96 if (mPix2Encode[linkID].col == col0) { // pixel in left column
97 left = 1;
98 linkID = mPix2Encode[linkID].nextInRow; // unlink processed pixel
99 }
100 if (linkID != -1 && mPix2Encode[linkID].col == col1) { // pixel in right column
101 right = 1;
102 linkID = mPix2Encode[linkID].nextInRow; // unlink processed pixel
103 }
104 short addr0 = rowID << 1;
105 if (rowID & 0x1) { // odd rows: right to left numbering
106 if (right) {
107 hits[nHits++] = addr0;
108 }
109 if (left) {
110 hits[nHits++] = addr0 + 1;
111 }
112 } else { // even rows: left to right numbering
113 if (left) {
114 hits[nHits++] = addr0;
115 }
116 if (right) {
117 hits[nHits++] = addr0 + 1;
118 }
119 }
120 if (linkID == -1) {
121 mFirstInRow[ir] = -1;
122 continue;
123 } // this row is finished
124 mFirstInRow[ir] = linkID; // link remaining hit pixels to row
125 }
126 //
127 int ih = 0;
128 if (nHits > 1) {
129 std::sort(hits.begin(), hits.begin() + nHits);
130 }
131 while ((ih < nHits)) {
132 short addrE, addrW = hits[ih++]; // address of the reference hit
133 uint8_t mask = 0;
134 short addrLim = addrW + HitMapSize + 1; // 1+address of furthest hit can be put in the map
135 while ((ih < nHits && (addrE = hits[ih]) < addrLim)) {
136 mask |= 0x1 << (addrE - addrW - 1);
137 ih++;
138 }
139 if (mask) { // flag DATALONG
140 buffer.addFast(makeDataLong(dcol, addrW));
141 buffer.addFast(mask);
142 } else {
143 buffer.addFast(makeDataShort(dcol, addrW));
144 }
145 nData++;
146 }
147 //
148 return nData;
149}
150
151//_____________________________________
152void AlpideCoder::resetMap()
153{
154 // reset map of hits for current chip
155 mFirstInRow.clear();
156 mPix2Encode.clear();
157}
class for the ALPIDE data decoding/encoding
uint64_t bc
Definition RawEventData.h:5
uint32_t col
Definition RawData.h:4
static constexpr int NDColInReg
Definition AlpideCoder.h:81
int encodeChip(PayLoadCont &buffer, const o2::itsmft::ChipPixelData &chipData, uint16_t chipInModule, uint16_t bc, uint16_t roflags=0)
static constexpr int HitMapSize
Definition AlpideCoder.h:82
static constexpr int NRegions
Definition AlpideCoder.h:80
const std::vector< PixelData > & getData() const
Definition PixelData.h:115
NoiseMap class for the ITS and MFT.
Definition NoiseMap.h:39
GLuint buffer
Definition glcorearb.h:655
GLdouble GLdouble right
Definition glcorearb.h:4077
GLint GLint GLsizei GLint GLenum GLenum const void * pixels
Definition glcorearb.h:275
GLint GLuint mask
Definition glcorearb.h:291
GLuint id
Definition glcorearb.h:650
uint8_t itsSharedClusterMap uint8_t
o2::InteractionRecord ir(0, 0)