Belle II Software development
Root2Binary.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 <rawdata/modules/Root2Binary.h>
10
11using namespace std;
12using namespace Belle2;
13
14//#define DEBUG
15
16//-----------------------------------------------------------------
17// Register the Module
18//-----------------------------------------------------------------
19REG_MODULE(Root2Binary);
20
21//-----------------------------------------------------------------
22// Implementation
23//-----------------------------------------------------------------
24
26{
27 m_fp_out = NULL;
28 addParam("outputFileName", m_fname_out, "Output binary filename", string(""));
29}
30
32{
33}
34
36{
37 B2INFO("Root2Binary: initialize() started.");
38
39 m_fp_out = fopen(m_fname_out.c_str(), "w");
40 if (!m_fp_out) {
41 char err_buf[500];
42 sprintf(err_buf, "Cannot open an output file(%s): %s : Exiting...\n",
43 strerror(errno), m_fname_out.c_str());
44 printf("%s\n", err_buf);
45 // print_err.PrintError(err_buf, __FILE__, __PRETTY_FUNCTION__, __LINE__);
46 exit(-1);
47 }
48
49 B2INFO("Root2Binary: initialize() done.");
50}
51
53{
54 //fill Run data
55 // fclose( m_fp_out );
56 B2INFO("endRun done.");
57}
58
59
61{
62 fclose(m_fp_out);
63 B2INFO("terminate called");
64}
65
66
67void Root2BinaryModule::writeEvent(RawDataBlock* raw_dblk, int* first_flag, int* break_flag, int* dblk_pos, unsigned int* dblk_eve)
68{
69 //
70 // Data Block
71 //
72 *break_flag = 0;
73 *first_flag = 0;
74
75
76 for (int j = *dblk_pos; j < raw_dblk->GetNumEntries(); j++) {
77 printf("numentries %d %d\n", raw_dblk->GetNumEntries(), j);
78
79
80 unsigned int prev_eve = *dblk_eve;
81 int num_nodes = 1;
82 int num_events = 1;
83 int delete_flag = 0;
84 int nwords = raw_dblk->GetBlockNwords(j);
85 int* temp_buf = raw_dblk->GetBuffer(j);
86
87
88 if (raw_dblk->CheckFTSWID(j)) {
89 RawFTSW temp_raw_ftsw;
90 temp_raw_ftsw.SetBuffer(temp_buf, nwords, delete_flag, num_nodes, num_events);
91 *dblk_eve = temp_raw_ftsw.GetEveNo(0);
92 } else {
93 RawCOPPER temp_raw_copper;
94 temp_raw_copper.SetBuffer(temp_buf, nwords, delete_flag, num_nodes, num_events);
95 *dblk_eve = temp_raw_copper.GetEveNo(0);
96 }
97
98 if (*dblk_eve != prev_eve && *first_flag == 1) {
99 *dblk_pos = j;
100 return;
101 } else {
102 fwrite((char*)temp_buf, 1, nwords * 4, m_fp_out);
103 printf("eve %u size %d j %d\n", *dblk_eve, nwords * 4, j);
104 }
105
106 *first_flag = 1;
107 }
108 *dblk_pos = 0;
109
110 return;
111}
112
113
114
115
117{
118
119
120 B2INFO("Root2Binary: event() started.");
121
122
123
124 //
125 // Data Block
126 //
127 StoreArray<RawDataBlock> raw_dblkarray;
128 StoreArray<RawFTSW> raw_ftswarray;
129 StoreArray<RawCOPPER> raw_copperarray;
130 StoreArray<RawSVD> raw_svdarray;
131 StoreArray<RawCDC> raw_cdcarray;
132 StoreArray<RawTOP> raw_bpidarray;
133 StoreArray<RawARICH> raw_epidarray;
134 StoreArray<RawKLM> raw_klmarray;
135 StoreArray<RawECL> raw_eclarray;
136
137 int dblk_array = 0;
138 int ftsw_array = 0;
139 int copper_array = 0;
140 int svd_array = 0;
141 int cdc_array = 0;
142 int ecl_array = 0;
143 int bpid_array = 0;
144 int epid_array = 0;
145 int klm_array = 0;
146
147 int dblk_pos = 0;
148 int ftsw_pos = 0;
149 int copper_pos = 0;
150 int svd_pos = 0;
151 int cdc_pos = 0;
152 int ecl_pos = 0;
153 int bpid_pos = 0;
154 int epid_pos = 0;
155 int klm_pos = 0;
156
157 unsigned int dblk_eve;// = 0;
158 unsigned int ftsw_eve;// = 0;
159 unsigned int copper_eve;// = 0;
160 unsigned int svd_eve;// = 0;
161 unsigned int cdc_eve;// = 0;
162 unsigned int ecl_eve;// = 0;
163 unsigned int bpid_eve;// = 0;
164 unsigned int epid_eve;// = 0;
165 unsigned int klm_eve;// = 0;
166
167
168
169 while (true) {
170 int write_flag = 0;
171
172 //
173 // DataBlock
174 //
175 int break_flag;
176 int first_flag;
177
178
179 break_flag = 0;
180 first_flag = 0;
181 dblk_eve = 0;
182 int array_entries = raw_dblkarray.getEntries();
183 for (int i = dblk_array; i < array_entries; i++) {
184 write_flag = 1;
185 writeEvent(raw_dblkarray[ i ], &first_flag, &break_flag, &dblk_pos, &dblk_eve);
186 if (break_flag == 1) {
187 dblk_array = i;
188 break;
189 }
190 if (i == array_entries - 1) {
191 dblk_array = array_entries;
192 }
193 }
194
195 break_flag = 0;
196 first_flag = 0;
197 ftsw_eve = 0;
198 array_entries = raw_ftswarray.getEntries();
199 for (int i = ftsw_array; i < array_entries; i++) {
200 write_flag = 1;
201 writeEvent(raw_ftswarray[ i ], &first_flag, &break_flag, &ftsw_pos, &ftsw_eve);
202 if (break_flag == 1) {
203 ftsw_array = i;
204 break;
205 }
206 if (i == array_entries - 1) {
207 ftsw_array = array_entries;
208 }
209 }
210
211
212 break_flag = 0;
213 first_flag = 0;
214 copper_eve = 0;
215 array_entries = raw_copperarray.getEntries();
216 for (int i = copper_array; i < array_entries; i++) {
217 write_flag = 1;
218 writeEvent(raw_copperarray[ i ], &first_flag, &break_flag, &copper_pos, &copper_eve);
219 if (break_flag == 1) {
220 copper_array = i;
221 break;
222 }
223 if (i == array_entries - 1) {
224 copper_array = array_entries;
225 }
226 }
227
228
229 break_flag = 0;
230 first_flag = 0;
231 svd_eve = 0;
232 array_entries = raw_svdarray.getEntries();
233 for (int i = svd_array; i < array_entries; i++) {
234 write_flag = 1;
235 writeEvent(raw_svdarray[ i ], &first_flag, &break_flag, &svd_pos, &svd_eve);
236 if (break_flag == 1) {
237 svd_array = i;
238 break;
239 }
240 if (i == array_entries - 1) {
241 svd_array = array_entries;
242 }
243 }
244
245
246 break_flag = 0;
247 first_flag = 0;
248 cdc_eve = 0;
249 array_entries = raw_cdcarray.getEntries();
250 for (int i = cdc_array; i < array_entries; i++) {
251 write_flag = 1;
252 writeEvent(raw_cdcarray[ i ], &first_flag, &break_flag, &cdc_pos, &cdc_eve);
253 if (break_flag == 1) {
254 cdc_array = i;
255 break;
256 }
257 if (i == array_entries - 1) {
258 cdc_array = array_entries;
259 }
260 }
261
262
263 break_flag = 0;
264 first_flag = 0;
265 bpid_eve = 0;
266 array_entries = raw_bpidarray.getEntries();
267 for (int i = bpid_array; i < array_entries; i++) {
268 write_flag = 1;
269 writeEvent(raw_bpidarray[ i ], &first_flag, &break_flag, &bpid_pos, &bpid_eve);
270 if (break_flag == 1) {
271 bpid_array = i;
272 break;
273 }
274 if (i == array_entries - 1) {
275 bpid_array = array_entries;
276 }
277 }
278
279
280
281 break_flag = 0;
282 first_flag = 0;
283 epid_eve = 0;
284 array_entries = raw_epidarray.getEntries();
285 for (int i = epid_array; i < array_entries; i++) {
286 write_flag = 1;
287 writeEvent(raw_epidarray[ i ], &first_flag, &break_flag, &epid_pos, &epid_eve);
288 if (break_flag == 1) {
289 epid_array = i;
290 break;
291 }
292 if (i == array_entries - 1) {
293 epid_array = array_entries;
294 }
295 }
296
297
298
299 break_flag = 0;
300 first_flag = 0;
301 ecl_eve = 0;
302 array_entries = raw_eclarray.getEntries();
303 for (int i = ecl_array; i < array_entries; i++) {
304 write_flag = 1;
305 writeEvent(raw_eclarray[ i ], &first_flag, &break_flag, &ecl_pos, &ecl_eve);
306 if (break_flag == 1) {
307 ecl_array = i;
308 break;
309 }
310 if (i == array_entries - 1) {
311 ecl_array = array_entries;
312 }
313 }
314
315 break_flag = 0;
316 first_flag = 0;
317 klm_eve = 0;
318 array_entries = raw_klmarray.getEntries();
319 for (int i = klm_array; i < array_entries; i++) {
320 write_flag = 1;
321 writeEvent(raw_klmarray[ i ], &first_flag, &break_flag, &klm_pos, &klm_eve);
322 if (break_flag == 1) {
323 klm_array = i;
324 break;
325 }
326 if (i == array_entries - 1) {
327 klm_array = array_entries;
328 }
329 }
330 if (write_flag == 0)break;
331 }
332
333 printf("loop %d\n", n_basf2evt);
334 n_basf2evt++;
335 return;
336
337}
Module to get data from DataStore and send it to another network node.
int n_basf2evt
No. of sent events.
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
The RawDataBlock class Base class for rawdata handling.
Definition: RawDataBlock.h:27
virtual int * GetBuffer(int n)
get nth buffer pointer
Definition: RawDataBlock.h:53
virtual int CheckFTSWID(int n)
get FTSW ID to check whether this data block is FTSW data or not
Definition: RawDataBlock.h:101
virtual int GetNumEntries()
get # of data blocks = (# of nodes)*(# of events)
Definition: RawDataBlock.h:67
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlock.h:94
The Raw FTSW class.
Definition: RawFTSW.h:30
unsigned int GetEveNo(int n)
Get event #.
Definition: RawFTSW.h:65
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: RawFTSW.cc:107
virtual void writeEvent(RawDataBlock *raw_dblk, int *first_flag, int *break_flag, int *dblk_pos, unsigned int *dblk_eve)
write the contents of an event
Definition: Root2Binary.cc:67
Root2BinaryModule()
Constructor.
Definition: Root2Binary.cc:25
FILE * m_fp_out
File descripter.
Definition: Root2Binary.h:52
virtual void initialize() override
Called at the beginning of data processing.
Definition: Root2Binary.cc:35
virtual void event() override
Called for each event.
Definition: Root2Binary.cc:116
virtual ~Root2BinaryModule()
Destructor.
Definition: Root2Binary.cc:31
virtual void endRun() override
Called if the current run ends.
Definition: Root2Binary.cc:52
virtual void terminate() override
Called at the end of data processing.
Definition: Root2Binary.cc:60
std::string m_fname_out
Output filename.
Definition: Root2Binary.h:55
Accessor to arrays stored in the data store.
Definition: StoreArray.h:113
int getEntries() const
Get the number of objects in the array.
Definition: StoreArray.h:216
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
unsigned int GetEveNo(int n)
get subrun #(8bit)
Definition: RawCOPPER.h:390
Abstract base class for different kinds of events.
STL namespace.