forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVertexer.h
More file actions
160 lines (133 loc) · 5.1 KB
/
Vertexer.h
File metadata and controls
160 lines (133 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
///
/// \file Vertexer.h
/// \brief
/// \author matteo.concas@cern.ch
#ifndef O2_ITS_TRACKING_VERTEXER_H_
#define O2_ITS_TRACKING_VERTEXER_H_
#include <chrono>
#include <fstream>
#include <iomanip>
#include <array>
#include <iosfwd>
#include <memory>
#include <oneapi/tbb/task_arena.h>
#include "ITStracking/Constants.h"
#include "ITStracking/Definitions.h"
#include "ITStracking/Configuration.h"
#include "ITStracking/TimeFrame.h"
#include "ITStracking/VertexerTraits.h"
#include "ITStracking/BoundedAllocator.h"
namespace o2::its
{
template <int nLayers>
class Vertexer
{
using TimeFrameN = TimeFrame<nLayers>;
using VertexerTraitsN = VertexerTraits<nLayers>;
using LogFunc = std::function<void(const std::string& s)>;
public:
Vertexer(VertexerTraitsN* traits);
virtual ~Vertexer() = default;
Vertexer(const Vertexer&) = delete;
Vertexer& operator=(const Vertexer&) = delete;
void adoptTimeFrame(TimeFrameN& tf);
auto& getVertParameters() const { return mTraits->getVertexingParameters(); }
void setParameters(const std::vector<VertexingParameters>& vertParams) { mVertParams = vertParams; }
const auto& getParameters() const noexcept { return mVertParams; }
void setMemoryPool(std::shared_ptr<BoundedMemoryResource> pool) { mMemoryPool = pool; }
std::vector<Vertex> exportVertices();
VertexerTraitsN* getTraits() const { return mTraits; };
float clustersToVertices(LogFunc = [](const std::string& s) { std::cout << s << '\n'; });
void filterMCTracklets();
template <typename... T>
void findTracklets(T&&... args)
{
mTraits->computeTracklets(std::forward<T>(args)...);
}
template <typename... T>
void validateTracklets(T&&... args)
{
mTraits->computeTrackletMatching(std::forward<T>(args)...);
}
template <typename... T>
void findVertices(T&&... args)
{
mTraits->computeVertices(std::forward<T>(args)...);
}
void addTruthSeeds() { mTraits->addTruthSeedingVertices(); }
template <typename... T>
void initialiseVertexer(T&&... args)
{
mTraits->initialise(std::forward<T>(args)...);
}
template <typename... T>
void initialiseTimeFrame(T&&... args);
// Utils
template <typename... T>
float evaluateTask(void (Vertexer::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args);
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);
void setNThreads(int n, std::shared_ptr<tbb::task_arena>& arena) { mTraits->setNThreads(n, arena); }
private:
std::uint32_t mTimeFrameCounter = 0;
VertexerTraitsN* mTraits = nullptr; /// Observer pointer, not owned by this class
TimeFrameN* mTimeFrame = nullptr; /// Observer pointer, not owned by this class
std::vector<VertexingParameters> mVertParams;
std::shared_ptr<BoundedMemoryResource> mMemoryPool;
enum State {
Init = 0,
Trackleting,
Validating,
Finding,
TruthSeeding,
NStates,
};
State mCurState{Init};
static constexpr std::array<const char*, NStates> StateNames{"Initialisation", "Tracklet finding", "Tracklet validation", "Vertex finding", "Truth seeding"};
};
template <int nLayers>
template <typename... T>
float Vertexer<nLayers>::evaluateTask(void (Vertexer<nLayers>::*task)(T...), std::string_view taskName, int iteration, LogFunc& logger, T&&... args)
{
float diff{0.f};
if constexpr (constants::DoTimeBenchmarks) {
auto start = std::chrono::high_resolution_clock::now();
(this->*task)(std::forward<T>(args)...);
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> diff_t{end - start};
diff = diff_t.count();
std::stringstream sstream;
if (taskName.empty()) {
sstream << diff << "\t";
} else {
sstream << std::setw(2) << " - " << taskName << " completed in: " << diff << " ms";
}
logger(sstream.str());
if (mVertParams[0].SaveTimeBenchmarks) {
std::string taskNameStr(taskName);
std::transform(taskNameStr.begin(), taskNameStr.end(), taskNameStr.begin(),
[](unsigned char c) { return std::tolower(c); });
std::replace(taskNameStr.begin(), taskNameStr.end(), ' ', '_');
if (std::ofstream file{"its_time_benchmarks.txt", std::ios::app}) {
file << "vtx:" << iteration << '\t' << taskNameStr << '\t' << diff << '\n';
}
}
} else {
(this->*task)(std::forward<T>(args)...);
}
return diff;
}
} // namespace o2::its
#endif