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