Skip to content

Commit b92d246

Browse files
matthiasrichterktf
authored andcommitted
Moving NameHeader definition to separate file
1 parent 6e3e677 commit b92d246

File tree

7 files changed

+99
-56
lines changed

7 files changed

+99
-56
lines changed

Algorithm/test/headerstack.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <iomanip>
2222
#include <cstring> // memcmp
2323
#include "Headers/DataHeader.h" // hexdump
24+
#include "Headers/NameHeader.h"
2425
#include "../include/Algorithm/HeaderStack.h"
2526

2627
using DataHeader = o2::Header::DataHeader;

DataFormats/Headers/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ O2_SETUP(NAME ${MODULE_NAME})
77
# Define the source and header files
88
set(SRCS
99
src/DataHeader.cxx
10+
src/NameHeader.cxx
1011
src/HeartbeatFrame.cxx
1112
src/TimeStamp.cxx
1213
)
1314

1415
set(HEADERS
1516
include/${MODULE_NAME}/DataHeader.h
17+
include/${MODULE_NAME}/NameHeader.h
1618
include/${MODULE_NAME}/HeartbeatFrame.h
1719
include/${MODULE_NAME}/TimeStamp.h
1820
)

DataFormats/Headers/include/Headers/DataHeader.h

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -519,58 +519,6 @@ struct Stack {
519519
}
520520
};
521521

522-
//__________________________________________________________________________________________________
523-
/// @struct NameHeader
524-
/// @brief an example data header containing a name of an object as a null terminated char arr.
525-
/// this is a template! at instantiation the template parameter determines the
526-
/// size of the held string array.
527-
/// a caveat with decoding is you have to use Header::get<NameHeader<0>>(buffer)
528-
/// to get it out of a buffer. May improve in the future if enough people complain.
529-
/// @ingroup aliceo2_dataformats_dataheader
530-
template <size_t N>
531-
struct NameHeader : public BaseHeader {
532-
static const uint32_t sVersion;
533-
static const o2::Header::HeaderType sHeaderType;
534-
static const o2::Header::SerializationMethod sSerializationMethod;
535-
NameHeader()
536-
: BaseHeader(sizeof(NameHeader), sHeaderType, sSerializationMethod, sVersion)
537-
, name()
538-
{
539-
memset(&name[0],'\0',N);
540-
}
541-
542-
NameHeader(std::string in)
543-
: BaseHeader(sizeof(NameHeader), sHeaderType, sSerializationMethod, sVersion)
544-
, name()
545-
{
546-
//std::copy(in.begin(), in.begin()+N, name);
547-
// here we actually wnat a null terminated string
548-
strncpy(name,in.c_str(),N);
549-
name[N-1] = '\0';
550-
}
551-
552-
NameHeader& operator=(const std::string string) {
553-
std::copy(string.begin(), string.begin()+N, name);
554-
return *this;
555-
}
556-
private:
557-
char name[N];
558-
};
559-
560-
template <size_t N>
561-
const o2::Header::HeaderType NameHeader<N>::sHeaderType = "NameHead";
562-
563-
// dirty trick to always have access to the headertypeID of a templated header type
564-
// TODO: find out if this can be done in a nicer way + is this realy necessary?
565-
template <>
566-
const o2::Header::HeaderType NameHeader<0>::sHeaderType;
567-
568-
template <size_t N>
569-
const SerializationMethod NameHeader<N>::sSerializationMethod = gSerializationMethodNone;
570-
571-
template <size_t N>
572-
const uint32_t NameHeader<N>::sVersion = 1;
573-
574522
//__________________________________________________________________________________________________
575523
/// this 128 bit type for a header field describing the payload data type
576524
struct printDataDescription {
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
/// @brief O2 data header classes, header example
12+
///
13+
/// origin: CWG4
14+
/// @author Mikolaj Krzewicki, mkrzewic@cern.ch
15+
/// @author Matthias Richter, Matthias.Richter@cern.ch
16+
/// @author David Rohr, drohr@cern.ch
17+
18+
#ifndef NAMEHEADER_H
19+
#define NAMEHEADER_H
20+
21+
#include <string>
22+
#include "Headers/DataHeader.h"
23+
24+
namespace o2 {
25+
namespace Header {
26+
27+
/// @struct NameHeader
28+
/// @brief an example data header containing a name of an object as a null terminated char arr.
29+
/// this is a template! at instantiation the template parameter determines the
30+
/// size of the held string array.
31+
/// a caveat with decoding is you have to use Header::get<NameHeader<0>>(buffer)
32+
/// to get it out of a buffer. May improve in the future if enough people complain.
33+
/// @ingroup aliceo2_dataformats_dataheader
34+
template <size_t N>
35+
struct NameHeader : public BaseHeader {
36+
static const uint32_t sVersion;
37+
static const o2::Header::HeaderType sHeaderType;
38+
static const o2::Header::SerializationMethod sSerializationMethod;
39+
NameHeader()
40+
: BaseHeader(sizeof(NameHeader), sHeaderType, sSerializationMethod, sVersion)
41+
, name()
42+
{
43+
memset(&name[0],'\0',N);
44+
}
45+
46+
NameHeader(std::string in)
47+
: BaseHeader(sizeof(NameHeader), sHeaderType, sSerializationMethod, sVersion)
48+
, name()
49+
{
50+
// here we actually want a null terminated string
51+
strncpy(name, in.c_str(), N);
52+
name[N-1] = '\0';
53+
}
54+
55+
NameHeader& operator=(const std::string string) {
56+
std::copy(string.begin(), string.begin()+N, name);
57+
return *this;
58+
}
59+
private:
60+
char name[N];
61+
};
62+
63+
template <size_t N>
64+
const o2::Header::HeaderType NameHeader<N>::sHeaderType = "NameHead";
65+
66+
// dirty trick to always have access to the headertypeID of a templated header type
67+
// TODO: find out if this can be done in a nicer way + is this realy necessary?
68+
template <>
69+
const o2::Header::HeaderType NameHeader<0>::sHeaderType;
70+
71+
template <size_t N>
72+
const SerializationMethod NameHeader<N>::sSerializationMethod = gSerializationMethodNone;
73+
74+
template <size_t N>
75+
const uint32_t NameHeader<N>::sVersion = 1;
76+
77+
}
78+
}
79+
80+
#endif //NAMEHEADER_H

DataFormats/Headers/src/DataHeader.cxx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ const uint32_t o2::Header::DataHeader::sVersion = 1;
7777
const o2::Header::HeaderType o2::Header::DataHeader::sHeaderType = String2<uint64_t>("DataHead");
7878
const o2::Header::SerializationMethod o2::Header::DataHeader::sSerializationMethod = o2::Header::gSerializationMethodNone;
7979

80-
//storage fr NameHeader static
81-
template <>
82-
const o2::Header::HeaderType o2::Header::NameHeader<0>::sHeaderType = "NameHead";
83-
8480
using namespace o2::Header;
8581

8682
//__________________________________________________________________________________________________
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright CERN and copyright holders of ALICE O2. This software is
2+
// distributed under the terms of the GNU General Public License v3 (GPL
3+
// Version 3), copied verbatim in the file "COPYING".
4+
//
5+
// See http://alice-o2.web.cern.ch/license for full licensing information.
6+
//
7+
// In applying this license CERN does not waive the privileges and immunities
8+
// granted to it by virtue of its status as an Intergovernmental Organization
9+
// or submit itself to any jurisdiction.
10+
11+
#include "Headers/NameHeader.h"
12+
13+
//storage for NameHeader static
14+
template <>
15+
const o2::Header::HeaderType o2::Header::NameHeader<0>::sHeaderType = "NameHead";

Utilities/O2MessageMonitor/src/O2MessageMonitor.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <options/FairMQProgOptions.h>
3333
#include <FairMQLogger.h>
3434
#include "Headers/DataHeader.h"
35+
#include "Headers/NameHeader.h"
3536

3637
using namespace std;
3738
using namespace o2::Header;

0 commit comments

Comments
 (0)