Belle II Software  release-06-00-14
PreRawCOPPERFormat_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 PRERAWCOPPERFORMAT_LATEST_H
10 #define PRERAWCOPPERFORMAT_LATEST_H
11 
12 // Includes
13 #include <rawdata/dataobjects/PostRawCOPPERFormat_latest.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_latest(int* bufin, int nwords);
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 
56  // virtual int GetBufferPos(int n);
57 
58  //
59  // Get information from 13words "COPPER header" attached by COPPER board
60  //
62  /* cppcheck-suppress missingOverride */
63  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
64 
65  //
66  // Get information from "B2link(attached by FEE and HLSB) header"
67  //
69  // virtual int* GetFTSW2Words(int n);
70 
72  /* cppcheck-suppress missingOverride */
73  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
74 
76  /* cppcheck-suppress missingOverride */
77  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
78 
79  //
80  // read magic word to check data
81  //
83  /* cppcheck-suppress missingOverride */
84  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
85 
87  /* cppcheck-suppress missingOverride */
88  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
89 
91  /* cppcheck-suppress missingOverride */
92  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
93 
95  /* cppcheck-suppress missingOverride */
96  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
97 
99  /* cppcheck-suppress missingOverride */
100  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
101 
103  /* cppcheck-suppress missingOverride */
104  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
105 
107  /* cppcheck-suppress missingOverride */
108  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
109  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
110 
112  /* cppcheck-suppress missingOverride */
113  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
114 
116  /* cppcheck-suppress missingOverride */
117  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
118 
120  /* cppcheck-suppress missingOverride */
121  void CheckData(int n,
122  unsigned int prev_evenum, unsigned int* cur_evenum,
123  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
124  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
125 
127  /* cppcheck-suppress missingOverride */
128  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
129 
131  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
132 
134  int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
135  // int CalcReducedDataSize(RawDataBlock* raw_datablk);
136 
138  void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
139  // void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
140 
142  int CalcReducedNwords(int n);
143 
145  int CopyReducedBuffer(int n, int* buf_to);
146 
148  int CheckCRC16(int n, int finesse_num);
149 
151  /* cppcheck-suppress missingOverride */
152  int* PackDetectorBuf(int* packed_buf_nwords,
153  int* detector_buf_1st, int nwords_1st,
154  int* detector_buf_2nd, int nwords_2nd,
155  int* detector_buf_3rd, int nwords_3rd,
156  int* detector_buf_4th, int nwords_4th,
157  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
158 
160  /* cppcheck-suppress missingOverride */
161  int* PackDetectorBuf(int* packed_buf_nwords,
162  int* const(&detector_buf_ch)[MAX_PCIE40_CH],
163  int const(&nwords_ch)[MAX_PCIE40_CH],
164  RawCOPPERPackerInfo rawcpr_info) OVERRIDE_CPP17;
165 
167  /* cppcheck-suppress missingOverride */
168  int* GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17;
169 
170  //
171  // Data Format : "B2Link HSLB Header"
172  //
173  enum {
174  POS_MAGIC_B2LHSLB = 0,
175  // POS_EVE_CNT_B2LHSLB = 1,
176  SIZE_B2LHSLB_HEADER = 1
177  };
178 
179  // Data Format : "B2Link FEE Header"
180  // modified by Nov. 21, 2013, Nakao-san's New firmware?
181  enum {
182  POS_TT_CTIME_TYPE = 0,
183  POS_TT_TAG = 1,
184  POS_TT_UTIME = 2,
185  POS_EXP_RUN = 3,
186  POS_B2L_CTIME = 4,
187  SIZE_B2LFEE_HEADER = 5
188  };
189 
190 
191  //
192  // Data Format : B2Link FEE Trailer
193  //
194  enum {
195  POS_TT_CTIME_B2LFEE = 0,
196  POS_CHKSUM_B2LFEE = 1,
197  SIZE_B2LFEE_TRAILER = 2
198  };
199 
200 
201  //
202  // Data Format : "B2Link HSLB Trailer"
203  //
204  enum {
205  POS_CHKSUM_B2LHSLB = 0,
206  SIZE_B2LHSLB_TRAILER = 1
207  };
208 
209  //
210  // magic words attached by HSLB
211  //
212  enum {
213  B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
214  B2LHSLB_TRAILER_MAGIC = 0xFF550000
215  };
216 
219 
220  protected :
222  // ClassDefOverride(PreRawCOPPERFormat_latest, 2);
223 
224  };
225 
226 
228  {
229 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
230  CheckB2LFEEHeaderVersion(n);
231 #endif
232  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
233  return &(m_buffer[ pos_nwords ]);
234  }
235 
236 
237 
238  inline unsigned int PreRawCOPPERFormat_latest::GetMagicDriverHeader(int/* n */)
239  {
240  char err_buf[500];
241  sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
242  __FILE__, __PRETTY_FUNCTION__, __LINE__);
243  printf("[DEBUG] %s\n", err_buf);
244  B2FATAL(err_buf);
245  return 0;
246  }
247 
248  inline unsigned int PreRawCOPPERFormat_latest::GetMagicFPGAHeader(int/* n */)
249  {
250  char err_buf[500];
251  sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
252  __FILE__, __PRETTY_FUNCTION__, __LINE__);
253  printf("[DEBUG] %s\n", err_buf);
254  B2FATAL(err_buf);
255  return 0;
256  }
257 
259  {
260  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
261 
262  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
263 
264  return (unsigned int)(m_buffer[ pos_nwords ]);
265  }
266 
268  {
269  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
270  return (unsigned int)(m_buffer[ pos_nwords ]);
271  }
272 
273 
275  {
276  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
277  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
278  return m_buffer[ pos_nwords ];
279  }
280 
281 
282  inline unsigned int PreRawCOPPERFormat_latest::GetCOPPERCounter(int/* n */)
283  {
284  char err_buf[500];
285  sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
286  __FILE__, __PRETTY_FUNCTION__, __LINE__);
287  printf("[DEBUG] %s\n", err_buf);
288  B2FATAL(err_buf);
289  return 0;
290  }
291 
293  {
294  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
295  return (unsigned int)(m_buffer[ pos_nwords ]);
296  }
297 
298  inline int* PreRawCOPPERFormat_latest::GetDetectorBuffer(int n, int finesse_num)
299  {
300  if (GetFINESSENwords(n, finesse_num) > 0) {
301  return (GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER);
302  }
303  return NULL;
304  }
305 
306  inline int PreRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
307  {
308  int nwords = 0;
309  if (GetFINESSENwords(n, finesse_num) > 0) {
310  nwords = GetFINESSENwords(n, finesse_num)
311  - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
312  }
313  return nwords;
314  }
315 
316 
318 }
319 #endif
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
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
virtual ~PreRawCOPPERFormat_latest()
Constructor using existing pointer to raw data 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
PostRawCOPPERFormat_latest m_reduced_rawcpr
data fromat after size reduction
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 GetOffset1stFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot A buffer position
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
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
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
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
int GetTrlNwords()
Set magic word.
int * GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to detector buffer.
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
int * GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to a FINESSE buffer.
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
get a checksum on trailer
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17
Get the size of a finesse buffer.
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Abstract base class for different kinds of events.