Belle II Software  release-08-01-10
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 
16 using namespace std;
17 using namespace Belle2;
18 
19 // Global variable
20 //RawSend* RAWCDC = NULL;
21 
22 // Framework interface
23 REG_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 
47 GenRawSendModule::~GenRawSendModule()
48 {
49  //printf("GenRawSendModule: Destructor called \n");
50 
51 }
52 
53 // Module functions
54 
55 void GenRawSendModule::initialize()
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
69  m_sock = new EvtSocketSend(m_dest, m_port);
70 
71 }
72 
73 void GenRawSendModule::beginRun()
74 {
75 }
76 
77 
78 void GenRawSendModule::event()
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 
122 void GenRawSendModule::endRun()
123 {
124 
125 }
126 
127 
128 void GenRawSendModule::terminate()
129 {
130  printf("GenRawSendModule : termination called\n");
131 
132 }
133 
Base class for Modules.
Definition: Module.h:72
#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.