Belle II Software  release-08-01-10
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 
14 using namespace std;
15 using namespace Belle2;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_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;
40  m_compressionLevel = 0;
41 
42  //Parameter definition
43  B2INFO("Ds2Sample: Constructor done.");
44 }
45 
46 
47 Ds2SampleModule::~Ds2SampleModule()
48 {
49 }
50 
51 void Ds2SampleModule::initialize()
52 {
53 
54  // m_rbuf = new RingBuffer(m_rbufname.c_str(), RBUFSIZE);
55  m_rbuf = new RingBuffer(m_rbufname.c_str());
56  m_streamer = new DataStoreStreamer(m_compressionLevel);
57  m_streamer->setStreamingObjects(m_saveObjs);
58 
59  B2INFO("Ds2Sample initialized.");
60 }
61 
62 
63 void Ds2SampleModule::beginRun()
64 {
65  B2INFO("Ds2Sample: beginRun called.");
66 }
67 
68 
69 void Ds2SampleModule::event()
70 {
71  // Stream DataStore in EvtMessage
72  EvtMessage* msg = m_streamer->streamDataStore(DataStore::c_Event);
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 
87 void Ds2SampleModule::endRun()
88 {
89  //fill Run data
90 
91  printf("Ds2Sample: endRun called.....\n");
92  B2INFO("Ds2Sample: endRun done.");
93 }
94 
95 
96 void Ds2SampleModule::terminate()
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.
A class definition of an input module for Sequential ROOT I/O.
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
Class to manage a Ring Buffer placed in an IPC shared memory.
Definition: RingBuffer.h:39
#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.