Belle II Software  release-05-01-25
PostRawCOPPERFormat_latest.h
1 //+
2 // File : PostRawCOPPERFormat_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 POSTRAWCOPPERFORMAT_LATEST_H
10 #define POSTRAWCOPPERFORMAT_LATEST_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_latest.h>
19 #include <rawdata/CRCCalculator.h>
20 
21 //#include <framework/datastore/DataStore.h>
22 //#include <TObject.h>
23 
24 // version #
25 #define POST_RAWCOPPER_FORMAT_VER1 1
26 
27 //#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
28 
29 namespace Belle2 {
41  public:
44 
46  //PostRawCOPPERFormat_latest(int* bufin, int nwords);
49 
50  //
51  // Get position of or pointer to data
52  //
54  // POINTER TO "DETECTOR BUFFER"
55  //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
57 
59  int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
60 
62  int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
63 
65  int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
66 
68  int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
69 
71  int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
73 
75  // virtual int GetBufferPos(int n);
76 
77  //
78  // Get information from 13words "COPPER header" attached by COPPER board
79  //
81  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
82 
84  int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
85 
87  int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
88 
89  //
90  // Get information from "B2link(attached by FEE and HLSB) header"
91  //
93  // virtual int* GetFTSW2Words(int n);
94 
96  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
97 
99  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
100 
101  //
102  // read magic word to check data
103  //
105  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
106 
108  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
109 
111  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
112 
114  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
115 
117  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
118 
120  int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17;
121 
123  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
124 
126  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
127  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
128 
130  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
131 
133  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
134 
136  void CheckData(int n,
137  unsigned int prev_evenum, unsigned int* cur_evenum,
138  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
139  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
140 
142  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
143 
145  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
146 
148  int CheckCRC16(int n, int finesse_num);
149 
151  int* PackDetectorBuf(int* packed_buf_nwords,
152  int* detector_buf_1st, int nwords_1st,
153  int* detector_buf_2nd, int nwords_2nd,
154  int* detector_buf_3rd, int nwords_3rd,
155  int* detector_buf_4th, int nwords_4th,
156  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
157 
158  //
159  // size of "COPPER front header" and "COPPER trailer"
160  //
162 
163  enum {
164  SIZE_COPPER_DRIVER_HEADER = 0,
165  SIZE_COPPER_DRIVER_TRAILER = 0
166  };
167 
168  // Data Format : "COPPER header"
169  enum {
170  SIZE_COPPER_HEADER = 0
171  };
172 
173  // Data Format : "COPPER Trailer"
174  enum {
175  SIZE_COPPER_TRAILER = 0
176  };
177 
178  // Data Format : "B2Link HSLB Header"
179  enum {
180  POS_B2LHSLB_MAGIC = 0,
181  SIZE_B2LHSLB_HEADER = 1
182  };
183 
184 
185  // Data Format : "B2Link FEE Header"
186  enum {
187  POS_B2L_CTIME = 0,
188  SIZE_B2LFEE_HEADER = 1
189  };
190 
191  // Data Format : B2Link FEE Trailer
192  enum {
193  POS_B2LFEE_ERRCNT_CRC16 = 0,
194  SIZE_B2LFEE_TRAILER = 1
195  };
196 
197  //
198  // Data Format : "B2Link HSLB Trailer"
199  //
200  enum {
201  SIZE_B2LHSLB_TRAILER = 0
202  };
203 
204 
205 
206  protected :
208  // ClassDefOverride(PostRawCOPPERFormat_latest, 2);
209 
210  };
211 
213  {
214  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
215  return pos_nwords;
216  }
217 
219  {
220 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
221  CheckB2LFEEHeaderVersion(n);
222 #endif
223  if (Get1stFINESSENwords(n) > 0) {
224  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
225  return &(m_buffer[ pos_nwords ]);
226  }
227  return NULL;
228  }
229 
231  {
232 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
233  CheckB2LFEEHeaderVersion(n);
234 #endif
235  if (Get2ndFINESSENwords(n) > 0) {
236  int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
237  return &(m_buffer[ pos_nwords ]);
238  }
239  return NULL;
240  }
241 
243  {
244 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
245  CheckB2LFEEHeaderVersion(n);
246 #endif
247  if (Get3rdFINESSENwords(n) > 0) {
248  int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
249  return &(m_buffer[ pos_nwords ]);
250  }
251  return NULL;
252  }
253 
255  {
256 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
257  CheckB2LFEEHeaderVersion(n);
258 #endif
259  if (Get4thFINESSENwords(n) > 0) {
260  int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
261  return &(m_buffer[ pos_nwords ]);
262  }
263  return NULL;
264  }
265 
267  {
268  int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
269  return &(m_buffer[ pos_nwords ]);
270  /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
271  /* CheckB2LFEEHeaderVersion(n); */
272  /* #endif */
273  /* int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
274  /* return &(m_buffer[ pos_nwords ]); */
275  }
276 
278  {
279  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
280  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
281  return m_buffer[ pos_nwords ];
282  }
283 
284 
286  {
287  char err_buf[500];
288  sprintf(err_buf, "[FATAL] This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
289  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
290  printf("%s", err_buf);
291  std::string err_str = err_buf; throw (err_str);
292  return 0;
293  }
294 
296  {
297  char err_buf[500];
298  sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
299  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
300  printf("%s", err_buf);
301  std::string err_str = err_buf; throw (err_str);
302  return 0;
303  }
304 
306  {
307  char err_buf[500];
308  sprintf(err_buf, "[FATAL] This function is not supported. (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 
315 
317  {
318  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
319 
320  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
321 
322  return (unsigned int)(m_buffer[ pos_nwords ]);
323  }
324 
326  {
327  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
328  return (unsigned int)(m_buffer[ pos_nwords ]);
329  }
330 
331 
333  {
334  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
335  return (unsigned int)(m_buffer[ pos_nwords ]);
336  }
337 
338  inline int PostRawCOPPERFormat_latest::GetEventCRC16Value(int n, int finesse_num)
339  {
340  int fin_nwords = GetFINESSENwords(n, finesse_num);
341  if (fin_nwords > 0) {
342  int* buf = GetFINESSEBuffer(n, finesse_num) + fin_nwords
343  - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
344  return (int)(*buf & 0xffff);
345  }
346  return -1;
347  }
348 
350 }
351 
352 #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::PostRawCOPPERFormat_latest::GetMagicFPGATrailer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
Definition: PostRawCOPPERFormat_latest.h:316
Belle2::PostRawCOPPERFormat_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: PostRawCOPPERFormat_latest.cc:308
Belle2::PostRawCOPPERFormat_latest::CheckCRC16
int CheckCRC16(int n, int finesse_num)
check magic words
Definition: PostRawCOPPERFormat_latest.cc:216
Belle2::PostRawCOPPERFormat_latest::GetOffset1stFINESSE
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17
get # of offset words for FINESSE slot A buffer position
Definition: PostRawCOPPERFormat_latest.h:212
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::PostRawCOPPERFormat_latest::GetFINESSENwords
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
Definition: PostRawCOPPERFormat_latest.cc:50
Belle2::RawCOPPERFormat_latest::Get1stFINESSENwords
int Get1stFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot A buffer
Definition: RawCOPPERFormat_latest.h:286
Belle2::RawCOPPERFormat::GetFINESSEBuffer
virtual int * GetFINESSEBuffer(int n, int finesse_num)
get FINESSE buffer pointer
Definition: RawCOPPERFormat.cc:65
Belle2::PostRawCOPPERFormat_latest::CheckCOPPERMagic
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
Definition: PostRawCOPPERFormat_latest.cc:170
Belle2::PostRawCOPPERFormat_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: PostRawCOPPERFormat_latest.cc:119
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::PostRawCOPPERFormat_latest::GetB2LFEE32bitEventNumber
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_latest.cc:104
Belle2::RawCOPPERFormat::GetOffset2ndFINESSE
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
Definition: RawCOPPERFormat.h:360
Belle2::PostRawCOPPERFormat_latest::Get2ndDetectorBuffer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot B
Definition: PostRawCOPPERFormat_latest.h:230
Belle2::PostRawCOPPERFormat_latest::GetExpRunSubrunBuf
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_latest.h:266
Belle2::PostRawCOPPERFormat_latest::GetDriverChkSum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
Definition: PostRawCOPPERFormat_latest.h:277
Belle2::PostRawCOPPERFormat_latest::CalcDriverChkSum
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
Definition: PostRawCOPPERFormat_latest.cc:39
Belle2::PostRawCOPPERFormat_latest::GetDetectorNwords
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
Definition: PostRawCOPPERFormat_latest.cc:28
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::PostRawCOPPERFormat_latest::CheckB2LHSLBMagicWords
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words
Definition: PostRawCOPPERFormat_latest.cc:206
Belle2::PostRawCOPPERFormat_latest::GetEventCRC16Value
int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17
Get CRC16 value for an event.
Definition: PostRawCOPPERFormat_latest.h:338
Belle2::PostRawCOPPERFormat_latest::GetMagicDriverHeader
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Definition: PostRawCOPPERFormat_latest.h:295
Belle2::PostRawCOPPERFormat_latest::PostRawCOPPERFormat_latest
PostRawCOPPERFormat_latest()
Default constructor.
Definition: PostRawCOPPERFormat_latest.cc:19
Belle2::RawCOPPERFormat::GetOffset4thFINESSE
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
Definition: RawCOPPERFormat.h:370
Belle2::PostRawCOPPERFormat_latest::GetMagicFPGAHeader
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
Definition: PostRawCOPPERFormat_latest.h:305
Belle2::PostRawCOPPERFormat_latest::GetTrailerChksum
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
Get checksum in RawTrailer.
Definition: PostRawCOPPERFormat_latest.h:332
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PostRawCOPPERFormat_latest::Get3rdDetectorBuffer
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot C
Definition: PostRawCOPPERFormat_latest.h:242
Belle2::PostRawCOPPERFormat_latest::CheckUtimeCtimeTRGType
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
Definition: PostRawCOPPERFormat_latest.cc:183
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::PostRawCOPPERFormat_latest::~PostRawCOPPERFormat_latest
virtual ~PostRawCOPPERFormat_latest()
Constructor using existing pointer to raw data buffer.
Definition: PostRawCOPPERFormat_latest.cc:23
Belle2::RawCOPPERFormat_latest::Get4thFINESSENwords
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
Definition: RawCOPPERFormat_latest.h:301
Belle2::PostRawCOPPERFormat_latest::GetMagicDriverTrailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
Definition: PostRawCOPPERFormat_latest.h:325
Belle2::RawCOPPERFormat_latest::Get3rdFINESSENwords
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot C buffer
Definition: RawCOPPERFormat_latest.h:296
Belle2::RawCOPPERFormat_latest::Get2ndFINESSENwords
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot B buffer
Definition: RawCOPPERFormat_latest.h:291
Belle2::PostRawCOPPERFormat_latest::Get4thDetectorBuffer
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot D
Definition: PostRawCOPPERFormat_latest.h:254
Belle2::PostRawCOPPERFormat_latest::GetCOPPERCounter
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
Definition: PostRawCOPPERFormat_latest.h:285
Belle2::PostRawCOPPERFormat_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: PostRawCOPPERFormat_latest.cc:192
Belle2::PostRawCOPPERFormat_latest::Get1stDetectorBuffer
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17
get Detector buffer of slot A
Definition: PostRawCOPPERFormat_latest.h:218