Belle II Software  release-08-01-10
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). More...
 
 EvtMessage (const EvtMessage &evtmsg)
 Copy constructor (m_data is copied). More...
 
 ~EvtMessage ()
 Destructor. More...
 
EvtMessageoperator= (const EvtMessage &obj)
 Assignment (m_data is copied). More...
 
char * buffer ()
 Get buffer address. More...
 
void buffer (const char *)
 Set existing buffer address (copies buffer)
 
int size () const
 Get size of message including headers. More...
 
int paddedSize () const
 Same as size(), but as size of an integer array. More...
 
int msg_size () const
 Get size of message body.
 
unsigned int getVersion () const
 get version of the header. More...
 
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.

Constructor & Destructor Documentation

◆ EvtMessage() [1/2]

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);
44  setMsg(msg, size, type);
45  m_ownsBuffer = true;
46 }
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
char * m_data
Pointer to the internal EvtMessage buffer.
Definition: EvtMessage.h:148
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
bool m_ownsBuffer
Wether to clean up m_data in destructor.
Definition: EvtMessage.h:149
int size() const
Get size of message including headers.
Definition: EvtMessage.cc:94
Header structure of streamed object list.
Definition: EvtMessage.h:28

◆ EvtMessage() [2/2]

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.

◆ ~EvtMessage()

~EvtMessage ( )

Destructor.

Destructor of EvtMessage class.

Definition at line 56 of file EvtMessage.cc.

Member Function Documentation

◆ buffer()

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.

◆ 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.

◆ 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.

◆ 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.

◆ 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.


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