Belle II Software development
EvtMessage Class Reference

Class to manage streamed object. More...

#include <EvtMessage.h>

Public Types

enum  EMessageFlags { c_MsgCompressed = 1 }
 Flags for the message. More...
 

Public Member Functions

 EvtMessage (char *buf=nullptr)
 build EvtMessage from existing buffer (no copy, but does not take ownership).
 
 EvtMessage (const char *msg, int size, ERecordType type)
 build EvtMessage by allocating new message buffer (sobjs is copied).
 
 EvtMessage (const EvtMessage &evtmsg)
 Copy constructor (m_data is copied).
 
 ~EvtMessage ()
 Destructor.
 
EvtMessageoperator= (const EvtMessage &obj)
 Assignment (m_data is copied).
 
char * buffer ()
 Get buffer address.
 
void buffer (const char *)
 Set existing buffer address (copies buffer)
 
int size () const
 Get size of message including headers.
 
int paddedSize () const
 Same as size(), but as size of an integer array.
 
int msg_size () const
 Get size of message body.
 
unsigned int getVersion () const
 get version of the header.
 
unsigned int getMsgFlags () const
 Get flags of the message.
 
void setMsgFlags (unsigned int flags)
 Set flags for the message.
 
void addMsgFlags (unsigned int flags)
 Add flags to the message.
 
bool hasMsgFlags (unsigned int flags) const
 Check if the message has the given flags.
 
ERecordType type () const
 Get record type.
 
void type (ERecordType)
 Set record type.
 
struct timeval time () const
 Get time stamp.
 
void setTime (const struct timeval &time)
 Set time stamp.
 
int src () const
 Get source IP of message.
 
void src (int src)
 Set source IP of message.
 
int dest () const
 Get destination IP of message.
 
void dest (int dest)
 Set destination IP of message.
 
EvtHeaderheader ()
 Get pointer to EvtHeader.
 
const EvtHeadergetHeader () const
 Get pointer to EvtHeader.
 
char * msg ()
 Get pointer to message body.
 

Static Public Attributes

static const unsigned int c_MaxEventSize = 200000000
 maximal EvtMessage size, in bytes (200MB).
 

Private Member Functions

void setMsg (const char *msg, int size, ERecordType type)
 Copy message into newly allocated buffer.
 

Private Attributes

char * m_data
 Pointer to the internal EvtMessage buffer.
 
bool m_ownsBuffer
 Wether to clean up m_data in destructor.
 

Detailed Description

Class to manage streamed object.

Binary stream consists of: Fields in EvtHeader (see definition) List of streamed objects, each consisting of: word 1 : size of object word 2- : streamed object

Definition at line 59 of file EvtMessage.h.

Member Enumeration Documentation

◆ EMessageFlags

Flags for the message.

Enumerator
c_MsgCompressed 

indicates that the message body is compressed and should be uncompressed using ROOT R__unzip_header and R__unzip before use

Definition at line 66 of file EvtMessage.h.

66 {
70 };
@ c_MsgCompressed
indicates that the message body is compressed and should be uncompressed using ROOT R__unzip_header a...
Definition: EvtMessage.h:69

Constructor & Destructor Documentation

◆ EvtMessage() [1/3]

EvtMessage ( char *  buf = nullptr)
explicit

build EvtMessage from existing buffer (no copy, but does not take ownership).

Definition at line 27 of file EvtMessage.cc.

27 :
28 m_data(data),
29 m_ownsBuffer(false)
30{
31}
char * m_data
Pointer to the internal EvtMessage buffer.
Definition: EvtMessage.h:148
bool m_ownsBuffer
Wether to clean up m_data in destructor.
Definition: EvtMessage.h:149

◆ EvtMessage() [2/3]

EvtMessage ( const char *  msg,
int  size,
ERecordType  type = MSG_EVENT 
)

build EvtMessage by allocating new message buffer (sobjs is copied).

Constructor of EvtMessage allocating new buffer.

Parameters
msgdata
sizeLength of the data (TMessage)
typetype of the message

Definition at line 37 of file EvtMessage.cc.

38{
39 int fullsize = size + sizeof(EvtHeader);
40 int bufsize = roundToNearestInt(fullsize);
41 m_data = new char[bufsize]; // Allocate new buffer
42 // zero extra bytes
43 memset(m_data + fullsize, 0, bufsize - fullsize);
45 m_ownsBuffer = true;
46}
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
void setMsg(const char *msg, int size, ERecordType type)
Copy message into newly allocated buffer.
Definition: EvtMessage.cc:179
char * msg()
Get pointer to message body.
Definition: EvtMessage.cc:172
int size() const
Get size of message including headers.
Definition: EvtMessage.cc:94
Header structure of streamed object list.
Definition: EvtMessage.h:28

◆ EvtMessage() [3/3]

EvtMessage ( const EvtMessage evtmsg)

Copy constructor (m_data is copied).

Copy constructor of EvtMessage class.

Parameters
evtmsgOriginal EvtMessage object

Definition at line 50 of file EvtMessage.cc.

51{
52 *this = evtmsg;
53}

◆ ~EvtMessage()

~EvtMessage ( )

Destructor.

Destructor of EvtMessage class.

Definition at line 56 of file EvtMessage.cc.

57{
58 if (m_ownsBuffer)
59 delete [] m_data;
60}

Member Function Documentation

◆ addMsgFlags()

void addMsgFlags ( unsigned int  flags)
inline

Add flags to the message.

Definition at line 113 of file EvtMessage.h.

113{ header()->flags |= flags;}
EvtHeader * header()
Get pointer to EvtHeader.
Definition: EvtMessage.cc:161
UInt_t flags
flags concerning the content of the message.
Definition: EvtMessage.h:37

◆ buffer() [1/2]

char * buffer ( )

Get buffer address.

If you own the EvtMessage object, the memory is guaranteed to be at least sizeof(int) * paddedSize() bytes. Bytes exceeding size() are zeroed.

Definition at line 76 of file EvtMessage.cc.

77{
78 return m_data;
79}

◆ buffer() [2/2]

void buffer ( const char *  bufadr)

Set existing buffer address (copies buffer)

Definition at line 81 of file EvtMessage.cc.

82{
83 UInt_t size = *(UInt_t*)bufadr;
84 int bufsize = roundToNearestInt(size);
85 m_data = new char[bufsize];
86 memcpy(m_data, bufadr, size);
87 for (int i = bufsize - size; i > 0; i--)
88 m_data[bufsize - i] = '\0'; //zero extra bytes
89 m_ownsBuffer = true;
90}

◆ dest() [1/2]

int dest ( ) const

Get destination IP of message.

Definition at line 136 of file EvtMessage.cc.

137{
138 return ((reinterpret_cast<EvtHeader*>(m_data))->dest);
139}
int dest() const
Get destination IP of message.
Definition: EvtMessage.cc:136

◆ dest() [2/2]

void dest ( int  dest)

Set destination IP of message.

Definition at line 141 of file EvtMessage.cc.

142{
143 (reinterpret_cast<EvtHeader*>(m_data))->dest = dest;
144}

◆ getHeader()

const EvtHeader * getHeader ( ) const

Get pointer to EvtHeader.

Definition at line 166 of file EvtMessage.cc.

167{
168 return (reinterpret_cast<const EvtHeader*>(m_data));
169}

◆ getMsgFlags()

unsigned int getMsgFlags ( ) const
inline

Get flags of the message.

Definition at line 109 of file EvtMessage.h.

109{ return getVersion() > 0 ? getHeader()->flags : 0; }
unsigned int getVersion() const
get version of the header.
Definition: EvtMessage.h:107
const EvtHeader * getHeader() const
Get pointer to EvtHeader.
Definition: EvtMessage.cc:166

◆ getVersion()

unsigned int getVersion ( ) const
inline

get version of the header.

Returns 0 for no valid version information

Definition at line 107 of file EvtMessage.h.

107{ return ((getHeader()->version & 0xFFFFFF00) == 0xBEEFED00) ? (getHeader()->version & 0xFF) : 0;}
UInt_t version
version field.
Definition: EvtMessage.h:48

◆ hasMsgFlags()

bool hasMsgFlags ( unsigned int  flags) const
inline

Check if the message has the given flags.

Definition at line 115 of file EvtMessage.h.

115{ return (getMsgFlags() & flags) == flags; }
unsigned int getMsgFlags() const
Get flags of the message.
Definition: EvtMessage.h:109

◆ header()

EvtHeader * header ( )

Get pointer to EvtHeader.

Definition at line 161 of file EvtMessage.cc.

162{
163 return (reinterpret_cast<EvtHeader*>(m_data));
164}

◆ msg()

char * msg ( )

Get pointer to message body.

Definition at line 172 of file EvtMessage.cc.

173{
174 return (m_data + sizeof(EvtHeader));
175}

◆ msg_size()

int msg_size ( ) const

Get size of message body.

Definition at line 108 of file EvtMessage.cc.

109{
110 return ((reinterpret_cast<EvtHeader*>(m_data))->size - sizeof(EvtHeader));
111}

◆ operator=()

EvtMessage & operator= ( const EvtMessage obj)

Assignment (m_data is copied).

Overridden assign operator.

Parameters
objSource object

Definition at line 64 of file EvtMessage.cc.

65{
66 if (this != &obj) {
67 if (m_ownsBuffer)
68 delete [] m_data;
69 buffer(obj.m_data); //copy m_data
70 m_ownsBuffer = true; //already set by buffer(), but let's be explicit
71 }
72
73 return *this;
74}
char * buffer()
Get buffer address.
Definition: EvtMessage.cc:76

◆ paddedSize()

int paddedSize ( ) const

Same as size(), but as size of an integer array.

Use this for passing EvtMessage to RingBuffer::insq().

Definition at line 99 of file EvtMessage.cc.

100{
101 const int sizeBytes = size();
102 //round up to next int boundary
103 return roundToNearestInt(sizeBytes) / sizeof(int);
104}

◆ setMsg()

void setMsg ( const char *  msg,
int  size,
ERecordType  type 
)
private

Copy message into newly allocated buffer.

Definition at line 179 of file EvtMessage.cc.

180{
181 //initialize message header properly
182 new (m_data) EvtHeader(size + sizeof(EvtHeader), type);
183 struct timeval tv;
184 gettimeofday(&tv, nullptr);
185 this->setTime(tv);
186 if (size > 0)
187 memcpy(m_data + sizeof(EvtHeader), msgin, size);
188}
void setTime(const struct timeval &time)
Set time stamp.
Definition: EvtMessage.cc:154

◆ setMsgFlags()

void setMsgFlags ( unsigned int  flags)
inline

Set flags for the message.

Definition at line 111 of file EvtMessage.h.

111{ header()->flags = flags;}

◆ setTime()

void setTime ( const struct timeval &  time)

Set time stamp.

Definition at line 154 of file EvtMessage.cc.

155{
156 (reinterpret_cast<EvtHeader*>(m_data))->time_sec = tbuf.tv_sec;
157 (reinterpret_cast<EvtHeader*>(m_data))->time_usec = tbuf.tv_usec;
158}

◆ size()

int size ( ) const

Get size of message including headers.

Often, you'll want to use paddedSize() instead.

Definition at line 94 of file EvtMessage.cc.

95{
96 return ((reinterpret_cast<EvtHeader*>(m_data))->size);
97}

◆ src() [1/2]

int src ( ) const

Get source IP of message.

Definition at line 125 of file EvtMessage.cc.

126{
127 return ((reinterpret_cast<EvtHeader*>(m_data))->src);
128}
int src() const
Get source IP of message.
Definition: EvtMessage.cc:125

◆ src() [2/2]

void src ( int  src)

Set source IP of message.

Definition at line 130 of file EvtMessage.cc.

131{
132 (reinterpret_cast<EvtHeader*>(m_data))->src = src;
133}

◆ time()

struct timeval time ( ) const

Get time stamp.

Definition at line 147 of file EvtMessage.cc.

147 {
148 struct timeval tv;
149 tv.tv_sec = (reinterpret_cast<EvtHeader*>(m_data))->time_sec;
150 tv.tv_usec = (reinterpret_cast<EvtHeader*>(m_data))->time_usec;
151 return tv;
152}

◆ type() [1/2]

ERecordType type ( ) const

Get record type.

Definition at line 114 of file EvtMessage.cc.

115{
116 return ((reinterpret_cast<EvtHeader*>(m_data))->rectype);
117}

◆ type() [2/2]

void type ( ERecordType  type)

Set record type.

Definition at line 119 of file EvtMessage.cc.

120{
121 (reinterpret_cast<EvtHeader*>(m_data))->rectype = type;
122}

Member Data Documentation

◆ c_MaxEventSize

const unsigned int c_MaxEventSize = 200000000
static

maximal EvtMessage size, in bytes (200MB).

Definition at line 63 of file EvtMessage.h.

◆ m_data

char* m_data
private

Pointer to the internal EvtMessage buffer.

Definition at line 148 of file EvtMessage.h.

◆ m_ownsBuffer

bool m_ownsBuffer
private

Wether to clean up m_data in destructor.

Definition at line 149 of file EvtMessage.h.


The documentation for this class was generated from the following files: