Belle II Software development
RawCOPPERFormat.h
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#ifndef RAWCOPPERFORMAT_H
10#define RAWCOPPERFORMAT_H
11
12// Includes
13#include <stdio.h>
14#include <string>
15#include <vector>
16#include <rawdata/RawCOPPERPackerInfo.h>
17#include <rawdata/dataobjects/RawDataBlockFormat.h>
18
19/* #include <framework/datastore/DataStore.h> */
20/* #include <TObject.h> */
21
22//#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
23
24#define DETECTOR_MASK 0xFF000000 // tentative
25#define COPPERID_MASK 0x00FFFFFF // tentative
26#define SVD_ID 0x01000000 // tentative
27#define CDC_ID 0x02000000 // tentative
28#define TOP_ID 0x03000000 // tentative
29#define ARICH_ID 0x04000000 // tentative
30#define BECL_ID 0x05000000 // tentative
31#define EECL_ID 0x06000000 // tentative
32#define BKLM_ID 0x07000000 // tentative
33#define EKLM_ID 0x08000000 // tentative
34#define TRGDATA_ID 0x10000000 // tentative
35#define CDCTRGDATA_ID 0x11000000 // tentative
36#define TOPTRGDATA_ID 0x12000000 // tentative
37#define ECLTRGDATA_ID 0x13000000 // tentative
38#define KLMTRGDATA_ID 0x14000000 // tentative
39#define GDLTRGDATA_ID 0x15000000 // tentative
40
41
42namespace Belle2 {
53 // class RawCOPPERFormat : public TObject {
55 public:
56 /* //! Default constructor */
58
60 //RawCOPPERFormat(int* bufin, int nwords);
62 virtual ~RawCOPPERFormat() {}
63
64 //
65 // Functions for RawDataBlock
66 //
68 /* void SetBuffer(int* bufin, int nwords, int delete_flag, int num_events, int num_nodes); */
69
70 /* //! Get total length of m_buffer */
71 /* virtual int TotalBufNwords(); */
72
73 /* //! get nth buffer pointer */
74 /* virtual int* GetBuffer(int n); */
75
76 /* //! get pointer to buffer(m_buffer) */
77 /* virtual int* GetWholeBuffer(); */
78
79 /* //! get # of data blocks = (# of nodes)*(# of events) */
80 /* virtual int GetNumEntries() { return m_num_events * m_num_nodes; } */
81
82 /* //! get # of data sources(e.g. # of COPPER boards) in m_buffer */
83 /* virtual int GetNumNodes() { return m_num_nodes; } */
84
85 /* //! get # of events in m_buffer */
86 /* virtual int GetNumEvents() { return m_num_events; } */
87
88 /* //! get size of a data block */
89 /* virtual int GetBlockNwords(int n); */
90
91 /* //! print out data */
92 /* virtual void PrintData(int* buf, int nwords); */
93
94 /* enum { */
95 /* POS_NWORDS = 0, */
96 /* POS_NODE_ID = 6 */
97 /* }; */
98
99 /* enum { */
100 /* // Tentatively needed to distinguish new and old FTSW format, which will be changed in Nov. 2013 */
101 /* POS_FTSW_ID_OLD = 5, */
102 /* TEMP_POS_NWORDS_HEADER = 1, */
103 /* OLD_FTSW_NWORDS_HEADER = 6 */
104 /* }; */
105
106 //
107 // Functions for RawCOPPER
108 //
109
110 // POINTER TO "DETECTOR BUFFER"
111 //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
112
114 virtual int GetDetectorNwords(int n, int finesse_num) = 0;
115
117 virtual int Get1stDetectorNwords(int n) = 0;
118
120 virtual int Get2ndDetectorNwords(int n) = 0;
121
123 virtual int Get3rdDetectorNwords(int n) = 0;
124
126 virtual int Get4thDetectorNwords(int n) = 0;
127
129 virtual int* GetDetectorBuffer(int n, int finesse_num);
130
132 virtual int* Get1stDetectorBuffer(int n) = 0;
133
135 virtual int* Get2ndDetectorBuffer(int n) = 0;
136
138 virtual int* Get3rdDetectorBuffer(int n) = 0;
139
141 virtual int* Get4thDetectorBuffer(int n) = 0;
143
144 /* //! get posistion of COPPER block in unit of word */
145 /* virtual int GetBufferPos(int n) = 0; */
146
148 virtual int* GetRawHdrBufPtr(int n);
149
151 virtual int* GetRawTrlBufPtr(int n) = 0;
152
154 virtual int* GetFINESSEBuffer(int n, int finesse_num);
155
157 virtual int* Get1stFINESSEBuffer(int n);
158
160 virtual int* Get2ndFINESSEBuffer(int n);
161
163 virtual int* Get3rdFINESSEBuffer(int n);
164
166 virtual int* Get4thFINESSEBuffer(int n);
167
168
169
170 //
171 // Get information from "RawCOPPERFormat header" attached by DAQ software
172 //
173
175 virtual int GetExpNo(int n) = 0;
176
177 virtual unsigned int GetExpRunSubrun(int n) = 0;
178
179 virtual int GetRunNo(int n) = 0;
180
181 virtual int GetSubRunNo(int n) = 0;
182
183 virtual unsigned int GetEveNo(int n) = 0;
184
185 virtual int GetDataType(int n) = 0;
186
187 virtual int GetTruncMask(int n) = 0;
188
190 virtual unsigned int GetErrorBitFlag(int n) = 0;
191
193 virtual void AddErrorBitFlag(int n, unsigned int error_bit_flag) = 0;
194
196 virtual int GetPacketCRCError(int n);
197
199 virtual int GetEventCRCError(int n);
200
202 virtual int GetEventCRC16Value(int n, int finesse_num);
203
205 virtual unsigned int GetNodeID(int n) = 0;
206
207 //
208 // Get information from 13words "COPPER header" attached by COPPER board
209 //
211 virtual unsigned int GetCOPPERCounter(int n) = 0;
212
214 virtual int GetNumFINESSEBlock(int n) = 0;
215
217 virtual int GetOffsetFINESSE(int n, int finesse);
218
220 virtual int GetOffset1stFINESSE(int n) = 0;
221
223 virtual int GetOffset2ndFINESSE(int n);
224
226 virtual int GetOffset3rdFINESSE(int n);
227
229 virtual int GetOffset4thFINESSE(int n);
230
232 virtual int GetFINESSENwords(int n, int finesse) = 0;
233
235 virtual int Get1stFINESSENwords(int n) = 0;
236
238 virtual int Get2ndFINESSENwords(int n) = 0;
239
241 virtual int Get3rdFINESSENwords(int n) = 0;
242
244 virtual int Get4thFINESSENwords(int n) = 0;
245
246 //
247 // Get information from "B2link(attached by FEE and HLSB) header"
248 //
250 // virtual int* GetFTSW2Words(int n) = 0;
251
253 virtual int* GetExpRunSubrunBuf(int n) = 0;
254
256 virtual unsigned int GetB2LFEE32bitEventNumber(int n) = 0;
257
258 //
259 // read magic word to check data
260 //
262 virtual unsigned int GetMagicDriverHeader(int n) = 0;
263
265 virtual unsigned int GetMagicFPGAHeader(int n) = 0;
266
268 virtual unsigned int GetMagicFPGATrailer(int n) = 0;
269
271 virtual unsigned int GetMagicDriverTrailer(int n) = 0;
272
274 virtual unsigned int GetTrailerChksum(int n) = 0 ;
275
277 virtual bool CheckCOPPERMagic(int n) = 0;
278
279#ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
281 virtual void CheckB2LFEEHeaderVersion(int n) = 0;
282#endif
283
285 virtual unsigned int GetTTCtimeTRGType(int n) = 0;
286
288 virtual unsigned int GetTTUtime(int n) = 0;
289
291 virtual unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
292 unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) = 0;
293
295 virtual unsigned int GetDriverChkSum(int n) = 0;
296
298 virtual unsigned int CalcDriverChkSum(int n) = 0;
299
300
302 virtual void CheckData(int n,
303 unsigned int prev_evenum, unsigned int* cur_evenum,
304 unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
305 unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) = 0;
306
308 virtual void CheckUtimeCtimeTRGType(int n) = 0;
309
311 virtual int GetTTCtime(int n) = 0;
312
314 virtual int GetTRGType(int n) = 0;
315
317 virtual void GetTTTimeVal(int n, struct timeval* tv) = 0;
318
320 virtual unsigned int CalcXORChecksum(int* buf, int nwords);
321
323 virtual int* PackDetectorBuf(int* packed_buf_nwords,
324 int* detector_buf_1st, int nwords_1st,
325 int* detector_buf_2nd, int nwords_2nd,
326 int* detector_buf_3rd, int nwords_3rd,
327 int* detector_buf_4th, int nwords_4th,
328 RawCOPPERPackerInfo rawcprpacker_info) = 0;
329
331 virtual int* PackDetectorBuf(int* packed_buf_nwords,
332 int* const(&detector_buf_ch)[MAX_PCIE40_CH],
333 int const(&nwords_ch)[MAX_PCIE40_CH],
334 RawCOPPERPackerInfo rawcpr_info);
335
337 virtual int GetMaxNumOfCh(int n) = 0;
338
340 virtual void CompareHeaderValue(int n, const unsigned int (&input_val)[MAX_PCIE40_CH],
341 std::vector<std::vector< unsigned int> >& result);
342
344 virtual void GetNodeName(int n, char* node_name, int bufsize);
345
347 virtual void GetNodeName(char* node_name, unsigned int node_id, int bufsize);
348
350 virtual bool CheckOnlineRemovedDataBit(int n, int finesse_num);
351
352 protected :
353
354 /* /// number of words of buffer */
355 /* int m_nwords; */
356
357 /* /// number of nodes in this object */
358 /* int m_num_nodes; */
359
360 /* /// number of events in this object */
361 /* int m_num_events; */
362
363 /* /// Buffer to access data */
364 /* int* m_buffer; //! not recorded */
365
367 // ClassDef(RawCOPPERFormat, 3);
368
369 };
370
371
372
374 {
375 int pos_nwords = GetBufferPos(n);
376 return &(m_buffer[ pos_nwords ]);
377 }
378
379
381 {
383 }
384
386 {
388 }
389
391 {
393 }
394
395
396
398 {
399 int pos_nwords = GetOffset1stFINESSE(n);
400 if (pos_nwords >= m_nwords) {
401 printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n", m_nwords, pos_nwords);
402 for (int i = 0; i < m_nwords; i++) {
403 printf("%.8x ", m_buffer[ i ]);
404 if ((i % 10) == 9) printf("\n");
405 }
406 B2FATAL("Data size is smaller than data position info. Exiting...");
407 }
408 return &(m_buffer[ pos_nwords]);
409 }
410
412 {
413 int pos_nwords = GetOffset2ndFINESSE(n);
414 if (pos_nwords >= m_nwords) {
415 printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n", m_nwords, pos_nwords);
416 for (int i = 0; i < m_nwords; i++) {
417 printf("%.8x ", m_buffer[ i ]);
418 if ((i % 10) == 9) printf("\n");
419 }
420 B2FATAL("Data size is smaller than data position info. Exiting...");
421 }
422 return &(m_buffer[ pos_nwords]);
423 }
424
426 {
427 int pos_nwords = GetOffset3rdFINESSE(n);
428 if (pos_nwords >= m_nwords) {
429 printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n", m_nwords, pos_nwords);
430 for (int i = 0; i < m_nwords; i++) {
431 printf("%.8x ", m_buffer[ i ]);
432 if ((i % 10) == 9) printf("\n");
433 }
434 B2FATAL("Data size is smaller than data position info. Exiting...");
435 }
436 return &(m_buffer[ pos_nwords]);
437 }
438
440 {
441 int pos_nwords = GetOffset4thFINESSE(n);
442 if (pos_nwords >= m_nwords) {
443 printf("[DEBUG] Data size(0x%.8x) is smaller than data position info(0x%.8x). Exiting...\n", m_nwords, pos_nwords);
444 for (int i = 0; i < m_nwords; i++) {
445 printf("%.8x ", m_buffer[ i ]);
446 if ((i % 10) == 9) printf("\n");
447 }
448 B2FATAL("Data size is smaller than data position info. Exiting...");
449 }
450 return &(m_buffer[ pos_nwords]);
451 }
452
453
455}
456
457#endif
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
virtual int Get4thFINESSENwords(int n)=0
get data size of FINESSE slot D buffer
virtual int GetDataType(int n)=0
get contents of header
virtual unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int *cur_exprunsubrun_no)=0
should be called by DeSerializerCOPPER.cc and fill contents in RawHeader
virtual unsigned int GetEveNo(int n)=0
get subrun #(8bit)
virtual void AddErrorBitFlag(int n, unsigned int error_bit_flag)=0
Add Detected Error bitflag.
virtual int GetMaxNumOfCh(int n)=0
Get the max number of channels in a readout board.
virtual int * Get4thDetectorBuffer(int n)=0
get Detector Buffer of slot D
virtual void CompareHeaderValue(int n, const unsigned int(&input_val)[MAX_PCIE40_CH], std::vector< std::vector< unsigned int > > &result)
Compare value from different channels and make a statistics table.
virtual int Get2ndFINESSENwords(int n)=0
get data size of FINESSE slot B buffer
virtual int Get3rdFINESSENwords(int n)=0
get data size of FINESSE slot C buffer
virtual int GetTRGType(int n)=0
Get trgtype.
virtual int GetExpNo(int n)=0
get Experimental # from header
virtual unsigned int GetNodeID(int n)=0
get node-ID from data
virtual int GetTruncMask(int n)=0
get contents of header
virtual unsigned int GetTrailerChksum(int n)=0
Get checksum in RawTrailer.
virtual int GetFINESSENwords(int n, int finesse)=0
get data size of FINESSE buffer
virtual int Get1stDetectorNwords(int n)=0
get Detector buffer length of slot A
virtual unsigned int GetMagicDriverTrailer(int n)=0
get magic word of COPPER driver trailer
virtual int Get2ndDetectorNwords(int n)=0
get Detector buffer length of slot B
virtual int GetOffsetFINESSE(int n, int finesse)
get # of offset words
virtual 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)=0
Pack data (format ver. = -1 -> Select the latest format version)
virtual unsigned int CalcXORChecksum(int *buf, int nwords)
calc XOR checksum
virtual int * Get2ndDetectorBuffer(int n)=0
get Detector Buffer of slot B
virtual int Get4thDetectorNwords(int n)=0
get Detector buffer length of slot D
virtual bool CheckOnlineRemovedDataBit(int n, int finesse_num)
Check if COPPER Magic words are correct.
virtual int * GetRawTrlBufPtr(int n)=0
get buffer pointer of rawcopper trailer
virtual bool CheckCOPPERMagic(int n)=0
Check if COPPER Magic words are correct.
virtual unsigned int GetB2LFEE32bitEventNumber(int n)=0
get b2l block from "FEE b2link header"
virtual int GetOffset1stFINESSE(int n)=0
get # of offset words for FINESSE slot A buffer position
virtual unsigned int GetExpRunSubrun(int n)=0
get Experimental # from header
virtual int * GetDetectorBuffer(int n, int finesse_num)
get Detector buffer
virtual unsigned int CalcDriverChkSum(int n)=0
calc COPPER driver's checksum value
virtual unsigned int GetMagicFPGAHeader(int n)=0
get magic word of COPPER FPGA header
virtual int GetTTCtime(int n)=0
Get ctime.
virtual unsigned int GetMagicDriverHeader(int n)=0
get magic word of COPPER driver header
virtual int GetNumFINESSEBlock(int n)=0
get # of FINNESEs which contains data
virtual 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)=0
check data contents
virtual unsigned int GetTTUtime(int n)=0
Check if COPPER Magic words are correct.
virtual unsigned int GetMagicFPGATrailer(int n)=0
get magic word of COPPER FPGA trailer
virtual int GetEventCRC16Value(int n, int finesse_num)
Get Event CRC16 value.
virtual void GetNodeName(int n, char *node_name, int bufsize)
Get hostname of a node from the RawCOPPER header.
virtual unsigned int GetDriverChkSum(int n)=0
read COPPER driver's checksum value
virtual void GetTTTimeVal(int n, struct timeval *tv)=0
Get timeval.
virtual unsigned int GetErrorBitFlag(int n)=0
get contents of header
virtual unsigned int GetCOPPERCounter(int n)=0
get COPPER counter(not event number)
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
virtual int * Get3rdDetectorBuffer(int n)=0
get Detector Buffer of slot C
virtual unsigned int GetTTCtimeTRGType(int n)=0
Check if COPPER Magic words are correct.
virtual ~RawCOPPERFormat()
Constructor using existing pointer to raw data buffer.
virtual int GetSubRunNo(int n)=0
get run # (14bit)
virtual int * Get1stDetectorBuffer(int n)=0
get Detector buffer of slot A
virtual void CheckUtimeCtimeTRGType(int n)=0
check data contents
virtual int GetEventCRCError(int n)
check CRC event Error
virtual int Get3rdDetectorNwords(int n)=0
get Detector buffer length of slot C
virtual int GetPacketCRCError(int n)
check CRC packet Error
virtual int * GetExpRunSubrunBuf(int n)=0
get b2l block from "FEE b2link header"
virtual int GetDetectorNwords(int n, int finesse_num)=0
set buffer ( delete_flag : m_buffer is freeed( = 0 )/ not freeed( = 1 ) in Destructer )
virtual int GetRunNo(int n)=0
Exp# (10bit) run# (14bit) restart # (8bit)
virtual int Get1stFINESSENwords(int n)=0
get data size of FINESSE slot A buffer
struct to contain header information used by RawCOPPERFormat::Packer()
The RawDataBlockFormat class Format information for rawdata handling.
virtual int GetBufferPos(int n)
get position of data block in word
int m_nwords
number of words of buffer
virtual int * GetRawHdrBufPtr(int n)
get buffer pointer of rawcopper header(Currently same as GetBufferPos)
virtual int * Get3rdFINESSEBuffer(int n)
get FINESSE buffer pointer for slot C
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
virtual int * Get2ndFINESSEBuffer(int n)
get FINESSE buffer pointer for slot B
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
virtual int GetOffset3rdFINESSE(int n)
get # of offset words for FINESSE slot C buffer position
virtual int * Get4thFINESSEBuffer(int n)
get FINESSE buffer pointer for slot D
virtual int * Get1stFINESSEBuffer(int n)
get FINESSE buffer pointer for slot A
Abstract base class for different kinds of events.