|
23 | 23 | #include "GPUConstantMem.h" // TODO: Try to get rid of as many GPUConstantMem includes as possible! |
24 | 24 | #include "GPUTPCCompressionKernels.h" |
25 | 25 | #include "GPUTPCDecompressionKernels.h" |
| 26 | +#include "SimulationDataFormat/ConstMCTruthContainer.h" |
| 27 | +#include "SimulationDataFormat/MCCompLabel.h" |
26 | 28 | #include "utils/strtag.h" |
27 | 29 |
|
28 | 30 | #include <numeric> |
@@ -52,6 +54,9 @@ int32_t GPUChainTracking::RunTPCCompression() |
52 | 54 | TransferMemoryResourcesToGPU(myStep, &Compressor, 0); |
53 | 55 | runKernel<GPUMemClean16>(GetGridAutoStep(0, RecoStep::TPCCompression), CompressorShadow.mClusterStatus, Compressor.mMaxClusters * sizeof(CompressorShadow.mClusterStatus[0])); |
54 | 56 | runKernel<GPUTPCCompressionKernels, GPUTPCCompressionKernels::step0attached>(GetGridAuto(0)); |
| 57 | + if (GetProcessingSettings().tpcWriteClustersAfterRejection) { |
| 58 | + WriteReducedClusters(); |
| 59 | + } |
55 | 60 | runKernel<GPUTPCCompressionKernels, GPUTPCCompressionKernels::step1unattached>(GetGridAuto(0)); |
56 | 61 | TransferMemoryResourcesToHost(myStep, &Compressor, 0); |
57 | 62 | #ifdef GPUCA_TPC_GEOMETRY_O2 |
@@ -434,3 +439,56 @@ int32_t GPUChainTracking::RunTPCDecompression() |
434 | 439 | DoDebugDump(GPUChainTrackingDebugFlags::TPCDecompressedClusters, &GPUChainTracking::DumpClusters, *mDebugFile, mIOPtrs.clustersNative); |
435 | 440 | return 0; |
436 | 441 | } |
| 442 | + |
| 443 | +void GPUChainTracking::WriteReducedClusters() |
| 444 | +{ |
| 445 | + GPUTPCCompression& Compressor = processors()->tpcCompressor; |
| 446 | + mClusterNativeAccessReduced = std::make_unique<ClusterNativeAccess>(); |
| 447 | + uint32_t nOutput = 0; |
| 448 | + for (uint32_t iSec = 0; iSec < GPUCA_NSECTORS; iSec++) { |
| 449 | + for (uint32_t iRow = 0; iRow < GPUCA_ROW_COUNT; iRow++) { |
| 450 | + mClusterNativeAccessReduced->nClusters[iSec][iRow] = 0; |
| 451 | + for (uint32_t i = 0; i < mIOPtrs.clustersNative->nClusters[iSec][iRow]; i++) { |
| 452 | + mClusterNativeAccessReduced->nClusters[iSec][iRow] += !Compressor.rejectCluster(mIOPtrs.clustersNative->clusterOffset[iSec][iRow] + i, param(), mIOPtrs); |
| 453 | + } |
| 454 | + nOutput += mClusterNativeAccessReduced->nClusters[iSec][iRow]; |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + GPUOutputControl* clOutput = mSubOutputControls[GPUTrackingOutputs::getIndex(&GPUTrackingOutputs::clustersNative)]; |
| 459 | + if (!clOutput || !clOutput->allocator) { |
| 460 | + throw std::runtime_error("No output allocator for clusterNative available"); |
| 461 | + } |
| 462 | + auto* clBuffer = (ClusterNative*)clOutput->allocator(nOutput * sizeof(ClusterNative)); |
| 463 | + mClusterNativeAccessReduced->clustersLinear = clBuffer; |
| 464 | + mClusterNativeAccessReduced->setOffsetPtrs(); |
| 465 | + |
| 466 | + std::pair<o2::dataformats::ConstMCLabelContainer*, o2::dataformats::ConstMCLabelContainerView*> labelBuffer; |
| 467 | + if (mIOPtrs.clustersNative->clustersMCTruth) { |
| 468 | + GPUOutputControl* labelOutput = mSubOutputControls[GPUTrackingOutputs::getIndex(&GPUTrackingOutputs::clusterLabels)]; |
| 469 | + if (!labelOutput || !labelOutput->allocator) { |
| 470 | + throw std::runtime_error("No output allocator for clusterNative labels available"); |
| 471 | + } |
| 472 | + ClusterNativeAccess::ConstMCLabelContainerViewWithBuffer* labelContainer = reinterpret_cast<ClusterNativeAccess::ConstMCLabelContainerViewWithBuffer*>(labelOutput->allocator(0)); |
| 473 | + labelBuffer = {&labelContainer->first, &labelContainer->second}; |
| 474 | + } |
| 475 | + |
| 476 | + nOutput = 0; |
| 477 | + o2::dataformats::MCLabelContainer tmpContainer; |
| 478 | + for (uint32_t i = 0; i < mIOPtrs.clustersNative->nClustersTotal; i++) { |
| 479 | + if (!Compressor.rejectCluster(i, param(), mIOPtrs)) { |
| 480 | + if (mIOPtrs.clustersNative->clustersMCTruth) { |
| 481 | + for (const auto& element : mIOPtrs.clustersNative->clustersMCTruth->getLabels(i)) { |
| 482 | + tmpContainer.addElement(nOutput, element); |
| 483 | + } |
| 484 | + } |
| 485 | + clBuffer[nOutput++] = mIOPtrs.clustersNative->clustersLinear[i]; |
| 486 | + } |
| 487 | + } |
| 488 | + mIOPtrs.clustersNativeReduced = mClusterNativeAccessReduced.get(); |
| 489 | + if (mIOPtrs.clustersNative->clustersMCTruth) { |
| 490 | + tmpContainer.flatten_to(*labelBuffer.first); |
| 491 | + *labelBuffer.second = *labelBuffer.first; |
| 492 | + mClusterNativeAccessReduced->clustersMCTruth = labelBuffer.second; |
| 493 | + } |
| 494 | +} |
0 commit comments