Belle II Software  release-05-01-25
PostRawCOPPERFormat_v1.h
1 //+
2 // File : PostRawCOPPERFormat_v1.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_V1_H
10 #define POSTRAWCOPPERFORMAT_V1_H
11 
12 // Includes
13 #include <stdio.h>
14 #include <string>
15 
16 #include <rawdata/dataobjects/RawCOPPERFormat_v1.h>
17 #include <rawdata/CRCCalculator.h>
18 
19 // version #
20 #define POST_RAWCOPPER_FORMAT_VER1 1
21 
22 //#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
23 
24 namespace Belle2 {
36  public:
39 
41  //PostRawCOPPERFormat_v1(int* bufin, int nwords);
43  virtual ~PostRawCOPPERFormat_v1();
44 
45  //
46  // Get position of or pointer to data
47  //
49  // POINTER TO "DETECTOR BUFFER"
50  //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
52 
54  int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
55 
57  int* Get1stDetectorBuffer(int n) OVERRIDE_CPP17;
58 
60  int* Get2ndDetectorBuffer(int n) OVERRIDE_CPP17;
61 
63  int* Get3rdDetectorBuffer(int n) OVERRIDE_CPP17;
64 
66  int* Get4thDetectorBuffer(int n) OVERRIDE_CPP17;
68 
70  // virtual int GetBufferPos(int n);
71 
72  //
73  // Get information from 13words "COPPER header" attached by COPPER board
74  //
76  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
77 
79  int GetOffset1stFINESSE(int n) OVERRIDE_CPP17;
80 
82  int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17;
83 
84  //
85  // Get information from "B2link(attached by FEE and HLSB) header"
86  //
88  // virtual int* GetFTSW2Words(int n);
89 
91  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
92 
94  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
95 
96  //
97  // read magic word to check data
98  //
100  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
101 
103  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
104 
106  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
107 
109  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
110 
112  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
113 
115  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
116 
118  unsigned int FillTopBlockRawHeader(unsigned int m_node_id, unsigned int prev_eve32,
119  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
120 
122  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
123 
125  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
126 
128  void CheckData(int n,
129  unsigned int prev_evenum, unsigned int* cur_evenum,
130  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
131  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
132 
134  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
135 
137  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
138 
140  int CheckCRC16(int n, int finesse_num);
141 
143  int* PackDetectorBuf(int* packed_buf_nwords,
144  int* detector_buf_1st, int nwords_1st,
145  int* detector_buf_2nd, int nwords_2nd,
146  int* detector_buf_3rd, int nwords_3rd,
147  int* detector_buf_4th, int nwords_4th,
148  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
149 
150  //
151  // size of "COPPER front header" and "COPPER trailer"
152  //
154 
155  enum {
156  SIZE_COPPER_DRIVER_HEADER = 0,
157  SIZE_COPPER_DRIVER_TRAILER = 0
158  };
159 
160  // Data Format : "COPPER header"
161  enum {
162  SIZE_COPPER_HEADER = 0
163  };
164 
165  // Data Format : "COPPER Trailer"
166  enum {
167  SIZE_COPPER_TRAILER = 0
168  };
169 
170  // Data Format : "B2Link HSLB Header"
171  enum {
172  POS_B2LHSLB_MAGIC = 0,
173  SIZE_B2LHSLB_HEADER = 1
174  };
175 
176 
177  // Data Format : "B2Link FEE Header"
178  enum {
179  POS_B2L_CTIME = 0,
180  SIZE_B2LFEE_HEADER = 1
181  };
182 
183  // Data Format : B2Link FEE Trailer
184  enum {
185  POS_B2LFEE_CRC16 = 0,
186  SIZE_B2LFEE_TRAILER = 1
187  };
188 
189  //
190  // Data Format : "B2Link HSLB Trailer"
191  //
192  enum {
193  SIZE_B2LHSLB_TRAILER = 0
194  };
195 
196 
197 
198  protected :
200  // ClassDefOverride(PostRawCOPPERFormat_v1, 2);
201 
202  };
203 
205  {
206  int pos_nwords = GetBufferPos(n) + tmp_header.RAWHEADER_NWORDS + SIZE_COPPER_HEADER;
207  return pos_nwords;
208  }
209 
211  {
212 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
213  CheckB2LFEEHeaderVersion(n);
214 #endif
215  if (Get1stFINESSENwords(n) > 0) {
216  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
217  return &(m_buffer[ pos_nwords ]);
218  }
219  return NULL;
220  }
221 
223  {
224 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
225  CheckB2LFEEHeaderVersion(n);
226 #endif
227  if (Get2ndFINESSENwords(n) > 0) {
228  int pos_nwords = GetOffset2ndFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
229  return &(m_buffer[ pos_nwords ]);
230  }
231  return NULL;
232  }
233 
235  {
236 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
237  CheckB2LFEEHeaderVersion(n);
238 #endif
239  if (Get3rdFINESSENwords(n) > 0) {
240  int pos_nwords = GetOffset3rdFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
241  return &(m_buffer[ pos_nwords ]);
242  }
243  return NULL;
244  }
245 
247  {
248 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
249  CheckB2LFEEHeaderVersion(n);
250 #endif
251  if (Get4thFINESSENwords(n) > 0) {
252  int pos_nwords = GetOffset4thFINESSE(n) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER;
253  return &(m_buffer[ pos_nwords ]);
254  }
255  return NULL;
256  }
257 
259  {
260  int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
261  return &(m_buffer[ pos_nwords ]);
262  /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
263  /* CheckB2LFEEHeaderVersion(n); */
264  /* #endif */
265  /* int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
266  /* return &(m_buffer[ pos_nwords ]); */
267  }
268 
269  inline unsigned int PostRawCOPPERFormat_v1::GetDriverChkSum(int n)
270  {
271  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
272  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
273  return m_buffer[ pos_nwords ];
274  }
275 
276 
277  inline unsigned int PostRawCOPPERFormat_v1::GetCOPPERCounter(int n)
278  {
279  char err_buf[500];
280  sprintf(err_buf, "This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
281  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
282  std::string err_str = err_buf; throw (err_str);
283  return 0;
284  }
285 
287  {
288  char err_buf[500];
289  sprintf(err_buf, "This function is not supported. (block %d) Exiting...\n %s %s %d\n",
290  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
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, "This function is not supported. (block %d) Exiting...\n %s %s %d\n",
299  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
300  std::string err_str = err_buf; throw (err_str);
301  return 0;
302  }
303 
304 
306  {
307  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
308 
309  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
310 
311  return (unsigned int)(m_buffer[ pos_nwords ]);
312  }
313 
315  {
316  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
317  return (unsigned int)(m_buffer[ pos_nwords ]);
318  }
319 
320 
321  inline unsigned int PostRawCOPPERFormat_v1::GetTrailerChksum(int n)
322  {
323  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
324  return (unsigned int)(m_buffer[ pos_nwords ]);
325  }
326 
327 
328 
329 
331 }
332 
333 #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_v1::GetMagicFPGATrailer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
Definition: PostRawCOPPERFormat_v1.h:305
Belle2::PostRawCOPPERFormat_v1::GetOffset1stFINESSE
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17
get # of offset words for FINESSE slot A buffer position
Definition: PostRawCOPPERFormat_v1.h:204
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_v1::Get1stFINESSENwords
int Get1stFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot A buffer
Definition: RawCOPPERFormat_v1.h:264
Belle2::RawCOPPERFormat_v1::tmp_header
RawHeader_v1 tmp_header
header ( not recorded )
Definition: RawCOPPERFormat_v1.h:153
Belle2::PostRawCOPPERFormat_v1::CheckUtimeCtimeTRGType
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
Definition: PostRawCOPPERFormat_v1.cc:227
Belle2::RawCOPPERFormat::GetOffset2ndFINESSE
virtual int GetOffset2ndFINESSE(int n)
get # of offset words for FINESSE slot B buffer position
Definition: RawCOPPERFormat.h:360
Belle2::PostRawCOPPERFormat_v1::CalcDriverChkSum
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
Definition: PostRawCOPPERFormat_v1.cc:76
Belle2::PostRawCOPPERFormat_v1::Get2ndDetectorBuffer
int * Get2ndDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot B
Definition: PostRawCOPPERFormat_v1.h:222
Belle2::PostRawCOPPERFormat_v1::GetExpRunSubrunBuf
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_v1.h:258
Belle2::RawCOPPERFormat_v1::tmp_trailer
RawTrailer_v1 tmp_trailer
trailer ( not recorded )
Definition: RawCOPPERFormat_v1.h:156
Belle2::PostRawCOPPERFormat_v1::GetDriverChkSum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
Definition: PostRawCOPPERFormat_v1.h:269
Belle2::RawTrailer_v1::GetTrlNwords
int GetTrlNwords()
Set magic word.
Definition: RawTrailer_v1.h:132
Belle2::PostRawCOPPERFormat_v1::GetFINESSENwords
int GetFINESSENwords(int n, int finesse) OVERRIDE_CPP17
get data size of FINESSE buffer
Definition: PostRawCOPPERFormat_v1.cc:87
Belle2::PostRawCOPPERFormat_v1::GetB2LFEE32bitEventNumber
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_v1.cc:139
Belle2::PostRawCOPPERFormat_v1::~PostRawCOPPERFormat_v1
virtual ~PostRawCOPPERFormat_v1()
Constructor using existing pointer to raw data buffer.
Definition: PostRawCOPPERFormat_v1.cc:25
Belle2::PostRawCOPPERFormat_v1::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_v1.cc:237
Belle2::PostRawCOPPERFormat_v1::GetMagicDriverHeader
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Definition: PostRawCOPPERFormat_v1.h:286
Belle2::PostRawCOPPERFormat_v1::GetDetectorNwords
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
Definition: PostRawCOPPERFormat_v1.cc:63
Belle2::RawCOPPERFormat::GetOffset4thFINESSE
virtual int GetOffset4thFINESSE(int n)
get # of offset words for FINESSE slot D buffer position
Definition: RawCOPPERFormat.h:370
Belle2::PostRawCOPPERFormat_v1::GetMagicFPGAHeader
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
Definition: PostRawCOPPERFormat_v1.h:295
Belle2::PostRawCOPPERFormat_v1::GetTrailerChksum
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
Get checksum in RawTrailer.
Definition: PostRawCOPPERFormat_v1.h:321
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PostRawCOPPERFormat_v1::Get3rdDetectorBuffer
int * Get3rdDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot C
Definition: PostRawCOPPERFormat_v1.h:234
Belle2::RawDataBlockFormat::GetBlockNwords
virtual int GetBlockNwords(int n)
get size of a data block
Definition: RawDataBlockFormat.cc:107
Belle2::RawCOPPERFormat_v1::Get4thFINESSENwords
int Get4thFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot D buffer
Definition: RawCOPPERFormat_v1.h:279
Belle2::PostRawCOPPERFormat_v1::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_v1.cc:151
Belle2::PostRawCOPPERFormat_v1::CheckB2LHSLBMagicWords
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words
Definition: PostRawCOPPERFormat_v1.cc:250
Belle2::RawCOPPERFormat_v1
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
Definition: RawCOPPERFormat_v1.h:35
Belle2::PostRawCOPPERFormat_v1::CheckCOPPERMagic
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
Definition: PostRawCOPPERFormat_v1.cc:217
Belle2::PostRawCOPPERFormat_v1::GetMagicDriverTrailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
Definition: PostRawCOPPERFormat_v1.h:314
Belle2::RawCOPPERFormat_v1::Get3rdFINESSENwords
int Get3rdFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot C buffer
Definition: RawCOPPERFormat_v1.h:274
Belle2::PostRawCOPPERFormat_v1
The Raw COPPER class ver.1 ( the latest version since May, 2014 ) This class stores data received by ...
Definition: PostRawCOPPERFormat_v1.h:35
Belle2::RawCOPPERFormat_v1::Get2ndFINESSENwords
int Get2ndFINESSENwords(int n) OVERRIDE_CPP17
get data size of FINESSE slot B buffer
Definition: RawCOPPERFormat_v1.h:269
Belle2::PostRawCOPPERFormat_v1::Get4thDetectorBuffer
int * Get4thDetectorBuffer(int n) OVERRIDE_CPP17
get Detector Buffer of slot D
Definition: PostRawCOPPERFormat_v1.h:246
Belle2::PostRawCOPPERFormat_v1::GetCOPPERCounter
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
Definition: PostRawCOPPERFormat_v1.h:277
Belle2::PostRawCOPPERFormat_v1::PostRawCOPPERFormat_v1
PostRawCOPPERFormat_v1()
Default constructor.
Definition: PostRawCOPPERFormat_v1.cc:21
Belle2::PostRawCOPPERFormat_v1::Get1stDetectorBuffer
int * Get1stDetectorBuffer(int n) OVERRIDE_CPP17
get Detector buffer of slot A
Definition: PostRawCOPPERFormat_v1.h:210
Belle2::PostRawCOPPERFormat_v1::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_v1.cc:318
Belle2::PostRawCOPPERFormat_v1::CheckCRC16
int CheckCRC16(int n, int finesse_num)
check magic words
Definition: PostRawCOPPERFormat_v1.cc:260