Belle II Software development
Ds2SampleModule.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/expreco/modules/Ds2SampleModule.h>
10#include <framework/datastore/DataStore.h>
11
12#include <stdlib.h>
13
14using namespace std;
15using namespace Belle2;
16
17//-----------------------------------------------------------------
18// Register the Module
19//-----------------------------------------------------------------
20REG_MODULE(Ds2Sample);
21
22//-----------------------------------------------------------------
23// Implementation
24//-----------------------------------------------------------------
25
27{
28 //Set module properties
29 setDescription("Encode DataStore into RingBuffer");
30
31 addParam("RingBufferName", m_rbufname, "Name of RingBuffer",
32 string("OutputRbuf"));
33 addParam("CompressionLevel", m_compressionLevel, "Compression level",
34 0);
35 vector<string> emptyvector;
36 addParam("saveObjs", m_saveObjs, "List of objects/arrays to be saved", emptyvector);
37
38 m_rbuf = NULL;
39 m_nsent = 0;
41
42 //Parameter definition
43 B2INFO("Ds2Sample: Constructor done.");
44}
45
46
47Ds2SampleModule::~Ds2SampleModule()
48{
49}
50
52{
53
54 // m_rbuf = new RingBuffer(m_rbufname.c_str(), RBUFSIZE);
55 m_rbuf = new RingBuffer(m_rbufname.c_str());
58
59 B2INFO("Ds2Sample initialized.");
60}
61
62
64{
65 B2INFO("Ds2Sample: beginRun called.");
66}
67
68
70{
71 // Stream DataStore in EvtMessage
73
74 // Put the message in ring buffer. If failed, just skip the event
75 m_rbuf->insq((int*)msg->buffer(), msg->paddedSize());
76
77 B2INFO("Ds2Sample: objs sent in buffer. Size = " << msg->size());
78
79 // Release EvtMessage buffer
80 delete msg;
81
82 // return
83 m_nsent++;
84
85}
86
88{
89 //fill Run data
90
91 printf("Ds2Sample: endRun called.....\n");
92 B2INFO("Ds2Sample: endRun done.");
93}
94
95
97{
98 delete m_streamer;
99
100 // RingBuffer should not be deleted
101
102 B2INFO("Ds2Sample: terminate called");
103}
104
Stream/restore DataStore objects to/from EvtMessage.
EvtMessage * streamDataStore(bool addPersistentDurability, bool streamTransientObjects=false)
Store DataStore objects in EvtMessage.
void setStreamingObjects(const std::vector< std::string > &list)
Set names of objects to be streamed/destreamed.
@ 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.
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.
Ds2SampleModule()
Constructor / Destructor.
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 saved.
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
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
int insq(const int *buf, int size, bool checkTx=false)
Append a buffer to the RingBuffer.
Definition: RingBuffer.cc:189
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:560
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
STL namespace.