Skip to content

Commit 997c963

Browse files
committed
TPC: Make cluster decompression more modular to use it in CTF skimming
1 parent b57b586 commit 997c963

4 files changed

Lines changed: 163 additions & 97 deletions

File tree

GPU/GPUTracking/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ set(HDRS_INSTALL
158158
DataTypes/GPUNewCalibValues.h
159159
DataTypes/GPUTRDInterfaceO2Track.h
160160
Base/GPUParam.inc
161+
DataCompression/TPCClusterDecompressor.inc
161162
Merger/GPUTPCGMMergerTypes.h
162163
Global/GPUErrorCodes.h
163164
Global/GPUChainTrackingDefs.h

GPU/GPUTracking/DataCompression/TPCClusterDecompressor.cxx

Lines changed: 3 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <algorithm>
2020
#include <cstring>
2121
#include <atomic>
22+
#include "TPCClusterDecompressor.inc"
2223

2324
using namespace GPUCA_NAMESPACE::gpu;
2425
using namespace o2::tpc;
@@ -51,84 +52,7 @@ int TPCClusterDecompressor::decompress(const CompressedClusters* clustersCompres
5152
offset += clustersCompressed->nTrackClusters[lasti++];
5253
}
5354
lasti++;
54-
float zOffset = 0;
55-
unsigned int slice = clustersCompressed->sliceA[i];
56-
unsigned int row = clustersCompressed->rowA[i];
57-
GPUTPCCompressionTrackModel track;
58-
unsigned int j;
59-
for (j = 0; j < clustersCompressed->nTrackClusters[i]; j++) {
60-
unsigned int pad = 0, time = 0;
61-
if (j) {
62-
unsigned char tmpSlice = clustersCompressed->sliceLegDiffA[offset - i - 1];
63-
bool changeLeg = (tmpSlice >= NSLICES);
64-
if (changeLeg) {
65-
tmpSlice -= NSLICES;
66-
}
67-
if (clustersCompressed->nComppressionModes & GPUSettings::CompressionDifferences) {
68-
slice += tmpSlice;
69-
if (slice >= NSLICES) {
70-
slice -= NSLICES;
71-
}
72-
row += clustersCompressed->rowDiffA[offset - i - 1];
73-
if (row >= GPUCA_ROW_COUNT) {
74-
row -= GPUCA_ROW_COUNT;
75-
}
76-
} else {
77-
slice = tmpSlice;
78-
row = clustersCompressed->rowDiffA[offset - i - 1];
79-
}
80-
if (changeLeg && track.Mirror()) {
81-
break;
82-
}
83-
if (track.Propagate(param.tpcGeometry.Row2X(row), param.SliceParam[slice].Alpha)) {
84-
break;
85-
}
86-
unsigned int timeTmp = clustersCompressed->timeResA[offset - i - 1];
87-
if (timeTmp & 800000) {
88-
timeTmp |= 0xFF000000;
89-
}
90-
time = timeTmp + ClusterNative::packTime(CAMath::Max(0.f, param.tpcGeometry.LinearZ2Time(slice, track.Z() + zOffset)));
91-
float tmpPad = CAMath::Max(0.f, CAMath::Min((float)param.tpcGeometry.NPads(GPUCA_ROW_COUNT - 1), param.tpcGeometry.LinearY2Pad(slice, row, track.Y())));
92-
pad = clustersCompressed->padResA[offset - i - 1] + ClusterNative::packPad(tmpPad);
93-
time = time & 0xFFFFFF;
94-
pad = (unsigned short)pad;
95-
if (pad >= param.tpcGeometry.NPads(row) * ClusterNative::scalePadPacked) {
96-
if ((signed short)pad >= (signed short)(-2 * ClusterNative::scalePadPacked)) {
97-
pad = 0;
98-
} else {
99-
pad = param.tpcGeometry.NPads(row) * ClusterNative::scalePadPacked - 1;
100-
}
101-
}
102-
if (param.par.continuousMaxTimeBin > 0 && time >= maxTime) {
103-
if (time >= 0xFFFFFF - 2 * ClusterNative::scaleTimePacked) {
104-
time = 0;
105-
} else {
106-
time = maxTime;
107-
}
108-
}
109-
} else {
110-
time = clustersCompressed->timeA[i];
111-
pad = clustersCompressed->padA[i];
112-
}
113-
std::vector<ClusterNative>& clusterVector = clusters[slice][row];
114-
auto& lock = locks[slice][row];
115-
while (lock.test_and_set(std::memory_order_acquire)) {
116-
}
117-
clusterVector.emplace_back(time, clustersCompressed->flagsA[offset], pad, clustersCompressed->sigmaTimeA[offset], clustersCompressed->sigmaPadA[offset], clustersCompressed->qMaxA[offset], clustersCompressed->qTotA[offset]);
118-
auto& cluster = clusterVector.back();
119-
float y = param.tpcGeometry.LinearPad2Y(slice, row, cluster.getPad());
120-
float z = param.tpcGeometry.LinearTime2Z(slice, cluster.getTime());
121-
lock.clear(std::memory_order_release);
122-
if (j == 0) {
123-
zOffset = z;
124-
track.Init(param.tpcGeometry.Row2X(row), y, z - zOffset, param.SliceParam[slice].Alpha, clustersCompressed->qPtA[i], param);
125-
}
126-
if (j + 1 < clustersCompressed->nTrackClusters[i] && track.Filter(y, z - zOffset, row)) {
127-
break;
128-
}
129-
offset++;
130-
}
131-
offset += clustersCompressed->nTrackClusters[i] - j;
55+
decompressTrack(clustersCompressed, param, maxTime, i, offset, clusters, locks);
13256
}
13357
size_t nTotalClusters = clustersCompressed->nAttachedClusters + clustersCompressed->nUnattachedClusters;
13458
ClusterNative* clusterBuffer = allocator(nTotalClusters);
@@ -150,27 +74,9 @@ int TPCClusterDecompressor::decompress(const CompressedClusters* clustersCompres
15074
if (clusters[i][j].size()) {
15175
memcpy((void*)buffer, (const void*)clusters[i][j].data(), clusters[i][j].size() * sizeof(clusterBuffer[0]));
15276
}
153-
unsigned int time = 0;
154-
unsigned short pad = 0;
15577
ClusterNative* cl = buffer + clusters[i][j].size();
15678
unsigned int end = offsets[i][j] + ((i * GPUCA_ROW_COUNT + j >= clustersCompressed->nSliceRows) ? 0 : clustersCompressed->nSliceRowClusters[i * GPUCA_ROW_COUNT + j]);
157-
for (unsigned int k = offsets[i][j]; k < end; k++) {
158-
/*if (cl >= clustersNative.clustersLinear + nTotalClusters) {
159-
throw std::runtime_error("Bad TPC CTF data, decoded more clusters than announced");
160-
}*/
161-
if (clustersCompressed->nComppressionModes & GPUSettings::CompressionDifferences) {
162-
unsigned int timeTmp = clustersCompressed->timeDiffU[k];
163-
if (timeTmp & 800000) {
164-
timeTmp |= 0xFF000000;
165-
}
166-
time += timeTmp;
167-
pad += clustersCompressed->padDiffU[k];
168-
} else {
169-
time = clustersCompressed->timeDiffU[k];
170-
pad = clustersCompressed->padDiffU[k];
171-
}
172-
*(cl++) = ClusterNative(time, clustersCompressed->flagsU[k], pad, clustersCompressed->sigmaTimeU[k], clustersCompressed->sigmaPadU[k], clustersCompressed->qMaxU[k], clustersCompressed->qTotU[k]);
173-
}
79+
decompressHits(clustersCompressed, offsets[i][j], end, cl);
17480
std::sort(buffer, buffer + clustersNative.nClusters[i][j]);
17581
}
17682
}

GPU/GPUTracking/DataCompression/TPCClusterDecompressor.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,16 @@ class TPCClusterDecompressor
3636
int decompress(const o2::tpc::CompressedClustersFlat* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, std::function<o2::tpc::ClusterNative*(size_t)> allocator, const GPUParam& param);
3737
int decompress(const o2::tpc::CompressedClusters* clustersCompressed, o2::tpc::ClusterNativeAccess& clustersNative, std::function<o2::tpc::ClusterNative*(size_t)> allocator, const GPUParam& param);
3838

39+
template <typename... Args>
40+
void decompressTrack(const o2::tpc::CompressedClusters* clustersCompressed, const GPUParam& param, const unsigned int maxTime, const unsigned int i, unsigned int& offset, Args&... args);
41+
template <typename... Args>
42+
void decompressHits(const o2::tpc::CompressedClusters* clustersCompressed, const unsigned int start, const unsigned int end, Args&... args);
43+
3944
protected:
45+
template <typename... Args>
46+
auto& decompressTrackStore(const o2::tpc::CompressedClusters* clustersCompressed, const unsigned int offset, unsigned int slice, unsigned int row, unsigned int pad, unsigned int time, Args&... args);
47+
template <typename... Args>
48+
auto& decompressHitsStore(const o2::tpc::CompressedClusters* clustersCompressed, unsigned int k, unsigned int time, unsigned short pad, Args&... args);
4049
};
4150
} // namespace GPUCA_NAMESPACE::gpu
4251

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
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+
12+
/// \file TPCClusterDecompressor.inc
13+
/// \author David Rohr
14+
15+
#include "TPCClusterDecompressor.h"
16+
#include "GPUO2DataTypes.h"
17+
#include "GPUParam.h"
18+
#include "GPUTPCCompressionTrackModel.h"
19+
#include <algorithm>
20+
#include <cstring>
21+
#include <atomic>
22+
23+
using namespace GPUCA_NAMESPACE::gpu;
24+
using namespace o2::tpc;
25+
26+
template <>
27+
inline auto& TPCClusterDecompressor::decompressTrackStore(const o2::tpc::CompressedClusters* clustersCompressed, const unsigned int offset, unsigned int slice, unsigned int row, unsigned int pad, unsigned int time, std::vector<ClusterNative>& clusterVector)
28+
{
29+
clusterVector.emplace_back(time, clustersCompressed->flagsA[offset], pad, clustersCompressed->sigmaTimeA[offset], clustersCompressed->sigmaPadA[offset], clustersCompressed->qMaxA[offset], clustersCompressed->qTotA[offset]);
30+
return clusterVector.back();
31+
}
32+
33+
template <>
34+
inline auto& TPCClusterDecompressor::decompressTrackStore(const o2::tpc::CompressedClusters* clustersCompressed, const unsigned int offset, unsigned int slice, unsigned int row, unsigned int pad, unsigned int time, std::vector<ClusterNative> (&clusters)[NSLICES][GPUCA_ROW_COUNT], std::atomic_flag (&locks)[NSLICES][GPUCA_ROW_COUNT])
35+
{
36+
std::vector<ClusterNative>& clusterVector = clusters[slice][row];
37+
auto& lock = locks[slice][row];
38+
while (lock.test_and_set(std::memory_order_acquire)) {
39+
}
40+
auto& cluster = decompressTrackStore(clustersCompressed, offset, slice, row, pad, time, clusterVector);
41+
lock.clear(std::memory_order_release);
42+
return cluster;
43+
}
44+
45+
template <typename... Args>
46+
inline void TPCClusterDecompressor::decompressTrack(const CompressedClusters* clustersCompressed, const GPUParam& param, const unsigned int maxTime, const unsigned int i, unsigned int& offset, Args&... args)
47+
{
48+
float zOffset = 0;
49+
unsigned int slice = clustersCompressed->sliceA[i];
50+
unsigned int row = clustersCompressed->rowA[i];
51+
GPUTPCCompressionTrackModel track;
52+
unsigned int j;
53+
for (j = 0; j < clustersCompressed->nTrackClusters[i]; j++) {
54+
unsigned int pad = 0, time = 0;
55+
if (j) {
56+
unsigned char tmpSlice = clustersCompressed->sliceLegDiffA[offset - i - 1];
57+
bool changeLeg = (tmpSlice >= NSLICES);
58+
if (changeLeg) {
59+
tmpSlice -= NSLICES;
60+
}
61+
if (clustersCompressed->nComppressionModes & GPUSettings::CompressionDifferences) {
62+
slice += tmpSlice;
63+
if (slice >= NSLICES) {
64+
slice -= NSLICES;
65+
}
66+
row += clustersCompressed->rowDiffA[offset - i - 1];
67+
if (row >= GPUCA_ROW_COUNT) {
68+
row -= GPUCA_ROW_COUNT;
69+
}
70+
} else {
71+
slice = tmpSlice;
72+
row = clustersCompressed->rowDiffA[offset - i - 1];
73+
}
74+
if (changeLeg && track.Mirror()) {
75+
break;
76+
}
77+
if (track.Propagate(param.tpcGeometry.Row2X(row), param.SliceParam[slice].Alpha)) {
78+
break;
79+
}
80+
unsigned int timeTmp = clustersCompressed->timeResA[offset - i - 1];
81+
if (timeTmp & 800000) {
82+
timeTmp |= 0xFF000000;
83+
}
84+
time = timeTmp + ClusterNative::packTime(CAMath::Max(0.f, param.tpcGeometry.LinearZ2Time(slice, track.Z() + zOffset)));
85+
float tmpPad = CAMath::Max(0.f, CAMath::Min((float)param.tpcGeometry.NPads(GPUCA_ROW_COUNT - 1), param.tpcGeometry.LinearY2Pad(slice, row, track.Y())));
86+
pad = clustersCompressed->padResA[offset - i - 1] + ClusterNative::packPad(tmpPad);
87+
time = time & 0xFFFFFF;
88+
pad = (unsigned short)pad;
89+
if (pad >= param.tpcGeometry.NPads(row) * ClusterNative::scalePadPacked) {
90+
if ((signed short)pad >= (signed short)(-2 * ClusterNative::scalePadPacked)) {
91+
pad = 0;
92+
} else {
93+
pad = param.tpcGeometry.NPads(row) * ClusterNative::scalePadPacked - 1;
94+
}
95+
}
96+
if (param.par.continuousMaxTimeBin > 0 && time >= maxTime) {
97+
if (time >= 0xFFFFFF - 2 * ClusterNative::scaleTimePacked) {
98+
time = 0;
99+
} else {
100+
time = maxTime;
101+
}
102+
}
103+
} else {
104+
time = clustersCompressed->timeA[i];
105+
pad = clustersCompressed->padA[i];
106+
}
107+
auto& cluster = decompressTrackStore(clustersCompressed, offset, slice, row, pad, time, args...);
108+
float y = param.tpcGeometry.LinearPad2Y(slice, row, cluster.getPad());
109+
float z = param.tpcGeometry.LinearTime2Z(slice, cluster.getTime());
110+
if (j == 0) {
111+
zOffset = z;
112+
track.Init(param.tpcGeometry.Row2X(row), y, z - zOffset, param.SliceParam[slice].Alpha, clustersCompressed->qPtA[i], param);
113+
}
114+
if (j + 1 < clustersCompressed->nTrackClusters[i] && track.Filter(y, z - zOffset, row)) {
115+
break;
116+
}
117+
offset++;
118+
}
119+
offset += clustersCompressed->nTrackClusters[i] - j;
120+
}
121+
122+
template <>
123+
inline auto& TPCClusterDecompressor::decompressHitsStore(const CompressedClusters* clustersCompressed, unsigned int k, unsigned int time, unsigned short pad, ClusterNative* &cl)
124+
{
125+
return ((*(cl++) = ClusterNative(time, clustersCompressed->flagsU[k], pad, clustersCompressed->sigmaTimeU[k], clustersCompressed->sigmaPadU[k], clustersCompressed->qMaxU[k], clustersCompressed->qTotU[k])));
126+
}
127+
128+
template <typename... Args>
129+
inline void TPCClusterDecompressor::decompressHits(const CompressedClusters* clustersCompressed, const unsigned int start, const unsigned int end, Args&... args)
130+
{
131+
unsigned int time = 0;
132+
unsigned short pad = 0;
133+
for (unsigned int k = start; k < end; k++) {
134+
/*if (cl >= clustersNative.clustersLinear + nTotalClusters) {
135+
throw std::runtime_error("Bad TPC CTF data, decoded more clusters than announced");
136+
}*/
137+
if (clustersCompressed->nComppressionModes & GPUSettings::CompressionDifferences) {
138+
unsigned int timeTmp = clustersCompressed->timeDiffU[k];
139+
if (timeTmp & 800000) {
140+
timeTmp |= 0xFF000000;
141+
}
142+
time += timeTmp;
143+
pad += clustersCompressed->padDiffU[k];
144+
} else {
145+
time = clustersCompressed->timeDiffU[k];
146+
pad = clustersCompressed->padDiffU[k];
147+
}
148+
decompressHitsStore(clustersCompressed, k, time, pad, args...);
149+
}
150+
}

0 commit comments

Comments
 (0)