8#include "daq/storage/BinData.h"
10#include "daq/slc/base/IOException.h"
16const unsigned int BinData::TRAILER_MAGIC = 0x7FFF0007;
18BinData::BinData(
void* buf)
22 m_header->nword_in_header =
sizeof(
BinHeader) / 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;
31BinData::~BinData() noexcept
36void BinData::setBuffer(
void* buf)
41 m_body = (
unsigned int*)(((
char*)buf) +
sizeof(
BinHeader));
47unsigned int BinData::recvEvent(
TCPSocket& socket)
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));
54 const int nbytes_remains = getByteSize() -
sizeof(
BinHeader);
55 count += socket.read(m_body, nbytes_remains);
57 if (m_trailer->magic != TRAILER_MAGIC) {
58 throw (
IOException(
"unexpected header trailer magic %08x",
64unsigned int BinData::sendEvent(
TCPSocket& socket)
const
66 return socket.write(m_buf, getByteSize());
69void BinData::print() noexcept
71 printf(
"headerwords=%d, nwords=%d, nboard=%d, nevent=%d, evtno=%d, expno=%d, runno=%d, subno=%d, nodeid=%d, trailer=%04x\n",
Abstract base class for different kinds of events.