Skip to content

Commit f1c8ce7

Browse files
authored
Flatten cell neighbours structure (#12121)
1 parent ce9b4ea commit f1c8ce7

File tree

3 files changed

+36
-23
lines changed

3 files changed

+36
-23
lines changed

Detectors/ITSMFT/ITS/tracking/include/ITStracking/TimeFrame.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ class TimeFrame
156156
std::vector<std::vector<float>>& getCellSeedsChi2() { return mCellSeedsChi2; }
157157

158158
std::vector<std::vector<int>>& getCellsLookupTable();
159-
std::vector<std::vector<std::vector<int>>>& getCellsNeighbours();
159+
std::vector<std::vector<int>>& getCellsNeighbours();
160+
std::vector<std::vector<int>>& getCellsNeighboursLUT();
160161
std::vector<Road<5>>& getRoads();
161162
std::vector<TrackITSExt>& getTracks(int rof) { return mTracks[rof]; }
162163
std::vector<MCCompLabel>& getTracksLabel(const int rof) { return mTracksLabel[rof]; }
@@ -256,7 +257,8 @@ class TimeFrame
256257
std::vector<std::vector<o2::track::TrackParCovF>> mCellSeeds;
257258
std::vector<std::vector<float>> mCellSeedsChi2;
258259
std::vector<std::vector<int>> mCellsLookupTable;
259-
std::vector<std::vector<std::vector<int>>> mCellsNeighbours;
260+
std::vector<std::vector<int>> mCellsNeighbours;
261+
std::vector<std::vector<int>> mCellsNeighboursLUT;
260262
std::vector<Road<5>> mRoads;
261263
std::vector<std::vector<MCCompLabel>> mTracksLabel;
262264
std::vector<std::vector<TrackITSExt>> mTracks;
@@ -550,10 +552,8 @@ inline std::vector<std::vector<int>>& TimeFrame::getCellsLookupTable()
550552
return mCellsLookupTable;
551553
}
552554

553-
inline std::vector<std::vector<std::vector<int>>>& TimeFrame::getCellsNeighbours()
554-
{
555-
return mCellsNeighbours;
556-
}
555+
inline std::vector<std::vector<int>>& TimeFrame::getCellsNeighbours() { return mCellsNeighbours; }
556+
inline std::vector<std::vector<int>>& TimeFrame::getCellsNeighboursLUT() { return mCellsNeighboursLUT; }
557557

558558
inline std::vector<Road<5>>& TimeFrame::getRoads() { return mRoads; }
559559

Detectors/ITSMFT/ITS/tracking/src/TimeFrame.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ void TimeFrame::initialise(const int iteration, const TrackingParameters& trkPar
266266
mCellSeedsChi2.resize(trkParam.CellsPerRoad());
267267
mCellsLookupTable.resize(trkParam.CellsPerRoad() - 1);
268268
mCellsNeighbours.resize(trkParam.CellsPerRoad() - 1);
269+
mCellsNeighboursLUT.resize(trkParam.CellsPerRoad() - 1);
269270
mCellLabels.resize(trkParam.CellsPerRoad());
270271
mTracklets.resize(std::min(trkParam.TrackletsPerRoad(), maxLayers - 1));
271272
mTrackletLabels.resize(trkParam.TrackletsPerRoad());
@@ -406,6 +407,7 @@ void TimeFrame::initialise(const int iteration, const TrackingParameters& trkPar
406407
if (iLayer < (int)mCells.size() - 1) {
407408
mCellsLookupTable[iLayer].clear();
408409
mCellsNeighbours[iLayer].clear();
410+
mCellsNeighboursLUT[iLayer].clear();
409411
}
410412
}
411413
}
@@ -420,9 +422,7 @@ unsigned long TimeFrame::getArtefactsMemory()
420422
size += sizeof(Cell) * cells.size();
421423
}
422424
for (auto& cellsN : mCellsNeighbours) {
423-
for (auto& vec : cellsN) {
424-
size += sizeof(int) * vec.size();
425-
}
425+
size += sizeof(int) * cellsN.size();
426426
}
427427
return size + sizeof(Road<5>) * mRoads.size();
428428
}

Detectors/ITSMFT/ITS/tracking/src/TrackerTraits.cxx

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "ITStracking/TrackerTraits.h"
1717

18+
#include <algorithm>
1819
#include <cassert>
1920
#include <iostream>
2021

@@ -394,8 +395,13 @@ void TrackerTraits::findCellsNeighbours(const int iteration)
394395

395396
int layerCellsNum{static_cast<int>(mTimeFrame->getCells()[iLayer].size())};
396397
const int nextLayerCellsNum{static_cast<int>(mTimeFrame->getCells()[iLayer + 1].size())};
397-
mTimeFrame->getCellsNeighbours()[iLayer].resize(nextLayerCellsNum);
398398

399+
mTimeFrame->getCellsNeighboursLUT()[iLayer].clear();
400+
mTimeFrame->getCellsNeighboursLUT()[iLayer].resize(nextLayerCellsNum, 0);
401+
std::vector<std::pair<int, int>> cellsNeighbours;
402+
cellsNeighbours.reserve(nextLayerCellsNum);
403+
404+
std::vector<std::vector<int>> easyWay(nextLayerCellsNum);
399405
for (int iCell{0}; iCell < layerCellsNum; ++iCell) {
400406

401407
const Cell& currentCell{mTimeFrame->getCells()[iLayer][iCell]};
@@ -426,15 +432,25 @@ void TrackerTraits::findCellsNeighbours(const int iteration)
426432
continue;
427433
}
428434

429-
mTimeFrame->getCellsNeighbours()[iLayer][iNextCell].push_back(iCell);
430-
435+
mTimeFrame->getCellsNeighboursLUT()[iLayer][iNextCell]++;
436+
cellsNeighbours.push_back(std::make_pair(iCell, iNextCell));
437+
easyWay[iNextCell].push_back(iCell);
431438
const int currentCellLevel{currentCell.getLevel()};
432439

433440
if (currentCellLevel >= nextCell.getLevel()) {
434441
nextCell.setLevel(currentCellLevel + 1);
435442
}
436443
}
437444
}
445+
std::sort(cellsNeighbours.begin(), cellsNeighbours.end(), [](const std::pair<int, int>& a, const std::pair<int, int>& b) {
446+
return a.second < b.second;
447+
});
448+
mTimeFrame->getCellsNeighbours()[iLayer].clear();
449+
mTimeFrame->getCellsNeighbours()[iLayer].reserve(cellsNeighbours.size());
450+
for (auto& cellNeighboursIndex : cellsNeighbours) {
451+
mTimeFrame->getCellsNeighbours()[iLayer].push_back(cellNeighboursIndex.first);
452+
}
453+
std::inclusive_scan(mTimeFrame->getCellsNeighboursLUT()[iLayer].begin(), mTimeFrame->getCellsNeighboursLUT()[iLayer].end(), mTimeFrame->getCellsNeighboursLUT()[iLayer].begin());
438454
}
439455
}
440456

@@ -457,11 +473,11 @@ void TrackerTraits::findRoads(const int iteration)
457473
if (iLevel == 1) {
458474
continue;
459475
}
460-
const int cellNeighboursNum{static_cast<int>(
461-
mTimeFrame->getCellsNeighbours()[iLayer - 1][iCell].size())};
476+
const int startNeighbourId{iCell ? mTimeFrame->getCellsNeighboursLUT()[iLayer - 1][iCell - 1] : 0};
477+
const int endNeighbourId{mTimeFrame->getCellsNeighboursLUT()[iLayer - 1][iCell]};
462478
bool isFirstValidNeighbour = true;
463-
for (int iNeighbourCell{0}; iNeighbourCell < cellNeighboursNum; ++iNeighbourCell) {
464-
const int neighbourCellId = mTimeFrame->getCellsNeighbours()[iLayer - 1][iCell][iNeighbourCell];
479+
for (int iNeighbourCell{startNeighbourId}; iNeighbourCell < endNeighbourId; ++iNeighbourCell) {
480+
const int neighbourCellId = mTimeFrame->getCellsNeighbours()[iLayer - 1][iNeighbourCell];
465481
const Cell& neighbourCell = mTimeFrame->getCells()[iLayer - 1][neighbourCellId];
466482
if (iLevel - 1 != neighbourCell.getLevel()) {
467483
continue;
@@ -973,14 +989,11 @@ void TrackerTraits::traverseCellsTree(const int currentCellId, const int current
973989
mTimeFrame->getRoads().back().addCell(currentLayerId, currentCellId);
974990

975991
if (currentLayerId > 0 && currentCellLevel > 1) {
976-
const int cellNeighboursNum{static_cast<int>(
977-
mTimeFrame->getCellsNeighbours()[currentLayerId - 1][currentCellId].size())};
978992
bool isFirstValidNeighbour = true;
979-
980-
for (int iNeighbourCell{0}; iNeighbourCell < cellNeighboursNum; ++iNeighbourCell) {
981-
982-
const int neighbourCellId =
983-
mTimeFrame->getCellsNeighbours()[currentLayerId - 1][currentCellId][iNeighbourCell];
993+
const int startNeighbourId = currentCellId ? mTimeFrame->getCellsNeighboursLUT()[currentLayerId - 1][currentCellId - 1] : 0;
994+
const int endNeighbourId = mTimeFrame->getCellsNeighboursLUT()[currentLayerId - 1][currentCellId];
995+
for (int iNeighbourCell{startNeighbourId}; iNeighbourCell < endNeighbourId; ++iNeighbourCell) {
996+
const int neighbourCellId = mTimeFrame->getCellsNeighbours()[currentLayerId - 1][iNeighbourCell];
984997
const Cell& neighbourCell = mTimeFrame->getCells()[currentLayerId - 1][neighbourCellId];
985998

986999
if (currentCellLevel - 1 != neighbourCell.getLevel()) {

0 commit comments

Comments
 (0)