Belle II Software  release-08-01-10
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 
11 using namespace std;
12 using namespace Belle2;
13 
14 RawRevRb2Sock::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 
25 RawRevRb2Sock::~RawRevRb2Sock(void)
26 {
27  delete m_sock;
28  delete m_rbuf;
29 }
30 
31 int RawRevRb2Sock::SendEvent(void)
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 
47 int RawRevRb2Sock::Reconnect(void)
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 
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
Abstract base class for different kinds of events.