8 #include "daq/storage/EventBuffer.h"
16 unsigned int EventBuffer::size() throw()
18 return sizeof(int) * (m_nword);
21 EventBuffer::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++) {
35 void 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++) {
44 EventBuffer::~EventBuffer()
49 bool 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);
56 bool EventBuffer::isReadable() throw()
58 if (m_buf == NULL)
return false;
59 bool readable = m_header.nword_in - m_header.nword_out > 0;
63 unsigned 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;
72 i_w = m_header.nword_in % m_nword;
73 i_r = m_header.nword_out % m_nword;
74 if ((serial == 0 || serial - 1 == m_header.count_in) &&
75 m_header.nword_in - m_header.nword_out < m_nword - (nword + 1)) {
77 unsigned int count = m_nword - i_w;
78 if (nword + 1 < count) {
80 memcpy((m_buf + i_w + 1), buf,
sizeof(
int) * nword);
83 memcpy((m_buf + i_w + 1), buf,
sizeof(
int) * count);
85 memcpy(m_buf, buf + count,
sizeof(
int) * (nword - count));
89 memcpy((m_buf + i_w + 1), buf,
sizeof(
int) * nword);
94 m_header.nword_in += nword + 1;
95 unsigned int count = ++m_header.count_in;
101 if (m_buf == NULL)
return 0;
103 unsigned int i_w = 0;
104 unsigned int i_r = 0;
105 unsigned int nword = 0;
107 i_w = m_header.nword_in % m_nword;
108 i_r = m_header.nword_out % m_nword;
111 if (m_header.nword_in - m_header.nword_out >= (nword + 1)) {
113 memcpy(buf, (m_buf + i_r + 1),
sizeof(
int) * nword);
115 }
else if (i_w < i_r) {
116 if (m_nword - i_r > nword) {
117 memcpy(buf, (m_buf + i_r + 1),
sizeof(
int) * nword);
120 unsigned int count = m_nword - i_r;
121 memcpy(buf, (m_buf + i_r + 1),
sizeof(
int) * count);
123 memcpy(buf + count, m_buf,
sizeof(
int) * (nword - count));
131 m_header.nword_out += nword + 1;
132 unsigned int count = ++m_header.count_out;
Abstract base class for different kinds of events.