3535#include " ITStracking/Tracklet.h"
3636#include " ITStracking/IndexTableUtils.h"
3737#include " ITStracking/ExternalAllocator.h"
38+ #include " ITStracking/BoundedAllocator.h"
3839
3940#include " SimulationDataFormat/MCCompLabel.h"
4041#include " SimulationDataFormat/MCTruthContainer.h"
@@ -59,6 +60,37 @@ class ROFRecord;
5960
6061namespace its
6162{
63+
64+ template <typename T>
65+ void deepVectorClear (std::vector<T>& vec)
66+ {
67+ std::vector<T>().swap (vec);
68+ }
69+
70+ template <typename T>
71+ void deepVectorClear (BoundedVector<T>& vec)
72+ {
73+ vec = BoundedVector<T>(vec.get_allocator ().resource ());
74+ }
75+
76+ template <typename T>
77+ void deepVectorClear (std::vector<BoundedVector<T>>& vec)
78+ {
79+ for (auto & v : vec) {
80+ v = BoundedVector<T>(v.get_allocator ().resource ());
81+ }
82+ }
83+
84+ template <typename T>
85+ void clearResizeBoundedVector (std::vector<BoundedVector<T>>& vec, size_t size, BoundedMemoryResource* bmr)
86+ {
87+ vec.clear ();
88+ vec.reserve (size);
89+ for (size_t i{0 }; i < size; ++i) {
90+ vec.emplace_back (bmr);
91+ }
92+ }
93+
6294using Vertex = o2::dataformats::Vertex<o2::dataformats::TimeStamp<int >>;
6395
6496template <int nLayers = 7 >
@@ -164,8 +196,8 @@ struct TimeFrame {
164196 auto & getCellsLookupTable () { return mCellsLookupTable ; }
165197 auto & getCellsNeighbours () { return mCellsNeighbours ; }
166198 auto & getCellsNeighboursLUT () { return mCellsNeighboursLUT ; }
167- std::vector<Road<nLayers - 2 >> & getRoads () { return mRoads ; }
168- std::vector<TrackITSExt> & getTracks (int rofId) { return mTracks [rofId]; }
199+ auto & getRoads () { return mRoads ; }
200+ auto & getTracks (int rofId) { return mTracks [rofId]; }
169201 std::vector<MCCompLabel>& getTracksLabel (const int rofId) { return mTracksLabel [rofId]; }
170202 std::vector<MCCompLabel>& getLinesLabel (const int rofId) { return mLinesLabels [rofId]; }
171203 std::vector<std::pair<MCCompLabel, float >>& getVerticesMCRecInfo () { return mVerticesMCRecInfo ; }
@@ -179,8 +211,12 @@ struct TimeFrame {
179211 auto getNumberOfExtendedTracks () const { return mNExtendedTracks ; }
180212 auto getNumberOfUsedExtendedClusters () const { return mNExtendedUsedClusters ; }
181213
214+ void setMemoryPool (std::shared_ptr<BoundedMemoryResource>& pool) { mMemoryPool = pool; }
215+ auto & getMemoryPool () const noexcept { return mMemoryPool ; }
216+ bool usesMemoryPool () const noexcept { return true ; }
182217 bool checkMemory (unsigned long max) { return getArtefactsMemory () < max; }
183- unsigned long getArtefactsMemory ();
218+ unsigned long getArtefactsMemory () const ;
219+ void printArtefactsMemory () const ;
184220 int getROFCutClusterMult () const { return mCutClusterMult ; };
185221 int getROFCutVertexMult () const { return mCutVertexMult ; };
186222 int getROFCutAllMult () const { return mCutClusterMult + mCutVertexMult ; }
@@ -189,7 +225,7 @@ struct TimeFrame {
189225 void computeTrackletsPerROFScans ();
190226 void computeTracletsPerClusterScans ();
191227 int & getNTrackletsROF (int rofId, int combId) { return mNTrackletsPerROF [combId][rofId]; }
192- std::vector<Line> & getLines (int rofId) { return mLines [rofId]; }
228+ auto & getLines (int rofId) { return mLines [rofId]; }
193229 int getNLinesTotal () const
194230 {
195231 return std::accumulate (mLines .begin (), mLines .end (), 0 , [](int sum, const auto & l) { return sum + l.size (); });
@@ -234,6 +270,7 @@ struct TimeFrame {
234270 void addClusterExternalIndexToLayer (int layer, const int idx) { mClusterExternalIndices [layer].push_back (idx); }
235271
236272 void resetVectors ();
273+ void resetTracklets ();
237274
238275 // / Debug and printing
239276 void checkTrackletLUTs ();
@@ -279,29 +316,32 @@ struct TimeFrame {
279316 }
280317 }
281318
282- std::array<std::vector <Cluster>, nLayers> mUnsortedClusters ;
283- std::vector<std::vector <Tracklet>> mTracklets ;
284- std::vector<std::vector <CellSeed>> mCells ;
285- std::vector<std::vector <o2::track::TrackParCovF>> mCellSeeds ;
286- std::vector<std::vector <float >> mCellSeedsChi2 ;
287- std::vector <Road<nLayers - 2 >> mRoads ;
288- std::vector<std::vector <TrackITSExt>> mTracks ;
289- std::vector<std::vector <int >> mCellsNeighbours ;
290- std::vector<std::vector <int >> mCellsLookupTable ;
319+ std::array<BoundedVector <Cluster>, nLayers> mUnsortedClusters ;
320+ std::vector<BoundedVector <Tracklet>> mTracklets ;
321+ std::vector<BoundedVector <CellSeed>> mCells ;
322+ std::vector<BoundedVector <o2::track::TrackParCovF>> mCellSeeds ;
323+ std::vector<BoundedVector <float >> mCellSeedsChi2 ;
324+ BoundedVector <Road<nLayers - 2 >> mRoads ;
325+ std::vector<BoundedVector <TrackITSExt>> mTracks ;
326+ std::vector<BoundedVector <int >> mCellsNeighbours ;
327+ std::vector<BoundedVector <int >> mCellsLookupTable ;
291328 std::vector<uint8_t > mMultiplicityCutMask ;
292329
293330 const o2::base::PropagatorImpl<float >* mPropagatorDevice = nullptr ; // Needed only for GPU
294- void dropTracks ()
331+
332+ void wipe ()
295333 {
296- for (auto & v : mTracks ) {
334+ for (auto & v : mUnsortedClusters ) {
297335 deepVectorClear (v);
298336 }
299- }
300-
301- template <typename T>
302- void deepVectorClear (std::vector<T>& vec)
303- {
304- std::vector<T>().swap (vec);
337+ deepVectorClear (mTracks );
338+ deepVectorClear (mTracklets );
339+ deepVectorClear (mCells );
340+ deepVectorClear (mCellSeeds );
341+ deepVectorClear (mCellSeedsChi2 );
342+ deepVectorClear (mRoads );
343+ deepVectorClear (mCellsNeighbours );
344+ deepVectorClear (mCellsLookupTable );
305345 }
306346
307347 virtual void prepareClusters (const TrackingParameters& trkParam, const int maxLayers);
@@ -341,11 +381,16 @@ struct TimeFrame {
341381 unsigned int mNoVertexROF = 0 ;
342382 std::vector<int > mTotVertPerIteration ;
343383 // \Vertexer
384+
385+ std::shared_ptr<BoundedMemoryResource> mMemoryPool ;
344386};
345387
346388template <int nLayers>
347389inline gsl::span<const Vertex> TimeFrame<nLayers>::getPrimaryVertices(int rofId) const
348390{
391+ if (mPrimaryVertices .empty ()) {
392+ return {};
393+ }
349394 const int start = mROFramesPV [rofId];
350395 const int stop_idx = rofId >= mNrof - 1 ? mNrof : rofId + 1 ;
351396 int delta = mMultiplicityCutMask [rofId] ? mROFramesPV [stop_idx] - start : 0 ; // return empty span if Rof is excluded
@@ -364,6 +409,9 @@ inline gsl::span<const std::pair<MCCompLabel, float>> TimeFrame<nLayers>::getPri
364409template <int nLayers>
365410inline gsl::span<const Vertex> TimeFrame<nLayers>::getPrimaryVertices(int romin, int romax) const
366411{
412+ if (mPrimaryVertices .empty ()) {
413+ return {};
414+ }
367415 return {&mPrimaryVertices [mROFramesPV [romin]], static_cast <gsl::span<const Vertex>::size_type>(mROFramesPV [romax + 1 ] - mROFramesPV [romin])};
368416}
369417
0 commit comments