Project
Loading...
Searching...
No Matches
ZeroSuppress.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
15#include <cmath>
16#include <iostream>
17#include <array>
18
22
24#include "TPCBase/Mapper.h"
25#include "TPCBase/CRU.h"
26
27#include "DataFormatsTPC/Defs.h"
29
30using namespace o2::tpc;
31using namespace o2::tpc::constants;
32
34{
35 std::cout << "Zero Suppress process call" << std::endl;
36}
37
38void ZeroSuppress::DecodeZSPages(gsl::span<const ZeroSuppressedContainer8kb>* z0in, std::vector<Digit>* outDigits, int firstHBF)
39{
40 std::vector<Digit>& digits = *outDigits;
41 std::vector<unsigned int> _ADC = {};
43 gsl::span<const ZeroSuppressedContainer8kb>& z0input = *z0in;
44
45 for (auto inputPage : z0input) {
46 unsigned char* pageStart = reinterpret_cast<unsigned char*>(&inputPage);
47 unsigned char* startPtr = pageStart;
48 unsigned char* nextPage = pageStart + TPCZSHDR::TPC_ZS_PAGE_SIZE;
49
50 ZeroSuppressedContainer* z0Container = reinterpret_cast<ZeroSuppressedContainer*>(startPtr);
51 unsigned int _adcBits = (z0Container->hdr.version == 1) ? 10 : ((z0Container->hdr.version == 2) ? 12 : 0);
52 if (!_adcBits) {
53 if ((int)z0Container->hdr.nADCsamples) {
54 std::cout << "unsupported zero suppressed version" << std::endl;
55 break;
56 } else {
57 continue;
58 }
59 }
60 uint16_t _CRUID = z0Container->hdr.cruID;
61 uint16_t _timeOffset = z0Container->hdr.timeOffset;
62 unsigned int mask = static_cast<unsigned int>(pow(2, _adcBits)) - 1;
63 float decodeFactor = 1.0 / (1 << (_adcBits - 10));
64
65 const o2::header::RAWDataHeader* rdh = (const o2::header::RAWDataHeader*)&inputPage;
66 auto orbit = o2::raw::RDHUtils::getHeartBeatOrbit(rdh);
67 int timeBin = (_timeOffset + (o2::raw::RDHUtils::getHeartBeatOrbit(rdh) - firstHBF) * o2::constants::lhc::LHCMaxBunches) / LHCBCPERTIMEBIN;
68
69 unsigned int ct = 0;
70 startPtr += (sizeof(z0Container->rdh) + sizeof(z0Container->hdr)); // move to first time bin
71 // iterate through all time bins indicated in the z0 header
72 for (int tb = 0; tb < z0Container->hdr.nTimeBinSpan; tb++) {
73 startPtr += (startPtr - pageStart) % 2;
74 TPCZSTBHDR* tbHdr = reinterpret_cast<TPCZSTBHDR*>(startPtr);
75 unsigned int numberRows = __builtin_popcount((tbHdr->rowMask & 0x7FFF)); // number of ones, excluding upper/lower bit
76 if (startPtr > nextPage) {
77 throw std::runtime_error("pointer for time bin outside current zs page");
78 }
79 unsigned int rowUpperOffset = (tbHdr->rowMask & (1 << 15)) ? (mapper.getNumberOfRowsRegion(_CRUID % 10) / 2) : 0;
80 unsigned int _timeBin = timeBin + tb;
81
82 //if rows in timebin
83 if ((numberRows != 0)) {
84 startPtr += 2 * numberRows;
85 for (unsigned int pos = 0; pos < 15; pos++) { // TODO: end iterations at max number of rows for that endpoint
86 if (tbHdr->rowMask & (1 << pos)) { //row bit set decode row
87 unsigned int _row = pos + rowUpperOffset;
88 uint8_t numberSequences = *startPtr;
89 uint8_t numberADCs = *(startPtr + (2 * numberSequences));
90
91 unsigned char* _adcstart = startPtr + 2 * numberSequences + 1;
92 unsigned int length = (numberADCs * _adcBits + 7) / 8;
93 unsigned int temp = 0;
94 unsigned int t = 0;
95 unsigned int shift = 0;
96 unsigned int a1 = 0;
97 unsigned int count = 0;
98 if (_adcstart + length > nextPage) {
99 throw std::runtime_error("pointer for current sequence outside current zs page");
100 }
101 for (unsigned int a = 0; a < length; a++) {
102 temp = (*_adcstart) << shift;
103 _adcstart++;
104 t |= temp;
105 shift += 8;
106 while (shift >= _adcBits) {
107 a1 = t & mask;
108 _ADC[count] = a1;
109 count++;
110 shift -= _adcBits;
111 t >>= _adcBits;
112 }
113 }
114 for (unsigned int nADC = 0; nADC < numberADCs; nADC++) {
115 for (unsigned int seq = 0; seq < numberSequences; seq++) {
116 unsigned int seqLength = seq ? startPtr[2 * (seq + 1)] - startPtr[2 * seq] : startPtr[2];
117 for (unsigned int s = 0; s < seqLength; s++) {
118 digits.emplace_back(Digit((int)_CRUID, (float)(_ADC[nADC] * decodeFactor), (int)(_row + mapper.getGlobalRowOffsetRegion(_CRUID % 10)), (int)(*(startPtr + 2 * seq + 1) + s), _timeBin));
119 nADC++;
120 }
121 }
122 }
123 startPtr += (numberSequences * 2) + length + 1;
124 }
125 }
126
127 } else { // pointer + empty tb hdr
128 startPtr += 2;
129 continue;
130 }
131 }
132 }
133}
Definition of the TPC Digit.
Helper class for memory management of TPC Data Formats, external from the actual data type classes to...
uint64_t orbit
Definition RawEventData.h:6
const GPUTPCGMMerger::trackCluster & a1
Header to collect LHC related constants.
uint16_t pos
Definition RawData.h:3
int getGlobalRowOffsetRegion(int region) const
Definition Mapper.h:313
int getNumberOfRowsRegion(int region) const
Definition Mapper.h:309
void DecodeZSPages(gsl::span< const ZeroSuppressedContainer8kb > *z0in, std::vector< Digit > *outDigits, int firstHBF)
GLint GLsizei count
Definition glcorearb.h:399
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
GLboolean GLboolean GLboolean GLboolean a
Definition glcorearb.h:1233
GLint GLuint mask
Definition glcorearb.h:291
constexpr int LHCMaxBunches
constexpr int LHCBCPERTIMEBIN
Definition Constants.h:38
Global TPC definitions and constants.
Definition SimTraits.h:167
unsigned char nTimeBinSpan
unsigned char version
unsigned short timeOffset
unsigned short cruID
static constexpr size_t TPC_ZS_PAGE_SIZE
unsigned short nADCsamples
static constexpr unsigned int MAX_DIGITS_IN_PAGE
unsigned short rowMask
std::vector< Digit > digits