Skip to content

Commit fdab6db

Browse files
authored
ITS: make clang-tidy happy (#14372)
* ITS: selective clang-tidy finds Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch> * ITS: IOUtils remove obsolte functions --------- Signed-off-by: Felix Schlepper <felix.schlepper@cern.ch>
1 parent 3d2a03c commit fdab6db

File tree

12 files changed

+49
-152
lines changed

12 files changed

+49
-152
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ inline static const o2::itsmft::ChipMappingITS& getChipMappingITS()
7272
return MP;
7373
}
7474

75-
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<5>>>&,
77-
const std::unordered_map<int, Label>&);
78-
7975
template <class iterator, typename T>
8076
o2::math_utils::Point3D<T> extractClusterData(const itsmft::CompClusterExt& c, iterator& iter, const itsmft::TopologyDictionary* dict, T& sig2y, T& sig2z)
8177
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ struct TimeFrame {
333333
bounded_vector<int> mBogusClusters; /// keep track of clusters with wild coordinates
334334

335335
bounded_vector<std::pair<unsigned long long, bool>> mRoadLabels;
336-
int mCutClusterMult;
337-
int mCutVertexMult;
336+
int mCutClusterMult{-999};
337+
int mCutVertexMult{-999};
338338

339339
// Vertexer
340340
std::vector<bounded_vector<int>> mNTrackletsPerROF;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ class Tracker
6363
void adoptTimeFrame(TimeFrame<NLayers>& tf);
6464

6565
void clustersToTracks(
66-
LogFunc = [](const std::string& s) { std::cout << s << '\n'; },
67-
LogFunc = [](const std::string& s) { std::cerr << s << '\n'; });
66+
const LogFunc& = [](const std::string& s) { std::cout << s << '\n'; },
67+
const LogFunc& = [](const std::string& s) { std::cerr << s << '\n'; });
6868

6969
void setParameters(const std::vector<TrackingParameters>& p) { mTrkParams = p; }
7070
void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool) { mMemoryPool = pool; }
@@ -113,7 +113,7 @@ class Tracker
113113
Roading,
114114
NStates,
115115
};
116-
State mCurState;
116+
State mCurState{TFInit};
117117
static constexpr std::array<const char*, NStates> StateNames{"TimeFrame initialisation", "Tracklet finding", "Cell finding", "Neighbour finding", "Road finding"};
118118
};
119119

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Vertexer
106106
Finding,
107107
NStates,
108108
};
109-
State mCurState;
109+
State mCurState{Init};
110110
static constexpr std::array<const char*, NStates> StateNames{"Initialisation", "Tracklet finding", "Tracklet validation", "Vertex finding"};
111111
};
112112

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ class VertexerTraits
8686
bounded_vector<o2::MCCompLabel>*,
8787
const int iteration = 0);
8888

89-
const bounded_vector<std::pair<int, int>> selectClusters(const int* indexTable,
90-
const std::array<int, 4>& selectedBinsRect,
91-
const IndexTableUtils& utils);
89+
bounded_vector<std::pair<int, int>> selectClusters(const int* indexTable,
90+
const std::array<int, 4>& selectedBinsRect,
91+
const IndexTableUtils& utils);
9292

9393
// utils
9494
auto& getVertexingParameters() { return mVrtParams; }

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ using namespace o2::its;
2424

2525
using math_utils::computePhi;
2626
using math_utils::getNormalizedPhi;
27-
using math_utils::hypot;
2827

2928
Cluster::Cluster(const float x, const float y, const float z, const int index)
3029
: xCoordinate{x},

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

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515

1616
#include "ITStracking/IOUtils.h"
1717

18+
#include <gsl/span>
19+
#include <vector>
20+
#include <array>
21+
#include <string>
1822
#include <iostream>
1923
#include <cstdlib>
2024
#include <fstream>
2125
#include <sstream>
2226
#include <tuple>
23-
#include <unordered_set>
2427
#include <utility>
2528

2629
#include "ITSBase/GeometryTGeo.h"
@@ -35,10 +38,7 @@ constexpr int PrimaryVertexLayerId{-1};
3538
constexpr int EventLabelsSeparator{-1};
3639
} // namespace
3740

38-
namespace o2
39-
{
40-
namespace its
41-
{
41+
using namespace o2::its;
4242

4343
/// convert compact clusters to 3D spacepoints
4444
void ioutils::convertCompactClusters(gsl::span<const itsmft::CompClusterExt> clusters,
@@ -57,8 +57,8 @@ void ioutils::convertCompactClusters(gsl::span<const itsmft::CompClusterExt> clu
5757
}
5858
}
5959

60-
for (auto& c : clusters) {
61-
float sigmaY2, sigmaZ2, sigmaYZ = 0;
60+
for (const auto& c : clusters) {
61+
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
6262
auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
6363
auto& cl3d = output.emplace_back(c.getSensorID(), geom->getMatrixT2L(c.getSensorID()) ^ locXYZ); // local --> tracking
6464
if (applyMisalignment) {
@@ -83,9 +83,9 @@ void ioutils::loadEventData(ROframe& event, gsl::span<const itsmft::CompClusterE
8383
geom->fillMatrixCache(o2::math_utils::bit2Mask(o2::math_utils::TransformType::T2L, o2::math_utils::TransformType::L2G));
8484
int clusterId{0};
8585

86-
for (auto& c : clusters) {
87-
int layer = geom->getLayer(c.getSensorID());
88-
float sigmaY2, sigmaZ2, sigmaYZ = 0;
86+
for (const auto& c : clusters) {
87+
const int layer = geom->getLayer(c.getSensorID());
88+
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
8989
auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
9090
auto sensorID = c.getSensorID();
9191
// Inverse transformation to the local --> tracking
@@ -118,9 +118,9 @@ int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe& event, g
118118

119119
auto first = rof.getFirstEntry();
120120
auto clusters_in_frame = rof.getROFData(clusters);
121-
for (auto& c : clusters_in_frame) {
122-
int layer = geom->getLayer(c.getSensorID());
123-
float sigmaY2, sigmaZ2, sigmaYZ = 0;
121+
for (const auto& c : clusters_in_frame) {
122+
const int layer = geom->getLayer(c.getSensorID());
123+
float sigmaY2{0}, sigmaZ2{0}, sigmaYZ{0};
124124
auto locXYZ = extractClusterData(c, pattIt, dict, sigmaY2, sigmaZ2);
125125
auto sensorID = c.getSensorID();
126126
// Inverse transformation to the local --> tracking
@@ -141,100 +141,5 @@ int ioutils::loadROFrameData(const o2::itsmft::ROFRecord& rof, ROframe& event, g
141141
event.addClusterExternalIndexToLayer(layer, first + clusterId);
142142
clusterId++;
143143
}
144-
return clusters_in_frame.size();
144+
return (int)clusters_in_frame.size();
145145
}
146-
147-
std::vector<std::unordered_map<int, Label>> ioutils::loadLabels(const int eventsNum, const std::string& fileName)
148-
{
149-
std::vector<std::unordered_map<int, Label>> labelsMap{};
150-
std::unordered_map<int, Label> currentEventLabelsMap{};
151-
std::ifstream inputStream{};
152-
std::string line{};
153-
int monteCarloId{}, pdgCode{}, numberOfClusters{};
154-
float transverseMomentum{}, phi{}, pseudorapidity{};
155-
156-
labelsMap.reserve(eventsNum);
157-
158-
inputStream.open(fileName);
159-
std::getline(inputStream, line);
160-
161-
while (std::getline(inputStream, line)) {
162-
163-
std::istringstream inputStringStream(line);
164-
165-
if (inputStringStream >> monteCarloId) {
166-
167-
if (monteCarloId == EventLabelsSeparator) {
168-
169-
labelsMap.emplace_back(currentEventLabelsMap);
170-
currentEventLabelsMap.clear();
171-
172-
} else {
173-
174-
if (inputStringStream >> transverseMomentum >> phi >> pseudorapidity >> pdgCode >> numberOfClusters) {
175-
176-
if (std::abs(pdgCode) == constants::pdgcodes::PionCode && numberOfClusters == 7) {
177-
178-
currentEventLabelsMap.emplace(std::piecewise_construct, std::forward_as_tuple(monteCarloId),
179-
std::forward_as_tuple(monteCarloId, transverseMomentum, phi,
180-
pseudorapidity, pdgCode, numberOfClusters));
181-
}
182-
}
183-
}
184-
}
185-
}
186-
187-
labelsMap.emplace_back(currentEventLabelsMap);
188-
189-
return labelsMap;
190-
}
191-
192-
// void ioutils::writeRoadsReport(std::ofstream& correctRoadsOutputStream, std::ofstream& duplicateRoadsOutputStream,
193-
// std::ofstream& fakeRoadsOutputStream, const std::vector<std::vector<Road<5>>>& roads,
194-
// const std::unordered_map<int, Label>& labelsMap)
195-
// {
196-
// const int numVertices{static_cast<int>(roads.size())};
197-
// std::unordered_set<int> foundMonteCarloIds{};
198-
199-
// correctRoadsOutputStream << EventLabelsSeparator << std::endl;
200-
// fakeRoadsOutputStream << EventLabelsSeparator << std::endl;
201-
202-
// for (int iVertex{0}; iVertex < numVertices; ++iVertex) {
203-
204-
// const std::vector<Road<5>>& currentVertexRoads{roads[iVertex]};
205-
// const int numRoads{static_cast<int>(currentVertexRoads.size())};
206-
207-
// for (int iRoad{0}; iRoad < numRoads; ++iRoad) {
208-
209-
// const Road<5>& currentRoad{currentVertexRoads[iRoad]};
210-
// const int currentRoadLabel{currentRoad.getLabel()};
211-
212-
// if (!labelsMap.count(currentRoadLabel)) {
213-
214-
// continue;
215-
// }
216-
217-
// const Label& currentLabel{labelsMap.at(currentRoadLabel)};
218-
219-
// if (currentRoad.isFakeRoad()) {
220-
221-
// fakeRoadsOutputStream << currentLabel << std::endl;
222-
223-
// } else {
224-
225-
// if (foundMonteCarloIds.count(currentLabel.monteCarloId)) {
226-
227-
// duplicateRoadsOutputStream << currentLabel << std::endl;
228-
229-
// } else {
230-
231-
// correctRoadsOutputStream << currentLabel << std::endl;
232-
// foundMonteCarloIds.emplace(currentLabel.monteCarloId);
233-
// }
234-
// }
235-
// }
236-
// }
237-
// }
238-
239-
} // namespace its
240-
} // namespace o2

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void TimeFrame<nLayers>::addPrimaryVertices(const bounded_vector<Vertex>& vertic
7474
for (const auto& vertex : vertices) {
7575
mPrimaryVertices.emplace_back(vertex);
7676
if (!isBeamPositionOverridden) {
77-
const int w{vertex.getNContributors()};
77+
const float w = vertex.getNContributors();
7878
mBeamPos[0] = (mBeamPos[0] * mBeamPosWeight + vertex.getX() * w) / (mBeamPosWeight + w);
7979
mBeamPos[1] = (mBeamPos[1] * mBeamPosWeight + vertex.getY() * w) / (mBeamPosWeight + w);
8080
mBeamPosWeight += w;
@@ -126,7 +126,7 @@ void TimeFrame<nLayers>::addPrimaryVertices(const gsl::span<const Vertex>& verti
126126
mPrimaryVertices.emplace_back(vertex); // put a copy in the present
127127
mTotVertPerIteration[iteration]++;
128128
if (!isBeamPositionOverridden) { // beam position is updated only at first occurrence of the vertex. A bit sketchy if we have past/future vertices, it should not impact too much.
129-
const int w{vertex.getNContributors()};
129+
const float w = vertex.getNContributors();
130130
mBeamPos[0] = (mBeamPos[0] * mBeamPosWeight + vertex.getX() * w) / (mBeamPosWeight + w);
131131
mBeamPos[1] = (mBeamPos[1] * mBeamPosWeight + vertex.getY() * w) / (mBeamPosWeight + w);
132132
mBeamPosWeight += w;
@@ -166,7 +166,7 @@ int TimeFrame<nLayers>::loadROFrameData(gsl::span<o2::itsmft::ROFRecord> rofs,
166166
clearResizeBoundedVector(mClusterSize, clusters.size(), mMemoryPool.get());
167167
for (auto& rof : rofs) {
168168
for (int clusterId{rof.getFirstEntry()}; clusterId < rof.getFirstEntry() + rof.getNEntries(); ++clusterId) {
169-
auto& c = clusters[clusterId];
169+
const auto& c = clusters[clusterId];
170170

171171
int layer = geom->getLayer(c.getSensorID());
172172

@@ -280,7 +280,7 @@ void TimeFrame<nLayers>::prepareClusters(const TrackingParameters& trkParam, con
280280
c.radius = h.r;
281281
c.indexTableBinIndex = h.bin;
282282
}
283-
for (unsigned int iB{0}; iB < clsPerBin.size(); ++iB) {
283+
for (int iB{0}; iB < (int)clsPerBin.size(); ++iB) {
284284
mIndexTables[iLayer][rof * (trkParam.ZBins * trkParam.PhiBins + 1) + iB] = lutPerBin[iB];
285285
}
286286
for (auto iB{clsPerBin.size()}; iB < (trkParam.ZBins * trkParam.PhiBins + 1); iB++) {
@@ -374,7 +374,7 @@ void TimeFrame<nLayers>::initialise(const int iteration, const TrackingParameter
374374
const float cosTheta1half = o2::gpu::CAMath::Sqrt(1.f - Sq(0.5f * r1 * oneOverR));
375375
const float cosTheta2half = o2::gpu::CAMath::Sqrt(1.f - Sq(0.5f * r2 * oneOverR));
376376
float x = r2 * cosTheta1half - r1 * cosTheta2half;
377-
float delta = o2::gpu::CAMath::Sqrt(1. / (1.f - 0.25f * Sq(x * oneOverR)) * (Sq(0.25f * r1 * r2 * Sq(oneOverR) / cosTheta2half + cosTheta1half) * Sq(res1) + Sq(0.25f * r1 * r2 * Sq(oneOverR) / cosTheta1half + cosTheta2half) * Sq(res2)));
377+
float delta = o2::gpu::CAMath::Sqrt(1.f / (1.f - 0.25f * Sq(x * oneOverR)) * (Sq(0.25f * r1 * r2 * Sq(oneOverR) / cosTheta2half + cosTheta1half) * Sq(res1) + Sq(0.25f * r1 * r2 * Sq(oneOverR) / cosTheta1half + cosTheta2half) * Sq(res2)));
378378
mPhiCuts[iLayer] = std::min(o2::gpu::CAMath::ASin(0.5f * x * oneOverR) + 2.f * mMSangles[iLayer] + delta, constants::math::Pi * 0.5f);
379379
}
380380
}
@@ -401,13 +401,13 @@ template <int nLayers>
401401
unsigned long TimeFrame<nLayers>::getArtefactsMemory() const
402402
{
403403
unsigned long size{0};
404-
for (auto& trkl : mTracklets) {
404+
for (const auto& trkl : mTracklets) {
405405
size += sizeof(Tracklet) * trkl.size();
406406
}
407-
for (auto& cells : mCells) {
407+
for (const auto& cells : mCells) {
408408
size += sizeof(CellSeed) * cells.size();
409409
}
410-
for (auto& cellsN : mCellsNeighbours) {
410+
for (const auto& cellsN : mCellsNeighbours) {
411411
size += sizeof(int) * cellsN.size();
412412
}
413413
return size + sizeof(Road<nLayers - 2>) * mRoads.size();
@@ -422,9 +422,7 @@ void TimeFrame<nLayers>::printArtefactsMemory() const
422422
template <int nLayers>
423423
void TimeFrame<nLayers>::fillPrimaryVerticesXandAlpha()
424424
{
425-
if (mPValphaX.size()) {
426-
mPValphaX.clear();
427-
}
425+
deepVectorClear(mPValphaX);
428426
mPValphaX.reserve(mPrimaryVertices.size());
429427
for (auto& pv : mPrimaryVertices) {
430428
mPValphaX.emplace_back(std::array<float, 2>{o2::gpu::CAMath::Hypot(pv.getX(), pv.getY()), math_utils::computePhi(pv.getX(), pv.getY())});

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Tracker::Tracker(TrackerTraits7* traits) : mTraits(traits)
4141
mTrkParams.resize(1);
4242
}
4343

44-
void Tracker::clustersToTracks(LogFunc logger, LogFunc error)
44+
void Tracker::clustersToTracks(const LogFunc& logger, const LogFunc& error)
4545
{
4646
LogFunc evalLog = [](const std::string&) {};
4747

@@ -195,7 +195,7 @@ void Tracker::computeRoadsMClabels()
195195
bool found{false};
196196
for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
197197
std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
198-
for (auto& label : cl0labs) {
198+
for (const auto& label : cl0labs) {
199199
if (label == occurrence.first) {
200200
++occurrence.second;
201201
found = true;
@@ -204,7 +204,7 @@ void Tracker::computeRoadsMClabels()
204204
}
205205
}
206206
if (!found) {
207-
for (auto& label : cl0labs) {
207+
for (const auto& label : cl0labs) {
208208
occurrences.emplace_back(label, 1);
209209
}
210210
}
@@ -277,7 +277,7 @@ void Tracker::computeTracksMClabels()
277277
bool found{false};
278278
for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
279279
std::pair<o2::MCCompLabel, size_t>& occurrence = occurrences[iOcc];
280-
for (auto& label : labels) {
280+
for (const auto& label : labels) {
281281
if (label == occurrence.first) {
282282
++occurrence.second;
283283
found = true;
@@ -286,7 +286,7 @@ void Tracker::computeTracksMClabels()
286286
}
287287
}
288288
if (!found) {
289-
for (auto& label : labels) {
289+
for (const auto& label : labels) {
290290
occurrences.emplace_back(label, 1);
291291
}
292292
}
@@ -302,7 +302,7 @@ void Tracker::computeTracksMClabels()
302302
auto clid = track.getClusterIndex(ic);
303303
if (clid != constants::its::UnusedIndex) {
304304
auto labelsSpan = mTimeFrame->getClusterLabels(ic, clid);
305-
for (auto& currentLabel : labelsSpan) {
305+
for (const auto& currentLabel : labelsSpan) {
306306
if (currentLabel == maxOccurrencesValue) {
307307
pattern |= 0x1 << (16 + ic); // set bit if correct
308308
break;
@@ -335,7 +335,7 @@ void Tracker::rectifyClusterIndices()
335335

336336
void Tracker::getGlobalConfiguration()
337337
{
338-
auto& tc = o2::its::TrackerParamConfig::Instance();
338+
const auto& tc = o2::its::TrackerParamConfig::Instance();
339339
if (tc.useMatCorrTGeo) {
340340
mTraits->setCorrType(o2::base::PropagatorImpl<float>::MatCorrType::USEMatCorrTGeo);
341341
} else if (tc.useFastMaterial) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void TrackerTraits<nLayers>::computeLayerTracklets(const int iteration, int iROF
101101
const float inverseR0{1.f / currentCluster.radius};
102102

103103
for (int iV{startVtx}; iV < endVtx; ++iV) {
104-
auto& primaryVertex{primaryVertices[iV]};
104+
const auto& primaryVertex{primaryVertices[iV]};
105105
if (primaryVertex.isFlagSet(2) && iteration != 3) {
106106
continue;
107107
}
@@ -830,8 +830,8 @@ void TrackerTraits<nLayers>::findRoads(const int iteration)
830830
mTaskArena.execute([&] {
831831
bounded_vector<int> perSeedCount(trackSeeds.size() + 1, 0, mMemoryPool.get());
832832
tbb::parallel_for(
833-
tbb::blocked_range<size_t>(size_t(0), trackSeeds.size()),
834-
[&](const tbb::blocked_range<size_t>& Seeds) {
833+
tbb::blocked_range<int>(0, (int)trackSeeds.size()),
834+
[&](const tbb::blocked_range<int>& Seeds) {
835835
for (int iSeed = Seeds.begin(); iSeed < Seeds.end(); ++iSeed) {
836836
const CellSeed& seed{trackSeeds[iSeed]};
837837
TrackITSExt temporaryTrack{seed};

0 commit comments

Comments
 (0)