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