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
32
33using namespace o2::header;
34
35//__________________________________________________________________________________________________
36bool 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//__________________________________________________________________________________________________
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//__________________________________________________________________________________________________
57{
58 return (that == gDataOriginAny ||
59 that == dataOrigin);
60}
61
62//__________________________________________________________________________________________________
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//__________________________________________________________________________________________________
73{
74 return (that == gSerializationMethodAny ||
75 that == payloadSerializationMethod);
76}
77
78//__________________________________________________________________________________________________
80{
81 return (magicStringInt == that.magicStringInt &&
82 dataOrigin == that.dataOrigin &&
83 dataDescription == that.dataDescription &&
84 subSpecification == that.subSpecification);
85}
86
87//__________________________________________________________________________________________________
89 : dataDescription(), dataOrigin()
90{
91}
92
93//__________________________________________________________________________________________________
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//__________________________________________________________________________________________________
107void 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}
int32_t i
GLenum GLenum GLsizei len
Definition glcorearb.h:4232
constexpr o2::header::DataOrigin gDataOriginAny
Definition DataHeader.h:560
constexpr o2::header::DataDescription gDataDescriptionAny
Definition DataHeader.h:595
O2 data header classes and API, v0.1.
Definition DetID.h:49
const uint64_t gInvalidToken64
default int representation of 'invalid' token for 8-byte char field
Definition DataHeader.h:319
constexpr o2::header::SerializationMethod gSerializationMethodAny
Definition DataHeader.h:325
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
const uint32_t gInvalidToken32
default int representation of 'invalid' token for 4-byte char field
Definition DataHeader.h:317
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52
o2::header::HeaderType description
header type description, set by derived header
Definition DataHeader.h:385
bool sanityCheck(uint32_t expectedVersion) const
static const o2::header::HeaderType sHeaderType
Definition DataHeader.h:356
void throwInconsistentStackError() const
uint32_t headerVersion
version of the entire header, set by the derived header
Definition DataHeader.h:382
static const o2::header::SerializationMethod sSerializationMethod
Definition DataHeader.h:357
static const uint32_t sVersion
Definition DataHeader.h:355
the main header struct
Definition DataHeader.h:618
DataDescription dataDescription
Definition DataHeader.h:636
SubSpecificationType subSpecification
Definition DataHeader.h:656
bool operator==(const DataHeader &) const
Helper struct to encode origin and description of data.
Definition DataHeader.h:757
bool operator==(const DataIdentifier &) const
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
ItgType itg[arraySize]
Definition DataHeader.h:218
constexpr size_t max
VectorOfTObjectPtrs other