Project
Loading...
Searching...
No Matches
RDHManip.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
14#include "RDHManip.h"
15#include <cassert>
16#include <fmt/format.h>
17#include <iostream>
18#include <string>
20#include "Headers/RDHAny.h"
22
23namespace
24{
25std::string triggerTypeAsString(uint32_t triggerType)
26{
27 std::string s;
28
29 if (triggerType == 0) {
30 s = "UNKNOWN";
31 }
32
33 if (triggerType & o2::trigger::ORBIT) {
34 s += "ORBIT ";
35 }
36 if (triggerType & o2::trigger::HB) {
37 s += "HB ";
38 }
39 if (triggerType & o2::trigger::HBr) {
40 s += "HBr ";
41 }
42 if (triggerType & o2::trigger::HC) {
43 s += "HC ";
44 }
45 if (triggerType & o2::trigger::PhT) {
46 s += "PhT ";
47 }
48 if (triggerType & o2::trigger::PP) {
49 s += "PP ";
50 }
51 if (triggerType & o2::trigger::Cal) {
52 s += "Cal ";
53 }
54 if (triggerType & o2::trigger::SOT) {
55 s += "SOT ";
56 }
57 if (triggerType & o2::trigger::EOT) {
58 s += "EOT ";
59 }
60 if (triggerType & o2::trigger::SOC) {
61 s += "SOC ";
62 }
63 if (triggerType & o2::trigger::EOC) {
64 s += "EOC ";
65 }
66 if (triggerType & o2::trigger::TF) {
67 s += "TF ";
68 }
69 if (triggerType & o2::trigger::TPC) {
70 s += "TPC ";
71 }
72 if (triggerType & o2::trigger::TPCrst) {
73 s += "TPCrst ";
74 }
75 if (triggerType & o2::trigger::TOF) {
76 s += "TOF ";
77 }
78 return s;
79}
80} // namespace
81
82namespace o2::header
83{
84std::ostream& operator<<(std::ostream& os, const o2::header::RDHAny& rdh)
85{
86 auto triggerType = o2::raw::RDHUtils::getTriggerType(rdh);
87 auto headerSize = o2::raw::RDHUtils::getHeaderSize(rdh);
88
89 os << fmt::format("version {:03d} headerSize {:03d} triggerType {:08x} {:s}\n",
91 headerSize,
92 triggerType,
93 triggerTypeAsString(triggerType));
94
95 os << fmt::format("cruId {:03d} dpwId {:02d} linkId {:03d}\n",
96 o2::raw::RDHUtils::getCRUID(rdh),
97 o2::raw::RDHUtils::getEndPointID(rdh),
98 o2::raw::RDHUtils::getLinkID(rdh));
99
100 auto memorySize = o2::raw::RDHUtils::getMemorySize(rdh);
101
102 os << fmt::format("offsetToNext {:05d} memorySize {:05d} {:s}\n",
103 o2::raw::RDHUtils::getOffsetToNext(rdh),
104 memorySize,
105 memorySize == headerSize ? "EMPTY" : "");
106
107 os << fmt::format("heartbeatOrbit{:010d} heartbeatBC {:04d} feeId {:6d}\n",
108 o2::raw::RDHUtils::getHeartBeatOrbit(rdh),
109 o2::raw::RDHUtils::getHeartBeatBC(rdh),
110 o2::raw::RDHUtils::getFEEID(rdh));
111
112 auto stop = o2::raw::RDHUtils::getStop(rdh);
113 os << fmt::format("stopBit {:1d} pagesCounter {:03d} packetCounter {:03d} {:s}\n",
114 stop,
115 o2::raw::RDHUtils::getPageCounter(rdh),
116 o2::raw::RDHUtils::getPacketCounter(rdh),
117 stop ? "STOP" : "");
118
119 return os;
120}
121
122} // namespace o2::header
123
124using namespace o2::header;
125
126namespace o2::mch::raw
127{
128
129void append(std::vector<std::byte>& buffer, uint64_t w)
130{
131 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x00000000000000FF)) >> 0)});
132 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x000000000000FF00)) >> 8)});
133 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x0000000000FF0000)) >> 16)});
134 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x00000000FF000000)) >> 24)});
135 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x000000FF00000000)) >> 32)});
136 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x0000FF0000000000)) >> 40)});
137 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0x00FF000000000000)) >> 48)});
138 buffer.emplace_back(std::byte{static_cast<uint8_t>((w & UINT64_C(0xFF00000000000000)) >> 56)});
139}
140
141void append(std::vector<uint32_t>& buffer, uint64_t w)
142{
143 buffer.emplace_back(static_cast<uint32_t>(w & 0xFFFFFFFF));
144 buffer.emplace_back(static_cast<uint32_t>((w & UINT64_C(0xFFFFFFFF00000000)) >> 32));
145}
146
147void appendRDH(std::vector<std::byte>& buffer, const o2::header::RDHAny& rdh)
148{
149 append(buffer, rdh.word0);
150 append(buffer, rdh.word1);
151 append(buffer, rdh.word2);
152 append(buffer, rdh.word3);
153 append(buffer, rdh.word4);
154 append(buffer, rdh.word5);
155 append(buffer, rdh.word6);
156 append(buffer, rdh.word7);
157}
158
159uint64_t eightBytes(gsl::span<const std::byte> buffer)
160{
161 return (static_cast<uint64_t>(buffer[0])) |
162 (static_cast<uint64_t>(buffer[1]) << 8) |
163 (static_cast<uint64_t>(buffer[2]) << 16) |
164 (static_cast<uint64_t>(buffer[3]) << 24) |
165 (static_cast<uint64_t>(buffer[4]) << 32) |
166 (static_cast<uint64_t>(buffer[5]) << 40) |
167 (static_cast<uint64_t>(buffer[6]) << 48) |
168 (static_cast<uint64_t>(buffer[7]) << 56);
169}
170
171o2::header::RDHAny createRDH(gsl::span<const std::byte> buffer, int version)
172{
173 auto minSize = sizeof(o2::header::RDHAny);
174 if (buffer.size() < minSize) {
175 throw std::invalid_argument(fmt::format("buffer should be at least {} bytes", minSize));
176 }
178
180
181 rdh.word0 = eightBytes(buffer.subspan(0));
182 rdh.word1 = eightBytes(buffer.subspan(8));
183 rdh.word2 = eightBytes(buffer.subspan(16));
184 rdh.word3 = eightBytes(buffer.subspan(24));
185 rdh.word4 = eightBytes(buffer.subspan(32));
186 rdh.word5 = eightBytes(buffer.subspan(40));
187 rdh.word6 = eightBytes(buffer.subspan(48));
188 rdh.word7 = eightBytes(buffer.subspan(56));
189
190 return rdh;
191}
192
193int forEachRDH(gsl::span<const std::byte> buffer, std::function<void(const void*)> f = nullptr)
194{
195 int index{0};
196 int nrdh{0};
197 while (index < buffer.size()) {
198 const void* rdhPtr = reinterpret_cast<const void*>(buffer.data() + index);
199 if (!o2::raw::RDHUtils::checkRDH(rdhPtr, true)) {
200 break;
201 }
202 nrdh++;
203 if (f) {
204 f(rdhPtr);
205 }
206 auto offsetToNext = o2::raw::RDHUtils::getOffsetToNext(rdhPtr);
207 if (offsetToNext == 0) {
208 return -1;
209 }
210 index += offsetToNext;
211 }
212 return nrdh;
213}
214
215int showRDHs(gsl::span<const std::byte> buffer)
216{
217 assert(buffer.size() % 4 == 0);
218 return forEachRDH(buffer, [](const void* rdhPtr) {
220 switch (version) {
221 case 3:
222 case 4:
223 std::cout << (*reinterpret_cast<const RAWDataHeaderV4*>(rdhPtr)) << "\n";
224 break;
225 case 5:
226 std::cout << (*reinterpret_cast<const RAWDataHeaderV5*>(rdhPtr)) << "\n";
227 break;
228 case 6:
229 std::cout << (*reinterpret_cast<const RAWDataHeaderV6*>(rdhPtr)) << "\n";
230 break;
231 case 7:
232 std::cout << (*reinterpret_cast<const RAWDataHeaderV7*>(rdhPtr)) << "\n";
233 break;
234 default:
235 throw std::invalid_argument(fmt::format("RDH version {} not yet supported by showRDHs function",
236 version));
237 }
238 });
239}
240
241int countRDHs(gsl::span<const std::byte> buffer)
242{
243 return forEachRDH(buffer);
244}
245
246} // namespace o2::mch::raw
Definition of the 32 Central Trigger System (CTS) Trigger Types defined in https://twiki....
Definition of the RAW Data Header.
uint32_t version
Definition RawData.h:8
GLuint buffer
Definition glcorearb.h:655
GLuint index
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
O2 data header classes and API, v0.1.
Definition DetID.h:49
std::ostream & operator<<(std::ostream &os, const o2::header::RDHAny &rdh)
Definition RDHManip.cxx:84
uint64_t eightBytes(gsl::span< const std::byte > buffer)
Definition RDHManip.cxx:159
o2::header::RDHAny createRDH(gsl::span< const std::byte > buffer, int version)
Definition RDHManip.cxx:171
int forEachRDH(gsl::span< const std::byte > buffer, std::function< void(const void *)> f=nullptr)
Definition RDHManip.cxx:193
void append(const char *msg, std::string &to)
int countRDHs(gsl::span< const std::byte > buffer)
Count the number of RDHs in the buffer.
Definition RDHManip.cxx:241
void appendRDH(std::vector< std::byte > &buffer, const o2::header::RDHAny &rdh)
Append bytes from RDH to the buffer.
Definition RDHManip.cxx:147
int showRDHs(gsl::span< const std::byte > buffer)
Dump the RDHs found in the buffer.
Definition RDHManip.cxx:215
constexpr uint32_t EOT
Definition Triggers.h:34
constexpr uint32_t TPC
Definition Triggers.h:39
constexpr uint32_t TPCrst
Definition Triggers.h:40
constexpr uint32_t PhT
Definition Triggers.h:30
constexpr uint32_t SOT
Definition Triggers.h:33
constexpr uint32_t PP
Definition Triggers.h:31
constexpr uint32_t HBr
Definition Triggers.h:28
constexpr uint32_t TF
Definition Triggers.h:37
constexpr uint32_t ORBIT
Definition Triggers.h:26
constexpr uint32_t EOC
Definition Triggers.h:36
constexpr uint32_t HC
Definition Triggers.h:29
constexpr uint32_t SOC
Definition Triggers.h:35
constexpr uint32_t Cal
Definition Triggers.h:32
constexpr uint32_t TOF
Definition Triggers.h:41
constexpr uint32_t HB
Definition Triggers.h:27
uint64_t word7
Definition RDHAny.h:37
uint64_t word6
Definition RDHAny.h:36
uint64_t word0
Definition RDHAny.h:30
uint64_t word1
Definition RDHAny.h:31
uint64_t word3
Definition RDHAny.h:33
uint64_t word2
Definition RDHAny.h:32
uint64_t word4
Definition RDHAny.h:34
uint64_t word5
Definition RDHAny.h:35
static bool checkRDH(const RDHv4 &rdh, bool verbose=true, bool checkZeros=false)
Definition RDHUtils.cxx:133
static void setVersion(H &rdh, uint8_t v, NOTPTR(H))
Definition RDHUtils.h:88
static constexpr int getVersion()
get numeric version of the RDH
Definition RDHUtils.h:58