Belle II Software  release-08-01-10
TxSocketModule.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/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  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 
Stream/restore DataStore objects to/from EvtMessage.
Class to manage streamed object.
Definition: EvtMessage.h:59
int size() const
Get size of message including headers.
Definition: EvtMessage.cc:94
Base class for Modules.
Definition: Module.h:72
A class definition of an input module for Sequential ROOT I/O.
#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.