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
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 std::vector<Vertex> exportVertices();
58 VertexerTraitsN* getTraits() const { return mTraits; };
59
60 float clustersToVertices(LogFunc = [](const std::string& s) { std::cout << s << '\n'; });
62
63 template <typename... T>
64 void findTracklets(T&&... args)
65 {
66 mTraits->computeTracklets(std::forward<T>(args)...);
67 }
68 template <typename... T>
69 void validateTracklets(T&&... args)
70 {
71 mTraits->computeTrackletMatching(std::forward<T>(args)...);
72 }
73 template <typename... T>
74 void findVertices(T&&... args)
75 {
76 mTraits->computeVertices(std::forward<T>(args)...);
77 }
78
80
81 template <typename... T>
82 void initialiseVertexer(T&&... args)
83 {
84 mTraits->initialise(std::forward<T>(args)...);
85 }
86 template <typename... T>
87 void initialiseTimeFrame(T&&... args);
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 const unsigned int trackletN01, const unsigned int trackletN12,
95 const unsigned selectedN, const unsigned int vertexN, const float initT,
96 const float trackletT, const float selecT, const 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 State {
110 Init = 0,
111 Trackleting,
112 Validating,
113 Finding,
114 TruthSeeding,
115 NStates,
116 };
117 State mCurState{Init};
118 static constexpr std::array<const char*, NStates> StateNames{"Initialisation", "Tracklet finding", "Tracklet validation", "Vertex finding", "Truth seeding"};
119};
120
121template <int nLayers>
122template <typename... T>
123float Vertexer<nLayers>::evaluateTask(void (Vertexer<nLayers>::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args)
124{
125 float diff{0.f};
126
127 if constexpr (constants::DoTimeBenchmarks) {
128 auto start = std::chrono::high_resolution_clock::now();
129 (this->*task)(std::forward<T>(args)...);
130 auto end = std::chrono::high_resolution_clock::now();
131
132 std::chrono::duration<double, std::milli> diff_t{end - start};
133 diff = diff_t.count();
134
135 std::stringstream sstream;
136 if (taskName.empty()) {
137 sstream << diff << "\t";
138 } else {
139 sstream << std::setw(2) << " - " << taskName << " completed in: " << diff << " ms";
140 }
141 logger(sstream.str());
142
143 if (mVertParams[0].SaveTimeBenchmarks) {
144 std::string taskNameStr(taskName);
145 std::transform(taskNameStr.begin(), taskNameStr.end(), taskNameStr.begin(),
146 [](unsigned char c) { return std::tolower(c); });
147 std::replace(taskNameStr.begin(), taskNameStr.end(), ' ', '_');
148 if (std::ofstream file{"its_time_benchmarks.txt", std::ios::app}) {
149 file << "vtx:" << iteration << '\t' << taskNameStr << '\t' << diff << '\n';
150 }
151 }
152 } else {
153 (this->*task)(std::forward<T>(args)...);
154 }
155
156 return diff;
157}
158
159} // namespace o2::its
160#endif
uint32_t c
Definition RawData.h:2
Class to compute the primary vertex in ITS from tracklets.
virtual void computeTracklets(const int iteration=0)
virtual void initialise(const TrackingParameters &trackingParams, const int iteration=0)
virtual void computeVertices(const int iteration=0)
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
virtual void computeTrackletMatching(const int iteration=0)
void setNThreads(int n, std::shared_ptr< tbb::task_arena > &arena)
Definition Vertexer.h:98
void findVertices(T &&... args)
Definition Vertexer.h:74
void addTruthSeeds()
Definition Vertexer.h:79
void findTracklets(T &&... args)
Definition Vertexer.h:64
void setMemoryPool(std::shared_ptr< BoundedMemoryResource > &pool)
Definition Vertexer.h:55
auto & getVertParameters() const
Definition Vertexer.h:52
float evaluateTask(void(Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc &logger, T &&... args)
void initialiseVertexer(T &&... args)
Definition Vertexer.h:82
void initialiseTimeFrame(T &&... args)
const auto & getParameters() const noexcept
Definition Vertexer.h:54
void validateTracklets(T &&... args)
Definition Vertexer.h:69
void setParameters(const std::vector< VertexingParameters > &vertParams)
Definition Vertexer.h:53
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:100
virtual ~Vertexer()=default
void filterMCTracklets()
Vertexer(const Vertexer &)=delete
float clustersToVertices(LogFunc=[](const std::string &s) { std::cout<< s<< '\n';})
Definition Vertexer.cxx:39
void adoptTimeFrame(TimeFrameN &tf)
Definition Vertexer.cxx:93
std::vector< Vertex > exportVertices()
Vertexer & operator=(const Vertexer &)=delete
VertexerTraitsN * getTraits() const
Definition Vertexer.h:58
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:31
Defining DataPointCompositeObject explicitly as copiable.
std::unique_ptr< GPUReconstructionTimeframe > tf