Skip to content

Commit a130e7b

Browse files
committed
ITS: fix various different heapoverflows
1 parent dbb8144 commit a130e7b

File tree

5 files changed

+58
-66
lines changed

5 files changed

+58
-66
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ enum RecoIterationSteps : uint16_t {
113113
kUpdateVertexTable, // update the vertex table for the current pool of vertices
114114
kUpdateClusters, // update the cluster position wrt current beam constraint
115115
kInitMemory, // initialize all vectors to use memory resource
116-
kInitOnce, // initialize some object once
117116
};
118117

119118
struct RecoIteration {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct TimeFrame {
106106
int getTotalClustersPerROFrange(int rofMin, int range, int layerId) const;
107107
int getSortedIndex(int rofId, int layer, int idx) const { return mROFramesClusters[layer][rofId] + idx; }
108108
int getSortedStartIndex(const int rofId, const int layer) const { return mROFramesClusters[layer][rofId]; }
109-
int getNrof(int layer) const { return mROFramesClusters[layer].size(); }
109+
int getNrof(int layer) const { return mROFramesClusters[layer].size() - 1; }
110110

111111
auto& getMinRs() { return mMinR; }
112112
auto& getMaxRs() { return mMaxR; }
@@ -294,16 +294,16 @@ struct TimeFrame {
294294
std::array<float, 3> mMeanVertexXYInvErr;
295295
std::array<float, NLayers> mMinR;
296296
std::array<float, NLayers> mMaxR;
297-
bounded_vector<float> mMSangles;
298-
bounded_vector<float> mPhiCuts;
299-
bounded_vector<float> mPositionResolution;
297+
std::array<float, NLayers> mMSangles;
298+
std::array<float, NLayers - 1> mPhiCuts;
299+
std::array<float, NLayers> mPositionResolution;
300300
std::array<bounded_vector<uint8_t>, NLayers> mClusterSize;
301301

302302
bounded_vector<std::array<float, 2>> mPValphaX; /// PV x and alpha for track propagation
303303
std::vector<bounded_vector<MCCompLabel>> mTrackletLabels;
304304
std::vector<bounded_vector<MCCompLabel>> mCellLabels;
305305
std::vector<bounded_vector<int>> mCellsNeighboursLUT;
306-
bounded_vector<int> mBogusClusters; /// keep track of clusters with wild coordinates
306+
std::array<uint32_t, NLayers> mBogusClusters; /// keep track of clusters with wild coordinates
307307

308308
// lookup tables
309309
IndexTableUtilsN mIndexTableUtils;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ std::vector<RecoIteration> TrackingMode::getRecoIterations(TrackingMode::Type mo
274274
recoIterations[0].params.MaxChi2NDF = 40.;
275275
}
276276

277-
recoIterations[0].steps.set(kInitOnce); // always init some object once
278277
return recoIterations;
279278
}
280279

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void TimeFrame<NLayers>::resetROFrameData(size_t nRofs, int layer)
117117
deepVectorClear(mUnsortedClusters[iLayer], getMaybeExternalHostResource());
118118
deepVectorClear(mTrackingFrameInfo[iLayer], getMaybeExternalHostResource());
119119
deepVectorClear(mClusterExternalIndices[iLayer], mMemoryPool.get());
120-
clearResizeBoundedVector(mROFramesClusters[iLayer], nRofs, getMaybeExternalHostResource());
120+
clearResizeBoundedVector(mROFramesClusters[iLayer], nRofs + 1, getMaybeExternalHostResource());
121121
}
122122
}
123123

@@ -214,6 +214,7 @@ void TimeFrame<NLayers>::initialise(const RecoIteration& reco)
214214
{
215215
const auto& trkParam = reco.params;
216216
if (reco.steps[kInitMemory]) {
217+
mBogusClusters.fill(0); // reset bogus counter for this TF
217218
clearResizeBoundedVector(mCells, trkParam.CellsPerRoad(), mMemoryPool.get());
218219
clearResizeBoundedVector(mCellsLookupTable, trkParam.CellsPerRoad() - 1, mMemoryPool.get());
219220
clearResizeBoundedVector(mCellsNeighbours, trkParam.CellsPerRoad() - 1, mMemoryPool.get());
@@ -223,17 +224,14 @@ void TimeFrame<NLayers>::initialise(const RecoIteration& reco)
223224
clearResizeBoundedVector(mTrackletLabels, trkParam.TrackletsPerRoad(), mMemoryPool.get());
224225
clearResizeBoundedVector(mTrackletsLookupTable, trkParam.TrackletsPerRoad(), mMemoryPool.get());
225226
mIndexTableUtils.setTrackingParameters(trkParam);
226-
clearResizeBoundedVector(mPositionResolution, trkParam.NLayers, mMemoryPool.get());
227-
clearResizeBoundedVector(mBogusClusters, trkParam.NLayers, mMemoryPool.get());
228-
for (unsigned int iLayer{0}; iLayer < (int)mClusters.size(); ++iLayer) {
227+
for (int iLayer{0}; iLayer < trkParam.NLayers; ++iLayer) {
229228
clearResizeBoundedVector(mClusters[iLayer], mUnsortedClusters[iLayer].size(), getMaybeExternalHostResource());
230229
clearResizeBoundedVector(mUsedClusters[iLayer], mUnsortedClusters[iLayer].size(), getMaybeExternalHostResource());
231-
mPositionResolution[iLayer] = o2::gpu::CAMath::Sqrt(0.5f * (trkParam.SystErrorZ2[iLayer] + trkParam.SystErrorY2[iLayer]) + trkParam.LayerResolution[iLayer] * trkParam.LayerResolution[iLayer]);
232230
if (iLayer < (int)mCells.size()) {
233231
mTrackletsLookupTable[iLayer].resize(mClusters[iLayer + 1].size() + 1, 0);
234232
}
235233
}
236-
for (unsigned int iLayer{0}; iLayer < (int)mClusters.size(); ++iLayer) {
234+
for (int iLayer{0}; iLayer < NLayers; ++iLayer) {
237235
clearResizeBoundedVector(mIndexTables[iLayer], getNrof(iLayer) * ((trkParam.ZBins * trkParam.PhiBins) + 1), getMaybeExternalHostResource());
238236
}
239237
for (int iLayer{0}; iLayer < trkParam.NLayers; ++iLayer) {
@@ -251,13 +249,16 @@ void TimeFrame<NLayers>::initialise(const RecoIteration& reco)
251249
if (reco.steps[kUpdateClusters]) {
252250
prepareClusters(trkParam, reco.params.NLayers);
253251
}
254-
mMSangles.resize(trkParam.NLayers);
255-
mPhiCuts.resize(mClusters.size() - 1, 0.f);
252+
253+
// these change dynamically with the given tracking parameters
254+
mMSangles.fill(0.f);
255+
mPhiCuts.fill(0.f);
256+
mPositionResolution.fill(0.f);
256257
float oneOverR{0.001f * 0.3f * std::abs(mBz) / trkParam.TrackletMinPt};
257-
for (unsigned int iLayer{0}; iLayer < NLayers; ++iLayer) {
258+
for (int iLayer{0}; iLayer < trkParam.NLayers; ++iLayer) {
258259
mMSangles[iLayer] = math_utils::MSangle(0.14f, trkParam.TrackletMinPt, trkParam.LayerxX0[iLayer]);
259260
mPositionResolution[iLayer] = o2::gpu::CAMath::Sqrt(0.5f * (trkParam.SystErrorZ2[iLayer] + trkParam.SystErrorY2[iLayer]) + trkParam.LayerResolution[iLayer] * trkParam.LayerResolution[iLayer]);
260-
if (iLayer < mClusters.size() - 1) {
261+
if (iLayer < trkParam.NLayers - 1) {
261262
const float r1 = trkParam.LayerRadii[iLayer];
262263
const float r2 = trkParam.LayerRadii[iLayer + 1];
263264
const float res1 = mPositionResolution[iLayer];
@@ -270,7 +271,8 @@ void TimeFrame<NLayers>::initialise(const RecoIteration& reco)
270271
}
271272
}
272273

273-
if (reco.steps[kInitOnce]) {
274+
if (static bool initOnce{false}; !initOnce) {
275+
initOnce = true;
274276
// initialise the rolling vertex once with large weights
275277
mRollingVertex.setX(0.f);
276278
mRollingVertex.setY(0.f);
@@ -346,12 +348,8 @@ void TimeFrame<NLayers>::setMemoryPool(std::shared_ptr<BoundedMemoryResource> po
346348
initContainers(mClusterExternalIndices);
347349
initVector(mPrimaryVertices);
348350
initVector(mRoads);
349-
initVector(mMSangles);
350-
initVector(mPhiCuts);
351-
initVector(mPositionResolution);
352351
initContainers(mClusterSize);
353352
initVector(mPValphaX);
354-
initVector(mBogusClusters);
355353
initVector(mTracks);
356354
initContainers(mTracklets);
357355
initContainers(mCells);
@@ -383,12 +381,8 @@ void TimeFrame<NLayers>::wipe()
383381
deepVectorClear(mPrimaryVertices);
384382
deepVectorClear(mTrackletsLookupTable);
385383
deepVectorClear(mClusterExternalIndices);
386-
deepVectorClear(mMSangles);
387-
deepVectorClear(mPhiCuts);
388-
deepVectorClear(mPositionResolution);
389384
deepVectorClear(mClusterSize);
390385
deepVectorClear(mPValphaX);
391-
deepVectorClear(mBogusClusters);
392386
// if we use the external host allocator then the assumption is that we
393387
// don't clear the memory ourself
394388
if (!hasExternalHostAllocator()) {

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

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -467,46 +467,46 @@ void TrackerTraits<NLayers>::findCellSeeds(const int iteration)
467467

468468
/// DEBUG OUTPUT
469469
// dump cells and pot. their labels
470-
LOGP(info, "dumping cell seed candidates");
471-
auto ts = new utils::TreeStreamRedirector("cells.root");
472-
auto& s = (*ts) << "seeding";
473-
for (int iCell{0}; iCell < cells.size(); ++iCell) {
474-
auto cell = cells[iCell];
475-
dataformats::VertexBase vtx;
476-
dataformats::DCA dca;
477-
float z = cell.getZAt(0., getBz());
478-
if (z < -999.f) {
479-
z = mTimeFrame->getMeanVertex().getZ();
480-
}
481-
if (mTimeFrame->hasMeanVertex()) { // account for slope
482-
mTimeFrame->getMeanVertexConstraint()->setMeanXYVertexAtZ(vtx, z);
483-
}
484-
const auto& cls = cell.getClusters();
485-
const int sta = cell.getUserField();
486-
int startBC = std::numeric_limits<int>::max(), endBC = std::numeric_limits<int>::min();
487-
for (int i{sta}; i < 3; ++i) {
488-
int rof = mTimeFrame->getClusterROF(i, cls[i]);
489-
int rofStartBC = mTimeFrame->getROFOverlapTableView().getLayer(i).getROFStartInBC(rof);
490-
int rofEndBC = mTimeFrame->getROFOverlapTableView().getLayer(i).getROFEndInBC(rof);
491-
startBC = o2::gpu::CAMath::Min(startBC, rofStartBC);
492-
endBC = o2::gpu::CAMath::Max(endBC, rofEndBC);
493-
}
494-
auto cellC = cell;
495-
if (propagator->propagateToDCA(vtx, cellC, getBz(), 2.0f, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca, nullptr, 0, mRecoParams[iteration].params.SeedingDCATolerance)) {
496-
s << "cell=" << (const o2::track::TrackParCov&)cell
497-
<< "cellPV=" << (o2::track::TrackParCov)cellC
498-
<< "vtx=" << vtx
499-
<< "staBC=" << startBC
500-
<< "endBC=" << endBC;
501-
if (mTimeFrame->hasMCinformation() && mRecoParams[iteration].params.createArtefactLabels) {
502-
s << "cellLbl=" << mTimeFrame->getCellsLabel(0)[iCell];
503-
}
504-
s << "\n";
505-
}
506-
}
507-
ts->Close();
508-
delete ts;
509-
ts = nullptr;
470+
// LOGP(info, "dumping cell seed candidates");
471+
// auto ts = new utils::TreeStreamRedirector("cells.root");
472+
// auto& s = (*ts) << "seeding";
473+
// for (int iCell{0}; iCell < cells.size(); ++iCell) {
474+
// auto cell = cells[iCell];
475+
// dataformats::VertexBase vtx;
476+
// dataformats::DCA dca;
477+
// float z = cell.getZAt(0., getBz());
478+
// if (z < -999.f) {
479+
// z = mTimeFrame->getMeanVertex().getZ();
480+
// }
481+
// if (mTimeFrame->hasMeanVertex()) { // account for slope
482+
// mTimeFrame->getMeanVertexConstraint()->setMeanXYVertexAtZ(vtx, z);
483+
// }
484+
// const auto& cls = cell.getClusters();
485+
// const int sta = cell.getUserField();
486+
// int startBC = std::numeric_limits<int>::max(), endBC = std::numeric_limits<int>::min();
487+
// for (int i{sta}; i < 3; ++i) {
488+
// int rof = mTimeFrame->getClusterROF(i, cls[i]);
489+
// int rofStartBC = mTimeFrame->getROFOverlapTableView().getLayer(i).getROFStartInBC(rof);
490+
// int rofEndBC = mTimeFrame->getROFOverlapTableView().getLayer(i).getROFEndInBC(rof);
491+
// startBC = o2::gpu::CAMath::Min(startBC, rofStartBC);
492+
// endBC = o2::gpu::CAMath::Max(endBC, rofEndBC);
493+
// }
494+
// auto cellC = cell;
495+
// if (propagator->propagateToDCA(vtx, cellC, getBz(), 2.0f, o2::base::Propagator::MatCorrType::USEMatCorrLUT, &dca, nullptr, 0, mRecoParams[iteration].params.SeedingDCATolerance)) {
496+
// s << "cell=" << (const o2::track::TrackParCov&)cell
497+
// << "cellPV=" << (o2::track::TrackParCov)cellC
498+
// << "vtx=" << vtx
499+
// << "staBC=" << startBC
500+
// << "endBC=" << endBC;
501+
// if (mTimeFrame->hasMCinformation() && mRecoParams[iteration].params.createArtefactLabels) {
502+
// s << "cellLbl=" << mTimeFrame->getCellsLabel(0)[iCell];
503+
// }
504+
// s << "\n";
505+
// }
506+
// }
507+
// ts->Close();
508+
// delete ts;
509+
// ts = nullptr;
510510

511511
mTaskArena->execute([&] {
512512
// we get cells from the first three layers

0 commit comments

Comments
 (0)