8#include "daq/storage/EventBuffer.h"
16unsigned int EventBuffer::size() throw()
18 return sizeof(int) * (m_nword);
21EventBuffer::EventBuffer(
unsigned int nword)
24 char* buf = (
char*) malloc(size());
29 memset(&m_header, 0,
sizeof(Header));
30 for (
unsigned long long i = 0; i < m_nword; i++) {
35void EventBuffer::clear()
37 if (m_buf == NULL)
return;
38 memset(&m_header, 0,
sizeof(Header));
39 for (
unsigned long long i = 0; i < m_nword; i++) {
44EventBuffer::~EventBuffer()
49bool EventBuffer::isWritable(
int nword)
throw()
51 if (m_buf == NULL)
return false;
52 bool writable = m_header.nword_in - m_header.nword_out < m_nword - (nword + 1);
56bool EventBuffer::isReadable() throw()
58 if (m_buf == NULL)
return false;
59 bool readable = m_header.nword_in - m_header.nword_out > 0;
63unsigned int EventBuffer::write(
const int* buf,
unsigned int nword,
66 if (m_buf == NULL)
return 0;
67 if (nword == 0)
return 0;
68 if (nword > m_nword)
return -1;
71 unsigned int i_w = m_header.nword_in % m_nword;
72 unsigned int i_r = m_header.nword_out % m_nword;
73 if ((serial == 0 || serial - 1 == m_header.count_in) &&
74 m_header.nword_in - m_header.nword_out < m_nword - (nword + 1)) {
76 unsigned int count = m_nword - i_w;
77 if (nword + 1 < count) {
79 memcpy((m_buf + i_w + 1), buf,
sizeof(
int) * nword);
82 memcpy((m_buf + i_w + 1), buf,
sizeof(
int) * count);
84 memcpy(m_buf, buf + count,
sizeof(
int) * (nword - count));
88 memcpy((m_buf + i_w + 1), buf,
sizeof(
int) * nword);
93 m_header.nword_in += nword + 1;
94 unsigned int count = ++m_header.count_in;
100 if (m_buf == NULL)
return 0;
102 unsigned int nword = 0;
104 unsigned int i_w = m_header.nword_in % m_nword;
105 unsigned int i_r = m_header.nword_out % m_nword;
108 if (m_header.nword_in - m_header.nword_out >= (nword + 1)) {
110 memcpy(buf, (m_buf + i_r + 1),
sizeof(
int) * nword);
112 }
else if (i_w < i_r) {
113 if (m_nword - i_r > nword) {
114 memcpy(buf, (m_buf + i_r + 1),
sizeof(
int) * nword);
117 unsigned int count = m_nword - i_r;
118 memcpy(buf, (m_buf + i_r + 1),
sizeof(
int) * count);
120 memcpy(buf + count, m_buf,
sizeof(
int) * (nword - count));
128 m_header.nword_out += nword + 1;
129 unsigned int count = ++m_header.count_out;
Abstract base class for different kinds of events.