Belle II Software development
EventSampler Class Reference

Public Member Functions

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

Private Attributes

std::vector< EvtSocketSend * > m_socklist
 
RingBufferm_rbuf
 
int m_interval
 

Detailed Description

Definition at line 25 of file EventSampler.h.

Constructor & Destructor Documentation

◆ EventSampler()

EventSampler ( std::vector< std::string >  nodes,
int  port,
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>::iterator it = nodes.begin(); it != nodes.end(); ++it) {
25 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 = %lu\n", m_socklist.size());
37 fflush(stdout);
38}
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39

◆ ~EventSampler()

Definition at line 40 of file EventSampler.cc.

41{
42 for (vector<EvtSocketSend*>::iterator it = m_socklist.begin();
43 it != m_socklist.end(); ++it) {
44 EvtSocketSend* sock = *it;
45 delete sock;
46 m_socklist.erase(it);
47 }
48 delete m_rbuf;
49}

Member Function Documentation

◆ server()

int server ( )

Definition at line 51 of file EventSampler.cc.

52{
53 // printf ( "EventSampler : server started\n" );
54 fflush(stdout);
55 int nsample = 0;
56 for (;;) {
57 for (vector<EvtSocketSend*>::iterator it = m_socklist.begin();
58 it != m_socklist.end(); ++it) {
59 // Receive an event from connected socket
60 EvtSocketSend* sock = *it;
61 // printf ( "EventSampler : receiving event from sock %s\n",
62 // (sock->sock())->node() );
63 EvtMessage* msg = sock->recv();
64 // printf ( "Event Sampler : got event : %d\n", msg->size() );
65 // fflush ( stdout );
66 if (msg == NULL) {
67 printf("EventSampler : Error to receive data\n");
68 return -1;
69 }
70 // Put the message in ring buffer. If full, just skip the event.
71 m_rbuf->insq((int*)msg->buffer(), msg->paddedSize());
72 delete msg;
73 nsample++;
74 if (nsample % 1000 == 0)
75 printf("EventSampler : %d events sampled and queued\n", nsample);
76 usleep(m_interval);
77 }
78 }
79}
Class to manage streamed object.
Definition: EvtMessage.h:59
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
int insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:189

Member Data Documentation

◆ m_interval

int m_interval
private

Definition at line 35 of file EventSampler.h.

◆ m_rbuf

RingBuffer* m_rbuf
private

Definition at line 33 of file EventSampler.h.

◆ m_socklist

std::vector<EvtSocketSend*> m_socklist
private

Definition at line 32 of file EventSampler.h.


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