Project
Loading...
Searching...
No Matches
headerstack.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
16
17
#define BOOST_TEST_MODULE Test Algorithm HeaderStack
18
#define BOOST_TEST_MAIN
19
#define BOOST_TEST_DYN_LINK
20
#include <boost/test/unit_test.hpp>
21
#include <iostream>
22
#include <iomanip>
23
#include <cstring>
// memcmp
24
#include "
Headers/DataHeader.h
"
// hexdump
25
#include "
Headers/NameHeader.h
"
26
#include "
Headers/Stack.h
"
27
#include "../include/Algorithm/HeaderStack.h"
28
29
using
DataHeader
=
o2::header::DataHeader
;
30
using
HeaderStack
=
o2::header::Stack
;
31
32
BOOST_AUTO_TEST_CASE
(test_headerstack)
33
{
34
// make a header stack consisting of two O2 headers and extract them
35
// via function calls using dispatchHeaderStackCallback, and through object
36
// references using parseHeaderStack
37
o2::header::DataHeader
dh;
38
dh.
dataDescription
=
o2::header::DataDescription
(
"SOMEDATA"
);
39
dh.
dataOrigin
=
o2::header::DataOrigin
(
"TST"
);
40
dh.
subSpecification
= 0;
41
dh.
payloadSize
= 0;
42
43
using
Name8Header =
o2::header::NameHeader<8>
;
44
Name8Header nh(
"NAMEHDR"
);
45
46
o2::header::Stack
stack
(dh, nh);
47
48
// check that the call without any other arguments is compiling
49
o2::algorithm::dispatchHeaderStackCallback
(
stack
.data(),
stack
.size());
50
51
// lambda functor given as argument for dispatchHeaderStackCallback
52
auto
checkDataHeader = [&dh](
const
auto
& header) {
53
o2::header::hexDump
(
"Extracted DataHeader"
, &header,
sizeof
(header));
54
BOOST_CHECK
(header == dh);
55
};
56
57
// lambda functor given as argument for dispatchHeaderStackCallback
58
auto
checkNameHeader = [&nh](
const
auto
& header) {
59
o2::header::hexDump
(
"Extracted NameHeader"
, &header,
sizeof
(header));
60
// have to compare on byte level, no operator==
61
BOOST_CHECK
(memcmp(&header, &nh,
sizeof
(header)) == 0);
62
};
63
64
// check extraction of headers via callbacks
65
o2::algorithm::dispatchHeaderStackCallback
(
stack
.data(),
stack
.size(),
66
o2::header::DataHeader
(),
67
checkDataHeader,
68
Name8Header(),
69
checkNameHeader);
70
71
// check extraction of only one header via callback
72
o2::algorithm::dispatchHeaderStackCallback
(
stack
.data(),
stack
.size(),
73
Name8Header(),
74
checkNameHeader);
75
76
// check that the call without any other arguments is compiling
77
o2::algorithm::parseHeaderStack
(
stack
.data(),
stack
.size());
78
79
// check extraction of headers via object references
80
o2::header::DataHeader
targetDataHeader;
81
Name8Header targetNameHeader;
82
o2::algorithm::parseHeaderStack
(
stack
.data(),
stack
.size(),
83
targetDataHeader,
84
targetNameHeader);
85
86
BOOST_CHECK
(targetDataHeader == dh);
87
BOOST_CHECK
(memcmp(&targetNameHeader, &nh,
sizeof
(targetNameHeader)) == 0);
88
}
Stack.h
DataHeader.h
NameHeader.h
stack
uint32_t stack
Definition
RawData.h:1
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(test_headerstack)
Definition
headerstack.cxx:32
o2::algorithm::parseHeaderStack
void parseHeaderStack(PtrType ptr, SizeType size, HeaderType &header, MoreTypes &&... types)
Definition
HeaderStack.h:155
o2::algorithm::dispatchHeaderStackCallback
void dispatchHeaderStackCallback(PtrType ptr, SizeType size, HeaderType header, HeaderCallbackType onHeader, MoreTypes &&... types)
Definition
HeaderStack.h:90
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::DataDescription
Descriptor< gSizeDataDescriptionString > DataDescription
Definition
DataHeader.h:551
o2::header::DataOrigin
Descriptor< gSizeDataOriginString > DataOrigin
Definition
DataHeader.h:550
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::payloadSize
PayloadSizeType payloadSize
Definition
DataHeader.h:666
o2::header::DataHeader::dataOrigin
DataOrigin dataOrigin
Definition
DataHeader.h:641
o2::header::NameHeader
an example data header containing a name of an object as a null terminated char arr....
Definition
NameHeader.h:39
o2::header::Stack
a move-only header stack with serialized headers This is the flat buffer where all the headers in a m...
Definition
Stack.h:36
BOOST_CHECK
BOOST_CHECK(tree)
Algorithm
test
headerstack.cxx
Generated on Tue Feb 25 2025 23:16:07 for Project by
1.9.8