Belle II Software  release-08-01-10
PreRawCOPPERFormat_v2.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 PRERAWCOPPERFORMAT_V2_H
10 #define PRERAWCOPPERFORMAT_V2_H
11 
12 // Includes
13 #include <rawdata/dataobjects/PostRawCOPPERFormat_v2.h>
14 #include <rawdata/CRCCalculator.h>
15 
16 //#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
17 
18 
19 namespace Belle2 {
31  public:
34 
36  //PreRawCOPPERFormat_v2(int* bufin, int nwords);
38  virtual ~PreRawCOPPERFormat_v2();
39 
40  //
41  // Get position of or pointer to data
42  //
44  // POINTER TO "DETECTOR BUFFER"
45  //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
47 
48 
50  /* cppcheck-suppress missingOverride */
51  int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
52 
54  /* cppcheck-suppress missingOverride */
55  int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
56 
58  /* cppcheck-suppress missingOverride */
59  int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
60 
62  /* cppcheck-suppress missingOverride */
63  int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
64 
66  /* cppcheck-suppress missingOverride */
67  int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
69 
71  // virtual int GetBufferPos(int n);
72 
73  //
74  // Get information from 13words "COPPER header" attached by COPPER board
75  //
77  /* cppcheck-suppress missingOverride */
78  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
79 
81  /* cppcheck-suppress missingOverride */
82  int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
83 
85  /* cppcheck-suppress missingOverride */
86  int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
87 
88  //
89  // Get information from "B2link(attached by FEE and HLSB) header"
90  //
92  // virtual int* GetFTSW2Words(int n);
93 
95  /* cppcheck-suppress missingOverride */
96  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
97 
99  /* cppcheck-suppress missingOverride */
100  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
101 
102  //
103  // read magic word to check data
104  //
106  /* cppcheck-suppress missingOverride */
107  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
108 
110  /* cppcheck-suppress missingOverride */
111  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
112 
114  /* cppcheck-suppress missingOverride */
115  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
116 
118  /* cppcheck-suppress missingOverride */
119  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
120 
122  /* cppcheck-suppress missingOverride */
123  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
124 
126  /* cppcheck-suppress missingOverride */
127  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
128 
130  /* cppcheck-suppress missingOverride */
131  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
132  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
133 
135  /* cppcheck-suppress missingOverride */
136  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
137 
139  /* cppcheck-suppress missingOverride */
140  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
141 
143  /* cppcheck-suppress missingOverride */
144  void CheckData(int n,
145  unsigned int prev_evenum, unsigned int* cur_evenum,
146  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
147  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
148 
150  /* cppcheck-suppress missingOverride */
151  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
152 
154  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
155 
157  int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
158  // int CalcReducedDataSize(RawDataBlock* raw_datablk);
159 
161  void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
162  // void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
163 
165  int CalcReducedNwords(int n);
166 
168  int CopyReducedBuffer(int n, int* buf_to);
169 
171  int CheckCRC16(int n, int finesse_num);
172 
174  /* cppcheck-suppress missingOverride */
175  int* PackDetectorBuf(int* packed_buf_nwords,
176  int* detector_buf_1st, int nwords_1st,
177  int* detector_buf_2nd, int nwords_2nd,
178  int* detector_buf_3rd, int nwords_3rd,
179  int* detector_buf_4th, int nwords_4th,
180  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
181 
183 
184 
185  //
186  // size of "COPPER front header" and "COPPER trailer"
187  //
189  enum {
190  SIZE_COPPER_DRIVER_HEADER = 7,
191  SIZE_COPPER_DRIVER_TRAILER = 2
192  };
193 
194  //
195  // Data Format : "COPPER header"
196  //
197  enum {
198  POS_MAGIC_COPPER_1 = 0,
199  POS_EVE_NUM_COPPER = 1,
200  POS_SUBSYSTEM_ID = 2,
201  POS_CRATE_ID = 3,
202  POS_SLOT_ID = 4,
203  POS_MAGIC_COPPER_2 = 7,
204  POS_DATA_LENGTH = 8,
205  POS_CH_A_DATA_LENGTH = 9,
206  POS_CH_B_DATA_LENGTH = 10,
207  POS_CH_C_DATA_LENGTH = 11,
208  POS_CH_D_DATA_LENGTH = 12,
209 
210  SIZE_COPPER_HEADER = 13
211  };
212 
213 
214 
215  //
216  // Data Format : "COPPER Trailer"
217  //
218  enum {
219  POS_MAGIC_COPPER_3 = 0,
220  POS_CHKSUM_COPPER = 1,
221  POS_MAGIC_COPPER_4 = 2,
222 
223  SIZE_COPPER_TRAILER = 3
224  };
225 
226  //
227  // Data Format : "B2Link HSLB Header"
228  //
229  enum {
230  POS_MAGIC_B2LHSLB = 0,
231  // POS_EVE_CNT_B2LHSLB = 1,
232  SIZE_B2LHSLB_HEADER = 1
233  };
234 
235  // Data Format : "B2Link FEE Header"
236  // modified by Nov. 21, 2013, Nakao-san's New firmware?
237  enum {
238  POS_TT_CTIME_TYPE = 0,
239  POS_TT_TAG = 1,
240  POS_TT_UTIME = 2,
241  POS_EXP_RUN = 3,
242  POS_B2L_CTIME = 4,
243  SIZE_B2LFEE_HEADER = 5
244  };
245 
246 
247  //
248  // Data Format : B2Link FEE Trailer
249  //
250  enum {
251  POS_TT_CTIME_B2LFEE = 0,
252  POS_CHKSUM_B2LFEE = 1,
253  SIZE_B2LFEE_TRAILER = 2
254  };
255 
256 
257  //
258  // Data Format : "B2Link HSLB Trailer"
259  //
260  enum {
261  POS_CHKSUM_B2LHSLB = 0,
262  SIZE_B2LHSLB_TRAILER = 1
263  };
264 
265 
266 
267  //
268  // COPPER magic words
269  //
270  enum {
271  COPPER_MAGIC_DRIVER_HEADER = 0x7FFF0008,
272  COPPER_MAGIC_FPGA_HEADER = 0xFFFFFAFA,
273  COPPER_MAGIC_FPGA_TRAILER = 0xFFFFF5F5,
274  COPPER_MAGIC_DRIVER_TRAILER = 0x7FFF0009
275  };
276 
277 
278  //
279  // magic words attached by HSLB
280  //
281  enum {
282  B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
283  B2LHSLB_TRAILER_MAGIC = 0xFF550000
284  };
285 
288 
289  protected :
291  // ClassDefOverride(PreRawCOPPERFormat_v2, 2);
292 
293  };
294 
295 
297  {
298  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
299  return pos_nwords;
300  }
301 
302 
303 
305  {
306 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
307  CheckB2LFEEHeaderVersion(n);
308 #endif
309  if (Get1stFINESSENwords(n) > 0) {
310  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
311  return &(m_buffer[ pos_nwords ]);
312  }
313  return NULL;
314  }
315 
317  {
318 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
319  CheckB2LFEEHeaderVersion(n);
320 #endif
321  if (Get2ndFINESSENwords(n) > 0) {
322  int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
323  return &(m_buffer[ pos_nwords ]);
324  }
325  return NULL;
326  }
327 
329  {
330 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
331  CheckB2LFEEHeaderVersion(n);
332 #endif
333  if (Get3rdFINESSENwords(n) > 0) {
334  int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
335  return &(m_buffer[ pos_nwords ]);
336  }
337  return NULL;
338  }
339 
341  {
342 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
343  CheckB2LFEEHeaderVersion(n);
344 #endif
345  if (Get4thFINESSENwords(n) > 0) {
346  int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
347  return &(m_buffer[ pos_nwords ]);
348  }
349  return NULL;
350  }
351 
353  {
354 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
355  CheckB2LFEEHeaderVersion(n);
356 #endif
357  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
358  return &(m_buffer[ pos_nwords ]);
359  }
360 
361 
362 
364  {
365  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_1;
366  return (unsigned int)(m_buffer[ pos_nwords ]);
367  }
368 
369  inline unsigned int PreRawCOPPERFormat_v2::GetMagicFPGAHeader(int n)
370  {
371  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_2;
372  return (unsigned int)(m_buffer[ pos_nwords ]);
373  }
374 
376  {
377  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
378 
379  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
380 
381  return (unsigned int)(m_buffer[ pos_nwords ]);
382  }
383 
385  {
386  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
387  return (unsigned int)(m_buffer[ pos_nwords ]);
388  }
389 
390 
391  inline unsigned int PreRawCOPPERFormat_v2::GetDriverChkSum(int n)
392  {
393  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
394  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
395  return m_buffer[ pos_nwords ];
396  }
397 
398 
399  inline unsigned int PreRawCOPPERFormat_v2::GetCOPPERCounter(int n)
400  {
401  int pos_nwords = GetBufferPos(n) + POS_EVE_NUM_COPPER + tmp_header.RAWHEADER_NWORDS;
402  return (unsigned int)(m_buffer[ pos_nwords ]);
403  }
404 
405 
406 
407 
408  inline unsigned int PreRawCOPPERFormat_v2::GetTrailerChksum(int n)
409  {
410  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
411  return (unsigned int)(m_buffer[ pos_nwords ]);
412  }
414 }
415 #endif
The Raw COPPER class ver.2 This class stores data received by COPPER via belle2link Data from all det...
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words of B2link HSLB header/trailer
int CopyReducedBuffer(int n, int *buf_to)
copy data to reduced buffer
int CheckCRC16(int n, int finesse_num)
check CRC16 in B2LFEE trailer
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)
int CalcReducedNwords(int n)
calculate reduced data size
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
void CopyReducedData(int *bufin, int nwords, int num_events, int num_nodes, int *buf_to, int *nwords_to)
reduce and merge header/trailer
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
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
int CalcReducedDataSize(int *bufin, int nwords, int num_events, int num_nodes)
reduce and merge header/trailer
PostRawCOPPERFormat_v2 m_reduced_rawcpr
data fromat after size reduction
virtual ~PreRawCOPPERFormat_v2()
Constructor using existing pointer to raw data buffer.
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.
PreRawCOPPERFormat_v2()
Default constructor.
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
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
RawTrailer_v2 tmp_trailer
trailer ( not recorded )
RawHeader_v2 tmp_header
header ( not recorded )
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 GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17
get # of offset words for FINESSE slot A buffer position
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
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
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot B
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
int GetTrlNwords()
Set magic word.
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
get a checksum on trailer
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot D
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
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 * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot C
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17
get Detector buffer 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.