Belle II Software  release-05-01-25
RawRevSock2Rb.cc
1 //+
2 // File : RawRevSock2Rb.cc
3 // Description : Receive events from Socket and place them in Rbuf
4 //
5 // Author : Ryosuke Itoh, IPNS, KEK
6 // Date : 26 - Apr - 2012
7 //-
8 
9 #include "daq/rfarm/event/RawRevSock2Rb.h"
10 #include "daq/dataflow/REvtSocket.h"
11 
12 #include <unistd.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 RawRevSock2Rb::RawRevSock2Rb(string rbuf, string src, int port, string shmname, int id)
18 {
19  // m_rbuf = new RingBuffer(rbuf.c_str(), RBUFSIZE);
20  m_rbuf = new RingBuffer(rbuf.c_str());
21  m_sock = new RSocketRecv(src.c_str(), (u_int)port);
22  m_evtbuf = new char[MAXEVTSIZE];
23  m_flow = new RFFlowStat((char*)shmname.c_str(), id, m_rbuf);
24  m_buf = new int[MAXBUFSIZE];
25 
26 }
27 
28 RawRevSock2Rb::~RawRevSock2Rb(void)
29 {
30  delete m_sock;
31  delete m_rbuf;
32 }
33 
35 {
36  // Get a record from socket
37  int bufsize = m_sock->get_wordbuf(m_buf, MAXBUFSIZE);
38 
39  if (bufsize <= 0) {
40  return 0;
41  }
42  m_flow->log(bufsize * 4);
43 
44  // Put the message in ring buffer
45  int stat = 0;
46  for (;;) {
47  stat = m_rbuf->insq(m_buf, bufsize);
48  if (stat >= 0) break;
49  // usleep(100);
50  usleep(20);
51  }
52  return stat;
53 }
54 
55 int RawRevSock2Rb::Reconnect(int ntimes)
56 {
57  return m_sock->reconnect(ntimes);
58 }
59 
60 
Belle2::RSocketRecv
Definition: RSocketLib.h:58
RawRevSock2Rb::ReceiveEvent
int ReceiveEvent(void)
Event function.
Definition: RawRevSock2Rb.cc:34
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
RawRevSock2Rb::Reconnect
int Reconnect(int ntry)
Reconnect.
Definition: RawRevSock2Rb.cc:55
RawRevSock2Rb::RawRevSock2Rb
RawRevSock2Rb(std::string rbuf, std::string src, int port, std::string shmname, int id)
Constuctor and Destructor.
Definition: RawRevSock2Rb.cc:17