Belle II Software development
Ds2RbufModule.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/modules/Ds2RbufModule.h>
10
11#include <framework/datastore/DataStore.h>
12
13#include <stdlib.h>
14
15using namespace std;
16using namespace Belle2;
17
18//-----------------------------------------------------------------
19// Register the Module
20//-----------------------------------------------------------------
21REG_MODULE(Ds2Rbuf);
22
23//-----------------------------------------------------------------
24// Implementation
25//-----------------------------------------------------------------
26
28{
29 //Set module properties
30 setDescription("Encode DataStore into RingBuffer");
31
32 vector<string> emptyvector;
33 addParam("RingBufferName", m_rbufname, "Name of RingBuffer",
34 string("OutputRbuf"));
35 addParam("CompressionLevel", m_compressionLevel, "Compression level",
36 0);
37 addParam("saveObjs", m_saveobjs, "List of objects to be sent", emptyvector);
38
39 m_rbuf = NULL;
40 m_nsent = 0;
42
43 //Parameter definition
44 B2INFO("Ds2Rbuf: Constructor done.");
45}
46
47
48Ds2RbufModule::~Ds2RbufModule()
49{
50}
51
53{
54
55 // m_rbuf = new RingBuffer(m_rbufname.c_str(), RBUFSIZE);
56 m_rbuf = new RingBuffer(m_rbufname);
58 m_streamer->setStreamingObjects(m_saveobjs);
59
60 B2INFO("Ds2Rbuf initialized.");
61}
62
63
65{
66 B2INFO("Ds2Rbuf: beginRun called.");
67}
68
69
71{
72 // Stream DataStore in EvtMessage
73 EvtMessage* msg = m_streamer->streamDataStore(DataStore::c_Event);
74 // EvtMessage* msg = m_streamer->streamDataStore(DataStore::c_Event, false, true);
75
76 B2INFO("Ds2Rbuf: msgsize = " << msg->size());
77
78 // printf("message size = %d\n", msg->size());
79 // Put the message in ring buffer
80 for (;;) {
81 int stat = m_rbuf->insq((int*)msg->buffer(), msg->paddedSize());
82 if (stat >= 0) break;
83 usleep(100);
84 // usleep(20);
85 }
86
87 B2INFO("Ds2Rbuf: objs sent in buffer. Size = " << msg->size());
88
89 // Release EvtMessage buffer
90 delete msg;
91
92 // return
93 m_nsent++;
94
95}
96
98{
99 //fill Run data
100
101 printf("Ds2Rbuf: endRun called.....\n");
102 B2INFO("Ds2Rbuf: endRun done.");
103}
104
105
107{
108 delete m_streamer;
109
110 // RingBuffer should not be deleted
111
112 B2INFO("Ds2Rbuf: terminate called");
113}
114
Stream/restore DataStore objects to/from EvtMessage.
@ c_Event
Different object in each event, all objects/arrays are invalidated after event() function has been ca...
Definition DataStore.h:59
DataStoreStreamer * m_streamer
DataStore streamer.
void initialize() override
Module functions to be called from main process.
Ds2RbufModule()
Constructor / Destructor.
void event() override
This method is the core of the module.
void endRun() override
This method is called if the current run ends.
void terminate() override
This method is called at the end of the event processing.
void beginRun() override
Module functions to be called from event process.
int m_nsent
No. of sent events.
std::vector< std::string > m_saveobjs
List of objects to be transferred.
int m_compressionLevel
Compression parameter.
std::string m_rbufname
RingBuffer ID.
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 size() const
Get size of message including headers.
Definition EvtMessage.cc:94
void setDescription(const std::string &description)
Sets the description of the module.
Definition Module.cc:214
Module()
Constructor.
Definition Module.cc:30
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition RingBuffer.h:39
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition Module.h:649
Abstract base class for different kinds of events.
STL namespace.