Skip to content

Commit b8250cd

Browse files
authored
[O2-3671] ITS-tracking: make road a template class (#11209)
* ITS-tracking: make road a template class * Remove unused mLabel, further shrink size member
1 parent d66f402 commit b8250cd

12 files changed

Lines changed: 104 additions & 93 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ inline static const o2::itsmft::ChipMappingITS& getChipMappingITS()
7373
}
7474

7575
std::vector<std::unordered_map<int, Label>> loadLabels(const int, const std::string&);
76-
void writeRoadsReport(std::ofstream&, std::ofstream&, std::ofstream&, const std::vector<std::vector<Road>>&,
76+
void writeRoadsReport(std::ofstream&, std::ofstream&, std::ofstream&, const std::vector<std::vector<Road<5>>>&,
7777
const std::unordered_map<int, Label>&);
7878

7979
template <class iterator, typename T>

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

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
/// \brief
1414
///
1515

16-
#ifndef TRACKINGITSU_INCLUDE_ROAD_H_
17-
#define TRACKINGITSU_INCLUDE_ROAD_H_
16+
#ifndef TRACKINGCA_INCLUDE_ROAD_H
17+
#define TRACKINGCA_INCLUDE_ROAD_H
1818

1919
#ifndef GPUCA_GPUCODE_DEVICE
2020
#include <array>
@@ -28,11 +28,12 @@ namespace o2
2828
namespace its
2929
{
3030

31+
template <unsigned char maxRoadSize = 5>
3132
class Road final
3233
{
3334
public:
34-
Road();
35-
Road(int, int);
35+
GPUhd() Road() : mCellIds{}, mRoadSize{}, mIsFakeRoad{} { resetRoad(); }
36+
GPUhd() Road(int cellLayer, int cellId) : Road() { addCell(cellLayer, cellId); }
3637

3738
int getRoadSize() const;
3839
int getLabel() const;
@@ -41,30 +42,66 @@ class Road final
4142
void setFakeRoad(const bool);
4243
GPUhdni() int& operator[](const int&);
4344

44-
void resetRoad();
45-
void addCell(int, int);
45+
GPUhd() void resetRoad()
46+
{
47+
for (int i = 0; i < maxRoadSize; i++) {
48+
mCellIds[i] = constants::its::UnusedIndex;
49+
}
50+
mRoadSize = 0;
51+
}
4652

47-
static constexpr int mMaxRoadSize = 13;
53+
GPUhd() void addCell(int cellLayer, int cellId)
54+
{
55+
if (mCellIds[cellLayer] == constants::its::UnusedIndex) {
56+
++mRoadSize;
57+
}
58+
59+
mCellIds[cellLayer] = cellId;
60+
}
4861

4962
private:
50-
int mCellIds[mMaxRoadSize];
51-
int mRoadSize;
52-
int mLabel;
63+
int mCellIds[maxRoadSize];
64+
// int mLabel;
65+
unsigned char mRoadSize;
5366
bool mIsFakeRoad;
5467
};
5568

56-
inline int Road::getRoadSize() const { return mRoadSize; }
57-
58-
inline int Road::getLabel() const { return mLabel; }
59-
60-
inline void Road::setLabel(const int label) { mLabel = label; }
61-
62-
GPUhdi() int& Road::operator[](const int& i) { return mCellIds[i]; }
69+
template <unsigned char maxRoadSize>
70+
inline int Road<maxRoadSize>::getRoadSize() const
71+
{
72+
return mRoadSize;
73+
}
74+
75+
// template <unsigned char maxRoadSize>
76+
// inline int Road<maxRoadSize>::getLabel() const
77+
// {
78+
// return mLabel;
79+
// }
80+
81+
// template <unsigned char maxRoadSize>
82+
// inline void Road<maxRoadSize>::setLabel(const int label)
83+
// {
84+
// mLabel = label;
85+
// }
86+
87+
template <unsigned char maxRoadSize>
88+
GPUhdi() int& Road<maxRoadSize>::operator[](const int& i)
89+
{
90+
return mCellIds[i];
91+
}
6392

64-
inline bool Road::isFakeRoad() const { return mIsFakeRoad; }
93+
template <unsigned char maxRoadSize>
94+
inline bool Road<maxRoadSize>::isFakeRoad() const
95+
{
96+
return mIsFakeRoad;
97+
}
6598

66-
inline void Road::setFakeRoad(const bool isFakeRoad) { mIsFakeRoad = isFakeRoad; }
99+
template <unsigned char maxRoadSize>
100+
inline void Road<maxRoadSize>::setFakeRoad(const bool isFakeRoad)
101+
{
102+
mIsFakeRoad = isFakeRoad;
103+
}
67104
} // namespace its
68105
} // namespace o2
69106

70-
#endif /* TRACKINGITSU_INCLUDE_ROAD_H_ */
107+
#endif

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class TimeFrame
153153
std::vector<std::vector<Cell>>& getCells();
154154
std::vector<std::vector<int>>& getCellsLookupTable();
155155
std::vector<std::vector<std::vector<int>>>& getCellsNeighbours();
156-
std::vector<Road>& getRoads();
156+
std::vector<Road<5>>& getRoads();
157157
std::vector<TrackITSExt>& getTracks(int rof) { return mTracks[rof]; }
158158
std::vector<MCCompLabel>& getTracksLabel(const int rof) { return mTracksLabel[rof]; }
159159
std::vector<MCCompLabel>& getLinesLabel(const int rof) { return mLinesLabels[rof]; }
@@ -247,7 +247,7 @@ class TimeFrame
247247
std::vector<std::vector<Cell>> mCells;
248248
std::vector<std::vector<int>> mCellsLookupTable;
249249
std::vector<std::vector<std::vector<int>>> mCellsNeighbours;
250-
std::vector<Road> mRoads;
250+
std::vector<Road<5>> mRoads;
251251
std::vector<std::vector<MCCompLabel>> mTracksLabel;
252252
std::vector<std::vector<TrackITSExt>> mTracks;
253253
std::vector<int> mBogusClusters; /// keep track of clusters with wild coordinates
@@ -538,7 +538,7 @@ inline std::vector<std::vector<std::vector<int>>>& TimeFrame::getCellsNeighbours
538538
return mCellsNeighbours;
539539
}
540540

541-
inline std::vector<Road>& TimeFrame::getRoads() { return mRoads; }
541+
inline std::vector<Road<5>>& TimeFrame::getRoads() { return mRoads; }
542542

543543
inline gsl::span<Tracklet> TimeFrame::getFoundTracklets(int rofId, int combId)
544544
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ namespace its
4646
{
4747

4848
class TrackITSExt;
49-
typedef std::function<int(o2::gpu::GPUChainITS&, std::vector<Road>& roads, std::vector<const Cluster*>&, std::vector<const Cell*>&, const std::vector<std::vector<TrackingFrameInfo>>&, std::vector<TrackITSExt>&)> FuncRunITSTrackFit_t;
49+
typedef std::function<int(o2::gpu::GPUChainITS&, std::vector<Road<5>>& roads, std::vector<const Cluster*>&, std::vector<const Cell*>&, const std::vector<std::vector<TrackingFrameInfo>>&, std::vector<TrackITSExt>&)> FuncRunITSTrackFit_t;
5050

5151
class TrackerTraits
5252
{

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

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,52 +194,52 @@ std::vector<std::unordered_map<int, Label>> ioutils::loadLabels(const int events
194194
return labelsMap;
195195
}
196196

197-
void ioutils::writeRoadsReport(std::ofstream& correctRoadsOutputStream, std::ofstream& duplicateRoadsOutputStream,
198-
std::ofstream& fakeRoadsOutputStream, const std::vector<std::vector<Road>>& roads,
199-
const std::unordered_map<int, Label>& labelsMap)
200-
{
201-
const int numVertices{static_cast<int>(roads.size())};
202-
std::unordered_set<int> foundMonteCarloIds{};
197+
// void ioutils::writeRoadsReport(std::ofstream& correctRoadsOutputStream, std::ofstream& duplicateRoadsOutputStream,
198+
// std::ofstream& fakeRoadsOutputStream, const std::vector<std::vector<Road<5>>>& roads,
199+
// const std::unordered_map<int, Label>& labelsMap)
200+
// {
201+
// const int numVertices{static_cast<int>(roads.size())};
202+
// std::unordered_set<int> foundMonteCarloIds{};
203203

204-
correctRoadsOutputStream << EventLabelsSeparator << std::endl;
205-
fakeRoadsOutputStream << EventLabelsSeparator << std::endl;
204+
// correctRoadsOutputStream << EventLabelsSeparator << std::endl;
205+
// fakeRoadsOutputStream << EventLabelsSeparator << std::endl;
206206

207-
for (int iVertex{0}; iVertex < numVertices; ++iVertex) {
207+
// for (int iVertex{0}; iVertex < numVertices; ++iVertex) {
208208

209-
const std::vector<Road>& currentVertexRoads{roads[iVertex]};
210-
const int numRoads{static_cast<int>(currentVertexRoads.size())};
209+
// const std::vector<Road<5>>& currentVertexRoads{roads[iVertex]};
210+
// const int numRoads{static_cast<int>(currentVertexRoads.size())};
211211

212-
for (int iRoad{0}; iRoad < numRoads; ++iRoad) {
212+
// for (int iRoad{0}; iRoad < numRoads; ++iRoad) {
213213

214-
const Road& currentRoad{currentVertexRoads[iRoad]};
215-
const int currentRoadLabel{currentRoad.getLabel()};
214+
// const Road<5>& currentRoad{currentVertexRoads[iRoad]};
215+
// const int currentRoadLabel{currentRoad.getLabel()};
216216

217-
if (!labelsMap.count(currentRoadLabel)) {
217+
// if (!labelsMap.count(currentRoadLabel)) {
218218

219-
continue;
220-
}
219+
// continue;
220+
// }
221221

222-
const Label& currentLabel{labelsMap.at(currentRoadLabel)};
222+
// const Label& currentLabel{labelsMap.at(currentRoadLabel)};
223223

224-
if (currentRoad.isFakeRoad()) {
224+
// if (currentRoad.isFakeRoad()) {
225225

226-
fakeRoadsOutputStream << currentLabel << std::endl;
226+
// fakeRoadsOutputStream << currentLabel << std::endl;
227227

228-
} else {
228+
// } else {
229229

230-
if (foundMonteCarloIds.count(currentLabel.monteCarloId)) {
230+
// if (foundMonteCarloIds.count(currentLabel.monteCarloId)) {
231231

232-
duplicateRoadsOutputStream << currentLabel << std::endl;
232+
// duplicateRoadsOutputStream << currentLabel << std::endl;
233233

234-
} else {
234+
// } else {
235235

236-
correctRoadsOutputStream << currentLabel << std::endl;
237-
foundMonteCarloIds.emplace(currentLabel.monteCarloId);
238-
}
239-
}
240-
}
241-
}
242-
}
236+
// correctRoadsOutputStream << currentLabel << std::endl;
237+
// foundMonteCarloIds.emplace(currentLabel.monteCarloId);
238+
// }
239+
// }
240+
// }
241+
// }
242+
// }
243243

244244
} // namespace its
245245
} // namespace o2

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,11 @@
88
// In applying this license CERN does not waive the privileges and immunities
99
// granted to it by virtue of its status as an Intergovernmental Organization
1010
// or submit itself to any jurisdiction.
11-
///
12-
/// \file Road.cxx
13-
/// \brief
14-
///
1511

1612
#include "ITStracking/Road.h"
17-
#include <cassert>
18-
#include <iostream>
19-
2013
namespace o2
2114
{
2215
namespace its
2316
{
24-
25-
Road::Road() : mCellIds{}, mRoadSize{}, mIsFakeRoad{} { resetRoad(); }
26-
27-
Road::Road(int cellLayer, int cellId) : Road() { addCell(cellLayer, cellId); }
28-
29-
void Road::resetRoad()
30-
{
31-
for (int i = 0; i < mMaxRoadSize; i++) {
32-
mCellIds[i] = constants::its::UnusedIndex;
33-
}
34-
mRoadSize = 0;
35-
}
36-
37-
void Road::addCell(int cellLayer, int cellId)
38-
{
39-
if (mCellIds[cellLayer] == constants::its::UnusedIndex) {
40-
++mRoadSize;
41-
}
42-
43-
mCellIds[cellLayer] = cellId;
44-
}
4517
} // namespace its
4618
} // namespace o2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ unsigned long TimeFrame::getArtefactsMemory()
409409
size += sizeof(int) * vec.size();
410410
}
411411
}
412-
return size + sizeof(Road) * mRoads.size();
412+
return size + sizeof(Road<5>) * mRoads.size();
413413
}
414414

415415
void TimeFrame::fillPrimaryVerticesXandAlpha()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ void Tracker::computeRoadsMClabels()
153153

154154
for (int iRoad{0}; iRoad < roadsNum; ++iRoad) {
155155

156-
Road& currentRoad{mTimeFrame->getRoads()[iRoad]};
156+
Road<5>& currentRoad{mTimeFrame->getRoads()[iRoad]};
157157
std::vector<std::pair<MCCompLabel, size_t>> occurrences;
158158
bool isFakeRoad{false};
159159
bool isFirstRoadCell{true};

GPU/GPUTracking/Global/GPUChainITS.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,13 @@ int GPUChainITS::Finalize() { return 0; }
7676

7777
int GPUChainITS::RunChain() { return 0; }
7878

79-
int GPUChainITS::PrepareAndRunITSTrackFit(std::vector<o2::its::Road>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks)
79+
int GPUChainITS::PrepareAndRunITSTrackFit(std::vector<o2::its::Road<5>>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks)
8080
{
8181
mRec->PrepareEvent();
8282
return RunITSTrackFit(roads, clusters, cells, tf, tracks);
8383
}
8484

85-
int GPUChainITS::RunITSTrackFit(std::vector<o2::its::Road>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks)
85+
int GPUChainITS::RunITSTrackFit(std::vector<o2::its::Road<5>>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks)
8686
{
8787
auto threadContext = GetThreadContext();
8888
bool doGPU = GetRecoStepsGPU() & RecoStep::ITSTracking;

GPU/GPUTracking/Global/GPUChainITS.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
namespace o2::its
2020
{
2121
struct Cluster;
22+
template <unsigned char N>
2223
class Road;
2324
class Cell;
2425
struct TrackingFrameInfo;
@@ -41,8 +42,8 @@ class GPUChainITS : public GPUChain
4142
int RunChain() override;
4243
void MemorySize(size_t& gpuMem, size_t& pageLockedHostMem) override;
4344

44-
int PrepareAndRunITSTrackFit(std::vector<o2::its::Road>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks);
45-
int RunITSTrackFit(std::vector<o2::its::Road>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks);
45+
int PrepareAndRunITSTrackFit(std::vector<o2::its::Road<5>>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks);
46+
int RunITSTrackFit(std::vector<o2::its::Road<5>>& roads, std::vector<const o2::its::Cluster*>& clusters, std::vector<const o2::its::Cell*>& cells, const std::vector<std::vector<o2::its::TrackingFrameInfo>>& tf, std::vector<o2::its::TrackITSExt>& tracks);
4647

4748
o2::its::TrackerTraits* GetITSTrackerTraits();
4849
o2::its::VertexerTraits* GetITSVertexerTraits();

0 commit comments

Comments
 (0)