Belle II Software  release-08-01-10
RawCOPPERFormat_latest.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_LATEST_H
10 #define RAWCOPPERFORMAT_LATEST_H
11 
12 // Includes
13 #include <rawdata/dataobjects/RawCOPPERFormat.h>
14 #include <rawdata/dataobjects/RawHeader_latest.h>
15 #include <rawdata/dataobjects/RawTrailer_latest.h>
16 #include <rawdata/CRCCalculator.h>
17 /* #include <framework/datastore/DataStore.h> */
18 /* #include <TObject.h> */
19 
20 //#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
21 
22 namespace Belle2 {
35  public:
38 
40  //RawCOPPERFormat_latest(int* bufin, int nwords);
42  virtual ~RawCOPPERFormat_latest();
43 
44  //
45  // Get position of or pointer to data
46  //
48  // POINTER TO "DETECTOR BUFFER"
49  //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
51 
52 
54  /* cppcheck-suppress missingOverride */
55  int Get1stDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
56 
58  /* cppcheck-suppress missingOverride */
59  int Get2ndDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
60 
62  /* cppcheck-suppress missingOverride */
63  int Get3rdDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
64 
66  /* cppcheck-suppress missingOverride */
67  int Get4thDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
68 
70  /* cppcheck-suppress missingOverride */
71  int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17;
72 
74  /* cppcheck-suppress missingOverride */
75  int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17;
76 
78  /* cppcheck-suppress missingOverride */
79  int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17;
80 
82  /* cppcheck-suppress missingOverride */
83  int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17;
84 
86 
88  /* cppcheck-suppress missingOverride */
89  int* GetRawTrlBufPtr(int n) OVERRIDE_CPP17;
90 
91  //
92  // Get information from "RawCOPPERFormat_latest header" attached by DAQ software
93  //
94 
95  /* cppcheck-suppress missingOverride */
96  int GetExpNo(int n) OVERRIDE_CPP17;
97 
98  /* cppcheck-suppress missingOverride */
99  unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17;
100 
101  /* cppcheck-suppress missingOverride */
102  int GetRunNo(int n) OVERRIDE_CPP17;
103 
104  /* cppcheck-suppress missingOverride */
105  int GetSubRunNo(int n) OVERRIDE_CPP17;
106 
107  /* cppcheck-suppress missingOverride */
108  unsigned int GetEveNo(int n) OVERRIDE_CPP17;
109 
110  /* cppcheck-suppress missingOverride */
111  int GetDataType(int n) OVERRIDE_CPP17;
112 
113  /* cppcheck-suppress missingOverride */
114  int GetTruncMask(int n) OVERRIDE_CPP17;
115 
117  /* cppcheck-suppress missingOverride */
118  unsigned int GetErrorBitFlag(int n) OVERRIDE_CPP17;
119 
121  /* cppcheck-suppress missingOverride */
122  void AddErrorBitFlag(int n, unsigned int error_bit_flag) OVERRIDE_CPP17;
123 
125  /* cppcheck-suppress missingOverride */
126  int GetPacketCRCError(int n) OVERRIDE_CPP17;
127 
129  /* cppcheck-suppress missingOverride */
130  int GetEventCRCError(int n) OVERRIDE_CPP17;
131 
133  /* cppcheck-suppress missingOverride */
134  unsigned int GetNodeID(int n) OVERRIDE_CPP17;
135 
136  //
137  // Get information from 13words "COPPER header" attached by COPPER board
138  //
139 
141  /* cppcheck-suppress missingOverride */
142  virtual int GetNumFINESSEBlock(int n) OVERRIDE_CPP17;
143 
145  /* cppcheck-suppress missingOverride */
146  int Get1stFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
147 
149  /* cppcheck-suppress missingOverride */
150  int Get2ndFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
151 
153  /* cppcheck-suppress missingOverride */
154  int Get3rdFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
155 
157  /* cppcheck-suppress missingOverride */
158  int Get4thFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17;
159 
161  /* cppcheck-suppress missingOverride */
162  int GetOffset1stFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17;
163 
165  /* cppcheck-suppress missingOverride */
166  int GetOffset2ndFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17;
167 
169  /* cppcheck-suppress missingOverride */
170  int GetOffset3rdFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17;
171 
173  /* cppcheck-suppress missingOverride */
174  int GetOffset4thFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17;
175 
176  //
177  // Get information from "B2link(attached by FEE and HLSB) header"
178  //
180  // virtual int* GetFTSW2Words(int n);
181 
182 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
184  /* cppcheck-suppress missingOverride */
185  void CheckB2LFEEHeaderVersion(int n) OVERRIDE_CPP17;
186 #endif
187 
189  /* cppcheck-suppress missingOverride */
190  unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17;
191 
193  /* cppcheck-suppress missingOverride */
194  unsigned int GetTTUtime(int n) OVERRIDE_CPP17;
195 
196  /* //! calc COPPER driver's checksum value */
197  /* virtual unsigned int CalcDriverChkSum(int n) = 0; */
198 
199 
201  /* cppcheck-suppress missingOverride */
202  int GetTTCtime(int n) OVERRIDE_CPP17;
203 
205  /* cppcheck-suppress missingOverride */
206  int GetTRGType(int n) OVERRIDE_CPP17;
207 
209  /* cppcheck-suppress missingOverride */
210  void GetTTTimeVal(int n, struct timeval* tv) OVERRIDE_CPP17;
211 
213  /* cppcheck-suppress missingOverride */
214  int GetMaxNumOfCh(int n) OVERRIDE_CPP17;
215 
217  /* cppcheck-suppress missingOverride */
218  int* GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17;
219 
221  /* cppcheck-suppress missingOverride */
222  int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17;
223 
225  /* cppcheck-suppress missingOverride */
226  void CompareHeaderValue(int n, const unsigned int (&input_val)[MAX_PCIE40_CH],
227  std::vector<std::vector< unsigned int>>& summary_table) OVERRIDE_CPP17;
228 
230  enum {
231  DATA_FORMAT_VERSION = 4
232  };
233 
234  //
235  // size of "COPPER front header" and "COPPER trailer" (Common for pre/post format)
236  //
237  enum {
238  SIZE_COPPER_DRIVER_HEADER = 0,
239  SIZE_COPPER_DRIVER_TRAILER = 0
240  };
241 
242  // Data Format : "COPPER header"
243  enum {
244  SIZE_COPPER_HEADER = 0
245  };
246 
247  // Data Format : "COPPER Trailer"
248  enum {
249  SIZE_COPPER_TRAILER = 0
250  };
251 
252  // Format of the last 16bits in FF55**** trailer : 2023.9.26
253  // the least significant bit = 0
254  // the most significant bit = 15
255  enum {
256  ONLINE_REMOVED_DATA = 15
257  };
258 
261 
264 
265 
266  protected :
268  // ClassDefOverride(RawCOPPERFormat_latest, 2);
269  };
270 
271 
272 
273 
275  {
276  int pos_nwords;
277  if (n == (m_num_events * m_num_nodes) - 1) {
278  pos_nwords = m_nwords - tmp_trailer.GetTrlNwords();
279  } else {
280  pos_nwords = GetBufferPos(n + 1) - tmp_trailer.GetTrlNwords();
281  }
282  return &(m_buffer[ pos_nwords ]);
283  }
284 
286  {
288  return tmp_header.GetExpNo();
289  }
290 
291 
292  inline unsigned int RawCOPPERFormat_latest::GetExpRunSubrun(int n)
293  {
295  return tmp_header.GetExpRunSubrun();
296  }
297 
298 
300  {
302  return tmp_header.GetRunNo();
303  }
304 
305 
307  {
309  return tmp_header.GetSubRunNo();
310  }
311 
312  inline unsigned int RawCOPPERFormat_latest::GetEveNo(int n)
313  {
315  return tmp_header.GetEveNo();
316  }
317 
318 
319  inline unsigned int RawCOPPERFormat_latest::GetNodeID(int n)
320  {
322  return tmp_header.GetNodeID();
323  }
324 
325 
327  {
329  return tmp_header.GetDataType();
330  }
331 
333  {
335  return tmp_header.GetTruncMask();
336  }
337 
338  inline unsigned int RawCOPPERFormat_latest::GetErrorBitFlag(int n)
339  {
341  return tmp_header.GetErrorBitFlag();
342  }
343 
344  inline void RawCOPPERFormat_latest::AddErrorBitFlag(int n, unsigned int error_bit_flag)
345  {
347  tmp_header.AddErrorBitFlag(error_bit_flag);
348  return;
349  }
350 
352  {
354  return tmp_header.GetPacketCRCError();
355  }
356 
358  {
360  return tmp_header.GetEventCRCError();
361  }
362 
363  inline unsigned int RawCOPPERFormat_latest::GetTTCtimeTRGType(int n)
364  {
366  return tmp_header.GetTTCtimeTRGType();
367  }
368 
369  inline unsigned int RawCOPPERFormat_latest::GetTTUtime(int n)
370  {
372  return tmp_header.GetTTUtime();
373  }
374 
376  {
378  return tmp_header.GetTTCtime();
379  }
380 
382  {
384  return tmp_header.GetTRGType();
385  }
386 
387  inline void RawCOPPERFormat_latest::GetTTTimeVal(int n, struct timeval* tv)
388  {
391  return ;
392  }
393 
395  {
396  return MAX_PCIE40_CH;
397  }
398 
399  inline int RawCOPPERFormat_latest::GetFINESSENwords(int n, int finesse_num)
400  {
401 
402  // check if finesse_num is in a range
403  if (finesse_num < 0 || finesse_num >= MAX_PCIE40_CH) {
404  char err_buf[500];
405  sprintf(err_buf, "[FATAL] Invalid finesse # (=%d): %s %s %d\n", finesse_num,
406  __FILE__, __PRETTY_FUNCTION__, __LINE__);
407  printf("[DEBUG] %s\n", err_buf);
408  B2FATAL(err_buf);
409  return 0;
410  }
411 
412  int pos_nwords = GetBufferPos(n) + (tmp_header.POS_CH_POS_TABLE + finesse_num);
413  int nwords = 0;
414 
415  if (finesse_num == (MAX_PCIE40_CH - 1)) {
416  nwords = GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - m_buffer[ pos_nwords ];
417  } else {
418  nwords = m_buffer[ pos_nwords + 1 ] - m_buffer[ pos_nwords ];
419  }
420 
421  if (nwords < 0 || nwords > 1e6) {
422  char err_buf[500];
423  sprintf(err_buf, "[FATAL] ERROR_EVENT : # of words is strange. %d (ch=%d) : eve 0x%x exp %d run %d sub %d\n %s %s %d\n",
424  nwords, finesse_num,
425  GetEveNo(n), GetExpNo(n), GetRunNo(n), GetSubRunNo(n),
426  __FILE__, __PRETTY_FUNCTION__, __LINE__);
427  printf("[DEBUG] %s\n", err_buf);
428  B2FATAL(err_buf);
429  }
430  return nwords;
431  }
432 
433  inline int* RawCOPPERFormat_latest::GetFINESSEBuffer(int n, int finesse_num)
434  {
435  if (finesse_num >= MAX_PCIE40_CH || finesse_num < 0) {
436  char err_buf[500];
437  sprintf(err_buf, "[FATAL] Invalid finesse # : %s %s %d\n",
438  __FILE__, __PRETTY_FUNCTION__, __LINE__);
439  printf("[DEBUG] %s\n", err_buf);
440  B2FATAL(err_buf);
441  return NULL;
442  }
443 
444  if (GetFINESSENwords(n, finesse_num) > 0) {
445  int cur_pos = GetBufferPos(n)
446  + m_buffer[ GetBufferPos(n) + (tmp_header.POS_CH_POS_TABLE + finesse_num) ];
447 
448  if (m_nwords <= 0 || cur_pos >= m_nwords) {
449  char err_buf[500];
450  sprintf(err_buf, "[FATAL] The position of the buffer( block %d, ch %d) is out of bounds (m_nwords = %d) : %s %s %d\n",
451  n, finesse_num, m_nwords,
452  __FILE__, __PRETTY_FUNCTION__, __LINE__);
453  printf("[DEBUG] %s\n", err_buf);
454  B2FATAL(err_buf);
455  return NULL;
456  }
457  return (m_buffer + cur_pos);
458  }
459  return NULL;
460  }
461 
463 }
464 #endif
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
RawTrailer_latest tmp_trailer
trailer ( not recorded )
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector Buffer of slot D
int Get1stDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector buffer length of slot A
int Get4thDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector buffer length of slot D
int Get2ndDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector buffer length of slot B
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get data size of FINESSE slot C buffer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector Buffer of slot B
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector Buffer of slot C
int GetOffset3rdFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot C buffer position
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get data size of FINESSE slot B buffer
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot A buffer position
RawCOPPERFormat_latest()
Default constructor.
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector buffer of slot A
virtual int GetNumFINESSEBlock(int n) OVERRIDE_CPP17
get # of FINNESEs which contains data
virtual ~RawCOPPERFormat_latest()
Constructor using existing pointer to raw data buffer.
int Get3rdDetectorNwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get Detector buffer length of slot C
int GetOffset4thFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot D buffer position
int Get1stFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get data size of FINESSE slot A buffer
int GetOffset2ndFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot B buffer position
void CompareHeaderValue(int n, const unsigned int(&input_val)[MAX_PCIE40_CH], std::vector< std::vector< unsigned int >> &summary_table) OVERRIDE_CPP17
Check header value of all channels.
int Get4thFINESSENwords(int n) OVERRIDE_CPP17 FINAL_CPP17
get data size of FINESSE slot D buffer
RawHeader_latest tmp_header
header ( not recorded )
The Raw COPPER class This class stores data received by COPPER via belle2linkt Data from all detector...
int m_num_events
number of events in this object
int m_num_nodes
number of nodes in this object
virtual int GetBlockNwords(int n)
get size of a data block
virtual int GetBufferPos(int n)
get position of data block in word
virtual int * GetBuffer(int n)
get nth buffer pointer
int m_nwords
number of words of buffer
The Raw Header class ver.1 ( the latest version since May, 2014 ) This class defines the format of th...
void SetBuffer(int *bufin)
set buffer
The Raw Trailer class ver.1 ( the latest version since May, 2014 ) This class defines the format of t...
int GetMaxNumOfCh(int n) OVERRIDE_CPP17
Get the max number of channels in a readout board.
int GetTTCtime(int n) OVERRIDE_CPP17
Get ctime.
int GetEventCRCError(int n) OVERRIDE_CPP17
check CRC event Error
unsigned int GetEveNo()
get restart #(8bit)
unsigned int GetEveNo(int n) OVERRIDE_CPP17
get subrun #(8bit)
int GetTruncMask(int n) OVERRIDE_CPP17
get contents of header
int GetPacketCRCError()
Get Packet CRC error flag.
unsigned int GetErrorBitFlag(int n) OVERRIDE_CPP17
get contents of header
int GetTRGType(int n) OVERRIDE_CPP17
Get trgtype.
void AddErrorBitFlag(unsigned int error_bit_flag)
Add Detected Error bitflag.
int GetTTCtime()
get contents of header
void GetTTTimeVal(struct timeval *tv)
get contents of header
void GetTTTimeVal(int n, struct timeval *tv) OVERRIDE_CPP17
Get timeval.
int GetSubRunNo()
get run # (14bit)
int GetTrlNwords()
Set magic word.
void AddErrorBitFlag(int n, unsigned int error_bit_flag) OVERRIDE_CPP17
Add Detected Error bitflag.
unsigned int GetExpRunSubrun(int n) OVERRIDE_CPP17
get Experimental # from header
int * GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to a FINESSE buffer.
int GetExpNo(int n) OVERRIDE_CPP17
get Experimental # from header
int GetDataType()
get contents of header
unsigned int GetTTUtime()
get contents of header
int GetTRGType()
get TRGType
int GetRunNo(int n) OVERRIDE_CPP17
Exp# (10bit) run# (14bit) restart # (8bit)
int GetPacketCRCError(int n) OVERRIDE_CPP17
check CRC packet Error
unsigned int GetNodeID()
get contents of header
int GetRunNo()
get contents of header
unsigned int GetTTUtime(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
unsigned int GetNodeID(int n) OVERRIDE_CPP17
get node-ID from data
int GetDataType(int n) OVERRIDE_CPP17
get contents of header
int * GetRawTrlBufPtr(int n) OVERRIDE_CPP17
get buffer pointer of rawcopper trailer
int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17
Get the size of a finesse buffer.
int GetTruncMask()
get contents of header
unsigned int GetErrorBitFlag()
get contents of header
int GetEventCRCError()
Get Detected Error bitflag.
unsigned int GetTTCtimeTRGType()
get contents of header
unsigned int GetTTCtimeTRGType(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
unsigned int GetExpRunSubrun()
get contents of header
int GetExpNo()
get a run/exp number combined word
int GetSubRunNo(int n) OVERRIDE_CPP17
get run # (14bit)
Abstract base class for different kinds of events.