Belle II Software  release-05-02-19
PostRawCOPPERFormat_v2.h
1 //+
2 // File : PostRawCOPPERFormat_v2.h
3 // Description : Module to handle raw data from COPPER
4 //
5 // Author : Satoru Yamada, IPNS, KEK
6 // Date : 2 - Aug - 2013
7 //-
8 
9 #ifndef POSTRAWCOPPERFORMAT_V2_H
10 #define POSTRAWCOPPERFORMAT_V2_H
11 
12 // Includes
13 /* #include <stdio.h> */
14 /* #include <stdlib.h> */
15 /* #include <string> */
16 /* #include <sys/time.h> */
17 
18 #include <rawdata/dataobjects/RawCOPPERFormat_v2.h>
19 #include <rawdata/CRCCalculator.h>
20 
21 //#include <framework/datastore/DataStore.h>
22 //#include <TObject.h>
23 
24 //#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
25 
26 namespace Belle2 {
38  public:
41 
43  //PostRawCOPPERFormat_v2(int* bufin, int nwords);
45  virtual ~PostRawCOPPERFormat_v2();
46 
47  //
48  // Get position of or pointer to data
49  //
51  // POINTER TO "DETECTOR BUFFER"
52  //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
54 
56  /* cppcheck-suppress missingOverride */
57  int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
58 
60  /* cppcheck-suppress missingOverride */
61  int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
62 
64  /* cppcheck-suppress missingOverride */
65  int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
66 
68  /* cppcheck-suppress missingOverride */
69  int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
70 
72  /* cppcheck-suppress missingOverride */
73  int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
75 
77  // virtual int GetBufferPos(int n);
78 
79  //
80  // Get information from 13words "COPPER header" attached by COPPER board
81  //
83  /* cppcheck-suppress missingOverride */
84  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
85 
87  /* cppcheck-suppress missingOverride */
88  int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
89 
91  /* cppcheck-suppress missingOverride */
92  int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
93 
94  //
95  // Get information from "B2link(attached by FEE and HLSB) header"
96  //
98  // virtual int* GetFTSW2Words(int n);
99 
101  /* cppcheck-suppress missingOverride */
102  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
103 
105  /* cppcheck-suppress missingOverride */
106  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
107 
108  //
109  // read magic word to check data
110  //
112  /* cppcheck-suppress missingOverride */
113  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
114 
116  /* cppcheck-suppress missingOverride */
117  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
118 
120  /* cppcheck-suppress missingOverride */
121  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
122 
124  /* cppcheck-suppress missingOverride */
125  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
126 
128  /* cppcheck-suppress missingOverride */
129  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
130 
132  /* cppcheck-suppress missingOverride */
133  int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17;
134 
136  /* cppcheck-suppress missingOverride */
137  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
138 
140  /* cppcheck-suppress missingOverride */
141  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
142  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
143 
145  /* cppcheck-suppress missingOverride */
146  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
147 
149  /* cppcheck-suppress missingOverride */
150  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
151 
153  /* cppcheck-suppress missingOverride */
154  void CheckData(int n,
155  unsigned int prev_evenum, unsigned int* cur_evenum,
156  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
157  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
158 
160  /* cppcheck-suppress missingOverride */
161  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
162 
164  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
165 
167  int CheckCRC16(int n, int finesse_num);
168 
170  /* cppcheck-suppress missingOverride */
171  int* PackDetectorBuf(int* packed_buf_nwords,
172  int* detector_buf_1st, int nwords_1st,
173  int* detector_buf_2nd, int nwords_2nd,
174  int* detector_buf_3rd, int nwords_3rd,
175  int* detector_buf_4th, int nwords_4th,
176  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
177 
178  //
179  // size of "COPPER front header" and "COPPER trailer"
180  //
182 
183  enum {
184  SIZE_COPPER_DRIVER_HEADER = 0,
185  SIZE_COPPER_DRIVER_TRAILER = 0
186  };
187 
188  // Data Format : "COPPER header"
189  enum {
190  SIZE_COPPER_HEADER = 0
191  };
192 
193  // Data Format : "COPPER Trailer"
194  enum {
195  SIZE_COPPER_TRAILER = 0
196  };
197 
198  // Data Format : "B2Link HSLB Header"
199  enum {
200  POS_B2LHSLB_MAGIC = 0,
201  SIZE_B2LHSLB_HEADER = 1
202  };
203 
204 
205  // Data Format : "B2Link FEE Header"
206  enum {
207  POS_B2L_CTIME = 0,
208  SIZE_B2LFEE_HEADER = 1
209  };
210 
211  // Data Format : B2Link FEE Trailer
212  enum {
213  POS_B2LFEE_ERRCNT_CRC16 = 0,
214  SIZE_B2LFEE_TRAILER = 1
215  };
216 
217  //
218  // Data Format : "B2Link HSLB Trailer"
219  //
220  enum {
221  SIZE_B2LHSLB_TRAILER = 0
222  };
223 
224 
225 
226  protected :
228  // ClassDefOverride(PostRawCOPPERFormat_v2, 2);
229 
230  };
231 
233  {
234  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
235  return pos_nwords;
236  }
237 
239  {
240 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
241  CheckB2LFEEHeaderVersion(n);
242 #endif
243  if (Get1stFINESSENwords(n) > 0) {
244  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
245  return &(m_buffer[ pos_nwords ]);
246  }
247  return NULL;
248  }
249 
251  {
252 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
253  CheckB2LFEEHeaderVersion(n);
254 #endif
255  if (Get2ndFINESSENwords(n) > 0) {
256  int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
257  return &(m_buffer[ pos_nwords ]);
258  }
259  return NULL;
260  }
261 
263  {
264 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
265  CheckB2LFEEHeaderVersion(n);
266 #endif
267  if (Get3rdFINESSENwords(n) > 0) {
268  int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
269  return &(m_buffer[ pos_nwords ]);
270  }
271  return NULL;
272  }
273 
275  {
276 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
277  CheckB2LFEEHeaderVersion(n);
278 #endif
279  if (Get4thFINESSENwords(n) > 0) {
280  int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
281  return &(m_buffer[ pos_nwords ]);
282  }
283  return NULL;
284  }
285 
287  {
288  int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
289  return &(m_buffer[ pos_nwords ]);
290  /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
291  /* CheckB2LFEEHeaderVersion(n); */
292  /* #endif */
293  /* int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
294  /* return &(m_buffer[ pos_nwords ]); */
295  }
296 
297  inline unsigned int PostRawCOPPERFormat_v2::GetDriverChkSum(int n)
298  {
299  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
300  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
301  return m_buffer[ pos_nwords ];
302  }
303 
304 
305  inline unsigned int PostRawCOPPERFormat_v2::GetCOPPERCounter(int n)
306  {
307  char err_buf[500];
308  sprintf(err_buf, "[FATAL] This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
309  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
310  printf("%s", err_buf);
311  std::string err_str = err_buf; throw (err_str);
312  return 0;
313  }
314 
316  {
317  char err_buf[500];
318  sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
319  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
320  printf("%s", err_buf);
321  std::string err_str = err_buf; throw (err_str);
322  return 0;
323  }
324 
326  {
327  char err_buf[500];
328  sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
329  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
330  printf("%s", err_buf);
331  std::string err_str = err_buf; throw (err_str);
332  return 0;
333  }
334 
335 
337  {
338  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
339 
340  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
341 
342  return (unsigned int)(m_buffer[ pos_nwords ]);
343  }
344 
346  {
347  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
348  return (unsigned int)(m_buffer[ pos_nwords ]);
349  }
350 
351 
352  inline unsigned int PostRawCOPPERFormat_v2::GetTrailerChksum(int n)
353  {
354  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
355  return (unsigned int)(m_buffer[ pos_nwords ]);
356  }
357 
358  inline int PostRawCOPPERFormat_v2::GetEventCRC16Value(int n, int finesse_num)
359  {
360  int fin_nwords = GetFINESSENwords(n, finesse_num);
361  if (fin_nwords > 0) {
362  int* buf = GetFINESSEBuffer(n, finesse_num) + fin_nwords
363  - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
364  return (int)(*buf & 0xffff);
365  }
366  return -1;
367  }
369 }
370 
371 #endif
Belle2::RawCOPPERPackerInfo
struct to contain header information used by RawCOPPERFormat::Packer()
Definition: RawCOPPERPackerInfo.h:12
Belle2::RawCOPPERFormat::GetOffset3rdFINESSE
virtual int GetOffset3rdFINESSE(int n)
get # of offset words for FINESSE slot C buffer position
Definition: RawCOPPERFormat.h:382
Belle2::PostRawCOPPERFormat_v2::GetMagicFPGATrailer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
Definition: PostRawCOPPERFormat_v2.h:336
Belle2::PostRawCOPPERFormat_v2::GetOffset1stFINESSE
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17
get # of offset words for FINESSE slot A buffer position
Definition: PostRawCOPPERFormat_v2.h:232
Belle2::RawDataBlockFormat::m_buffer
int * m_buffer
Buffer.
Definition: RawDataBlockFormat.h:98
Belle2::RawDataBlockFormat::GetBufferPos
virtual int GetBufferPos(int n)
get position of data block in word
Definition: RawDataBlockFormat.cc:30
Belle2::RawCOPPERFormat_v2::Get1stFINESSENwords
int Get1stFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot A buffer
Definition: RawCOPPERFormat_v2.h:318
Belle2::RawCOPPERFormat::GetFINESSEBuffer
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
Definition: RawCOPPERFormat.cc:65
Belle2::RawCOPPERFormat_v2::tmp_header
RawHeader_v2 tmp_header
header ( not recorded )
Definition: RawCOPPERFormat_v2.h:192
Belle2::PostRawCOPPERFormat_v2::GetB2LFEE32bitEventNumber
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_v2.cc:107
Belle2::PostRawCOPPERFormat_v2::FillTopBlockRawHeader
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
Definition: PostRawCOPPERFormat_v2.cc:204
Belle2::RawCOPPERFormat::GetOffset2ndFINESSE
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
Definition: RawCOPPERFormat.h:377
Belle2::PostRawCOPPERFormat_v2::Get2ndDetectorBuffer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot B
Definition: PostRawCOPPERFormat_v2.h:250
Belle2::PostRawCOPPERFormat_v2::GetExpRunSubrunBuf
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_v2.h:286
Belle2::PostRawCOPPERFormat_v2::CheckData
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
Definition: PostRawCOPPERFormat_v2.cc:125
Belle2::PostRawCOPPERFormat_v2::CheckB2LHSLBMagicWords
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words
Definition: PostRawCOPPERFormat_v2.cc:218
Belle2::PostRawCOPPERFormat_v2::GetDetectorNwords
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
Definition: PostRawCOPPERFormat_v2.cc:28
Belle2::PostRawCOPPERFormat_v2::~PostRawCOPPERFormat_v2
virtual ~PostRawCOPPERFormat_v2()
Constructor using existing pointer to raw data buffer.
Definition: PostRawCOPPERFormat_v2.cc:23
Belle2::PostRawCOPPERFormat_v2::GetDriverChkSum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
Definition: PostRawCOPPERFormat_v2.h:297
Belle2::RawTrailer_v2::GetTrlNwords
int GetTrlNwords()
Set magic word.
Definition: RawTrailer_v2.h:130
Belle2::PostRawCOPPERFormat_v2::PackDetectorBuf
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)
Definition: PostRawCOPPERFormat_v2.cc:344
Belle2::RawCOPPERFormat_v2::tmp_trailer
RawTrailer_v2 tmp_trailer
trailer ( not recorded )
Definition: RawCOPPERFormat_v2.h:195
Belle2::PostRawCOPPERFormat_v2::CheckUtimeCtimeTRGType
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
Definition: PostRawCOPPERFormat_v2.cc:195
Belle2::PostRawCOPPERFormat_v2::GetEventCRC16Value
int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17
Get CRC16 value for an event.
Definition: PostRawCOPPERFormat_v2.h:358
Belle2::PostRawCOPPERFormat_v2::CalcDriverChkSum
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
Definition: PostRawCOPPERFormat_v2.cc:39
Belle2::PostRawCOPPERFormat_v2::GetMagicDriverHeader
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Definition: PostRawCOPPERFormat_v2.h:315
Belle2::PostRawCOPPERFormat_v2::GetFINESSENwords
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
Definition: PostRawCOPPERFormat_v2.cc:50
Belle2::PostRawCOPPERFormat_v2
The Raw COPPER class ver.2 This class stores data received by COPPER via belle2link Data from all det...
Definition: PostRawCOPPERFormat_v2.h:37
Belle2::RawCOPPERFormat::GetOffset4thFINESSE
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
Definition: RawCOPPERFormat.h:387
Belle2::PostRawCOPPERFormat_v2::GetMagicFPGAHeader
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
Definition: PostRawCOPPERFormat_v2.h:325
Belle2::PostRawCOPPERFormat_v2::GetTrailerChksum
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
Get checksum in RawTrailer.
Definition: PostRawCOPPERFormat_v2.h:352
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PostRawCOPPERFormat_v2::Get3rdDetectorBuffer
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot C
Definition: PostRawCOPPERFormat_v2.h:262
Belle2::RawDataBlockFormat::GetBlockNwords
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlockFormat.cc:107
Belle2::PostRawCOPPERFormat_v2::CheckCOPPERMagic
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
Definition: PostRawCOPPERFormat_v2.cc:179
Belle2::RawCOPPERFormat_v2::Get4thFINESSENwords
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
Definition: RawCOPPERFormat_v2.h:333
Belle2::PostRawCOPPERFormat_v2::GetMagicDriverTrailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
Definition: PostRawCOPPERFormat_v2.h:345
Belle2::RawCOPPERFormat_v2::Get3rdFINESSENwords
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot C buffer
Definition: RawCOPPERFormat_v2.h:328
Belle2::RawCOPPERFormat_v2::Get2ndFINESSENwords
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot B buffer
Definition: RawCOPPERFormat_v2.h:323
Belle2::PostRawCOPPERFormat_v2::CheckCRC16
int CheckCRC16(int n, int finesse_num)
check magic words
Definition: PostRawCOPPERFormat_v2.cc:228
Belle2::PostRawCOPPERFormat_v2::PostRawCOPPERFormat_v2
PostRawCOPPERFormat_v2()
Default constructor.
Definition: PostRawCOPPERFormat_v2.cc:19
Belle2::PostRawCOPPERFormat_v2::Get4thDetectorBuffer
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot D
Definition: PostRawCOPPERFormat_v2.h:274
Belle2::PostRawCOPPERFormat_v2::GetCOPPERCounter
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
Definition: PostRawCOPPERFormat_v2.h:305
Belle2::PostRawCOPPERFormat_v2::Get1stDetectorBuffer
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17
get Detector buffer of slot A
Definition: PostRawCOPPERFormat_v2.h:238
Belle2::RawCOPPERFormat_v2
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
Definition: RawCOPPERFormat_v2.h:36