Belle II Software development
RawRevRb2Sock.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
9#include "daq/rfarm/event/RawRevRb2Sock.h"
10
11using namespace std;
12using namespace Belle2;
13
14RawRevRb2Sock::RawRevRb2Sock(string rbuf, int port, string shmname, int id)
15{
16 // m_rbuf = new RingBuffer((char*)rbuf.c_str(), RBUFSIZE);
17 m_rbuf = new RingBuffer((char*)rbuf.c_str());
18 m_sock = new RSocketSend(port);
19 m_evtbuf = new int[MAXEVTSIZE];
20 m_flow = new RFFlowStat((char*)shmname.c_str(), id, m_rbuf);
21
22 m_sock->accept();
23}
24
25RawRevRb2Sock::~RawRevRb2Sock(void)
26{
27 delete m_sock;
28 delete m_rbuf;
29}
30
32{
33 // Get a record from ringbuf
34 int size;
35 while ((size = m_rbuf->remq(m_evtbuf)) == 0) {
36 // printf ( "Rx : evtbuf is not available yet....\n" );
37 // usleep(100);
38 usleep(20);
39 }
40 m_flow->log(size * 4);
41
42 int is = m_sock->put_wordbuf(m_evtbuf, size);
43 // if (is < 0) perror("put_wordbuf");
44 return is;
45}
46
48{
49 int port = m_sock->port();
50 delete m_sock;
51 m_sock = new RSocketSend((u_short)port);
52 m_sock->accept();
53 return 0; //TODO is it correct?
54}
55
56
int SendEvent(void)
Event function.
int Reconnect(void)
Reconnect.
RawRevRb2Sock(std::string rbuf, int port, std::string shmname, int id)
Constuctor and Destructor.
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:308
Abstract base class for different kinds of events.
STL namespace.