Belle II Software development
RxSocketModule.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/dataflow/modules/RxSocketModule.h>
10
11#include <TSystem.h>
12
13#include <stdlib.h>
14
15//#define MAXEVTSIZE 400000000
16
17using namespace std;
18using namespace Belle2;
19
20//-----------------------------------------------------------------
21// Register the Module
22//-----------------------------------------------------------------
23REG_MODULE(RxSocket);
24
25//-----------------------------------------------------------------
26// Implementation
27//-----------------------------------------------------------------
28
30{
31 //Set module properties
32 setDescription("Encode DataStore into RingBuffer");
33 // setPropertyFlags(c_Input | c_ParallelProcessingCertified);
34
35 addParam("Port", m_port, "Receiver Port", 1111);
36 m_nrecv = 0;
38
39 //Parameter definition
40 B2INFO("Rx: Constructor done.");
41}
42
43
44RxSocketModule::~RxSocketModule()
45{
46}
47
49{
50 // Load data objects definitions
51 gSystem->Load("libdataobjects");
52
53 // Open receiving socekt
55
56 // Initialize DataStoreStreamer
58
59 // Prefetch first record in RxSocket
60 EvtMessage* msg = m_recv->recv();
61 if (msg == NULL) {
62 return;
63 }
65
66 // Delete buffers
67 delete msg;
68
69 m_nrecv = -1;
70
71 B2INFO("Rx initialized.");
72}
73
74
76{
77 B2INFO("beginRun called.");
78}
79
80
82{
83 m_nrecv++;
84 // First event is already loaded
85 if (m_nrecv == 0) return;
86
87 // Get a record from socket
88 EvtMessage* msg = m_recv->recv();
89 if (msg == NULL) {
90 return;
91 }
92 B2INFO("Rx: got an event from Socket, size=" << msg->size());
93 // Check for termination record
94 if (msg->type() == MSG_TERMINATE) {
95 B2INFO("Rx: got termination message. Exitting....");
96 return;
97 // Flag End Of File !!!!!
98 // return msg->type(); // EOF
99 }
100
101 // Restore DataStore
103 B2INFO("Rx: DataStore Restored!!");
104
105 // Delete EvtMessage
106 delete msg;
107
108 return;
109}
110
112{
113 //fill Run data
114
115 B2INFO("endRun done.");
116}
117
118
120{
121 B2INFO("terminate called");
122}
123
Stream/restore DataStore objects to/from EvtMessage.
int restoreDataStore(EvtMessage *msg)
Restore DataStore objects from EvtMessage.
Class to manage streamed object.
Definition: EvtMessage.h:59
ERecordType type() const
Get record type.
Definition: EvtMessage.cc:114
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
DataStoreStreamer * m_streamer
DataStoreStreamer.
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.
int m_port
Receiver Port.
void beginRun() override
Module functions to be called from event process.
int m_nrecv
No. of sent events.
RxSocketModule()
Constructor / Destructor.
int m_compressionLevel
Compression Level.
EvtSocketRecv * m_recv
Reciever Socket.
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.