Belle II Software development
EventSampler Class Reference

Public Member Functions

 EventSampler (const std::vector< std::string > &nodes, int port, const std::string &rbufname, int interval=5000)
 
 EventSampler (const EventSampler &)=delete
 Copy constructor (disabled).
 
EventSampler & operator= (const EventSampler &)=delete
 Operator = (disabled).
 
int server ()
 

Private Attributes

std::vector< EvtSocketSend * > m_socklist
 
RingBuffer * m_rbuf
 
int m_interval
 

Detailed Description

Definition at line 25 of file EventSampler.h.

Constructor & Destructor Documentation

◆ EventSampler()

EventSampler ( const std::vector< std::string > & nodes,
int port,
const std::string & rbufname,
int interval = 5000 )

Definition at line 18 of file EventSampler.cc.

18 : m_interval(interval)
19{
20 // Attach to output RingBuffer
21 m_rbuf = new RingBuffer(rbufname.c_str());
22
23 // Open EvtSocket
24 for (vector<string>::const_iterator it = nodes.begin(); it != nodes.end(); ++it) {
25 const string& nodename = *it;
26 printf("EventSampler : connecting to %s (port %d)\n", nodename.c_str(), port);
27 EvtSocketSend* sock = new EvtSocketSend(nodename.c_str(), port);
28 if (sock == NULL) {
29 printf("EventSampler : error to connect to %s\n",
30 nodename.c_str());
31 } else {
32 m_socklist.push_back(sock);
33 }
34 fflush(stdout);
35 }
36 printf("EventSampler : init : socklist = %zu\n", m_socklist.size());
37 fflush(stdout);
38}

◆ ~EventSampler()

Definition at line 40 of file EventSampler.cc.

41{
42 for (EvtSocketSend* sock : m_socklist) {
43 delete sock;
44 }
45 m_socklist.clear();
46 delete m_rbuf;
47}

Member Function Documentation

◆ server()

int server ( )

Definition at line 49 of file EventSampler.cc.

50{
51 // printf ( "EventSampler : server started\n" );
52 fflush(stdout);
53 int nsample = 0;
54 for (;;) {
55 for (vector<EvtSocketSend*>::iterator it = m_socklist.begin();
56 it != m_socklist.end(); ++it) {
57 // Receive an event from connected socket
58 EvtSocketSend* sock = *it;
59 // printf ( "EventSampler : receiving event from sock %s\n",
60 // (sock->sock())->node() );
61 EvtMessage* msg = sock->recv();
62 // printf ( "Event Sampler : got event : %d\n", msg->size() );
63 // fflush ( stdout );
64 if (msg == NULL) {
65 printf("EventSampler : Error to receive data\n");
66 return -1;
67 }
68 // Put the message in ring buffer. If full, just skip the event.
69 m_rbuf->insq(reinterpret_cast<int*>(msg->buffer()), msg->paddedSize());
70 delete msg;
71 nsample++;
72 if (nsample % 1000 == 0)
73 printf("EventSampler : %d events sampled and queued\n", nsample);
74 usleep(m_interval);
75 }
76 }
77}
int paddedSize() const
Same as size(), but as size of an integer array.
Definition EvtMessage.cc:99
char * buffer()
Get buffer address.
Definition EvtMessage.cc:76

Member Data Documentation

◆ m_interval

int m_interval
private

Definition at line 40 of file EventSampler.h.

◆ m_rbuf

RingBuffer* m_rbuf
private

Definition at line 38 of file EventSampler.h.

◆ m_socklist

std::vector<EvtSocketSend*> m_socklist
private

Definition at line 37 of file EventSampler.h.


The documentation for this class was generated from the following files: