Project
Loading...
Searching...
No Matches
bench_Raw.cxx
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.
11
16
17#include "benchmark/benchmark.h"
18#include <vector>
19#include "Framework/Logger.h"
22#include "DPLUtils/RawParser.h"
25#include "MIDRaw/Decoder.h"
26#include "MIDRaw/Encoder.h"
27#include "MIDRaw/LinkDecoder.h"
28
29o2::mid::ColumnData getColData(uint8_t deId, uint8_t columnId, uint16_t nbp = 0, uint16_t bp1 = 0, uint16_t bp2 = 0, uint16_t bp3 = 0, uint16_t bp4 = 0)
30{
32 col.deId = deId;
33 col.columnId = columnId;
34 col.setNonBendPattern(nbp);
35 col.setBendPattern(bp1, 0);
36 col.setBendPattern(bp2, 1);
37 col.setBendPattern(bp3, 2);
38 col.setBendPattern(bp4, 3);
39 return col;
40}
41
42std::vector<uint8_t> generateTestData(size_t nTF, size_t nDataInTF, size_t nColDataInEvent, size_t nLinks = o2::mid::crateparams::sNGBTs)
43{
44 std::vector<o2::mid::ColumnData> colData;
45 colData.reserve(nColDataInEvent);
46 int maxNcols = 7;
47 int nDEs = nColDataInEvent / maxNcols;
48 int nColLast = nColDataInEvent % maxNcols;
49 if (nColLast > 0) {
50 ++nDEs;
51 }
52
53 // Generate data
54 for (int ide = 0; ide < nDEs; ++ide) {
55 int nCol = (ide == nDEs - 1) ? nColLast : maxNcols;
56 auto rpcLine = o2::mid::detparams::getRPCLine(ide);
57 int firstCol = (rpcLine < 3 || rpcLine > 5) ? 0 : 1;
58 for (int icol = firstCol; icol < nCol; ++icol) {
59 colData.emplace_back(getColData(ide, icol, 0xFF00, 0xFF0));
60 }
61 }
62
63 auto severity = fair::Logger::GetConsoleSeverity();
64 fair::Logger::SetConsoleSeverity(fair::Severity::warning);
65 o2::mid::Encoder encoder;
66 encoder.init();
67 std::string tmpConfigFilename = "tmp_MIDConfig.cfg";
68 encoder.getWriter().writeConfFile("MID", "RAWDATA", tmpConfigFilename.c_str(), false);
69 // Fill TF
70 for (size_t itf = 0; itf < nTF; ++itf) {
71 for (int ilocal = 0; ilocal < nDataInTF; ++ilocal) {
72 o2::InteractionRecord ir(ilocal, itf);
73 encoder.process(colData, ir, o2::mid::EventType::Standard);
74 }
75 }
76 encoder.finalize();
77
78 o2::raw::RawFileReader rawReader(tmpConfigFilename.c_str());
79 rawReader.init();
80 size_t nActiveLinks = rawReader.getNLinks() < nLinks ? rawReader.getNLinks() : nLinks;
81 std::vector<char> buffer;
82 for (size_t itf = 0; itf < rawReader.getNTimeFrames(); ++itf) {
83 rawReader.setNextTFToRead(itf);
84 for (size_t ilink = 0; ilink < nActiveLinks; ++ilink) {
85 auto& link = rawReader.getLink(ilink);
86 auto tfsz = link.getNextTFSize();
87 if (!tfsz) {
88 continue;
89 }
90 std::vector<char> linkBuffer(tfsz);
91 link.readNextTF(linkBuffer.data());
92 buffer.insert(buffer.end(), linkBuffer.begin(), linkBuffer.end());
93 }
94 }
95 fair::Logger::SetConsoleSeverity(severity);
96
97 std::remove("MID.raw");
98 std::remove(tmpConfigFilename.c_str());
99
100 std::vector<uint8_t> data(buffer.size());
101 memcpy(data.data(), buffer.data(), buffer.size());
102
103 return data;
104}
105
106static void BM_Decoder(benchmark::State& state)
107{
108 o2::mid::Decoder decoder;
109
110 int nTF = state.range(0);
111 int nEventPerTF = state.range(1);
112 int nFiredPerEvent = state.range(2);
113 double num{0};
114
115 auto inputData = generateTestData(nTF, nEventPerTF, nFiredPerEvent);
116
117 for (auto _ : state) {
118 decoder.process(inputData);
119 ++num;
120 }
121
122 state.counters["num"] = benchmark::Counter(num, benchmark::Counter::kIsRate);
123}
124
125static void BM_LinkDecoder(benchmark::State& state)
126{
127 auto decoder = o2::mid::createLinkDecoder(0);
128
129 int nTF = state.range(0);
130 int nEventPerTF = state.range(1);
131 int nFiredPerEvent = state.range(2);
132 double num{0};
133
134 auto inputData = generateTestData(nTF, nEventPerTF, nFiredPerEvent, 1);
135 std::vector<o2::mid::ROBoard> data;
136 std::vector<o2::mid::ROFRecord> rofs;
137
138 for (auto _ : state) {
139 data.clear();
140 rofs.clear();
141 o2::framework::RawParser parser(inputData.data(), inputData.size());
142 for (auto it = parser.begin(), end = parser.end(); it != end; ++it) {
143 if (it.size() == 0) {
144 continue;
145 }
146 auto* rdhPtr = it.template get_if<o2::header::RAWDataHeader>();
147 gsl::span<const uint8_t> payload(it.data(), it.size());
148 decoder->process(payload, *rdhPtr, data, rofs);
149 }
150 ++num;
151 }
152
153 state.counters["num"] = benchmark::Counter(num, benchmark::Counter::kIsRate);
154}
155
156static void CustomArguments(benchmark::internal::Benchmark* bench)
157{
158 // One per event
159 bench->Args({1, 1, 1});
160 bench->Args({10, 1, 1});
161 // One large data
162 bench->Args({1, 1, 70 * 4});
163 // Many small data
164 bench->Args({1, 100, 4});
165}
166
167BENCHMARK(BM_LinkDecoder)->Apply(CustomArguments)->Unit(benchmark::kNanosecond);
168BENCHMARK(BM_Decoder)->Apply(CustomArguments)->Unit(benchmark::kNanosecond);
169
benchmark::State & state
Strip pattern (aka digits)
Useful detector parameters for MID.
MID raw data decoder.
MID raw data encoder.
Class interface for the MID link decoder.
uint32_t col
Definition RawData.h:4
Generic parser for consecutive raw pages.
Reader for (multiple) raw data files.
std::vector< o2::mid::ColumnData > inputData
double num
BENCHMARK_MAIN()
BENCHMARK(BM_LinkDecoder) -> Apply(CustomArguments) ->Unit(benchmark::kNanosecond)
std::vector< uint8_t > generateTestData(size_t nTF, size_t nDataInTF, size_t nColDataInEvent, size_t nLinks=o2::mid::crateparams::sNGBTs)
Definition bench_Raw.cxx:42
o2::mid::ColumnData getColData(uint8_t deId, uint8_t columnId, uint16_t nbp=0, uint16_t bp1=0, uint16_t bp2=0, uint16_t bp3=0, uint16_t bp4=0)
Definition bench_Raw.cxx:29
void process(gsl::span< const uint8_t > bytes)
Definition Decoder.cxx:48
auto & getWriter()
Definition Encoder.h:51
void finalize(bool closeFile=true)
Definition Encoder.cxx:131
void init(std::string_view outDir=".", std::string_view fileFor="all", int verbosity=0, std::vector< ROBoardConfig > configurations=makeDefaultROBoardConfig())
Definition Encoder.cxx:30
void process(gsl::span< const ColumnData > data, InteractionRecord ir, EventType eventType=EventType::Standard)
Definition Encoder.cxx:150
void setNextTFToRead(uint32_t tf)
uint32_t getNTimeFrames() const
const LinkData & getLink(int i) const
GLuint buffer
Definition glcorearb.h:655
GLuint GLuint end
Definition glcorearb.h:469
GLboolean * data
Definition glcorearb.h:298
GLenum GLenum severity
Definition glcorearb.h:2513
std::unique_ptr< LinkDecoder > createLinkDecoder(const o2::header::RDHAny &rdh, uint16_t feeId, bool isDebugMode, uint8_t mask, const ElectronicsDelay &electronicsDelay, const FEEIdConfig &feeIdConfig)
Column data structure for MID.
Definition ColumnData.h:29
uint8_t deId
Index of the detection element.
Definition ColumnData.h:30
o2::InteractionRecord ir(0, 0)