Project
Loading...
Searching...
No Matches
DumpBuffer.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.
11
12#ifndef O2_MCH_RAW_IMPL_HELPERS_DUMPBUFFER_H
13#define O2_MCH_RAW_IMPL_HELPERS_DUMPBUFFER_H
14
19#include "MoveBuffer.h"
20#include <fmt/format.h>
21#include <gsl/span>
22#include <iostream>
23#include <limits>
24#include <vector>
25
26namespace o2::mch::raw::impl
27{
28
29template <typename T, std::enable_if_t<std::is_integral<T>::value, int> = 1>
30void dumpByteBuffer(gsl::span<T> buffer)
31{
32
33 int i{0};
34 while (i < buffer.size()) {
35 if (i % (16 / sizeof(T)) == 0) {
36 std::cout << fmt::format("\n{:8d} : ", i * sizeof(T));
37 }
38 std::cout << fmt::format("{:0{}X} ", buffer[i], sizeof(T) * 2);
39 i++;
40 }
41 std::cout << "\n";
42}
43
44inline void append(std::vector<std::byte>& buffer, uint64_t w)
45{
46 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x00000000000000FF)))});
47 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x000000000000FF00)) >> 8)});
48 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x0000000000FF0000)) >> 16)});
49 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x00000000FF000000)) >> 24)});
50 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x000000FF00000000)) >> 32)});
51 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x0000FF0000000000)) >> 40)});
52 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x00FF000000000000)) >> 48)});
53 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0xFF00000000000000)) >> 56)});
54}
55
56template <typename FORMAT>
57void dumpWord(std::ostream& out, uint64_t w);
58
59template <>
61{
62 // show word itself and it 10-bits parts
63 out << fmt::format("{:016X} {:4d} {:4d} {:4d} {:4d} {:4d} ",
64 w,
65 (w & 0x3FF0000000000) >> 40,
66 (w & 0xFFC0000000) >> 30,
67 (w & 0x3FF00000) >> 20,
68 (w & 0xFFC00) >> 10,
69 (w & 0x3FF));
70}
71
72template <>
74{
75 out << fmt::format("{:016X} ", w);
76}
77
78template <typename FORMAT, int VERSION = 0>
79void dumpWordInfo(std::ostream& out, uint64_t w, const char* spacer = "");
80
81template <>
82void dumpWordInfo<o2::mch::raw::BareFormat, 0>(std::ostream& out, uint64_t w, const char* /*spacer*/)
83{
84 static constexpr uint64_t FIFTYBITSATONE = (static_cast<uint64_t>(1) << 50) - 1;
85 SampaHeader h(w & FIFTYBITSATONE);
86 if (h == sampaSync()) {
87 out << "SYNC !!";
88 } else if (h.packetType() == SampaPacketType::Sync) {
89 out << "SYNC " << std::boolalpha << (h == sampaSync());
90 } else if (h.packetType() == SampaPacketType::Data) {
91 out << fmt::format(" n10 {:4d} chip {:2d} ch {:2d}",
92 h.nof10BitWords(), h.chipAddress(), h.channelAddress());
93 }
94}
95
96template <int VERSION>
97void dumpUserLogicWordInfo(std::ostream& out, uint64_t w, const char* spacer)
98{
100 out << "SYNC ";
101 }
102 if (w != 0xFEEDDEEDFEEDDEED && w != 0) {
104 out << spacer;
105 }
107 int gbt = header.linkID;
108 int elinkid = header.dsID;
109 int error = header.error;
110 bool incomplete = header.incomplete > 0;
111 out << fmt::format("GBT(0.11) {:2d} ELINKID(0..39) {:2d} ERR {:1d} INCOMPLETE {}",
112 gbt, elinkid, error, incomplete);
114 out << fmt::format("{:4d} {:4d} {:4d} {:4d} {:4d} ",
115 (w & 0x3FF0000000000) >> 40,
116 (w & 0xFFC0000000) >> 30,
117 (w & 0x3FF00000) >> 20,
118 (w & 0xFFC00) >> 10,
119 (w & 0x3FF));
120 }
121 }
122}
123
124template <>
126 const char* spacer)
127{
128 dumpUserLogicWordInfo<0>(out, w, spacer);
129}
130
131template <>
133 const char* spacer)
134{
135 dumpUserLogicWordInfo<1>(out, w, spacer);
136}
137
138template <typename FORMAT, int VERSION>
139void dumpBuffer(gsl::span<const std::byte> buffer, std::ostream& out = std::cout, size_t maxbytes = std::numeric_limits<size_t>::max())
140{
141 int i{0};
142 int inRDH{-1};
143 const void* rdhP{nullptr};
144 const char* spacer = " ";
145
146 if (buffer.size() < 8) {
147 out << "Should at least get 8 bytes to be able to dump\n";
148 return;
149 }
150 while ((i < buffer.size()) && i < maxbytes) {
151 if (i % 8 == 0) {
152 out << fmt::format("\n{:8d} : ", i);
153 }
155 dumpWord<FORMAT>(out, w);
156
157 if (inRDH >= 0) {
158 --inRDH;
159 }
160
161 if (buffer.size() >= i + 64) {
162 const void* testRDH = reinterpret_cast<const void*>(buffer.data() + i);
163 if (o2::raw::RDHUtils::checkRDH(testRDH, false)) {
164 rdhP = testRDH;
165 inRDH = 8;
166 out << "RDH ";
167 }
168 }
169
170 if (inRDH == 8) {
172 if (version >= 6) {
173 out << "SOURCE " << o2::raw::RDHUtils::getSourceID(rdhP) << " ";
174 }
175 out << fmt::format("VER {:2d} SIZ {:3d} FEEID {:5d}",
177 o2::raw::RDHUtils::getHeaderSize(rdhP),
178 o2::raw::RDHUtils::getFEEID(rdhP));
179 }
180
181 if (inRDH == 7) {
182 std::cout << spacer;
183 out << fmt::format("LINK {:3d} CRU {:3d} EP {:1d}",
184 o2::raw::RDHUtils::getLinkID(rdhP),
185 o2::raw::RDHUtils::getCRUID(rdhP),
186 o2::raw::RDHUtils::getEndPointID(rdhP));
187 }
188
189 if (inRDH == 6) {
190 std::cout << spacer;
191 out << fmt::format("ORBIT {:10d} BX {:4d}",
192 o2::raw::RDHUtils::getHeartBeatOrbit(rdhP),
193 o2::raw::RDHUtils::getHeartBeatBC(rdhP));
194 }
195
196 if (inRDH == 4) {
197 out << spacer;
198 out << fmt::format("TRIG 0x{:08X} PAGECOUNT {:5d}",
199 o2::raw::RDHUtils::getTriggerType(rdhP),
200 o2::raw::RDHUtils::getPageCounter(rdhP));
201 if (o2::raw::RDHUtils::getStop(rdhP)) {
202 out << " *STOP*";
203 }
204 }
205
206 if (inRDH == 2) {
207 out << spacer;
208 out << fmt::format("DET PAR {:5d} DET FIELD {:10d}",
209 o2::raw::RDHUtils::getDetectorPAR(rdhP),
210 o2::raw::RDHUtils::getDetectorField(rdhP));
211 }
212
213 if (inRDH <= 0) {
214 dumpWordInfo<FORMAT, VERSION>(out, w, spacer);
215 }
216 i += 8;
217 }
218 out << "\n";
219}
220
221template <typename FORMAT, int VERSION>
222void dumpBuffer(const std::vector<uint64_t>& buffer, std::ostream& out = std::cout, size_t maxbytes = std::numeric_limits<size_t>::max())
223{
224 std::vector<std::byte> b8;
225 for (auto w : buffer) {
226 append(b8, w);
227 }
228 dumpBuffer<FORMAT, VERSION>(b8, out, maxbytes);
229}
230} // namespace o2::mch::raw::impl
231#endif
std::vector< std::string > header
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
char error[CURL_ERROR_SIZE]
Definition of the RAW Data Header.
uint32_t version
Definition RawData.h:8
Class for time synchronization of RawReader instances.
SampaHeader is the 50-bits header word used in Sampa data transmission protocol.
Definition SampaHeader.h:51
GLuint buffer
Definition glcorearb.h:655
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
void dumpWord< o2::mch::raw::BareFormat >(std::ostream &out, uint64_t w)
Definition DumpBuffer.h:60
void dumpUserLogicWordInfo(std::ostream &out, uint64_t w, const char *spacer)
Definition DumpBuffer.h:97
uint64_t b8to64(gsl::span< const std::byte > buffer, size_t i)
Definition MoveBuffer.h:52
void dumpWordInfo< o2::mch::raw::UserLogicFormat, 0 >(std::ostream &out, uint64_t w, const char *spacer)
Definition DumpBuffer.h:125
void dumpWord< o2::mch::raw::UserLogicFormat >(std::ostream &out, uint64_t w)
Definition DumpBuffer.h:73
void dumpWordInfo(std::ostream &out, uint64_t w, const char *spacer="")
void dumpWord(std::ostream &out, uint64_t w)
void dumpByteBuffer(gsl::span< T > buffer)
Definition DumpBuffer.h:30
void append(std::vector< uint10_t > &b10, uint50_t value)
void dumpWordInfo< o2::mch::raw::UserLogicFormat, 1 >(std::ostream &out, uint64_t w, const char *spacer)
Definition DumpBuffer.h:132
void dumpBuffer(gsl::span< const std::byte > buffer, std::ostream &out=std::cout, size_t maxbytes=std::numeric_limits< size_t >::max())
Definition DumpBuffer.h:139
void dumpWordInfo< o2::mch::raw::BareFormat, 0 >(std::ostream &out, uint64_t w, const char *)
Definition DumpBuffer.h:82
constexpr bool isSampaSync(uint64_t w)
Whether the 50 LSB bits match the sync word.
SampaHeader sampaSync()
The 50-bits Sampa SYNC word.
static bool checkRDH(const RDHv4 &rdh, bool verbose=true, bool checkZeros=false)
Definition RDHUtils.cxx:133
static constexpr int getVersion()
get numeric version of the RDH
Definition RDHUtils.h:60