Belle II Software development
BinData.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#ifndef _Belle2_BinData_h
9#define _Belle2_BinData_h
10
11#include <daq/slc/system/TCPSocket.h>
12
13namespace Belle2 {
19 struct BinTrailer {
20 unsigned int reserved;
21 unsigned int magic; /* should be 0x7FFF000X */
22 };
23
24 struct BinHeader {
25 unsigned int nword; /* number of total words including header */
26 unsigned int nword_in_header; /* number of words of this header == 6 */
27 unsigned int nevent_nboard; /* number of board in this block, mostly # of COPPER */
28 unsigned int exp_run;
29 unsigned int event_number;
30 unsigned int node_id;
31 };
32
33 class BinData {
34
35 public:
36 static const unsigned int TRAILER_MAGIC;
37 static const unsigned int MAX_EVENT_WORDS = 2 * 1024 * 1024;
38
39 public:
40 BinData(void* buf = NULL);
41 ~BinData() noexcept;
42
43 public:
44 int getExpNumber() const { return (m_header->exp_run >> 22) & 0x3FF; };
45 int getRunNumber() const { return (m_header->exp_run & 0x3FFFFF) >> 8; };
46 int getSubNumber() const { return (m_header->exp_run & 0x3FFFFF) & 0xFF; };
47 int getEventNumber() const { return m_header->event_number; };
48 int setEventNumber(int number) { return m_header->event_number = number; };
49 int setExpNumber(int exp_no)
50 {
51 m_header->exp_run = ((exp_no & 0x3FF) << 22) | (m_header->exp_run & 0x3FFFFF);
52 return getExpNumber();
53 };
54 int setRunNumber(int run_no, int sub_no)
55 {
56 m_header->exp_run = (m_header->exp_run & 0xFFC00000) |
57 (run_no & 0x3FFFFF) << 8 | (sub_no & 0xFF);
58 return getRunNumber();
59 };
60 int getNEvent() const { return (m_header->nevent_nboard >> 16); };
61 int getNBoard() const { return (m_header->nevent_nboard & 0xFFFF); };
62 int setNEvent(int nev)
63 {
64 m_header->nevent_nboard = ((nev & 0xFFFF) << 16) | (m_header->nevent_nboard & 0xFFFF);
65 return getNEvent();
66 };
67 int setNBoard(int nb)
68 {
69 m_header->nevent_nboard = (m_header->nevent_nboard & 0xFFFF0000) | (nb & 0xFFFF);
70 return getNBoard();
71 };
72 void setWordSize(int nword) { m_header->nword = nword; };
73 int getWordSize() const { return m_header->nword; };
74 int getByteSize() const { return m_header->nword * 4; };
75 int getHeaderWordSize() const { return m_header->nword_in_header; };
76 int getHeaderByteSize() const { return m_header->nword_in_header * 4; };
77 int getBodyByteSize() const
78 {
79 return getByteSize() - sizeof(BinHeader) - sizeof(BinTrailer);
80 }
81 void setBodyWordSize(int nword)
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 }
87 int getBodyWordSize() const { return (getBodyByteSize() / 4); };
88 unsigned int getTrailerMagic()
89 {
90 m_trailer = reinterpret_cast<BinTrailer*>(m_body + getBodyWordSize());
91 return m_trailer->magic;
92 }
93 int getNodeId() const { return m_header->node_id; };
94 void setNodeId(int id) { m_header->node_id = id; };
95
96 public:
97 unsigned int recvEvent(TCPSocket& socket);
98 unsigned int sendEvent(TCPSocket& socket) const;
99 int* getBuffer() { return m_buf; }
100 const int* getBuffer() const { return m_buf; }
101 void setBuffer(void* buf);
102 void print() noexcept;
103
104 public:
105 BinHeader* getHeader() { return m_header; };
106 const BinHeader* getHeader() const { return m_header; };
107 BinTrailer* getTrailer() { return m_trailer; }
108 const BinTrailer* getTrailer() const { return m_trailer; }
109 unsigned int* getBody() { return m_body; };
110 const unsigned int* getBody() const { return m_body; };
111
112 protected:
113 BinTrailer* m_trailer;
114 BinHeader* m_header;
115 unsigned int* m_body;
116 mutable int* m_buf;
117
118 };
119
121}
122
123#endif
Abstract base class for different kinds of events.