Project
Loading...
Searching...
No Matches
Vertexer.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 O2_ITS_TRACKING_VERTEXER_H_
17#define O2_ITS_TRACKING_VERTEXER_H_
18
19#include <chrono>
20#include <fstream>
21#include <iomanip>
22#include <array>
23#include <iosfwd>
24#include <memory>
25#include <vector>
26
27#include <oneapi/tbb/task_arena.h>
28
34
35namespace o2::its
36{
37
38template <int NLayers>
40{
43 using LogFunc = std::function<void(const std::string& s)>;
44
45 public:
47 virtual ~Vertexer() = default;
48 Vertexer(const Vertexer&) = delete;
49 Vertexer& operator=(const Vertexer&) = delete;
50
52 auto& getVertParameters() const { return mTraits->getVertexingParameters(); }
53 void setParameters(const std::vector<VertexingParameters>& vertParams) { mVertParams = vertParams; }
54 const auto& getParameters() const noexcept { return mVertParams; }
55 void setMemoryPool(std::shared_ptr<BoundedMemoryResource> pool) { mMemoryPool = pool; }
56
57 float clustersToVertices(LogFunc = [](const std::string& s) { std::cout << s << '\n'; });
59 void printSummary() const;
60
61 template <typename... T>
62 void findTracklets(T&&... args)
63 {
64 mTraits->computeTracklets(std::forward<T>(args)...);
65 }
66 template <typename... T>
67 void validateTracklets(T&&... args)
68 {
69 mTraits->computeTrackletMatching(std::forward<T>(args)...);
70 }
71 template <typename... T>
72 void findVertices(T&&... args)
73 {
74 mTraits->computeVertices(std::forward<T>(args)...);
75 }
76
78
79 template <typename... T>
80 void initialiseVertexer(T&&... args)
81 {
82 mTraits->initialise(std::forward<T>(args)...);
83 }
84 template <typename... T>
85 void initialiseTimeFrame(T&&... args);
86
87 void sortVertices();
88
89 // Utils
90 template <typename... T>
91 float evaluateTask(void (Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args);
92
93 void printEpilog(LogFunc& logger,
94 unsigned int trackletN01, unsigned int trackletN12,
95 unsigned selectedN, unsigned int vertexN, unsigned int totalVertexN,
96 float initT, float trackletT, float selecT, float vertexT);
97
98 void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena) { mTraits->setNThreads(n, arena); }
99
100 private:
101 std::uint32_t mTimeFrameCounter = 0;
102
103 VertexerTraitsN* mTraits = nullptr;
104 TimeFrameN* mTimeFrame = nullptr;
105
106 std::vector<VertexingParameters> mVertParams;
107 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
108
109 enum Steps {
110 Init = 0,
111 Trackleting,
112 Selection,
113 Finding,
114 TruthSeeding,
115 NSteps,
116 };
117 Steps mCurStep{Init};
118 static constexpr std::array<const char*, NSteps> StateNames{"Initialisation", "Tracklet finding", "Tracklet selection", "Vertex finding", "Truth seeding"};
119 std::vector<std::array<TimingStats, NSteps>> mTimingStats;
120 void addTimingStatCurStep(int iteration, double timeMs);
121};
122
123template <int NLayers>
124template <typename... T>
125float Vertexer<NLayers>::evaluateTask(void (Vertexer<NLayers>::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args)
126{
127 float diff{0.f};
128
129 if (mVertParams[iteration].PrintMemory) {
130 mMemoryPool->resetPeakMemory();
131 }
132
133 if constexpr (constants::DoTimeBenchmarks) {
134 auto start = std::chrono::high_resolution_clock::now();
135 (this->*task)(std::forward<T>(args)...);
136 auto end = std::chrono::high_resolution_clock::now();
137
138 std::chrono::duration<double, std::milli> diff_t{end - start};
139 diff = diff_t.count();
140
141 std::stringstream sstream;
142 if (taskName.empty()) {
143 sstream << diff << "\t";
144 } else {
145 sstream << std::setw(2) << " - " << taskName << " completed in: " << diff << " ms";
146 }
147 logger(sstream.str());
148
149 if (mVertParams[iteration].SaveTimeBenchmarks) {
150 std::string taskNameStr(taskName);
151 std::transform(taskNameStr.begin(), taskNameStr.end(), taskNameStr.begin(),
152 [](unsigned char c) { return std::tolower(c); });
153 std::replace(taskNameStr.begin(), taskNameStr.end(), ' ', '_');
154 if (std::ofstream file{"its_time_benchmarks.txt", std::ios::app}) {
155 file << "vtx:" << iteration << '\t' << taskNameStr << '\t' << diff << '\n';
156 }
157 addTimingStatCurStep(iteration, diff);
158 }
159 } else {
160 (this->*task)(std::forward<T>(args)...);
161 }
162
163 if (mVertParams[iteration].PrintMemory) {
164 LOGP(info, "iter:{}:{}: {}", iteration, StateNames[mCurStep], mMemoryPool->asString());
165 }
166
167 return diff;
168}
169
170} // namespace o2::its
171#endif
uint32_t c
Definition RawData.h:2
Class to compute the primary vertex in ITS from tracklets.
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
virtual void computeVertices(const int iteration)
virtual void initialise(const TrackingParameters &trackingParams)
virtual void computeTrackletMatching(const int iteration)
virtual void computeTracklets(const int iteration)
Vertexer(const Vertexer &)=delete
void initialiseVertexer(T &&... args)
Definition Vertexer.h:80
float evaluateTask(void(Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc &logger, T &&... args)
void setParameters(const std::vector< VertexingParameters > &vertParams)
Definition Vertexer.h:53
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > pool)
Definition Vertexer.h:55
void initialiseTimeFrame(T &&... args)
const auto & getParameters() const noexcept
Definition Vertexer.h:54
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
Definition Vertexer.h:98
void addTruthSeeds()
Definition Vertexer.h:77
virtual ~Vertexer()=default
void adoptTimeFrame(TimeFrameN &tf)
Definition Vertexer.cxx:140
void printEpilog(LogFunc &logger, unsigned int trackletN01, unsigned int trackletN12, unsigned selectedN, unsigned int vertexN, unsigned int totalVertexN, float initT, float trackletT, float selecT, float vertexT)
Definition Vertexer.cxx:174
void validateTracklets(T &&... args)
Definition Vertexer.h:67
void printSummary() const
Definition Vertexer.cxx:159
Vertexer & operator=(const Vertexer &)=delete
float clustersToVertices(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Vertexer.cxx:34
void findTracklets(T &&... args)
Definition Vertexer.h:62
auto & getVertParameters() const
Definition Vertexer.h:52
void findVertices(T &&... args)
Definition Vertexer.h:72
void filterMCTracklets()
GLdouble n
Definition glcorearb.h:1982
GLuint GLuint end
Definition glcorearb.h:469
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint start
Definition glcorearb.h:469
constexpr bool DoTimeBenchmarks
Definition Constants.h:28
std::unique_ptr< GPUReconstructionTimeframe > tf