Belle II Software  release-05-01-25
RawRevRb2Sock.cc
1 //+
2 // File : RawRevRb2Sock.cc
3 // Description : Send events in RingBuffer to Socket
4 // Reverse Direction
5 //
6 // Author : Ryosuke Itoh, IPNS, KEK
7 // Date : 25 - Jul - 2013
8 //-
9 
10 #include "daq/rfarm/event/RawRevRb2Sock.h"
11 
12 using namespace std;
13 using namespace Belle2;
14 
15 RawRevRb2Sock::RawRevRb2Sock(string rbuf, int port, string shmname, int id)
16 {
17  // m_rbuf = new RingBuffer((char*)rbuf.c_str(), RBUFSIZE);
18  m_rbuf = new RingBuffer((char*)rbuf.c_str());
19  m_sock = new RSocketSend(port);
20  m_evtbuf = new int[MAXEVTSIZE];
21  m_flow = new RFFlowStat((char*)shmname.c_str(), id, m_rbuf);
22 
23  m_sock->accept();
24 }
25 
26 RawRevRb2Sock::~RawRevRb2Sock(void)
27 {
28  delete m_sock;
29  delete m_rbuf;
30 }
31 
32 int RawRevRb2Sock::SendEvent(void)
33 {
34  // Get a record from ringbuf
35  int size;
36  while ((size = m_rbuf->remq(m_evtbuf)) == 0) {
37  // printf ( "Rx : evtbuf is not available yet....\n" );
38  // usleep(100);
39  usleep(20);
40  }
41  m_flow->log(size * 4);
42 
43  int is = m_sock->put_wordbuf(m_evtbuf, size);
44  // if (is < 0) perror("put_wordbuf");
45  return is;
46 }
47 
48 int RawRevRb2Sock::Reconnect(void)
49 {
50  int port = m_sock->port();
51  delete m_sock;
52  m_sock = new RSocketSend((u_short)port);
53  m_sock->accept();
54 }
55 
56 
Belle2::RFFlowStat
Definition: RFFlowStat.h:28
Belle2::RingBuffer
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:36
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::RSocketSend
Definition: RSocketLib.h:25