Belle II Software development
RawCOPPERFormat_v0.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/dataobjects/RawCOPPERFormat_v0.h>
10
11
12using namespace std;
13using namespace Belle2;
14
15//#define DESY
16//#define NO_DATA_CHECK
17//#define WO_FIRST_EVENUM_CHECK
18
19//ClassImp(RawCOPPERFormat_v0);
20
22{
23}
24
26{
27}
28
30{
31 int min = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS;
32 int max = GetBufferPos(n) + GetBlockNwords(n)
33 - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
34 unsigned int chksum = 0;
35 for (int i = min; i < max; i++) {
36 chksum ^= m_buffer[ i ];
37 }
38 return chksum;
39}
40
41
43{
44
45 int cnt = 0;
46 int pos_nwords = GetBufferPos(n) + POS_CH_A_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
47 if (m_buffer[ pos_nwords ] > 0) cnt++;
48 pos_nwords = GetBufferPos(n) + POS_CH_B_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
49 if (m_buffer[ pos_nwords ] > 0) cnt++;
50 pos_nwords = GetBufferPos(n) + POS_CH_C_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
51 if (m_buffer[ pos_nwords ] > 0) cnt++;
52 pos_nwords = GetBufferPos(n) + POS_CH_D_DATA_LENGTH + tmp_header.RAWHEADER_NWORDS;
53 if (m_buffer[ pos_nwords ] > 0) cnt++;
54 return cnt;
55}
56
57int RawCOPPERFormat_v0::GetDetectorNwords(int n, int finesse_num)
58{
59 switch (finesse_num) {
60 case 0 :
61 return Get1stDetectorNwords(n);
62 break;
63 case 1 :
64 return Get2ndDetectorNwords(n);
65 break;
66 case 2 :
67 return Get3rdDetectorNwords(n);
68 break;
69 case 3 :
70 return Get4thDetectorNwords(n);
71 break;
72 default :
73 break;
74 }
75
76 char err_buf[500];
77 sprintf(err_buf, "Specifined FINESSE number( = %d ) is invalid. Exiting...\n %s %s %d\n", finesse_num,
78 __FILE__, __PRETTY_FUNCTION__, __LINE__);
79 printf("%s\n", err_buf); fflush(stdout);
80 B2FATAL(err_buf);
81}
82
83
84int RawCOPPERFormat_v0::GetFINESSENwords(int n, int finesse_num)
85{
86 switch (finesse_num) {
87 case 0 :
88 return Get1stFINESSENwords(n);
89 break;
90 case 1 :
91 return Get2ndFINESSENwords(n);
92 break;
93 case 2 :
94 return Get3rdFINESSENwords(n);
95 break;
96 case 3 :
97 return Get4thFINESSENwords(n);
98 break;
99 default :
100 break;
101 }
102
103 char err_buf[500];
104 sprintf(err_buf, "Specifined FINESSE number( = %d ) is invalid. Exiting...\n %s %s %d\n",
105 finesse_num, __FILE__, __PRETTY_FUNCTION__, __LINE__);
106 printf("%s\n", err_buf); fflush(stdout);
107 B2FATAL(err_buf);
108}
109
110
111
112
113
114
115
116
118{
119
120#ifndef READ_OLD_B2LFEE_FORMAT_FILE
121
122 int err_flag = 0;
123 unsigned int eve_num = 0;
124 int flag = 0;
125 unsigned int eve[4];
126 for (int i = 0; i < 4 ; i++) {
127 eve[ i ] = 12345678;
128 if (GetFINESSENwords(n, i) > 0) {
129 int pos_nwords = GetOffsetFINESSE(n, i) + SIZE_B2LHSLB_HEADER + POS_TT_TAG;
130 eve[ i ] = m_buffer[ pos_nwords ];
131 if (flag != 1) eve_num = eve[ i ];
132 if (eve_num != eve[ i ]) err_flag = 1;
133 flag = 1;
134 }
135 }
136
137 if (flag == 0) {
138 char err_buf[500];
139 sprintf(err_buf, "No HSLB data in COPPER data. Exiting...\n%s %s %d\n",
140 __FILE__, __PRETTY_FUNCTION__, __LINE__);
141 printf("%s\n", err_buf); fflush(stdout);
142 B2FATAL(err_buf);
143 }
144
145 if (err_flag == 1) {
146
147 char err_buf[500];
148 sprintf(err_buf, "CORRUPTED DATA: Different event number over HSLBs : slot A 0x%x : B 0x%x :C 0x%x : D 0x%x\n%s %s %d\n",
149 eve[ 0 ], eve[ 1 ], eve[ 2 ], eve[ 3 ],
150 __FILE__, __PRETTY_FUNCTION__, __LINE__);
151 printf("[DEBUG] [ERROR] %s\n", err_buf);
152#ifndef NO_DATA_CHECK
153 B2FATAL(err_buf);
154#endif //NO_DATA_CHECK
155 }
156 return eve_num;
157
158#else // READ_OLD_B2LFEE_FORMAT_FILE
159
160 char err_buf[500];
161 sprintf(err_buf, "You need comment out READ_OLD_B2LFEE_FORMAT_FILE if you are handling a new data format\n%s %s %d\n",
162 __FILE__, __PRETTY_FUNCTION__, __LINE__);
163 printf("%s", err_buf); fflush(stdout);
164 B2FATAL(err_buf);
165#endif // READ_OLD_B2LFEE_FORMAT_FILE
166
167}
168
169
170
171
173 unsigned int prev_evenum, unsigned int* cur_evenum_rawcprhdr,
174 unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
175 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
176{
177
178 char err_buf[500];
179 sprintf(err_buf,
180 "This function for format ver.0 is not supported. (n %d preveve %u eve %u prectr %u ctr %u prevrun %u run %u) Exiting...\n %s %s %d\n",
181 n, prev_evenum, *cur_evenum_rawcprhdr, prev_copper_ctr, *cur_copper_ctr,
182 prev_exprunsubrun_no, *cur_exprunsubrun_no,
183 __FILE__, __PRETTY_FUNCTION__, __LINE__);
184 printf("%s", err_buf); fflush(stdout);
185 B2FATAL(err_buf);
186
187// char err_buf[500];
188// int err_flag = 0;
189// //
190// // check Magic words
191// //
192// if (!CheckCOPPERMagic(n)) {
193// sprintf(err_buf, "CORRUPTED DATA: Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n%s %s %d\n",
194// GetMagicDriverHeader(n),
195// GetMagicFPGAHeader(n),
196// GetMagicFPGATrailer(n),
197// GetMagicDriverTrailer(n),
198// __FILE__, __PRETTY_FUNCTION__, __LINE__);
199// err_flag = 1;
200// }
201// //
202// // Event # check
203// //
204// *cur_evenum_rawcprhdr = GetEveNo(n);
205// unsigned int evenum_feehdr = GetB2LFEE32bitEventNumber(n);
206// if (*cur_evenum_rawcprhdr != evenum_feehdr) {
207// sprintf(err_buf,
208// "CORRUPTED DATA: Event # in RawCOPPERFormat_v0 header and FEE header is different : cprhdr 0x%x feehdr 0x%x : Exiting...\n%s %s %d\n",
209// *cur_evenum_rawcprhdr, evenum_feehdr,
210// __FILE__, __PRETTY_FUNCTION__, __LINE__);
211// err_flag = 1;
212// }
213
214// //
215// // Check incrementation of event #
216// //
217// *cur_runsubrun_no = GetRunNoSubRunNo(n);
218// if (
219// #ifdef WO_FIRST_EVENUM_CHECK
220// prev_evenum != 0xFFFFFFFF && *cur_evenum_rawcprhdr != 0
221// #else
222// prev_runsubrun_no == *cur_runsubrun_no && prev_runsubrun_no >= 0
223// #endif
224// ) {
225// if ((unsigned int)(prev_evenum + 1) != *cur_evenum_rawcprhdr) {
226// sprintf(err_buf, "CORRUPTED DATA: Event # jump : i %d prev 0x%x cur 0x%x : Exiting...\n%s %s %d\n",
227// n, prev_evenum, *cur_evenum_rawcprhdr,
228// __FILE__, __PRETTY_FUNCTION__, __LINE__);
229// err_flag = 1;
230// }
231// }
232
233
234// *cur_copper_ctr = GetCOPPERCounter(n);
235// if (
236// #ifdef WO_FIRST_EVENUM_CHECK
237// prev_copper_ctr != 0xFFFFFFFF
238// #else
239// true
240// #endif
241// ) {
242// if ((unsigned int)(prev_copper_ctr + 1) != *cur_copper_ctr) {
243// sprintf(err_buf, "COPPER counter jump : i %d prev 0x%x cur 0x%x :\n%s %s %d\n",
244// n, prev_copper_ctr, *cur_copper_ctr,
245// __FILE__, __PRETTY_FUNCTION__, __LINE__);
246
247// #ifdef DESY
248// //
249// // In DESY test, we ignore this error
250// //
251// printf("[DEBUG] [INFO] %s", err_buf);
252// #else
253// err_flag = 1;
254// #endif
255
256// }
257// }
258
259// //
260// // Check is utime and ctime_trgtype same over different FINESSE data
261// //
262// CheckUtimeCtimeTRGType(n);
263
264
265// //
266// // Check checksum calculated by COPPER driver
267// //
268// if (GetDriverChkSum(n) != CalcDriverChkSum(n)) {
269// sprintf(err_buf,
270// "CORRUPTED DATA: COPPER driver checkSum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n%s %s %d\n",
271// n,
272// GetBlockNwords(n),
273// *cur_evenum_rawcprhdr,
274// GetDriverChkSum(n),
275// CalcDriverChkSum(n),
276// __FILE__, __PRETTY_FUNCTION__, __LINE__);
277// err_flag = 1;
278// }
279
280
281// //
282// // Check checksum calculated by DeSerializerCOPPER()
283// //
284
285// tmp_trailer.SetBuffer(GetRawTrlBufPtr(n));
286// unsigned int xor_chksum = CalcXORChecksum(GetBuffer(n), GetBlockNwords(n) - tmp_trailer.GetTrlNwords());
287// if (tmp_trailer.GetChksum() != xor_chksum) {
288// sprintf(err_buf,
289// "CORRUPTED DATA: RawCOPPERFormat_v0 checksum error : block %d : length %d eve 0x%x : Trailer chksum 0x%.8x : calcd. now 0x%.8x\n %s %s %d\n",
290// n, GetBlockNwords(n), *cur_evenum_rawcprhdr, tmp_trailer.GetChksum(), xor_chksum,
291// __FILE__, __PRETTY_FUNCTION__, __LINE__);
292// err_flag = 1;
293// }
294
295
296// #ifdef DEBUG
297// printf("[DEBUG] eve %u %d %d %d %d\n",
298// GetEveNo(n),
299// Get1stDetectorNwords(n),
300// Get2ndDetectorNwords(n),
301// Get3rdDetectorNwords(n),
302// Get4thDetectorNwords(n)
303// );
304// printf("[DEBUG] ===COPPER BLOCK==============\n");
305// printData(GetBuffer(n), GetBlockNwords(n));
306
307// printf("[DEBUG] ===FINNESSE A ==============\n");
308// printData(Get1stDetectorBuffer(n), Get1stDetectorNwords(n));
309
310// printf("[DEBUG] ===FINNESSE B ==============\n");
311// printData(Get2ndDetectorBuffer(n), Get2ndDetectorNwords(n));
312
313// printf("[DEBUG] ===FINNESSE C ==============\n");
314// printData(Get3rdDetectorBuffer(n), Get3rdDetectorNwords(n));
315
316// printf("[DEBUG] ===FINNESSE D ==============\n");
317// printData(Get4thDetectorBuffer(n), Get4thDetectorNwords(n));
318// printf("[DEBUG] === END ==============\n");
319
320// #endif
321
322// if (err_flag == 1) {
323// printf("[DEBUG] ========== dump a data blcok : block # %d==========\n", n);
324// PrintData(GetBuffer(n), GetBlockNwords(n));
325// string err_str = err_buf;
326// throw (err_str);
327// // sleep(1234567);
328// // exit(-1);
329// }
330
331 return;
332
333}
334
336{
337 if (GetMagicDriverHeader(n) != COPPER_MAGIC_DRIVER_HEADER) {
338 return false;
339 } else if (GetMagicFPGAHeader(n) != COPPER_MAGIC_FPGA_HEADER) {
340 return false;
341 } else if (GetMagicFPGATrailer(n) != COPPER_MAGIC_FPGA_TRAILER) {
342 return false;
343 } else if (GetMagicDriverTrailer(n) != COPPER_MAGIC_DRIVER_TRAILER) {
344 return false;
345 }
346 return true;
347}
348
350{
351
352#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
353 CheckB2LFEEHeaderVersion(n);
354#endif
355 int err_flag = 0;
356 int flag = 0;
357 unsigned int temp_utime = 0, temp_ctime_trgtype = 0;
358 unsigned int utime[4], ctime_trgtype[4];
359 memset(utime, 0, sizeof(utime));
360 memset(ctime_trgtype, 0, sizeof(ctime_trgtype));
361
362 for (int i = 0; i < 4; i++) {
363 if (GetFINESSENwords(n, i) > 0) {
364 ctime_trgtype[ i ] = m_buffer[ GetOffsetFINESSE(n, i) +
365 SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
366 utime[ i ] = m_buffer[ GetOffsetFINESSE(n, i) +
367 SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
368 if (flag == 0) {
369 temp_ctime_trgtype = ctime_trgtype[ i ];
370 temp_utime = utime[ i ];
371 flag = 1;
372 } else {
373 if (temp_ctime_trgtype != ctime_trgtype[ i ]
374 || temp_utime != utime[ i ]) {
375 err_flag = 1;
376 }
377 }
378 }
379 }
380
381 if (err_flag != 0) {
382 for (int i = 0; i < 4; i++) {
383 printf("[DEBUG] FINESSE #=%d buffsize %d ctimeTRGtype 0x%.8x utime 0x%.8x\n",
384 i, GetFINESSENwords(n, i), ctime_trgtype[ i ], utime[ i ]);
385 }
386 char err_buf[500];
387 sprintf(err_buf, "CORRUPTED DATA: mismatch over FINESSEs. Exiting...\n %s %s %d\n",
388 __FILE__, __PRETTY_FUNCTION__, __LINE__);
389 printf("%s", err_buf); fflush(stdout);
390 B2FATAL(err_buf);
391 }
392 return;
393}
394
395
396unsigned int RawCOPPERFormat_v0::FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
397 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no)
398{
399
400 char err_buf[500];
401 sprintf(err_buf,
402 "This function for format ver.0 is not supported. (node %.8x preveve %u prevrun %u currun %u ) Exiting...\n %s %s %d\n",
403 m_node_id, prev_eve32, prev_exprunsubrun_no, *cur_exprunsubrun_no,
404 __FILE__, __PRETTY_FUNCTION__, __LINE__);
405 printf("%s", err_buf); fflush(stdout);
406 B2FATAL(err_buf);
407 return 0;
408
409// const int cpr_id = 0;
410// // m_temp_value = 12345678;
411// //
412// // This function only fills RawHeader contents for the first datablock.
413// // # of block should be 1
414// if (m_num_nodes * m_num_events != 1) {
415// char err_buf[500];
416// sprintf(err_buf,
417// "This function should be used for RawCOPPERFormat_v0 containing only one datablock, while. this object has num_nodes of %d and num_events of %d\n %s %s %d\n",
418// m_num_nodes, m_num_events, __FILE__, __PRETTY_FUNCTION__, __LINE__);
419// string err_str = err_buf; throw (err_str);
420// }
421
422// //////////////////////////////////////////////////
423// //
424// // Fill info in RawHeader
425// //
426// //////////////////////////////////////////////////
427
428// //
429// // Initialize a RawHeader part
430// //
431// memset(m_buffer, 0, sizeof(int) * tmp_header.RAWHEADER_NWORDS);
432// m_buffer[ tmp_header.POS_HDR_NWORDS ] = tmp_header.RAWHEADER_NWORDS;
433
434// //
435// // Check FINESSEs which containes data
436// //
437// int* copper_buf = &(m_buffer[ tmp_header.RAWHEADER_NWORDS ]);
438// if (copper_buf[ POS_CH_A_DATA_LENGTH ] == 0 &&
439// copper_buf[ POS_CH_B_DATA_LENGTH ] == 0 &&
440// copper_buf[ POS_CH_C_DATA_LENGTH ] == 0 &&
441// copper_buf[ POS_CH_D_DATA_LENGTH ] == 0) {
442// char err_buf[500];
443// sprintf(err_buf,
444// "No FINESSE data in a copper data block. Exiting...\n %s %s %d\n",
445// __FILE__, __PRETTY_FUNCTION__, __LINE__);
446// string err_str = err_buf; throw (err_str);
447// // sleep(12345678);
448// // exit(-1);
449// }
450
451// //
452// // Set total words info
453// //
454// int datablock_nwords =
455// tmp_header.RAWHEADER_NWORDS +
456// (copper_buf[ POS_DATA_LENGTH ]
457// + SIZE_COPPER_DRIVER_HEADER
458// + SIZE_COPPER_DRIVER_TRAILER)
459// + tmp_trailer.RAWTRAILER_NWORDS;
460// m_buffer[ tmp_header.POS_NWORDS ] = datablock_nwords;
461
462// //
463// // Check the consistency between data length and length in RawHeader
464// //
465// if (m_buffer[ tmp_header.POS_NWORDS ] != m_nwords) {
466// char err_buf[500];
467// sprintf(err_buf,
468// "CORRUPTED DATA: Data length is inconsistent m_nwords %d : nwords from COPPER data %d\n %s %s %d\n",
469// m_nwords, m_buffer[ tmp_header.POS_NWORDS ],
470// __FILE__, __PRETTY_FUNCTION__, __LINE__);
471// string err_str = err_buf; throw (err_str);
472// // sleep(12345678);
473// // exit(-1);
474// }
475
476// //
477// // Fill offset values
478// //
479// int offset_1st_finesse = tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
480// int offset_2nd_finesse = offset_1st_finesse + copper_buf[ POS_CH_A_DATA_LENGTH ];
481// int offset_3rd_finesse = offset_2nd_finesse + copper_buf[ POS_CH_B_DATA_LENGTH ];
482// int offset_4th_finesse = offset_3rd_finesse + copper_buf[ POS_CH_C_DATA_LENGTH ];
483// m_buffer[ tmp_header.POS_OFFSET_1ST_FINESSE ] = offset_1st_finesse;
484// m_buffer[ tmp_header.POS_OFFSET_2ND_FINESSE ] = offset_2nd_finesse;
485// m_buffer[ tmp_header.POS_OFFSET_3RD_FINESSE ] = offset_3rd_finesse;
486// m_buffer[ tmp_header.POS_OFFSET_4TH_FINESSE ] = offset_4th_finesse;
487
488// //
489// // Fill Exp/Run value
490// //
491// int* finesse_buf = &
492// (m_buffer[ offset_1st_finesse ]); // In any finesse implementations, the top finesse buffer should be at offset_1st_finesse;
493// m_buffer[ tmp_header.POS_EXP_RUN_NO ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_EXP_RUN ];
494
495
496// //
497// // Fill event #
498// //
499// unsigned int cur_ftsw_eve32 = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_TAG ];
500// m_buffer[ tmp_header.POS_EVE_NO ] = cur_ftsw_eve32;
501
502// //
503// // Copy FTSW words from B2LFEE header
504// //
505// m_buffer[ tmp_header.POS_TTCTIME_TRGTYPE ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_CTIME_TYPE ];
506// m_buffer[ tmp_header.POS_TTUTIME ] = finesse_buf[ SIZE_B2LHSLB_HEADER + POS_TT_UTIME ];
507
508// //
509// // Set node ID, trunc_mask, data_type
510// //
511// m_buffer[ tmp_header.POS_NODE_ID ] = m_node_id;
512// m_buffer[ tmp_header.POS_TRUNC_MASK_DATATYPE ] = ((m_trunc_mask << 31) & 0x80000000) | (m_data_type & 0x7FFFFFFF);
513
514// //
515// // Set RawHeader magic word
516// //
517// m_buffer[ tmp_header.POS_TERM_HEADER ] = tmp_header.MAGIC_WORD_TERM_HEADER;
518
519
520// //
521// // Add node-info
522// //
523// if (m_buffer[ tmp_header.POS_NUM_NODES ] < tmp_header.NUM_MAX_NODES) {
524// m_buffer[ tmp_header.POS_NODES_1 + m_buffer[ tmp_header.POS_NUM_NODES ] ] = m_node_id;
525// }
526// m_buffer[ tmp_header.POS_NUM_NODES ]++;
527
528
529
530// //////////////////////////////////////////////////
531// //
532// // Fill info in RawTrailer
533// //
534// //////////////////////////////////////////////////
535
536// //
537// // Calculate XOR checksum
538// //
539// unsigned int chksum_top = 0, chksum_body = 0, chksum_bottom = 0;
540
541// int top_end = tmp_header.RAWHEADER_NWORDS;
542// for (int i = 0; i < top_end; i++) {
543// chksum_top ^= m_buffer[ i ];
544// }
545// int body_end = datablock_nwords - SIZE_COPPER_DRIVER_TRAILER - tmp_trailer.RAWTRAILER_NWORDS;
546// for (int i = top_end; i < body_end; i++) {
547// chksum_body ^= m_buffer[ i ];
548// }
549
550// int bottom_end = datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS;
551// for (int i = body_end; i < bottom_end; i++) {
552// chksum_bottom ^= m_buffer[ i ];
553// }
554
555// //
556// // check COPPER driver checksum
557// //
558// if (chksum_body != (unsigned int)(m_buffer[ body_end ])) {
559// char err_buf[500];
560// sprintf(err_buf, "CORRUPTED DATA: COPPER driver checksum is not consistent.: calcd. %.8x data %.8x\n %s %s %d\n",
561// chksum_body, m_buffer[ body_end ],
562// __FILE__, __PRETTY_FUNCTION__, __LINE__);
563// string err_str = err_buf; throw (err_str);
564// // sleep(12345678);
565// // exit(-1);
566// }
567
568// //
569// // Fill trailer info (checksum, magic word)
570// //
571// unsigned int chksum = chksum_top ^ chksum_body ^ chksum_bottom;
572// int* trl = &(m_buffer[ datablock_nwords - tmp_trailer.RAWTRAILER_NWORDS ]);
573// trl[ tmp_trailer.POS_CHKSUM ] = chksum;
574// trl[ tmp_trailer.POS_TERM_WORD ] = tmp_trailer.MAGIC_WORD_TERM_TRAILER;
575
576
577// //////////////////////////////////////////////////
578// //
579// // Data check ( magic word, event incrementation )
580// //
581// //////////////////////////////////////////////////
582
583
584// //
585// // check magic words
586// //
587// int* fpga_trailer_magic = trl - 3;
588// int* driver_trailer_magic = trl - 1;
589// int err_flag = 0;
590// if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_1 ]) != COPPER_MAGIC_DRIVER_HEADER) {
591// err_flag = 1;
592// } else if ((unsigned int)(copper_buf[ POS_MAGIC_COPPER_2 ]) != COPPER_MAGIC_FPGA_HEADER) {
593// err_flag = 1;
594// } else if ((unsigned int)(*fpga_trailer_magic) != COPPER_MAGIC_FPGA_TRAILER) {
595// err_flag = 1;
596// } else if ((unsigned int)(*driver_trailer_magic) != COPPER_MAGIC_DRIVER_TRAILER) {
597// err_flag = 1;
598// }
599// if (err_flag == 1) {
600// char err_buf[500];
601// sprintf(err_buf, "CORRUPTED DATA: Invalid Magic word 0x7FFFF0008=%u 0xFFFFFAFA=%u 0xFFFFF5F5=%u 0x7FFF0009=%u\n %s %s %d\n",
602// GetMagicDriverHeader(cpr_id),
603// GetMagicFPGAHeader(cpr_id),
604// GetMagicFPGATrailer(cpr_id),
605// GetMagicDriverTrailer(cpr_id),
606// __FILE__, __PRETTY_FUNCTION__, __LINE__);
607// printf("[DEBUG] [ERROR] %s\n", err_buf);
608// #ifndef NO_DATA_CHECK
609// string err_str = err_buf; throw (err_str);
610
611// // sleep(12345678);
612// // exit(-1);
613// #endif
614// }
615
616// //
617// // check incrementation of event #
618// //
619// *cur_runsubrun_no = GetRunNoSubRunNo(cpr_id);
620// if (prev_runsubrun_no == *cur_runsubrun_no && prev_runsubrun_no >= 0) {
621// if (
622// #ifdef WO_FIRST_EVENUM_CHECK
623// (prev_eve32 + 1 != cur_ftsw_eve32) && (prev_eve32 != 0xFFFFFFFF && cur_ftsw_eve32 != 0)
624// #else
625// prev_eve32 + 1 != cur_ftsw_eve32
626// #endif
627// ) {
628
629// #ifndef NO_DATA_CHECK
630// char err_buf[500];
631// sprintf(err_buf, "CORRUPTED DATA: Invalid event_number. Exiting...: cur 32bit eve %u preveve %u prun %d crun %d\n %s %s %d\n",
632// cur_ftsw_eve32, prev_eve32,
633// prev_runsubrun_no, *cur_runsubrun_no,
634// __FILE__, __PRETTY_FUNCTION__, __LINE__);
635// printf("[DEBUG] [ERROR] %s\n", err_buf);
636
637// string err_str = err_buf;
638// printf("[DEBUG] i= %d : num entries %d : Tot words %d\n", 0 , GetNumEntries(), TotalBufNwords());
639// PrintData(GetBuffer(cpr_id), TotalBufNwords());
640// throw (err_str);
641// // exit(-1);
642// #endif
643
644// }
645// }
646
647// return cur_ftsw_eve32;
648
649}
650
651
652
653#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
654void RawCOPPERFormat_v0::CheckB2LFEEHeaderVersion(int n)
655{
656
657 int* temp_buf;
658
659 for (int i = 0; i < 4; i++) {
660 if (GetFINESSENwords(n, i) > 0) {
661 temp_buf = GetFINESSEBuffer(n, i);
662 if ((temp_buf[ 3 ] & 0x40000000) == 0) {
663#ifdef TEMP
664 // this word for exp/run
665 // old one (ver.1) used for SPring8 test in 2013
666 printf("[DEBUG] \033[31m");
667 printf("[DEBUG] ===Firmware ver. ERROR===\n ");
668 printf("[DEBUG] FTSW and b2tt firmwares was updated on Nov.22, 2013 and the header format attached by B2link was changed in the new firmwares.\n");
669 printf("[DEBUG] If you are going to take data now, Please update the firmware.\n");
670 printf("[DEBUG] For details, please see Nakao-san's e-mail [b2link_ml:0111] Re: [daq2ml:0159] beta version of trigger timing receiver firmware (b2tt) on bdaq SVN\n");
671 printf("[DEBUG] Or if you are going to read data taken before the update, please use basf2 software before rev. 7419\n");
672 printf("[DEBUG] About the format please see Nakao-san's B2GM slides(p. 13 and 15) http://kds.kek.jp/getFile.py/access?contribId=143&sessionId=38&resId=0&materialId=slides&confId=13911.\n");
673 printf("[DEBUG] Sorry for inconvenience.\n");
674 printf("[DEBUG] \033[0m");
675 fflush(stderr);
676 char err_buf[500];
677 sprintf(err_buf, "FTSW and b2tt firmwares are old. Exiting...\n %s %s %d\n",
678 __FILE__, __PRETTY_FUNCTION__, __LINE__);
679 printf("%s", err_buf); fflush(stdout);
680 B2FATAL(err_buf);
681#endif
682 } else {
683 // this word for 32bit unixtime
684 // new one (ver.2)
685 break;
686 }
687 }
688
689 if (i == 3) {
690#ifdef TEMP
691 char err_buf[500];
692 sprintf(err_buf, "RawCOPPERFormat_v0 contains no FINESSE data. Exiting...\n %s %s %d\n",
693 __FILE__, __PRETTY_FUNCTION__, __LINE__);
694 printf("%s", err_buf); fflush(stdout);
695 B2FATAL(err_buf);
696#endif
697 }
698 }
699 return;
700}
701#endif
702
703int* RawCOPPERFormat_v0::PackDetectorBuf(int* packed_buf_nwords,
704 int* detector_buf_1st, int nwords_1st,
705 int* detector_buf_2nd, int nwords_2nd,
706 int* detector_buf_3rd, int nwords_3rd,
707 int* detector_buf_4th, int nwords_4th,
708 RawCOPPERPackerInfo rawcprpacker_info)
709{
710 char err_buf[500];
711 sprintf(err_buf, "This function is not supported (%p %p %d %p %d %p %d %p %d %p ) Exiting...\n%s %s %d\n"
712 , packed_buf_nwords, detector_buf_1st, nwords_1st, detector_buf_2nd, nwords_2nd, detector_buf_3rd,
713 nwords_3rd, detector_buf_4th, nwords_4th, &rawcprpacker_info, __FILE__, __PRETTY_FUNCTION__, __LINE__);
714 printf("%s", err_buf); fflush(stdout);
715 B2FATAL(err_buf);
716}
int * PackDetectorBuf(int *packed_buf_nwords, int *detector_buf_1st, int nwords_1st, int *detector_buf_2nd, int nwords_2nd, int *detector_buf_3rd, int nwords_3rd, int *detector_buf_4th, int nwords_4th, RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17
Pack data (format ver. = -1 -> Select the latest format version)
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
RawTrailer_v0 tmp_trailer
trailer ( not recorded )
virtual ~RawCOPPERFormat_v0()
Constructor using existing pointer to raw data buffer.
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
RawHeader_v0 tmp_header
header ( not recorded )
virtual int GetNumFINESSEBlock(int n) OVERRIDE_CPP17
get # of FINNESEs which contains data
RawCOPPERFormat_v0()
Default constructor.
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
void CheckData(int n, unsigned int prev_evenum, unsigned int *cur_evenum, unsigned int prev_copper_ctr, unsigned int *cur_copper_ctr, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no) OVERRIDE_CPP17
check data contents
virtual int GetOffsetFINESSE(int n, int finesse)
get # of offset words
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
struct to contain header information used by RawCOPPERFormat::Packer()
virtual int GetBlockNwords(int n)
get size of a data block
virtual int GetBufferPos(int n)
get position of data block in word
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot C buffer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
int Get1stFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot A buffer
int Get3rdDetectorNwords(int n) OVERRIDE_CPP17
get Detector buffer length of slot C
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
int Get4thDetectorNwords(int n) OVERRIDE_CPP17
get Detector buffer length of slot D
int Get2ndDetectorNwords(int n) OVERRIDE_CPP17
get Detector buffer length of slot B
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
int Get1stDetectorNwords(int n) OVERRIDE_CPP17
get Detector buffer length of slot A
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot B buffer
Abstract base class for different kinds of events.
STL namespace.