Belle II Software development
DeSerializerHLT.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/DeSerializerHLT.h>
10
11// #include <daq/dataobjects/SendHeader.h>
12// #include <daq/dataobjects/SendTrailer.h>
13// #include <sys/mman.h>
14
15//#define MAXEVTSIZE 400000000
16#define CHECKEVT 5000
17
18#define NOT_USE_SOCKETLIB
19#define CLONE_ARRAY
20//#define DISCARD_DATA
21//#define CHECK_SUM
22//#define TIME_MONITOR
23//#define DEBUG
24
25using namespace std;
26using namespace Belle2;
27
28//-----------------------------------------------------------------
29// Register the Module
30//-----------------------------------------------------------------
31REG_MODULE(DeSerializerHLT);
32
33//-----------------------------------------------------------------
34// Implementation
35//-----------------------------------------------------------------
36
38{
39 B2INFO("DeSerializerHLT: Constructor done.");
40}
41
42
43DeSerializerHLTModule::~DeSerializerHLTModule()
44{
45}
46
47
48
50{
51 B2INFO("DeSerializerHLT: initialize() started.");
52
53 // Accept requests for connections
54 Connect();
55
56 // allocate buffer
57 for (int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
58 m_bufary[i] = new int[ BUF_SIZE_WORD ];
59 }
60 m_buffer = new int[ BUF_SIZE_WORD ];
61
62
63 // initialize buffer
64 for (int i = 0 ; i < NUM_PREALLOC_BUF; i++) {
65 memset(m_bufary[i], 0, BUF_SIZE_WORD * sizeof(int));
66 }
67
68 // Initialize EvtMetaData
69 m_eventMetaDataPtr.registerInDataStore();
70
71 // Initialize Array of RawCOPPER
72 raw_datablkarray.registerInDataStore();
73 rawcprarray.registerInDataStore();
74 raw_cdcarray.registerInDataStore();
75 raw_svdarray.registerInDataStore();
76 raw_bpidarray.registerInDataStore();
77 raw_epidarray.registerInDataStore();
78 raw_eclarray.registerInDataStore();
79 raw_klmarray.registerInDataStore();
80 raw_ftswarray.registerInDataStore();
81
82
83
84 if (m_dump_fname.size() > 0) {
86 }
87
88
89 // Initialize arrays for time monitor
90 memset(time_array0, 0, sizeof(time_array0));
91 memset(time_array1, 0, sizeof(time_array1));
92 memset(time_array2, 0, sizeof(time_array2));
93
94 // initialize buffer number
95 clearNumUsedBuf();
96
97 B2INFO("DeSerializerHLT: initialize() done.");
98
99}
100
101
102
104{
105 clearNumUsedBuf();
106
107 if (m_start_flag == 0) {
108 B2INFO("DeSerializerHLT: event() started.");
109 m_start_time = getTimeSec();
110 n_basf2evt = 0;
111 m_start_flag = 1;
112 }
113
114
115 // DataStore interface
116 for (int j = 0; j < NUM_EVT_PER_BASF2LOOP_PC; j++) {
117 // Get a record from socket
118 int total_buf_nwords = 0 ;
119 int delete_flag = 0;
120 int num_events_in_sendblock = 0;
121 int num_nodes_in_sendblock = 0;
122
123 // Receive data
124 int* temp_buf = recvData(&delete_flag, &total_buf_nwords,
125 &num_events_in_sendblock, &num_nodes_in_sendblock);
126 RawCOPPER temp_rawcopper;
127 temp_rawcopper.SetBuffer(temp_buf, total_buf_nwords, delete_flag, num_events_in_sendblock, num_nodes_in_sendblock);
128
129
130 // Store data to DataStore
131 for (int k = 0; k < temp_rawcopper.GetNumEvents(); k++) {
132 for (int l = 0; l < temp_rawcopper.GetNumNodes(); l++) {
133 int index = k * temp_rawcopper.GetNumEvents() + l;
134 int buf_nwords = temp_rawcopper.GetBlockNwords(index);
135
136 int* temp_buf2 = NULL;
137 int delete_flag2 = 0;
138 temp_buf2 = getNewBuffer(buf_nwords, &delete_flag2);
139 memcpy(temp_buf2, temp_rawcopper.GetBuffer(index), sizeof(int)*buf_nwords);
140 const int temp_num_events = 1;
141 const int temp_num_nodes = 1;
142
143 // RawHeader hdr;
144 // Fill data to Raw*** class
145
146 switch (temp_rawcopper.GetNodeID(k * num_nodes_in_sendblock + l) & DETECTOR_MASK) {
147 case CDC_ID :
148 RawCDC* rawcdc;
149 rawcdc = raw_cdcarray.appendNew();
150 rawcdc->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
151 break;
152 case SVD_ID :
153 RawSVD* rawsvd;
154 rawsvd = raw_svdarray.appendNew();
155 rawsvd->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
156 break;
157 case BECL_ID :
158 RawECL* rawecl;
159 rawecl = raw_eclarray.appendNew();
160 rawecl->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
161 break;
162 case TOP_ID :
163 RawTOP* rawbpid;
164 rawbpid = raw_bpidarray.appendNew();
165 rawbpid->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
166 break;
167 case ARICH_ID :
168 RawARICH* rawepid;
169 rawepid = raw_epidarray.appendNew();
170 rawepid->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
171 break;
172 case BKLM_ID :
173 RawKLM* rawklm;
174 rawklm = raw_klmarray.appendNew();
175 rawklm->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
176 break;
177 default :
178 RawCOPPER* rawcopper;
179 rawcopper = rawcprarray.appendNew();
180 rawcopper->SetBuffer(temp_buf2, buf_nwords, delete_flag2, temp_num_events, temp_num_nodes);
181 break;
182 }
183 // Fill header and trailer
184 }
185 }
186
187 m_totbytes += total_buf_nwords * sizeof(int);
188
189 if (delete_flag == 1) delete temp_buf;
190 }
191
192 //
193 // Update EventMetaData
194 //
195 m_eventMetaDataPtr.create();
196 m_eventMetaDataPtr->setExperiment(1);
197 m_eventMetaDataPtr->setRun(1);
198 m_eventMetaDataPtr->setEvent(n_basf2evt);
199
200 n_basf2evt++;
201
202
203 if (max_nevt >= 0 || max_seconds >= 0.) {
204 if ((n_basf2evt * NUM_EVT_PER_BASF2LOOP_PC >= max_nevt && max_nevt > 0)
205 || (getTimeSec() - m_start_time > max_seconds && max_seconds > 0.)) {
206 m_eventMetaDataPtr->setEndOfData();
207 }
208 }
209
210
211 return;
212}
void initialize() override
initialize functions
void event() override
Module functions to be called from event process.
DeSerializerHLTModule()
Constructor / Destructor.
int BUF_SIZE_WORD
size of buffer for one event (word)
Definition: DeSerializer.h:83
int n_basf2evt
No. of sent events.
Definition: DeSerializer.h:86
virtual int * getNewBuffer(int nwords, int *delete_flag)
Getbuffer.
std::string m_dump_fname
dump filename
Definition: DeSerializer.h:92
int * m_bufary[NUM_PREALLOC_BUF]
buffer
Definition: DeSerializer.h:101
virtual void openOutputFile()
Module functions to be called from event process.
double max_seconds
time to stop a run
Definition: DeSerializer.h:77
double getTimeSec()
store time info.
A class definition of an input module for Sequential ROOT I/O.
virtual int * recvData(int *delete_flag, int *total_m_size_word, int *num_events_in_sendblock, int *num_nodes_in_sendblock)
receive data
virtual int Connect()
Accept connection.
The Raw ARICH class Class for RawCOPPER class data taken by ARICH Currently, this class is almost sam...
Definition: RawARICH.h:27
The Raw CDC class Class for RawCOPPER class data taken by CDC Currently, this class is almost same as...
Definition: RawCDC.h:27
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
Definition: RawCOPPER.h:52
void SetBuffer(int *bufin, int nwords, int delete_flag, int num_events, int num_nodes) OVERRIDE_CPP17
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
Definition: RawCOPPER.cc:141
virtual int * GetBuffer(int n)
get nth buffer pointer
Definition: RawDataBlock.h:53
virtual int GetNumNodes()
get # of data sources(e.g. # of COPPER boards) in m_buffer
Definition: RawDataBlock.h:74
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlock.h:94
virtual int GetNumEvents()
get # of events in m_buffer
Definition: RawDataBlock.h:81
The Raw ECL class Class for RawCOPPER class data taken by ECL Currently, this class is almost same as...
Definition: RawECL.h:26
The Raw KLM class Class for RawCOPPER class data taken by KLM.
Definition: RawKLM.h:27
The Raw SVD class Class for RawCOPPER class data taken by SVD Currently, this class is almost same as...
Definition: RawSVD.h:26
The Raw TOP class Class for RawCOPPER class data taken by TOP Currently, this class is almost same as...
Definition: RawTOP.h:27
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
unsigned int GetNodeID(int n)
get node-ID from data
Definition: RawCOPPER.h:397
Abstract base class for different kinds of events.
STL namespace.