Belle II Software  release-05-02-19
TxSocketModule.cc
1 //+
2 // File : TxSocketModule.cc
3 // Description : Module to encode DataStore and place it in Ringbuffer
4 //
5 // Author : Ryosuke Itoh, IPNS, KEK
6 // Date : 13 - Aug - 2010
7 //-
8 
9 #include <daq/dataflow/modules/TxSocketModule.h>
10 
11 #include <framework/datastore/DataStore.h>
12 #include <framework/pcore/EvtMessage.h>
13 
14 using namespace std;
15 using namespace Belle2;
16 
17 //-----------------------------------------------------------------
18 // Register the Module
19 //-----------------------------------------------------------------
20 REG_MODULE(TxSocket)
21 
22 //-----------------------------------------------------------------
23 // Implementation
24 //-----------------------------------------------------------------
25 
27 {
28  //Set module properties
29  setDescription("Encode DataStore into RingBuffer");
30  // setPropertyFlags(c_Input | c_ParallelProcessingCertified);
31 
32  addParam("DestHostName", m_dest, "Destination host", string("localhost"));
33  addParam("DestPort", m_port, "Destination port", 1111);
34 
35  m_nsent = 0;
36  m_compressionLevel = 0;
37 
38  //Parameter definition
39  B2INFO("Tx: Constructor done.");
40 }
41 
42 
43 
44 TxSocketModule::~TxSocketModule()
45 {
46 }
47 
48 void TxSocketModule::initialize()
49 {
50 
51  // Open Socket
52  m_sock = new EvtSocketSend(m_dest, m_port);
53  m_streamer = new DataStoreStreamer(m_compressionLevel);
54 
55  B2INFO("Tx initialized.");
56 }
57 
58 
59 void TxSocketModule::beginRun()
60 {
61  B2INFO("beginRun called.");
62 }
63 
64 
65 void TxSocketModule::event()
66 {
67  // Stream DataStore in EvtMessage
68  EvtMessage* msg = m_streamer->streamDataStore(DataStore::c_Event);
69 
70  // Send the message to Socket
71  int stat = m_sock->send(msg);
72  B2INFO("Tx: objs sent in buffer. Size = " << msg->size());
73 
74  // Release EvtMessage buffer
75  delete msg;
76 
77 }
78 
79 void TxSocketModule::endRun()
80 {
81  //fill Run data
82 
83  B2INFO("endRun done.");
84 }
85 
86 
87 void TxSocketModule::terminate()
88 {
89  B2INFO("terminate called");
90 }
91 
Belle2::EvtSocketSend
Definition: EvtSocket.h:26
Belle2::TxSocketModule
A class definition of an input module for Sequential ROOT I/O.
Definition: TxSocketModule.h:30
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::EvtMessage
Class to manage streamed object.
Definition: EvtMessage.h:60
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::EvtMessage::size
int size() const
Get size of message including headers.
Definition: EvtMessage.cc:95
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DataStoreStreamer
Stream/restore DataStore objects to/from EvtMessage.
Definition: DataStoreStreamer.h:33