Belle II Software development
RevRb2Sock.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/RevRb2Sock.h"
10
11#include <unistd.h>
12
13using namespace std;
14using namespace Belle2;
15
16RevRb2Sock::RevRb2Sock(string rbuf, int port, string shmname, int id)
17{
18 // m_rbuf = new RingBuffer((char*)rbuf.c_str(), RBUFSIZE);
19 m_rbuf = new RingBuffer((char*)rbuf.c_str());
20 m_sock = new REvtSocketSend(port);
21 m_evtbuf = new char[MAXEVTSIZE];
22 m_flow = new RFFlowStat((char*)shmname.c_str(), id, m_rbuf);
23
24}
25
26RevRb2Sock::~RevRb2Sock(void)
27{
28 delete m_sock;
29 delete m_rbuf;
30}
31
33{
34 // Get a record from ringbuf
35 int size;
36 while ((size = m_rbuf->remq((int*)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 EvtMessage* msg = new EvtMessage(m_evtbuf); // Ptr copy, no overhead
44
45 if (msg->type() == MSG_TERMINATE) {
46 printf("EoF found. Exitting.....\n");
47 m_sock->send(msg);
48 delete msg;
49 return -1;
50 } else {
51 int is = m_sock->send(msg);
52 delete msg;
53 return is;
54 // return msg->size();
55 }
56}
57
Class to manage streamed object.
Definition: EvtMessage.h:59
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
int SendEvent(void)
Event function.
Definition: RevRb2Sock.cc:32
RevRb2Sock(std::string rbuf, int port, std::string shmname, int id)
Constuctor and Destructor.
Definition: RevRb2Sock.cc:16
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.