Belle II Software development
Rbuf2RbufModule.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/Rbuf2RbufModule.h>
10#include <TSystem.h>
11#include <stdlib.h>
12
13#include "framework/datastore/StoreObjPtr.h"
14#include "framework/dataobjects/EventMetaData.h"
15
16using namespace std;
17using namespace Belle2;
18
19//-----------------------------------------------------------------
20// Register the Module
21//-----------------------------------------------------------------
22REG_MODULE(Rbuf2Rbuf);
23
24//-----------------------------------------------------------------
25// Implementation
26//-----------------------------------------------------------------
27
29{
30 //Set module properties
31 setDescription("Encode DataStore into RingBuffer");
32 // setPropertyFlags(c_Input | c_ParallelProcessingCertified);
33
34 addParam("InputRbufName", m_name_rbufin, "Name of Input RingBuffer",
35 string("RBUFIN"));
36 addParam("OutputRbufName", m_name_rbufout, "Name of Output RingBuffer",
37 string("RBUFOUT"));
38
39 m_rbufin = NULL;
40 m_rbufout = NULL;
41 m_nrecv = 0;
42
43 //Parameter definition
44 B2INFO("Rx: Constructor done.");
45}
46
47
48Rbuf2RbufModule::~Rbuf2RbufModule()
49{
50}
51
53{
54 gSystem->Load("libdataobjects");
55
56 // Connect to Ring Buffers
57 m_rbufin = new RingBuffer(m_name_rbufin.c_str());
58 m_rbufout = new RingBuffer(m_name_rbufout.c_str());
59
60 // Initialize EvtMetaData
61 m_eventMetaData.registerInDataStore();
62
63 // Calls event function for TTree
64 event();
65
66 // Set m_nrecv to negative to tell the module is initialized
67 m_nrecv = -1;
68
69 B2INFO("Rx initialized.");
70}
71
72
74{
75 B2INFO("beginRun called.");
76}
77
78
80{
81 m_nrecv++;
82 // First event is already processed
83 if (m_nrecv == 0) return;
84
85 // Event buffer
86 int size;
87 int* evtbuf = new int[MAXEVTSIZE];
88
89 // Get a record from input ringbuf
90 while ((size = m_rbufin->remq(evtbuf)) == 0) {
91 // usleep(100);
92 usleep(20);
93 }
94
95 // Put the record in output ringbuf
96 for (;;) {
97 int stat = m_rbufout->insq(evtbuf, size);
98 if (stat >= 0) break;
99 // usleep(100);
100 usleep(20);
101 }
102
103 // Set EventMetaData
104 StoreObjPtr<EventMetaData> evtmetadata;
105 evtmetadata.create();
106 evtmetadata->setExperiment(1);
107 evtmetadata->setRun(1);
108 evtmetadata->setEvent(m_nrecv);
109
110 delete[] evtbuf;
111
112 B2INFO("Rbuf2Rbuf: RingBuffer copied!!");
113 return;
114 // return type;
115}
116
118{
119 //fill Run data
120
121 B2INFO("Rbuf2Rbuf: endRun done.");
122}
123
124
126{
127 B2INFO("Rbuf2Rbuf: terminate called");
128}
129
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
std::string m_name_rbufout
Output RingBuffer ID.
Rbuf2RbufModule()
Constructor / Destructor.
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.
StoreObjPtr< EventMetaData > m_eventMetaData
EventMetaData.
void beginRun() override
Module functions to be called from event process.
int m_nrecv
No. of sent events.
std::string m_name_rbufin
Input RingBuffer ID.
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
int remq(int *buf)
Pick up a buffer from the RingBuffer.
Definition: RingBuffer.cc:308
bool create(bool replace=false)
Create a default object in the data store.
Type-safe access to single objects in the data store.
Definition: StoreObjPtr.h:96
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.