Belle II Software development
ONSENBinData.cc
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#include "daq/storage/ONSENBinData.h"
9
10#include <arpa/inet.h>
11
12using namespace Belle2;
13
14ONSENBinData::ONSENBinData(void* buf) : BinData(buf)
15{
16
17}
18
19ONSENBinData::~ONSENBinData() throw()
20{
21
22}
23
24unsigned int ONSENBinData::getTrigger() const
25{
26 return (ntohs(m_start_frame->trigger_hi) << 16)
27 + ntohs(m_start_frame->trigger_lo);
28}
29
30unsigned int ONSENBinData::getTimetag() const
31{
32 uint64_t retval =
33 ((uint64_t)ntohs(m_start_frame->time_tag_hi) << 32)
34 | ((uint64_t)ntohs(m_start_frame->time_tag_mid) << 16)
35 | (uint64_t)ntohs(m_start_frame->time_tag_lo_and_type);
36 return (retval >> 4);
37}
38
39unsigned int ONSENBinData::getEventNumber() const
40{
41 unsigned int nframe = getFrameNumber();
42 if (nframe > MAX_PXD_FRAMES) return 0;
43 m_start_frame = reinterpret_cast<sose_frame_t*>(m_body + nframe + 2);
44 return getTrigger();
45}
46
47unsigned int ONSENBinData::getTriggerType() const
48{
49 return (ntohs(m_start_frame->time_tag_lo_and_type) & 0xF);
50}
51
52unsigned int ONSENBinData::getFrameNumber() const
53{
54 return ntohl(m_body[1]);
55}
56
57unsigned int ONSENBinData::getFrameByteSize() const
58{
59 const unsigned int nframe = getFrameNumber();
60 unsigned int nbyte = 0;
61 for (unsigned int i = 0; i < nframe; i++) {
62 nbyte += ntohl(m_body[2 + i]);
63 }
64 if (m_body[2 + nframe] != ntohs(0x3000)) {
65 return nbyte - 8;
66 } else {
67 return nbyte;
68 }
69}
70
71unsigned int ONSENBinData::getONSENMagic() const
72{
73 return ntohl(m_body[0]);
74}
75
Abstract base class for different kinds of events.