Project
Loading...
Searching...
No Matches
helpers.h
Go to the documentation of this file.
1// Copyright 2019-2023 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.
11
15
16#ifndef RANS_BENCHMARKS_HELPERS_H_
17#define RANS_BENCHMARKS_HELPERS_H_
18
20
21#ifdef ENABLE_VTUNE_PROFILER
22#include <ittnotify.h>
23#endif
24
25#ifdef RANS_ENABLE_JSON
26#include <rapidjson/document.h>
27#include <rapidjson/writer.h>
28#include <rapidjson/istreamwrapper.h>
29#include <rapidjson/ostreamwrapper.h>
30#endif // RANS_ENABLE_JSON
31#include <fairlogger/Logger.h>
32#include <algorithm>
33
35
36#ifdef RANS_PARALLEL_STL
37#include <execution>
38#endif
39
40#ifdef RANS_ENABLE_JSON
42
43 TPCCompressedClusters() = default;
44 TPCCompressedClusters(size_t nTracks,
45 size_t nAttachedClusters,
46 size_t nUnattachedClusters,
47 size_t nAttachedClustersReduced) : nTracks(nTracks),
48 nAttachedClusters(nAttachedClusters),
49 nUnattachedClusters(nUnattachedClusters),
50 nAttachedClustersReduced(nAttachedClustersReduced)
51 {
52 qTotA.resize(this->nAttachedClusters);
53 qMaxA.resize(this->nAttachedClusters);
54 flagsA.resize(this->nAttachedClusters);
55 rowDiffA.resize(this->nAttachedClustersReduced);
56 sliceLegDiffA.resize(this->nAttachedClustersReduced);
57 padResA.resize(this->nAttachedClustersReduced);
58 timeResA.resize(this->nAttachedClustersReduced);
59 sigmaPadA.resize(this->nAttachedClusters);
60 sigmaTimeA.resize(this->nAttachedClusters);
61
62 qPtA.resize(this->nTracks);
63 rowA.resize(this->nTracks);
64 sliceA.resize(this->nTracks);
65 timeA.resize(this->nTracks);
66 padA.resize(this->nTracks);
67
68 qTotU.resize(this->nUnattachedClusters);
69 qMaxU.resize(this->nUnattachedClusters);
70 flagsU.resize(this->nUnattachedClusters);
71 padDiffU.resize(this->nUnattachedClusters);
72 timeDiffU.resize(this->nUnattachedClusters);
73 sigmaPadU.resize(this->nUnattachedClusters);
74 sigmaTimeU.resize(this->nUnattachedClusters);
75
76 nTrackClusters.resize(this->nTracks);
77 nSliceRowClusters.resize(this->nSliceRows);
78 };
79
80 size_t nTracks = 0;
81 size_t nAttachedClusters = 0;
82 size_t nUnattachedClusters = 0;
83 size_t nAttachedClustersReduced = 0;
84 size_t nSliceRows = 36 * 152;
85
86 std::vector<uint16_t> qTotA{};
87 std::vector<uint16_t> qMaxA{};
88 std::vector<uint8_t> flagsA{};
89 std::vector<uint8_t> rowDiffA{};
90 std::vector<uint8_t> sliceLegDiffA{};
91 std::vector<uint16_t> padResA{};
92 std::vector<uint32_t> timeResA{};
93 std::vector<uint8_t> sigmaPadA{};
94 std::vector<uint8_t> sigmaTimeA{};
95
96 std::vector<uint8_t> qPtA{};
97 std::vector<uint8_t> rowA{};
98 std::vector<uint8_t> sliceA{};
99 std::vector<uint32_t> timeA{};
100 std::vector<uint16_t> padA{};
101
102 std::vector<uint16_t> qTotU{};
103 std::vector<uint16_t> qMaxU{};
104 std::vector<uint8_t> flagsU{};
105 std::vector<uint16_t> padDiffU{};
106 std::vector<uint32_t> timeDiffU{};
107 std::vector<uint8_t> sigmaPadU{};
108 std::vector<uint8_t> sigmaTimeU{};
109
110 std::vector<uint16_t> nTrackClusters{};
111 std::vector<uint32_t> nSliceRowClusters{};
112};
113
114class TPCJsonHandler : public rapidjson::BaseReaderHandler<rapidjson::UTF8<>, TPCJsonHandler>
115{
116 private:
117 class CurrentVector
118 {
119 public:
120 CurrentVector() = default;
121
122 template <typename T>
123 CurrentVector(std::vector<T>& vec) : mVectorConcept{std::make_unique<VectorWrapper<T>>(vec)} {};
124
125 inline void push_back(unsigned i) { mVectorConcept->push_back(i); };
126
127 struct VectorConcept {
128 virtual ~VectorConcept() = default;
129 virtual void push_back(unsigned i) = 0;
130 };
131
132 template <typename T>
133 struct VectorWrapper : VectorConcept {
134 VectorWrapper(std::vector<T>& vector) : mVector(vector){};
135
136 void push_back(unsigned i) override { mVector.push_back(static_cast<T>(i)); };
137
138 private:
139 std::vector<T>& mVector{};
140 };
141
142 std::unique_ptr<VectorConcept> mVectorConcept{};
143 };
144
145 public:
146 bool Null() { return true; };
147 bool Bool(bool b) { return true; };
148 bool Int(int i) { return this->Uint(static_cast<unsigned>(i)); };
149 bool Uint(unsigned i)
150 {
151 mCurrentVector.push_back(i);
152 return true;
153 };
154 bool Int64(int64_t i) { return this->Uint(static_cast<unsigned>(i)); };
155 bool Uint64(uint64_t i) { return this->Uint(static_cast<unsigned>(i)); };
156 bool Double(double d) { return this->Uint(static_cast<unsigned>(d)); };
157 bool RawNumber(const Ch* str, rapidjson::SizeType length, bool copy) { return true; };
158 bool String(const Ch* str, rapidjson::SizeType length, bool copy) { return true; };
159 bool StartObject() { return true; };
160 bool Key(const Ch* str, rapidjson::SizeType length, bool copy)
161 {
162 if (str == std::string{"qTotA"}) {
163 LOGP(info, "parsing {}", str);
164 mCurrentVector = CurrentVector{mCompressedClusters.qTotA};
165 } else if (str == std::string{"qMaxA"}) {
166 LOGP(info, "parsing {}", str);
167 mCurrentVector = CurrentVector{mCompressedClusters.qMaxA};
168 } else if (str == std::string{"flagsA"}) {
169 LOGP(info, "parsing {}", str);
170 mCurrentVector = CurrentVector{mCompressedClusters.flagsA};
171 } else if (str == std::string{"rowDiffA"}) {
172 LOGP(info, "parsing {}", str);
173 mCurrentVector = CurrentVector{mCompressedClusters.rowDiffA};
174 } else if (str == std::string{"sliceLegDiffA"}) {
175 LOGP(info, "parsing {}", str);
176 mCurrentVector = CurrentVector{mCompressedClusters.sliceLegDiffA};
177 } else if (str == std::string{"padResA"}) {
178 LOGP(info, "parsing {}", str);
179 mCurrentVector = CurrentVector{mCompressedClusters.padResA};
180 } else if (str == std::string{"timeResA"}) {
181 LOGP(info, "parsing {}", str);
182 mCurrentVector = CurrentVector{mCompressedClusters.timeResA};
183 } else if (str == std::string{"sigmaPadA"}) {
184 LOGP(info, "parsing {}", str);
185 mCurrentVector = CurrentVector{mCompressedClusters.sigmaPadA};
186 } else if (str == std::string{"sigmaTimeA"}) {
187 LOGP(info, "parsing {}", str);
188 mCurrentVector = CurrentVector{mCompressedClusters.sigmaTimeA};
189 } else if (str == std::string{"qPtA"}) {
190 LOGP(info, "parsing {}", str);
191 mCurrentVector = CurrentVector{mCompressedClusters.qPtA};
192 } else if (str == std::string{"rowA"}) {
193 LOGP(info, "parsing {}", str);
194 mCurrentVector = CurrentVector{mCompressedClusters.rowA};
195 } else if (str == std::string{"sliceA"}) {
196 LOGP(info, "parsing {}", str);
197 mCurrentVector = CurrentVector{mCompressedClusters.sliceA};
198 } else if (str == std::string{"timeA"}) {
199 LOGP(info, "parsing {}", str);
200 mCurrentVector = CurrentVector{mCompressedClusters.timeA};
201 } else if (str == std::string{"padA"}) {
202 LOGP(info, "parsing {}", str);
203 mCurrentVector = CurrentVector{mCompressedClusters.padA};
204 } else if (str == std::string{"qTotU"}) {
205 LOGP(info, "parsing {}", str);
206 mCurrentVector = CurrentVector{mCompressedClusters.qTotU};
207 } else if (str == std::string{"qMaxU"}) {
208 LOGP(info, "parsing {}", str);
209 mCurrentVector = CurrentVector{mCompressedClusters.qMaxU};
210 } else if (str == std::string{"flagsU"}) {
211 LOGP(info, "parsing {}", str);
212 mCurrentVector = CurrentVector{mCompressedClusters.flagsU};
213 } else if (str == std::string{"padDiffU"}) {
214 LOGP(info, "parsing {}", str);
215 mCurrentVector = CurrentVector{mCompressedClusters.padDiffU};
216 } else if (str == std::string{"timeDiffU"}) {
217 LOGP(info, "parsing {}", str);
218 mCurrentVector = CurrentVector{mCompressedClusters.timeDiffU};
219 } else if (str == std::string{"sigmaPadU"}) {
220 LOGP(info, "parsing {}", str);
221 mCurrentVector = CurrentVector{mCompressedClusters.sigmaPadU};
222 } else if (str == std::string{"sigmaTimeU"}) {
223 LOGP(info, "parsing {}", str);
224 mCurrentVector = CurrentVector{mCompressedClusters.sigmaTimeU};
225 } else if (str == std::string{"nTrackClusters"}) {
226 LOGP(info, "parsing {}", str);
227 mCurrentVector = CurrentVector{mCompressedClusters.nTrackClusters};
228 } else if (str == std::string{"nSliceRowClusters"}) {
229 LOGP(info, "parsing {}", str);
230 mCurrentVector = CurrentVector{mCompressedClusters.nSliceRowClusters};
231 } else {
232 throw o2::rans::IOError(fmt::format("invalid key: {}", str));
233 return false;
234 }
235 return true;
236 };
237 bool EndObject(rapidjson::SizeType memberCount)
238 {
239 LOGP(info, "parsed {} objects", memberCount);
240 return true;
241 };
242 bool StartArray()
243 {
244 return true;
245 };
246 bool EndArray(rapidjson::SizeType elementCount)
247 {
248 LOGP(info, "parsed {} elements", elementCount);
249 return true;
250 };
251
252 TPCCompressedClusters release() && { return std::move(mCompressedClusters); };
253
254 private:
255 TPCCompressedClusters mCompressedClusters;
256 CurrentVector mCurrentVector;
257};
258
259TPCCompressedClusters readFile(const std::string& filename)
260{
261 TPCCompressedClusters compressedClusters;
262 std::ifstream is(filename, std::ios_base::in);
263 if (is) {
264 rapidjson::IStreamWrapper isWrapper{is};
265 // rapidjson::Document document;
266 TPCJsonHandler handler;
267 rapidjson::Reader reader;
268 reader.Parse(isWrapper, handler);
269
270 compressedClusters = std::move(handler).release();
271
272 compressedClusters.nAttachedClusters = compressedClusters.qTotA.size();
273 compressedClusters.nAttachedClustersReduced = compressedClusters.rowDiffA.size();
274 compressedClusters.nUnattachedClusters = compressedClusters.qTotA.size();
275 compressedClusters.nTracks = compressedClusters.nTrackClusters.size();
276 is.close();
277 } else {
278 throw o2::rans::IOError(fmt::format("Could not open file {}", filename));
279 }
280 return compressedClusters;
281};
282#endif // RANS_ENABLE_JSON
283
284template <typename source_T, typename stream_T = uint32_t>
286
287 EncodeBuffer() = default;
288 EncodeBuffer(size_t sourceSize) : buffer(2 * sourceSize), literals()
289 {
290 literals.reserve(sourceSize + 32);
291 literalsEnd = literals.data();
292 encodeBufferEnd = buffer.data();
293 };
294
295 std::vector<stream_T> buffer{};
296 std::vector<source_T> literals{};
297 stream_T* encodeBufferEnd{buffer.data()};
299};
300
301template <typename source_T>
303
304 DecodeBuffer() = default;
305 DecodeBuffer(size_t sourceSize) : buffer(sourceSize){};
306
307 template <typename T>
308 bool operator==(const T& correct)
309 {
310#ifdef RANS_PARALLEL_STL
311 return std::equal(std::execution::par_unseq, buffer.begin(), buffer.end(), std::begin(correct), std::end(correct));
312#else
313 return std::equal(buffer.begin(), buffer.end(), std::begin(correct), std::end(correct));
314#endif // RANS_PARALLEL_STL
315 }
316
317 std::vector<source_T> buffer{};
318};
319
320#endif /* RANS_BENCHMARKS_HELPERS_H_ */
o2::monitoring::tags::Key Key
int64_t timeA
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events Show standalone event Run event generator maximum time bin of continuous for triggered for automatic continuous for automatic continuous triggered uint64_t
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char Directory with events to Events directory is and not inside events d
preprocessor defines to enable features based on CPU architecture
rans exceptions
GLboolean GLboolean GLboolean b
Definition glcorearb.h:1233
GLuint GLsizei GLsizei * length
Definition glcorearb.h:790
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
std::string filename()
bool readFile(std::string filename, o2::mid::Decoder &decoder, std::vector< o2::mid::ROBoard > &data, std::vector< o2::mid::ROFRecord > &rofRecords, unsigned long int nHBFs)
DecodeBuffer(size_t sourceSize)
Definition helpers.h:305
DecodeBuffer()=default
bool operator==(const T &correct)
Definition helpers.h:308
source_T * literalsEnd
Definition helpers.h:298
std::vector< source_T > literals
Definition helpers.h:296
stream_T * encodeBufferEnd
Definition helpers.h:297
EncodeBuffer()=default
EncodeBuffer(size_t sourceSize)
Definition helpers.h:288
std::vector< o2::ctf::BufferType > vec
const std::string str