Belle II Software light-2505-deimos
EvtMessage.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#pragma once
10
11#include <RtypesCore.h>
12
13struct timeval;
14
15namespace Belle2 {
20
25 enum ERecordType { MSG_EVENT, MSG_BEGIN_RUN, MSG_END_RUN, MSG_TERMINATE, MSG_NORECORD, MSG_STREAMERINFO };
26
28 struct EvtHeader {
30 EvtHeader(UInt_t aSize, ERecordType aRectype): size(aSize), rectype(aRectype) {}
31 UInt_t size;
33 Long64_t time_sec{0};
34 Long64_t time_usec{0};
35 UInt_t src{(UInt_t) - 1};
36 UInt_t dest{(UInt_t) - 1};
37 UInt_t flags{0};
39 UInt_t nObjects{0};
40 UInt_t nArrays{0};
41 UInt_t reserved[6] {0};
48 UInt_t version{0xBEEFED01};
49 };
50
59 class EvtMessage {
60
61 public:
63 const static unsigned int c_MaxEventSize = 200000000;
64
71
73 explicit EvtMessage(char* buf = nullptr);
75 EvtMessage(const char* msg, int size, ERecordType type);
77 EvtMessage(const EvtMessage& evtmsg);
80
82 EvtMessage& operator=(const EvtMessage& obj);
83
84
85 // Access functions
92 char* buffer();
94 void buffer(const char*);
95
97 int size() const;
102 int paddedSize() const;
104 int msg_size() const;
105
107 unsigned int getVersion() const { return ((getHeader()->version & 0xFFFFFF00) == 0xBEEFED00) ? (getHeader()->version & 0xFF) : 0;}
109 unsigned int getMsgFlags() const { return getVersion() > 0 ? getHeader()->flags : 0; }
111 void setMsgFlags(unsigned int flags) { header()->flags = flags;}
113 void addMsgFlags(unsigned int flags) { header()->flags |= flags;}
115 bool hasMsgFlags(unsigned int flags) const { return (getMsgFlags() & flags) == flags; }
116
118 ERecordType type() const;
120 void type(ERecordType);
121
123 struct timeval time() const;
125 void setTime(const struct timeval& time);
126
128 int src() const;
130 void src(int src);
131
133 int dest() const;
135 void dest(int dest);
136
138 EvtHeader* header();
140 const EvtHeader* getHeader() const;
142 char* msg();
143
144 private:
146 void setMsg(const char* msg, int size, ERecordType type);
147
148 char* m_data;
150 };
151
152}
Class to manage streamed object.
Definition EvtMessage.h:59
int dest() const
Get destination IP of message.
int msg_size() const
Get size of message body.
int paddedSize() const
Same as size(), but as size of an integer array.
Definition EvtMessage.cc:99
EvtMessage(char *buf=nullptr)
build EvtMessage from existing buffer (no copy, but does not take ownership).
Definition EvtMessage.cc:27
unsigned int getVersion() const
get version of the header.
Definition EvtMessage.h:107
ERecordType type() const
Get record type.
int src() const
Get source IP of message.
struct timeval time() const
Get time stamp.
bool hasMsgFlags(unsigned int flags) const
Check if the message has the given flags.
Definition EvtMessage.h:115
unsigned int getMsgFlags() const
Get flags of the message.
Definition EvtMessage.h:109
char * m_data
Pointer to the internal EvtMessage buffer.
Definition EvtMessage.h:148
EvtHeader * header()
Get pointer to EvtHeader.
char * buffer()
Get buffer address.
Definition EvtMessage.cc:76
~EvtMessage()
Destructor.
Definition EvtMessage.cc:56
void setMsgFlags(unsigned int flags)
Set flags for the message.
Definition EvtMessage.h:111
static const unsigned int c_MaxEventSize
maximal EvtMessage size, in bytes (200MB).
Definition EvtMessage.h:63
void setMsg(const char *msg, int size, ERecordType type)
Copy message into newly allocated buffer.
char * msg()
Get pointer to message body.
void addMsgFlags(unsigned int flags)
Add flags to the message.
Definition EvtMessage.h:113
bool m_ownsBuffer
Whether to clean up m_data in destructor.
Definition EvtMessage.h:149
void setTime(const struct timeval &time)
Set time stamp.
const EvtHeader * getHeader() const
Get pointer to EvtHeader.
EMessageFlags
Flags for the message.
Definition EvtMessage.h:66
@ c_MsgCompressed
indicates that the message body is compressed and should be uncompressed using ROOT R__unzip_header a...
Definition EvtMessage.h:69
EvtMessage & operator=(const EvtMessage &obj)
Assignment (m_data is copied).
Definition EvtMessage.cc:64
int size() const
Get size of message including headers.
Definition EvtMessage.cc:94
ERecordType
What type of message is this?
Definition EvtMessage.h:25
Abstract base class for different kinds of events.
Header structure of streamed object list.
Definition EvtMessage.h:28
Long64_t time_usec
micro seconds part of timeval.
Definition EvtMessage.h:34
UInt_t dest
destination IP.
Definition EvtMessage.h:36
UInt_t src
source IP.
Definition EvtMessage.h:35
EvtHeader(UInt_t aSize, ERecordType aRectype)
set number of words and record type.
Definition EvtMessage.h:30
UInt_t reserved[6]
Reserved for future use.
Definition EvtMessage.h:41
UInt_t version
version field.
Definition EvtMessage.h:48
UInt_t nArrays
number of objects in message.
Definition EvtMessage.h:40
ERecordType rectype
Type of message.
Definition EvtMessage.h:32
UInt_t nObjects
number of objects in message.
Definition EvtMessage.h:39
Long64_t time_sec
seconds part of timeval.
Definition EvtMessage.h:33
UInt_t flags
flags concerning the content of the message.
Definition EvtMessage.h:37
UInt_t size
Number of words in this record.
Definition EvtMessage.h:31