|
| 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