Project
Loading...
Searching...
No Matches
Tracker.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
15
16#ifndef TRACKINGITSU_INCLUDE_TRACKER_H_
17#define TRACKINGITSU_INCLUDE_TRACKER_H_
18
19#include <array>
20#include <chrono>
21#include <fstream>
22#include <iomanip>
23#include <iosfwd>
24#include <memory>
25#include <string_view>
26#include <utility>
27#include <sstream>
28#include <vector>
29
30#include <oneapi/tbb/task_arena.h>
31
37
38namespace o2
39{
40
41namespace gpu
42{
43class GPUChainITS;
44}
45namespace its
46{
47
48template <int NLayers>
50{
51 using LogFunc = std::function<void(const std::string& s)>;
52
53 public:
55
57
58 float clustersToTracks(
59 const LogFunc& = [](const std::string& s) { std::cout << s << '\n'; },
60 const LogFunc& = [](const std::string& s) { std::cerr << s << '\n'; });
61
62 // Self-contained seeding-vertex phase (own TimeFrame init + own timer), run before clustersToTracks.
64 const LogFunc& = [](const std::string& s) { std::cout << s << '\n'; });
65
66 void setParameters(const std::vector<TrackingParameters>& p) { mTrkParams = p; }
67 void setMemoryPool(std::shared_ptr<BoundedMemoryResource> pool) { mMemoryPool = pool; }
68 std::vector<TrackingParameters>& getParameters() { return mTrkParams; }
69 void setBz(float bz) { mTraits->setBz(bz); }
70 void setTimeSlice(size_t slice) noexcept { mTimeSlice = slice; }
71 void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena) { mTraits->setNThreads(n, arena); }
72 void printSummary() const;
74
75 private:
76 void initialiseTimeFrame(int iteration) { mTraits->initialiseTimeFrame(iteration); }
77 void computeTracklets(int iteration, int iVertex) { mTraits->computeLayerTracklets(iteration, iVertex); }
78 void computeCells(int iteration) { mTraits->computeLayerCells(iteration); }
79 void computeVertexCandidates(int iteration) { mTraits->computeVertexCandidates(iteration); }
80 void computeBeamFromVertices(int iteration) { mTraits->computeBeamFromVertices(iteration); }
81 void computeVertices(int iteration) { mTraits->computeVertices(iteration); }
82 void findCellsNeighbours(int iteration) { mTraits->findCellsNeighbours(iteration); }
83 void findRoads(int iteration) { mTraits->findRoads(iteration); }
84
85 void rectifyClusterIndices();
86 void sortTracks();
87
88 template <typename... T, typename... F>
89 float evaluateTask(void (Tracker::*task)(T...), std::string_view taskName, int iteration, const LogFunc& logger, F&&... args);
90
91 TrackerTraits<NLayers>* mTraits = nullptr;
92 TimeFrame<NLayers>* mTimeFrame = nullptr;
93
94 std::vector<TrackingParameters> mTrkParams;
95 o2::gpu::GPUChainITS* mRecoChain = nullptr;
96
97 size_t mTimeSlice{0}; // current timeslice
98 unsigned int mNumberOfDroppedTFs{0};
99 unsigned int mTimeFrameCounter{0};
100 double mTotalTime{0};
101 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
102
103 enum Steps {
104 TFInit = 0,
105 Trackleting,
106 Celling,
107 Neighbouring,
108 Roading,
109 Extending,
110 CellLinearising,
111 BeamPositioning,
112 SeedingVertices,
113 NSteps,
114 };
115 Steps mCurStep{TFInit};
116 static constexpr std::array<const char*, NSteps> StateNames{"TimeFrame initialisation", "Tracklet finding", "Cell finding", "Neighbour finding", "Road finding", "Track extending", "Cell linearisation", "Beam positioning", "Seeding vertices"};
117 std::vector<std::array<TimingStats, NSteps>> mTimingStats;
118 void addTimingStatCurStep(int iteration, double timeMs);
119};
120
121template <int NLayers>
122template <typename... T, typename... F>
123float Tracker<NLayers>::evaluateTask(void (Tracker<NLayers>::*task)(T...), std::string_view taskName, int iteration, const LogFunc& logger, F&&... args)
124{
125 float diff{0.f};
126
127 if (mTrkParams[iteration].PrintMemory) {
128 mMemoryPool->resetPeakMemory();
129 }
130
131 if constexpr (constants::DoTimeBenchmarks) {
132 auto start = std::chrono::high_resolution_clock::now();
133 (this->*task)(std::forward<F>(args)...);
134 auto end = std::chrono::high_resolution_clock::now();
135
136 std::chrono::duration<double, std::milli> diff_t{end - start};
137 diff = diff_t.count();
138
139 std::stringstream sstream;
140 if (taskName.empty()) {
141 sstream << diff << "\t";
142 } else {
143 sstream << std::setw(2) << " - " << taskName << " completed in: " << diff << " ms";
144 }
145 logger(sstream.str());
146
147 if (mTrkParams[iteration].SaveTimeBenchmarks) {
148 std::string taskNameStr(taskName);
149 std::transform(taskNameStr.begin(), taskNameStr.end(), taskNameStr.begin(),
150 [](unsigned char c) { return std::tolower(c); });
151 std::replace(taskNameStr.begin(), taskNameStr.end(), ' ', '_');
152 if (std::ofstream file{"its_time_benchmarks.txt", std::ios::app}) {
153 file << "trk:" << iteration << '\t' << taskNameStr << '\t' << diff << '\n';
154 }
155 addTimingStatCurStep(iteration, diff);
156 }
157
158 } else {
159 (this->*task)(std::forward<F>(args)...);
160 }
161
162 if (mTrkParams[iteration].PrintMemory) {
163 LOGP(info, "iter:{}:{}: {}", iteration, StateNames[mCurStep], mMemoryPool->asString());
164 }
165
166 return diff;
167}
168
169} // namespace its
170} // namespace o2
171
172#endif /* TRACKINGITSU_INCLUDE_TRACKER_H_ */
configStandalone Light OpenGL display display_light Apply smoothing to points Enable Z buffer Highlight links Highlight seeds Highlight sector tracks Highlight final tracks Show individual Show related Highlight grid Show only individual collision Color clusters belonging to track objects Set line Enable drawing TPC data Enable drawing TOF data Enable drawing magnetic field Set field line step count Invert colors configStandalone Heavy OpenGL display display_heavy Show tracks with ITS contribution Show tracks with TOF contribution Enable propagation of loopers Show clusters at nominal x of pad row for early transformed data Split CE tracks when they cross the central Mark clusters Mark adjacent clusters Hide rejected tracks Apply filter on tracks to be displayed Separate increase X h configStandalone Camera window renderer OpenGL display display_camera Orient the camera such that the y axis is always upwards Full Screen MultiSample Anti Downsampling Anti Enable Vertical Sync Target frame or if the backend cannot limit to the refresh Use OpenGL indirect draws to reduce number of draw calls Display h configStandalone Vulkan display display_vulkan Have uniform buffers in host accessible device memory h configStandalone Internal display display_internal Number of updates the Qt GUI may send ahead of the last one the display has before it waits for the display Opacity of the console background Number of console lines the history is shortened to this when it reaches twice the size Time in seconds an info message fades out after setInfoTime h OpenGL display display Font size Do not use Freetype for font Renderer for event Frontend to use for event ROOT macros used as track filter Console script file
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error s
Shared budgeted host allocation and bounded-vector utilities.
uint32_t c
Definition RawData.h:2
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > pool)
Definition Tracker.h:67
void setParameters(const std::vector< TrackingParameters > &p)
Definition Tracker.h:66
void adoptTimeFrame(TimeFrame< NLayers > &tf)
Definition Tracker.cxx:314
void printSummary() const
Definition Tracker.cxx:333
void computeTracksMClabels()
Definition Tracker.cxx:210
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
Definition Tracker.h:71
float clustersToTracks(const LogFunc &=[](const std::string &s) { std::cout<< s<< '\n';}, const LogFunc &=[](const std::string &s) { std::cerr<< s<< '\n';})
Definition Tracker.cxx:110
void setBz(float bz)
Definition Tracker.h:69
std::vector< TrackingParameters > & getParameters()
Definition Tracker.h:68
void setTimeSlice(size_t slice) noexcept
Definition Tracker.h:70
float clustersToVertices(const LogFunc &=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Tracker.cxx:39
GLdouble n
Definition glcorearb.h:1982
GLuint GLuint end
Definition glcorearb.h:469
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
uint8_t int statusCode int
constexpr bool DoTimeBenchmarks
Definition Constants.h:28
const float const float const float bz
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::unique_ptr< GPUReconstructionTimeframe > tf