Belle II Software development
BinData Class Reference
Inheritance diagram for BinData:
ONSENBinData

Public Member Functions

 BinData (void *buf=NULL)
 
int getExpNumber () const
 
int getRunNumber () const
 
int getSubNumber () const
 
int getEventNumber () const
 
int setEventNumber (int number)
 
int setExpNumber (int exp_no)
 
int setRunNumber (int run_no, int sub_no)
 
int getNEvent () const
 
int getNBoard () const
 
int setNEvent (int nev)
 
int setNBoard (int nb)
 
void setWordSize (int nword)
 
int getWordSize () const
 
int getByteSize () const
 
int getHeaderWordSize () const
 
int getHeaderByteSize () const
 
int getBodyByteSize () const
 
void setBodyWordSize (int nword)
 
int getBodyWordSize () const
 
unsigned int getTrailerMagic ()
 
int getNodeId () const
 
void setNodeId (int id)
 
unsigned int recvEvent (TCPSocket &socket)
 
unsigned int sendEvent (TCPSocket &socket) const
 
int * getBuffer ()
 
const int * getBuffer () const
 
void setBuffer (void *buf)
 
void print () noexcept
 
BinHeadergetHeader ()
 
const BinHeadergetHeader () const
 
BinTrailergetTrailer ()
 
const BinTrailergetTrailer () const
 
unsigned int * getBody ()
 
const unsigned int * getBody () const
 

Static Public Attributes

static const unsigned int TRAILER_MAGIC = 0x7FFF0007
 
static const unsigned int MAX_EVENT_WORDS = 2 * 1024 * 1024
 

Protected Attributes

BinTrailerm_trailer
 
BinHeaderm_header
 
unsigned int * m_body
 
int * m_buf
 

Detailed Description

Definition at line 33 of file BinData.h.

Constructor & Destructor Documentation

◆ BinData()

BinData ( void *  buf = NULL)

Definition at line 18 of file BinData.cc.

19{
20 if (buf != NULL) {
21 setBuffer(buf);
22 m_header->nword_in_header = sizeof(BinHeader) / 4;
23 m_header->nword = (sizeof(BinHeader) + sizeof(BinTrailer)) / 4;
24 m_header->nevent_nboard = 0;
25 m_header->exp_run = 0;
26 m_header->event_number = 0;
27 m_header->node_id = 0;
28 }
29}

◆ ~BinData()

~BinData ( )
noexcept

Definition at line 31 of file BinData.cc.

32{
33
34}

Member Function Documentation

◆ getBody() [1/2]

unsigned int * getBody ( )
inline

Definition at line 109 of file BinData.h.

109{ return m_body; };

◆ getBody() [2/2]

const unsigned int * getBody ( ) const
inline

Definition at line 110 of file BinData.h.

110{ return m_body; };

◆ getBodyByteSize()

int getBodyByteSize ( ) const
inline

Definition at line 77 of file BinData.h.

78 {
79 return getByteSize() - sizeof(BinHeader) - sizeof(BinTrailer);
80 }

◆ getBodyWordSize()

int getBodyWordSize ( ) const
inline

Definition at line 87 of file BinData.h.

87{ return (getBodyByteSize() / 4); };

◆ getBuffer() [1/2]

int * getBuffer ( )
inline

Definition at line 99 of file BinData.h.

99{ return m_buf; }

◆ getBuffer() [2/2]

const int * getBuffer ( ) const
inline

Definition at line 100 of file BinData.h.

100{ return m_buf; }

◆ getByteSize()

int getByteSize ( ) const
inline

Definition at line 74 of file BinData.h.

74{ return m_header->nword * 4; };

◆ getEventNumber()

int getEventNumber ( ) const
inline

Definition at line 47 of file BinData.h.

47{ return m_header->event_number; };

◆ getExpNumber()

int getExpNumber ( ) const
inline

Definition at line 44 of file BinData.h.

44{ return (m_header->exp_run >> 22) & 0x3FF; };

◆ getHeader() [1/2]

BinHeader * getHeader ( )
inline

Definition at line 105 of file BinData.h.

105{ return m_header; };

◆ getHeader() [2/2]

const BinHeader * getHeader ( ) const
inline

Definition at line 106 of file BinData.h.

106{ return m_header; };

◆ getHeaderByteSize()

int getHeaderByteSize ( ) const
inline

Definition at line 76 of file BinData.h.

76{ return m_header->nword_in_header * 4; };

◆ getHeaderWordSize()

int getHeaderWordSize ( ) const
inline

Definition at line 75 of file BinData.h.

75{ return m_header->nword_in_header; };

◆ getNBoard()

int getNBoard ( ) const
inline

Definition at line 61 of file BinData.h.

61{ return (m_header->nevent_nboard & 0xFFFF); };

◆ getNEvent()

int getNEvent ( ) const
inline

Definition at line 60 of file BinData.h.

60{ return (m_header->nevent_nboard >> 16); };

◆ getNodeId()

int getNodeId ( ) const
inline

Definition at line 93 of file BinData.h.

93{ return m_header->node_id; };

◆ getRunNumber()

int getRunNumber ( ) const
inline

Definition at line 45 of file BinData.h.

45{ return (m_header->exp_run & 0x3FFFFF) >> 8; };

◆ getSubNumber()

int getSubNumber ( ) const
inline

Definition at line 46 of file BinData.h.

46{ return (m_header->exp_run & 0x3FFFFF) & 0xFF; };

◆ getTrailer() [1/2]

BinTrailer * getTrailer ( )
inline

Definition at line 107 of file BinData.h.

107{ return m_trailer; }

◆ getTrailer() [2/2]

const BinTrailer * getTrailer ( ) const
inline

Definition at line 108 of file BinData.h.

108{ return m_trailer; }

◆ getTrailerMagic()

unsigned int getTrailerMagic ( )
inline

Definition at line 88 of file BinData.h.

89 {
90 m_trailer = reinterpret_cast<BinTrailer*>(m_body + getBodyWordSize());
91 return m_trailer->magic;
92 }

◆ getWordSize()

int getWordSize ( ) const
inline

Definition at line 73 of file BinData.h.

73{ return m_header->nword; };

◆ print()

void print ( )
noexcept

Definition at line 69 of file BinData.cc.

70{
71 printf("headerwords=%d, nwords=%d, nboard=%d, nevent=%d, evtno=%d, expno=%d, runno=%d, subno=%d, nodeid=%d, trailer=%04x\n",
72 getHeaderWordSize(),
73 getWordSize(),
74 // getBodyWordSize(),
75 getNBoard(),
76 getNEvent(),
77 getEventNumber(),
78 getExpNumber(),
79 getRunNumber(),
80 getSubNumber(),
81 getNodeId(),
82 getTrailerMagic());
83}

◆ recvEvent()

unsigned int recvEvent ( TCPSocket socket)

Definition at line 47 of file BinData.cc.

48{
49 unsigned int count = socket.read(m_header, sizeof(BinHeader));
50 if (m_header->nword_in_header * 4 != sizeof(BinHeader)) {
51 throw (IOException("unexpected header size %d words",
52 m_header->nword_in_header));
53 }
54 const int nbytes_remains = getByteSize() - sizeof(BinHeader);
55 count += socket.read(m_body, nbytes_remains);
56 m_trailer = (BinTrailer*)(((char*)m_body) + nbytes_remains - sizeof(BinTrailer));
57 if (m_trailer->magic != TRAILER_MAGIC) {
58 throw (IOException("unexpected header trailer magic %08x",
59 m_trailer->magic));
60 }
61 return count;
62}

◆ sendEvent()

unsigned int sendEvent ( TCPSocket socket) const

Definition at line 64 of file BinData.cc.

65{
66 return socket.write(m_buf, getByteSize());
67}

◆ setBodyWordSize()

void setBodyWordSize ( int  nword)
inline

Definition at line 81 of file BinData.h.

82 {
83 setWordSize(nword + (sizeof(BinHeader) + sizeof(BinTrailer)) / 4);
84 m_trailer = reinterpret_cast<BinTrailer*>(m_body + getBodyWordSize());
85 m_trailer->magic = TRAILER_MAGIC;
86 }

◆ setBuffer()

void setBuffer ( void *  buf)

Definition at line 36 of file BinData.cc.

37{
38 if (buf != NULL) {
39 m_buf = (int*)buf;
40 m_header = (BinHeader*)buf;
41 m_body = (unsigned int*)(((char*)buf) + sizeof(BinHeader));
42 } else {
43 m_buf = NULL;
44 }
45}

◆ setEventNumber()

int setEventNumber ( int  number)
inline

Definition at line 48 of file BinData.h.

48{ return m_header->event_number = number; };

◆ setExpNumber()

int setExpNumber ( int  exp_no)
inline

Definition at line 49 of file BinData.h.

50 {
51 m_header->exp_run = ((exp_no & 0x3FF) << 22) | (m_header->exp_run & 0x3FFFFF);
52 return getExpNumber();
53 };

◆ setNBoard()

int setNBoard ( int  nb)
inline

Definition at line 67 of file BinData.h.

68 {
69 m_header->nevent_nboard = (m_header->nevent_nboard & 0xFFFF0000) | (nb & 0xFFFF);
70 return getNBoard();
71 };

◆ setNEvent()

int setNEvent ( int  nev)
inline

Definition at line 62 of file BinData.h.

63 {
64 m_header->nevent_nboard = ((nev & 0xFFFF) << 16) | (m_header->nevent_nboard & 0xFFFF);
65 return getNEvent();
66 };

◆ setNodeId()

void setNodeId ( int  id)
inline

Definition at line 94 of file BinData.h.

94{ m_header->node_id = id; };

◆ setRunNumber()

int setRunNumber ( int  run_no,
int  sub_no 
)
inline

Definition at line 54 of file BinData.h.

55 {
56 m_header->exp_run = (m_header->exp_run & 0xFFC00000) |
57 (run_no & 0x3FFFFF) << 8 | (sub_no & 0xFF);
58 return getRunNumber();
59 };

◆ setWordSize()

void setWordSize ( int  nword)
inline

Definition at line 72 of file BinData.h.

72{ m_header->nword = nword; };

Member Data Documentation

◆ m_body

unsigned int* m_body
protected

Definition at line 115 of file BinData.h.

◆ m_buf

int* m_buf
mutableprotected

Definition at line 116 of file BinData.h.

◆ m_header

BinHeader* m_header
protected

Definition at line 114 of file BinData.h.

◆ m_trailer

BinTrailer* m_trailer
protected

Definition at line 113 of file BinData.h.

◆ MAX_EVENT_WORDS

const unsigned int MAX_EVENT_WORDS = 2 * 1024 * 1024
static

Definition at line 37 of file BinData.h.

◆ TRAILER_MAGIC

const unsigned int TRAILER_MAGIC = 0x7FFF0007
static

Definition at line 36 of file BinData.h.


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