Belle II Software  release-05-01-25
PreRawCOPPERFormat_latest.h
1 //+
2 // File : PreRawCOPPERFormat_latest.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 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  int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
51 
53  int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
54 
56  int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
57 
59  int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
60 
62  int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
64 
66  // virtual int GetBufferPos(int n);
67 
68  //
69  // Get information from 13words "COPPER header" attached by COPPER board
70  //
72  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
73 
75  int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
76 
78  int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
79 
80  //
81  // Get information from "B2link(attached by FEE and HLSB) header"
82  //
84  // virtual int* GetFTSW2Words(int n);
85 
87  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
88 
90  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
91 
92  //
93  // read magic word to check data
94  //
96  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
97 
99  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
100 
102  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
103 
105  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
106 
108  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
109 
111  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
112 
114  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
115  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
116 
118  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
119 
121  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
122 
124  void CheckData(int n,
125  unsigned int prev_evenum, unsigned int* cur_evenum,
126  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
127  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
128 
130  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
131 
133  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
134 
136  int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
137  // int CalcReducedDataSize(RawDataBlock* raw_datablk);
138 
140  void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
141  // void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
142 
144  int CalcReducedNwords(int n);
145 
147  int CopyReducedBuffer(int n, int* buf_to);
148 
150  int CheckCRC16(int n, int finesse_num);
151 
153  int* PackDetectorBuf(int* packed_buf_nwords,
154  int* detector_buf_1st, int nwords_1st,
155  int* detector_buf_2nd, int nwords_2nd,
156  int* detector_buf_3rd, int nwords_3rd,
157  int* detector_buf_4th, int nwords_4th,
158  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
159 
161 
162 
163  //
164  // size of "COPPER front header" and "COPPER trailer"
165  //
167  enum {
168  SIZE_COPPER_DRIVER_HEADER = 7,
169  SIZE_COPPER_DRIVER_TRAILER = 2
170  };
171 
172  //
173  // Data Format : "COPPER header"
174  //
175  enum {
176  POS_MAGIC_COPPER_1 = 0,
177  POS_EVE_NUM_COPPER = 1,
178  POS_SUBSYSTEM_ID = 2,
179  POS_CRATE_ID = 3,
180  POS_SLOT_ID = 4,
181  POS_MAGIC_COPPER_2 = 7,
182  POS_DATA_LENGTH = 8,
183  POS_CH_A_DATA_LENGTH = 9,
184  POS_CH_B_DATA_LENGTH = 10,
185  POS_CH_C_DATA_LENGTH = 11,
186  POS_CH_D_DATA_LENGTH = 12,
187 
188  SIZE_COPPER_HEADER = 13
189  };
190 
191 
192 
193  //
194  // Data Format : "COPPER Trailer"
195  //
196  enum {
197  POS_MAGIC_COPPER_3 = 0,
198  POS_CHKSUM_COPPER = 1,
199  POS_MAGIC_COPPER_4 = 2,
200 
201  SIZE_COPPER_TRAILER = 3
202  };
203 
204  //
205  // Data Format : "B2Link HSLB Header"
206  //
207  enum {
208  POS_MAGIC_B2LHSLB = 0,
209  // POS_EVE_CNT_B2LHSLB = 1,
210  SIZE_B2LHSLB_HEADER = 1
211  };
212 
213  // Data Format : "B2Link FEE Header"
214  // modified by Nov. 21, 2013, Nakao-san's New firmware?
215  enum {
216  POS_TT_CTIME_TYPE = 0,
217  POS_TT_TAG = 1,
218  POS_TT_UTIME = 2,
219  POS_EXP_RUN = 3,
220  POS_B2L_CTIME = 4,
221  SIZE_B2LFEE_HEADER = 5
222  };
223 
224 
225  //
226  // Data Format : B2Link FEE Trailer
227  //
228  enum {
229  POS_TT_CTIME_B2LFEE = 0,
230  POS_CHKSUM_B2LFEE = 1,
231  SIZE_B2LFEE_TRAILER = 2
232  };
233 
234 
235  //
236  // Data Format : "B2Link HSLB Trailer"
237  //
238  enum {
239  POS_CHKSUM_B2LHSLB = 0,
240  SIZE_B2LHSLB_TRAILER = 1
241  };
242 
243 
244 
245  //
246  // COPPER magic words
247  //
248  enum {
249  COPPER_MAGIC_DRIVER_HEADER = 0x7FFF0008,
250  COPPER_MAGIC_FPGA_HEADER = 0xFFFFFAFA,
251  COPPER_MAGIC_FPGA_TRAILER = 0xFFFFF5F5,
252  COPPER_MAGIC_DRIVER_TRAILER = 0x7FFF0009
253  };
254 
255 
256  //
257  // magic words attached by HSLB
258  //
259  enum {
260  B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
261  B2LHSLB_TRAILER_MAGIC = 0xFF550000
262  };
263 
266 
267  protected :
269  // ClassDefOverride(PreRawCOPPERFormat_latest, 2);
270 
271  };
272 
273 
275  {
276  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
277  return pos_nwords;
278  }
279 
280 
281 
283  {
284 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
285  CheckB2LFEEHeaderVersion(n);
286 #endif
287  if (Get1stFINESSENwords(n) > 0) {
288  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
289  return &(m_buffer[ pos_nwords ]);
290  }
291  return NULL;
292  }
293 
295  {
296 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
297  CheckB2LFEEHeaderVersion(n);
298 #endif
299  if (Get2ndFINESSENwords(n) > 0) {
300  int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
301  return &(m_buffer[ pos_nwords ]);
302  }
303  return NULL;
304  }
305 
307  {
308 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
309  CheckB2LFEEHeaderVersion(n);
310 #endif
311  if (Get3rdFINESSENwords(n) > 0) {
312  int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
313  return &(m_buffer[ pos_nwords ]);
314  }
315  return NULL;
316  }
317 
319  {
320 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
321  CheckB2LFEEHeaderVersion(n);
322 #endif
323  if (Get4thFINESSENwords(n) > 0) {
324  int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
325  return &(m_buffer[ pos_nwords ]);
326  }
327  return NULL;
328  }
329 
331  {
332 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
333  CheckB2LFEEHeaderVersion(n);
334 #endif
335  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
336  return &(m_buffer[ pos_nwords ]);
337  }
338 
339 
340 
342  {
343  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_1;
344  return (unsigned int)(m_buffer[ pos_nwords ]);
345  }
346 
348  {
349  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + POS_MAGIC_COPPER_2;
350  return (unsigned int)(m_buffer[ pos_nwords ]);
351  }
352 
354  {
355  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
356 
357  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
358 
359  return (unsigned int)(m_buffer[ pos_nwords ]);
360  }
361 
363  {
364  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
365  return (unsigned int)(m_buffer[ pos_nwords ]);
366  }
367 
368 
370  {
371  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
372  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
373  return m_buffer[ pos_nwords ];
374  }
375 
376 
378  {
379  int pos_nwords = GetBufferPos(n) + POS_EVE_NUM_COPPER + tmp_header.RAWHEADER_NWORDS;
380  return (unsigned int)(m_buffer[ pos_nwords ]);
381  }
382 
383 
384 
385 
387  {
388  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
389  return (unsigned int)(m_buffer[ pos_nwords ]);
390  }
391 
392 
393 
394 
395 
397 }
398 #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:365
Belle2::PreRawCOPPERFormat_latest::CheckUtimeCtimeTRGType
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
Definition: PreRawCOPPERFormat_latest.cc:325
Belle2::PreRawCOPPERFormat_latest::GetMagicFPGATrailer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
Definition: PreRawCOPPERFormat_latest.h:353
Belle2::PreRawCOPPERFormat_latest::GetOffset1stFINESSE
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17
get # of offset words for FINESSE slot A buffer position
Definition: PreRawCOPPERFormat_latest.h:274
Belle2::RawDataBlockFormat::m_buffer
int * m_buffer
Buffer.
Definition: RawDataBlockFormat.h:98
Belle2::PreRawCOPPERFormat_latest::~PreRawCOPPERFormat_latest
virtual ~PreRawCOPPERFormat_latest()
Constructor using existing pointer to raw data buffer.
Definition: PreRawCOPPERFormat_latest.cc:24
Belle2::RawDataBlockFormat::GetBufferPos
virtual int GetBufferPos(int n)
get position of data block in word
Definition: RawDataBlockFormat.cc:30
Belle2::RawCOPPERFormat_latest::Get1stFINESSENwords
int Get1stFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot A buffer
Definition: RawCOPPERFormat_latest.h:286
Belle2::PostRawCOPPERFormat_latest
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
Definition: PostRawCOPPERFormat_latest.h:40
Belle2::PreRawCOPPERFormat_latest
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
Definition: PreRawCOPPERFormat_latest.h:30
Belle2::PreRawCOPPERFormat_latest::PreRawCOPPERFormat_latest
PreRawCOPPERFormat_latest()
Default constructor.
Definition: PreRawCOPPERFormat_latest.cc:20
Belle2::PreRawCOPPERFormat_latest::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: PreRawCOPPERFormat_latest.cc:173
Belle2::PreRawCOPPERFormat_latest::CalcDriverChkSum
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
Definition: PreRawCOPPERFormat_latest.cc:28
Belle2::PreRawCOPPERFormat_latest::CalcReducedDataSize
int CalcReducedDataSize(int *bufin, int nwords, int num_events, int num_nodes)
reduce and merge header/trailer
Definition: PreRawCOPPERFormat_latest.cc:878
Belle2::RawCOPPERFormat::GetOffset2ndFINESSE
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
Definition: RawCOPPERFormat.h:360
Belle2::PreRawCOPPERFormat_latest::Get2ndDetectorBuffer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot B
Definition: PreRawCOPPERFormat_latest.h:294
Belle2::PreRawCOPPERFormat_latest::GetB2LFEE32bitEventNumber
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PreRawCOPPERFormat_latest.cc:106
Belle2::PreRawCOPPERFormat_latest::GetExpRunSubrunBuf
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PreRawCOPPERFormat_latest.h:330
Belle2::PreRawCOPPERFormat_latest::GetDriverChkSum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
Definition: PreRawCOPPERFormat_latest.h:369
Belle2::PreRawCOPPERFormat_latest::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: PreRawCOPPERFormat_latest.cc:1277
Belle2::PreRawCOPPERFormat_latest::CheckCRC16
int CheckCRC16(int n, int finesse_num)
check CRC16 in B2LFEE trailer
Definition: PreRawCOPPERFormat_latest.cc:1237
Belle2::RawTrailer_latest::GetTrlNwords
int GetTrlNwords()
Set magic word.
Definition: RawTrailer_latest.h:130
Belle2::RawCOPPERFormat_latest::tmp_header
RawHeader_latest tmp_header
header ( not recorded )
Definition: RawCOPPERFormat_latest.h:160
Belle2::PreRawCOPPERFormat_latest::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: PreRawCOPPERFormat_latest.cc:407
Belle2::PreRawCOPPERFormat_latest::CheckCOPPERMagic
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
Definition: PreRawCOPPERFormat_latest.cc:311
Belle2::PreRawCOPPERFormat_latest::GetMagicDriverHeader
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Definition: PreRawCOPPERFormat_latest.h:341
Belle2::PreRawCOPPERFormat_latest::CopyReducedData
void CopyReducedData(int *bufin, int nwords, int num_events, int num_nodes, int *buf_to, int *nwords_to)
reduce and merge header/trailer
Definition: PreRawCOPPERFormat_latest.cc:913
Belle2::PreRawCOPPERFormat_latest::GetDetectorNwords
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
Definition: PreRawCOPPERFormat_latest.cc:42
Belle2::PreRawCOPPERFormat_latest::CopyReducedBuffer
int CopyReducedBuffer(int n, int *buf_to)
copy data to reduced buffer
Definition: PreRawCOPPERFormat_latest.cc:989
Belle2::PreRawCOPPERFormat_latest::m_reduced_rawcpr
PostRawCOPPERFormat_latest m_reduced_rawcpr
data fromat after size reduction
Definition: PreRawCOPPERFormat_latest.h:265
Belle2::RawCOPPERFormat::GetOffset4thFINESSE
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
Definition: RawCOPPERFormat.h:370
Belle2::PreRawCOPPERFormat_latest::GetMagicFPGAHeader
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
Definition: PreRawCOPPERFormat_latest.h:347
Belle2::PreRawCOPPERFormat_latest::GetTrailerChksum
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
get a checksum on trailer
Definition: PreRawCOPPERFormat_latest.h:386
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PreRawCOPPERFormat_latest::Get3rdDetectorBuffer
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot C
Definition: PreRawCOPPERFormat_latest.h:306
Belle2::RawDataBlockFormat::GetBlockNwords
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlockFormat.cc:107
Belle2::RawCOPPERFormat_latest::tmp_trailer
RawTrailer_latest tmp_trailer
trailer ( not recorded )
Definition: RawCOPPERFormat_latest.h:163
Belle2::RawCOPPERFormat_latest
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
Definition: RawCOPPERFormat_latest.h:36
Belle2::RawCOPPERFormat_latest::Get4thFINESSENwords
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
Definition: RawCOPPERFormat_latest.h:301
Belle2::PreRawCOPPERFormat_latest::GetMagicDriverTrailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
Definition: PreRawCOPPERFormat_latest.h:362
Belle2::RawCOPPERFormat_latest::Get3rdFINESSENwords
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot C buffer
Definition: RawCOPPERFormat_latest.h:296
Belle2::PreRawCOPPERFormat_latest::CalcReducedNwords
int CalcReducedNwords(int n)
calculate reduced data size
Definition: PreRawCOPPERFormat_latest.cc:949
Belle2::RawCOPPERFormat_latest::Get2ndFINESSENwords
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot B buffer
Definition: RawCOPPERFormat_latest.h:291
Belle2::PreRawCOPPERFormat_latest::GetFINESSENwords
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
Definition: PreRawCOPPERFormat_latest.cc:55
Belle2::PreRawCOPPERFormat_latest::Get4thDetectorBuffer
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot D
Definition: PreRawCOPPERFormat_latest.h:318
Belle2::PreRawCOPPERFormat_latest::GetCOPPERCounter
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
Definition: PreRawCOPPERFormat_latest.h:377
Belle2::PreRawCOPPERFormat_latest::Get1stDetectorBuffer
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17
get Detector buffer of slot A
Definition: PreRawCOPPERFormat_latest.h:282
Belle2::PreRawCOPPERFormat_latest::CheckB2LHSLBMagicWords
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words of B2link HSLB header/trailer
Definition: PreRawCOPPERFormat_latest.cc:1213