Belle II Software development
GenRawSend.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/rawdata/modules/GenRawSend.h"
10
11#include <framework/datastore/StoreObjPtr.h>
12#include <framework/dataobjects/EventMetaData.h>
13
14#define HEADER_SIZE 23
15
16using namespace std;
17using namespace Belle2;
18
19// Global variable
20//RawSend* RAWCDC = NULL;
21
22// Framework interface
23REG_MODULE(GenRawSend);
24
25// Constructor and destructor
26
28{
29 //Set module properties
30 setDescription("GenRawSendModule module");
31 //printf("GenRawSendModule: Constructor called \n");
32
33 m_buffer = NULL;
34 m_nevt = 0;
35 //Parameter definition
36 addParam("EventDataBufferWords", BUF_SIZE_WORD, "DataBuffer words per event", 4800);
37 addParam("Size", m_size, "Raw Data Size", 256);
38 addParam("MaxEvent", m_maxevt, "Max Number of Event", 1000000);
39 addParam("DestHostName", m_dest, "Destination host", string("localhost"));
40 addParam("DestPort", m_port, "Destination port", 1111);
41
42
43 //cout << "GenRawSendModule : constructor called" << endl;
44}
45
46
48{
49 //printf("GenRawSendModule: Destructor called \n");
50
51}
52
53// Module functions
54
56{
57 m_buffer = new char[ BUF_SIZE_WORD ];
58 memset(m_buffer, 0, BUF_SIZE_WORD);
59
60 // Initialize EventMetaData
61 // StoreObjPtr<EventMetaData>::registerPersistent();
62 //Register the EventMetaData in the data store
63 m_eventMetaDataPtr.registerInDataStore();
64
65 // Initialize RawCOPPER
66 m_rawcopper.registerInDataStore();
67
68 // Open Socket
70
71}
72
74{
75}
76
77
79{
80
81 // Max event number
82 if (m_nevt > m_maxevt) return;
83
84 // Event Meta Data
85 m_eventMetaDataPtr.create();
86 m_eventMetaDataPtr->setExperiment(1);
87 m_eventMetaDataPtr->setRun(1);
88 m_eventMetaDataPtr->setEvent(m_nevt);
89
90 /*
91 // Header
92 unsigned int hdr[8];
93 hdr[0] = m_size + 8;
94 hdr[1] = m_nevt;
95
96 RawHeader rhdr ( hdr );
97 */
98
99 // Create RawCOPPER and fill buffer
100// m_rawcopper.create();
101// int* buf = m_rawcopper->AllocateBuffer(m_size + HEADER_SIZE);
102// buf[0] = m_size + HEADER_SIZE;
103// buf[1] = HEADER_SIZE;
104// buf[2] = m_size;
105// // memset ( (char*)&buf[HEADER_SIZE+1], 0, (m_size-1)*4 );
106// memcpy((char*)&buf[HEADER_SIZE + 1], m_buffer, (m_size - 1) * 4);
107
108// /* Dummy Data
109// int* buf = (int*)m_buffer;
110// buf[0] = m_size+HEADER_SIZE;
111// */
112
113// // Send Buffer
114// int nbytes = buf[0] * 4;
115// int stat = m_sock->send_buffer(nbytes, (char*)buf);
116// // printf ( "nbytes = %d, stat = %d\n", nbytes, stat );
117
118 m_nevt++;
119}
120
121
123{
124
125}
126
127
129{
130 printf("GenRawSendModule : termination called\n");
131
132}
133
virtual ~GenRawSendModule()
Destructor.
Definition: GenRawSend.cc:47
void initialize() override
Initialize the Module.
Definition: GenRawSend.cc:55
void event() override
Running over all events.
Definition: GenRawSend.cc:78
int BUF_SIZE_WORD
size of buffer for one event (word)
Definition: GenRawSend.h:59
GenRawSendModule()
Constructor.
Definition: GenRawSend.cc:27
void endRun() override
Is called after processing the last event of a run.
Definition: GenRawSend.cc:122
EvtSocketSend * m_sock
EvtSocket.
Definition: GenRawSend.h:76
void terminate() override
Is called at the end of your Module.
Definition: GenRawSend.cc:128
int m_port
Destination port.
Definition: GenRawSend.h:73
void beginRun() override
Called when entering a new run.
Definition: GenRawSend.cc:73
std::string m_dest
Destination Host.
Definition: GenRawSend.h:70
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
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.