12#ifndef O2_MCH_RAW_IMPL_HELPERS_DUMPBUFFER_H
13#define O2_MCH_RAW_IMPL_HELPERS_DUMPBUFFER_H
20#include <fmt/format.h>
29template <typename T, std::enable_if_t<std::is_integral<T>::value,
int> = 1>
35 if (
i % (16 /
sizeof(T)) == 0) {
36 std::cout << fmt::format(
"\n{:8d} : ",
i *
sizeof(T));
38 std::cout << fmt::format(
"{:0{}X} ",
buffer[
i],
sizeof(T) * 2);
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)});
56template <
typename FORMAT>
63 out << fmt::format(
"{:016X} {:4d} {:4d} {:4d} {:4d} {:4d} ",
65 (
w & 0x3FF0000000000) >> 40,
66 (
w & 0xFFC0000000) >> 30,
67 (
w & 0x3FF00000) >> 20,
75 out << fmt::format(
"{:016X} ",
w);
78template <
typename FORMAT,
int VERSION = 0>
79void dumpWordInfo(std::ostream& out, uint64_t
w,
const char* spacer =
"");
84 static constexpr uint64_t FIFTYBITSATONE = (
static_cast<uint64_t
>(1) << 50) - 1;
89 out <<
"SYNC " << std::boolalpha << (
h ==
sampaSync());
91 out << fmt::format(
" n10 {:4d} chip {:2d} ch {:2d}",
92 h.nof10BitWords(),
h.chipAddress(),
h.channelAddress());
102 if (
w != 0xFEEDDEEDFEEDDEED &&
w != 0) {
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,
128 dumpUserLogicWordInfo<0>(out,
w, spacer);
135 dumpUserLogicWordInfo<1>(out,
w, spacer);
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())
143 const void* rdhP{
nullptr};
144 const char* spacer =
" ";
147 out <<
"Should at least get 8 bytes to be able to dump\n";
150 while ((
i <
buffer.size()) &&
i < maxbytes) {
152 out << fmt::format(
"\n{:8d} : ",
i);
155 dumpWord<FORMAT>(out,
w);
162 const void* testRDH =
reinterpret_cast<const void*
>(
buffer.data() +
i);
173 out <<
"SOURCE " << o2::raw::RDHUtils::getSourceID(rdhP) <<
" ";
175 out << fmt::format(
"VER {:2d} SIZ {:3d} FEEID {:5d}",
177 o2::raw::RDHUtils::getHeaderSize(rdhP),
178 o2::raw::RDHUtils::getFEEID(rdhP));
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));
191 out << fmt::format(
"ORBIT {:10d} BX {:4d}",
192 o2::raw::RDHUtils::getHeartBeatOrbit(rdhP),
193 o2::raw::RDHUtils::getHeartBeatBC(rdhP));
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)) {
208 out << fmt::format(
"DET PAR {:5d} DET FIELD {:10d}",
209 o2::raw::RDHUtils::getDetectorPAR(rdhP),
210 o2::raw::RDHUtils::getDetectorField(rdhP));
214 dumpWordInfo<FORMAT, VERSION>(out,
w, spacer);
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())
224 std::vector<std::byte> b8;
228 dumpBuffer<FORMAT, VERSION>(b8, out, maxbytes);
Class for time synchronization of RawReader instances.
GLubyte GLubyte GLubyte GLubyte w
void dumpWord< o2::mch::raw::BareFormat >(std::ostream &out, uint64_t w)
void dumpUserLogicWordInfo(std::ostream &out, uint64_t w, const char *spacer)
uint64_t b8to64(gsl::span< const std::byte > buffer, size_t i)
void dumpWordInfo< o2::mch::raw::UserLogicFormat, 0 >(std::ostream &out, uint64_t w, const char *spacer)
void dumpWord< o2::mch::raw::UserLogicFormat >(std::ostream &out, uint64_t w)
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)
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)
void dumpBuffer(gsl::span< const std::byte > buffer, std::ostream &out=std::cout, size_t maxbytes=std::numeric_limits< size_t >::max())
void dumpWordInfo< o2::mch::raw::BareFormat, 0 >(std::ostream &out, uint64_t w, const char *)
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)
static constexpr int getVersion()
get numeric version of the RDH