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