|
20 | 20 | #include <map> |
21 | 21 | #include <memory> |
22 | 22 | #include <string> |
| 23 | +#include <numeric> |
23 | 24 |
|
24 | 25 | #ifdef GPUCA_TRACKLET_CONSTRUCTOR_DO_PROFILE |
25 | 26 | #include "bitmapfile.h" |
@@ -348,3 +349,44 @@ void GPUChainTracking::DumpClusters(std::ostream& out, const o2::tpc::ClusterNat |
348 | 349 | } |
349 | 350 | } |
350 | 351 | } |
| 352 | + |
| 353 | +void GPUChainTracking::DebugSortCompressedClusters(o2::tpc::CompressedClustersFlat* cls) |
| 354 | +{ |
| 355 | + o2::tpc::CompressedClusters c = *cls; |
| 356 | + std::vector<uint32_t> sorted(c.nTracks), offsets(c.nTracks); |
| 357 | + std::iota(sorted.begin(), sorted.end(), 0); |
| 358 | + auto sorter = [&c](const auto a, const auto b) { |
| 359 | + return std::tie(c.sliceA[a], c.rowA[a], c.timeA[a], c.padA[a], c.qPtA[a]) < |
| 360 | + std::tie(c.sliceA[b], c.rowA[b], c.timeA[b], c.padA[b], c.qPtA[b]); |
| 361 | + }; |
| 362 | + std::sort(sorted.begin(), sorted.end(), sorter); |
| 363 | + uint32_t offset = 0; |
| 364 | + for (uint32_t i = 0; i < c.nTracks; i++) { |
| 365 | + offsets[i] = offset; |
| 366 | + offset += c.nTrackClusters[i]; |
| 367 | + } |
| 368 | + |
| 369 | + auto sortArray = [&c, &sorted, &offsets](auto* src, size_t totalSize, auto getOffset, auto getSize) { |
| 370 | + auto buf = std::make_unique<std::remove_reference_t<decltype(src[0])>[]>(totalSize); |
| 371 | + memcpy(buf.get(), src, totalSize * sizeof(*src)); |
| 372 | + uint32_t targetOffset = 0; |
| 373 | + for (uint32_t i = 0; i < c.nTracks; i++) { |
| 374 | + const uint32_t j = sorted[i]; |
| 375 | + memcpy(src + targetOffset, buf.get() + getOffset(offsets[j], j), getSize(j) * sizeof(*src)); |
| 376 | + targetOffset += getSize(j); |
| 377 | + } |
| 378 | + }; |
| 379 | + auto sortMultiple = [&sortArray](size_t totalSize, auto getOffset, auto getSize, auto&&... arrays) { |
| 380 | + (..., sortArray(std::forward<decltype(arrays)>(arrays), totalSize, getOffset, getSize)); |
| 381 | + }; |
| 382 | + auto getFullOffset = [](uint32_t off, uint32_t ind) { return off; }; |
| 383 | + auto getReducedOffset = [](uint32_t off, uint32_t ind) { return off - ind; }; |
| 384 | + auto getIndex = [](uint32_t off, uint32_t ind) { return ind; }; |
| 385 | + auto getN = [&c](uint32_t j) { return c.nTrackClusters[j]; }; |
| 386 | + auto getN1 = [&c](uint32_t j) { return c.nTrackClusters[j] - 1; }; |
| 387 | + auto get1 = [](uint32_t j) { return 1; }; |
| 388 | + |
| 389 | + sortMultiple(c.nAttachedClusters, getFullOffset, getN, c.qTotA, c.qMaxA, c.flagsA, c.sigmaPadA, c.sigmaTimeA); |
| 390 | + sortMultiple(c.nAttachedClustersReduced, getReducedOffset, getN1, c.rowDiffA, c.sliceLegDiffA, c.padResA, c.timeResA); |
| 391 | + sortMultiple(c.nTracks, getIndex, get1, c.qPtA, c.rowA, c.sliceA, c.timeA, c.padA, c.nTrackClusters); // NOTE: This must be last, since nTrackClusters is used for handling the arrays above! |
| 392 | +} |
0 commit comments