Project
Loading...
Searching...
No Matches
DataHeader.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
23
24
#include "
Headers/DataHeader.h
"
25
#include <cstdio>
// printf
26
#include <cstring>
// strncpy
27
28
//storage for BaseHeader static members, all invalid
29
const
uint32_t
o2::header::BaseHeader::sVersion
=
o2::header::gInvalidToken32
;
30
const
o2::header::HeaderType
o2::header::BaseHeader::sHeaderType
=
o2::header::gInvalidToken64
;
31
const
o2::header::SerializationMethod
o2::header::BaseHeader::sSerializationMethod
=
o2::header::gInvalidToken64
;
32
33
using namespace
o2::header
;
34
35
//__________________________________________________________________________________________________
36
bool
o2::header::BaseHeader::sanityCheck
(uint32_t expectedVersion)
const
37
{
38
if
(this->
headerVersion
!= expectedVersion) {
39
std::string errmsg =
"header of type "
+ this->
description
.
as
<std::string>() +
" with invalid "
;
40
errmsg +=
"version: "
+
std::to_string
(this->
headerVersion
) +
" (expected "
+
std::to_string
(expectedVersion) +
")"
;
41
// for the moment we throw, there is no support for multiple versions of a particular header
42
// so we better spot non matching header stacks early, we migh change this later
43
throw
std::runtime_error(errmsg);
44
return
false
;
45
}
46
return
true
;
47
}
48
49
//__________________________________________________________________________________________________
50
void
o2::header::BaseHeader::throwInconsistentStackError
()
const
51
{
52
throw
std::runtime_error(
"inconsistent header stack, no O2 header at expected offset "
+
std::to_string
(this->headerSize) +
"for header of type "
+ this->description.as<std::string>());
53
}
54
55
//__________________________________________________________________________________________________
56
bool
o2::header::DataHeader::operator==
(
const
DataOrigin
& that)
const
57
{
58
return
(that ==
gDataOriginAny
||
59
that == dataOrigin);
60
}
61
62
//__________________________________________________________________________________________________
63
bool
o2::header::DataHeader::operator==
(
const
DataDescription
& that)
const
64
{
65
return
((that.
itg
[0] ==
gDataDescriptionAny
.
itg
[0] &&
66
that.
itg
[1] ==
gDataDescriptionAny
.
itg
[1]) ||
67
(that.
itg
[0] == dataDescription.itg[0] &&
68
that.
itg
[1] == dataDescription.itg[1]));
69
}
70
71
//__________________________________________________________________________________________________
72
bool
o2::header::DataHeader::operator==
(
const
SerializationMethod
& that)
const
73
{
74
return
(that ==
gSerializationMethodAny
||
75
that == payloadSerializationMethod);
76
}
77
78
//__________________________________________________________________________________________________
79
bool
o2::header::DataHeader::operator==
(
const
DataHeader
& that)
const
80
{
81
return
(magicStringInt == that.
magicStringInt
&&
82
dataOrigin == that.
dataOrigin
&&
83
dataDescription == that.
dataDescription
&&
84
subSpecification == that.
subSpecification
);
85
}
86
87
//__________________________________________________________________________________________________
88
o2::header::DataIdentifier::DataIdentifier
()
89
: dataDescription(), dataOrigin()
90
{
91
}
92
93
//__________________________________________________________________________________________________
94
bool
o2::header::DataIdentifier::operator==
(
const
DataIdentifier
&
other
)
const
95
{
96
if
(
other
.dataOrigin !=
gDataOriginAny
&& dataOrigin !=
other
.dataOrigin) {
97
return
false
;
98
}
99
if
(
other
.dataDescription !=
gDataDescriptionAny
&&
100
dataDescription !=
other
.dataDescription) {
101
return
false
;
102
}
103
return
true
;
104
}
105
106
//__________________________________________________________________________________________________
107
void
o2::header::hexDump
(
const
char
* desc,
const
void
* voidaddr,
size_t
len
,
size_t
max
)
108
{
109
size_t
i
;
110
unsigned
char
buff[17];
// stores the ASCII data
111
memset(&buff[0],
'\0'
, 17);
112
const
std::byte* addr =
reinterpret_cast<
const
std::byte*
>
(voidaddr);
113
114
// Output description if given.
115
if
(desc !=
nullptr
) {
116
printf(
"%s, "
, desc);
117
}
118
printf(
"%zu bytes:"
,
len
);
119
if
(
max
> 0 &&
len
>
max
) {
120
len
=
max
;
//limit the output if requested
121
printf(
" output limited to %zu bytes\n"
,
len
);
122
}
else
{
123
printf(
"\n"
);
124
}
125
126
// In case of null pointer addr
127
if
(addr ==
nullptr
) {
128
printf(
" nullptr, size: %zu\n"
,
len
);
129
return
;
130
}
131
132
// Process every byte in the data.
133
for
(
i
= 0;
i
<
len
;
i
++) {
134
// Multiple of 16 means new line (with line offset).
135
if
((
i
% 16) == 0) {
136
// Just don't print ASCII for the zeroth line.
137
if
(
i
!= 0) {
138
printf(
" %s\n"
, buff);
139
}
140
141
// Output the offset.
142
//printf (" %04x ", i);
143
printf(
" %p "
, &addr[
i
]);
144
}
145
146
// Now the hex code for the specific character.
147
printf(
" %02x"
, (
char
)addr[
i
]);
148
149
// And store a printable ASCII character for later.
150
if
(((
char
)addr[
i
] < 0x20) || ((
char
)addr[
i
] > 0x7e)) {
151
buff[
i
% 16] =
'.'
;
152
}
else
{
153
buff[
i
% 16] = (
char
)addr[
i
];
154
}
155
buff[(
i
% 16) + 1] =
'\0'
;
156
fflush(stdout);
157
}
158
159
// Pad out last line if not exactly 16 characters.
160
while
((
i
% 16) != 0) {
161
printf(
" "
);
162
fflush(stdout);
163
i
++;
164
}
165
166
// And print the final ASCII bit.
167
printf(
" %s\n"
, buff);
168
fflush(stdout);
169
}
DataHeader.h
i
int32_t i
Definition
GPUCommonAlgorithm.h:443
char
len
GLenum GLenum GLsizei len
Definition
glcorearb.h:4232
o2::header::gDataOriginAny
constexpr o2::header::DataOrigin gDataOriginAny
Definition
DataHeader.h:560
o2::header::gDataDescriptionAny
constexpr o2::header::DataDescription gDataDescriptionAny
Definition
DataHeader.h:595
o2::header
O2 data header classes and API, v0.1.
Definition
DetID.h:49
o2::header::gInvalidToken64
const uint64_t gInvalidToken64
default int representation of 'invalid' token for 8-byte char field
Definition
DataHeader.h:319
o2::header::gSerializationMethodAny
constexpr o2::header::SerializationMethod gSerializationMethodAny
Definition
DataHeader.h:325
o2::header::hexDump
void hexDump(const char *desc, const void *voidaddr, size_t len, size_t max=0)
helper function to print a hex/ASCII dump of some memory
Definition
DataHeader.cxx:107
o2::header::gInvalidToken32
const uint32_t gInvalidToken32
default int representation of 'invalid' token for 4-byte char field
Definition
DataHeader.h:317
std::to_string
std::string to_string(gsl::span< T, Size > span)
Definition
common.h:52
o2::header::BaseHeader::description
o2::header::HeaderType description
header type description, set by derived header
Definition
DataHeader.h:385
o2::header::BaseHeader::sanityCheck
bool sanityCheck(uint32_t expectedVersion) const
Definition
DataHeader.cxx:36
o2::header::BaseHeader::sHeaderType
static const o2::header::HeaderType sHeaderType
Definition
DataHeader.h:356
o2::header::BaseHeader::throwInconsistentStackError
void throwInconsistentStackError() const
Definition
DataHeader.cxx:50
o2::header::BaseHeader::headerVersion
uint32_t headerVersion
version of the entire header, set by the derived header
Definition
DataHeader.h:382
o2::header::BaseHeader::sSerializationMethod
static const o2::header::SerializationMethod sSerializationMethod
Definition
DataHeader.h:357
o2::header::BaseHeader::magicStringInt
uint32_t magicStringInt
Definition
DataHeader.h:364
o2::header::BaseHeader::sVersion
static const uint32_t sVersion
Definition
DataHeader.h:355
o2::header::DataHeader
the main header struct
Definition
DataHeader.h:618
o2::header::DataHeader::dataDescription
DataDescription dataDescription
Definition
DataHeader.h:636
o2::header::DataHeader::subSpecification
SubSpecificationType subSpecification
Definition
DataHeader.h:656
o2::header::DataHeader::operator==
bool operator==(const DataHeader &) const
Definition
DataHeader.cxx:79
o2::header::DataHeader::dataOrigin
DataOrigin dataOrigin
Definition
DataHeader.h:641
o2::header::DataIdentifier
Helper struct to encode origin and description of data.
Definition
DataHeader.h:757
o2::header::DataIdentifier::operator==
bool operator==(const DataIdentifier &) const
Definition
DataHeader.cxx:94
o2::header::DataIdentifier::DataIdentifier
DataIdentifier()
Definition
DataHeader.cxx:88
o2::header::Descriptor< gSizeHeaderDescriptionString >
o2::header::Descriptor::as
std::enable_if_t< std::is_same< T, std::string >::value==true, T > as() const
get the descriptor as std::string
Definition
DataHeader.h:301
o2::header::Descriptor::itg
ItgType itg[arraySize]
Definition
DataHeader.h:218
max
constexpr size_t max
Definition
test_Algorithm.cxx:49
other
VectorOfTObjectPtrs other
Definition
test_Algorithm.cxx:501
DataFormats
Headers
src
DataHeader.cxx
Generated on Tue Feb 25 2025 17:02:53 for Project by
1.9.8