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
26#include <oneapi/tbb/task_arena.h>
27
34
35namespace o2::its
36{
37
39
41{
42 static constexpr int NLayers{7};
44 using LogFunc = std::function<void(const std::string& s)>;
45
46 public:
47 Vertexer(VertexerTraits* traits);
48 virtual ~Vertexer() = default;
49 Vertexer(const Vertexer&) = delete;
50 Vertexer& operator=(const Vertexer&) = delete;
51
53 auto& getVertParameters() const { return mTraits->getVertexingParameters(); }
54 void setParameters(const std::vector<VertexingParameters>& vertParams) { mVertParams = vertParams; }
55 const auto& getParameters() const noexcept { return mVertParams; }
56 void setMemoryPool(std::shared_ptr<BoundedMemoryResource>& pool) { mMemoryPool = pool; }
57
58 std::vector<Vertex> exportVertices();
59 VertexerTraits* getTraits() const { return mTraits; };
60
61 float clustersToVertices(LogFunc = [](const std::string& s) { std::cout << s << '\n'; });
63
64 template <typename... T>
65 void findTracklets(T&&... args);
67 template <typename... T>
68 void validateTracklets(T&&... args);
69 template <typename... T>
70 void findVertices(T&&... args);
71
73
74 template <typename... T>
75 void initialiseVertexer(T&&... args);
76 template <typename... T>
77 void initialiseTimeFrame(T&&... args);
78
79 // Utils
80 void dumpTraits() { mTraits->dumpVertexerTraits(); }
81 template <typename... T>
82 float evaluateTask(void (Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args);
83
84 void printEpilog(LogFunc& logger,
85 const unsigned int trackletN01, const unsigned int trackletN12,
86 const unsigned selectedN, const unsigned int vertexN, const float initT,
87 const float trackletT, const float selecT, const float vertexT);
88
89 void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena) { mTraits->setNThreads(n, arena); }
90
91 private:
92 std::uint32_t mTimeFrameCounter = 0;
93
94 VertexerTraits* mTraits = nullptr;
95 TimeFrame7* mTimeFrame = nullptr;
96
97 std::vector<VertexingParameters> mVertParams;
98 std::shared_ptr<BoundedMemoryResource> mMemoryPool;
99
100 enum State {
101 Init = 0,
102 Trackleting,
103 Validating,
104 Finding,
105 TruthSeeding,
106 NStates,
107 };
108 State mCurState{Init};
109 static constexpr std::array<const char*, NStates> StateNames{"Initialisation", "Tracklet finding", "Tracklet validation", "Vertex finding", "Truth seeding"};
110};
111
112template <typename... T>
114{
115 mTraits->initialise(std::forward<T>(args)...);
116}
117
118template <typename... T>
119void Vertexer::findTracklets(T&&... args)
120{
121 mTraits->computeTracklets(std::forward<T>(args)...);
122}
123
124template <typename... T>
125inline void Vertexer::validateTracklets(T&&... args)
126{
127 mTraits->computeTrackletMatching(std::forward<T>(args)...);
128}
129
130template <typename... T>
131inline void Vertexer::findVertices(T&&... args)
132{
133 mTraits->computeVertices(std::forward<T>(args)...);
134}
135
136template <typename... T>
137float Vertexer::evaluateTask(void (Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args)
138{
139 float diff{0.f};
140
141 if constexpr (constants::DoTimeBenchmarks) {
142 auto start = std::chrono::high_resolution_clock::now();
143 (this->*task)(std::forward<T>(args)...);
144 auto end = std::chrono::high_resolution_clock::now();
145
146 std::chrono::duration<double, std::milli> diff_t{end - start};
147 diff = diff_t.count();
148
149 std::stringstream sstream;
150 if (taskName.empty()) {
151 sstream << diff << "\t";
152 } else {
153 sstream << std::setw(2) << " - " << taskName << " completed in: " << diff << " ms";
154 }
155 logger(sstream.str());
156
157 if (mVertParams[0].SaveTimeBenchmarks) {
158 std::string taskNameStr(taskName);
159 std::transform(taskNameStr.begin(), taskNameStr.end(), taskNameStr.begin(),
160 [](unsigned char c) { return std::tolower(c); });
161 std::replace(taskNameStr.begin(), taskNameStr.end(), ' ', '_');
162 if (std::ofstream file{"its_time_benchmarks.txt", std::ios::app}) {
163 file << "vtx:" << iteration << '\t' << taskNameStr << '\t' << diff << '\n';
164 }
165 }
166 } else {
167 (this->*task)(std::forward<T>(args)...);
168 }
169
170 return diff;
171}
172
173} // namespace o2::its
174#endif
uint32_t c
Definition RawData.h:2
Class to compute the primary vertex in ITS from tracklets.
virtual void computeTrackletMatching(const int iteration=0)
virtual void computeTracklets(const int iteration=0)
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
virtual void initialise(const TrackingParameters &trackingParams, const int iteration=0)
virtual void computeVertices(const int iteration=0)
auto & getVertParameters() const
Definition Vertexer.h:53
void findTracklets(T &&... args)
Definition Vertexer.h:119
void initialiseVertexer(T &&... args)
Definition Vertexer.h:113
void findTrivialMCTracklets()
void validateTracklets(T &&... args)
Definition Vertexer.h:125
void findVertices(T &&... args)
Definition Vertexer.h:131
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
Definition Vertexer.h:89
VertexerTraits * getTraits() const
Definition Vertexer.h:59
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
Definition Vertexer.h:56
void setParameters(const std::vector< VertexingParameters > &vertParams)
Definition Vertexer.h:54
void filterMCTracklets()
const auto & getParameters() const noexcept
Definition Vertexer.h:55
Vertexer(const Vertexer &)=delete
void initialiseTimeFrame(T &&... args)
void adoptTimeFrame(TimeFrame7 &tf)
Definition Vertexer.cxx:90
float evaluateTask(void(Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc &logger, T &&... args)
Definition Vertexer.h:137
void dumpTraits()
Definition Vertexer.h:80
Vertexer & operator=(const Vertexer &)=delete
float clustersToVertices(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Vertexer.cxx:37
void addTruthSeeds()
Definition Vertexer.h:72
std::vector< Vertex > exportVertices()
virtual ~Vertexer()=default
void printEpilog(LogFunc &logger, const unsigned int trackletN01, const unsigned int trackletN12, const unsigned selectedN, const unsigned int vertexN, const float initT, const float trackletT, const float selecT, const float vertexT)
Definition Vertexer.cxx:96
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:25
o2::dataformats::Vertex< o2::dataformats::TimeStamp< int > > Vertex
Definition TimeFrame.h:65
Defining DataPointCompositeObject explicitly as copiable.
std::unique_ptr< GPUReconstructionTimeframe > tf