Belle II Software  release-05-02-19
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 //#define USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
25 
26 namespace Belle2 {
38  public:
41 
43  //PostRawCOPPERFormat_latest(int* bufin, int nwords);
46 
47  //
48  // Get position of or pointer to data
49  //
51  // POINTER TO "DETECTOR BUFFER"
52  //( after removing "B2link headers" from "FINESSE buffer". THIS IS THE RAW DATA FROM A DETECTOR
54 
56  int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17;
57 
59 
61  // virtual int GetBufferPos(int n);
62 
63  //
64  // Get information from 13words "COPPER header" attached by COPPER board
65  //
67  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
68 
69  //
70  // Get information from "B2link(attached by FEE and HLSB) header"
71  //
73  // virtual int* GetFTSW2Words(int n);
74 
76  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
77 
79  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
80 
81  //
82  // read magic word to check data
83  //
85  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
86 
88  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
89 
91  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
92 
94  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
95 
97  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
98 
100  int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17;
101 
103  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
104 
106  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
107  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
108 
110  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
111 
113  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
114 
116  void CheckData(int n,
117  unsigned int prev_evenum, unsigned int* cur_evenum,
118  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
119  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
120 
122  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
123 
125  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
126 
128  int CheckCRC16(int n, int finesse_num);
129 
131  int* PackDetectorBuf(int* packed_buf_nwords,
132  int* detector_buf_1st, int nwords_1st,
133  int* detector_buf_2nd, int nwords_2nd,
134  int* detector_buf_3rd, int nwords_3rd,
135  int* detector_buf_4th, int nwords_4th,
136  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
137 
139  /* cppcheck-suppress missingOverride */
140  int* PackDetectorBuf(int* packed_buf_nwords,
141  int* const(&detector_buf_ch)[MAX_PCIE40_CH],
142  int const(&nwords_ch)[MAX_PCIE40_CH],
143  RawCOPPERPackerInfo rawcpr_info) OVERRIDE_CPP17;
144 
146  /* cppcheck-suppress missingOverride */
147  int* GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17;
148 
149  // Data Format : "B2Link PCIe40 ch Header"
150  enum {
151  POS_B2LHSLB_MAGIC = 0,
152  SIZE_B2LHSLB_HEADER = 1
153  };
154 
155 
156  // Data Format : "B2Link FEE Header"
157  enum {
158  POS_B2L_CTIME = 0,
159  SIZE_B2LFEE_HEADER = 1
160  };
161 
162  // Data Format : B2Link FEE Trailer
163  enum {
164  POS_B2LFEE_ERRCNT_CRC16 = 0,
165  SIZE_B2LFEE_TRAILER = 1
166  };
167 
168  //
169  // Data Format : "B2Link HSLB Trailer"
170  //
171  enum {
172  POS_B2LHSLB_TRL_MAGIC = 0,
173  SIZE_B2LHSLB_TRAILER = 1
174  };
175 
176 
177 
178  protected :
180  // ClassDefOverride(PostRawCOPPERFormat_latest, 2);
181 
182  };
183 
185  {
186  int pos_nwords = GetBufferPos(n) + tmp_header.POS_EXP_RUN_NO;
187  return &(m_buffer[ pos_nwords ]);
188  /* #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2 */
189  /* CheckB2LFEEHeaderVersion(n); */
190  /* #endif */
191  /* int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN; */
192  /* return &(m_buffer[ pos_nwords ]); */
193  }
194 
196  {
197  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
198  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
199  return m_buffer[ pos_nwords ];
200  }
201 
202 
204  {
205  char err_buf[500];
206  sprintf(err_buf, "[FATAL] This data format does not have COPPER counter.(block %d) Exiting...\n %s %s %d\n",
207  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
208  printf("%s", err_buf);
209  std::string err_str = err_buf; throw (err_str);
210  return 0;
211  }
212 
214  {
215  char err_buf[500];
216  sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
217  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
218  printf("%s", err_buf);
219  std::string err_str = err_buf; throw (err_str);
220  return 0;
221  }
222 
224  {
225  char err_buf[500];
226  sprintf(err_buf, "[FATAL] This function is not supported. (block %d) Exiting...\n %s %s %d\n",
227  n, __FILE__, __PRETTY_FUNCTION__, __LINE__);
228  printf("%s", err_buf);
229  std::string err_str = err_buf; throw (err_str);
230  return 0;
231  }
232 
233 
235  {
236  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
237 
238  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), tmp_trailer.GetTrlNwords());
239 
240  return (unsigned int)(m_buffer[ pos_nwords ]);
241  }
242 
244  {
245  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
246  return (unsigned int)(m_buffer[ pos_nwords ]);
247  }
248 
249 
251  {
252  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
253  return (unsigned int)(m_buffer[ pos_nwords ]);
254  }
255 
256  inline int PostRawCOPPERFormat_latest::GetEventCRC16Value(int n, int finesse_num)
257  {
258  int fin_nwords = GetFINESSENwords(n, finesse_num);
259  if (fin_nwords > 0) {
260  int* buf = GetFINESSEBuffer(n, finesse_num) + fin_nwords
261  - ((SIZE_B2LFEE_TRAILER - POS_B2LFEE_ERRCNT_CRC16) + SIZE_B2LHSLB_TRAILER) ;
262  return (int)(*buf & 0xffff);
263  }
264  return -1;
265  }
266 
267  inline int* PostRawCOPPERFormat_latest::GetDetectorBuffer(int n, int finesse_num)
268  {
269  if (GetFINESSENwords(n, finesse_num) > 0) {
270  return (GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER);
271  }
272  return NULL;
273  }
274 
275 
276  inline int PostRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
277  {
278  int nwords = 0;
279  if (GetFINESSENwords(n, finesse_num) > 0) {
280  nwords = GetFINESSENwords(n, finesse_num)
281  - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
282  }
283  return nwords;
284  }
285 
286 
288 }
289 
290 #endif
Belle2::RawCOPPERPackerInfo
struct to contain header information used by RawCOPPERFormat::Packer()
Definition: RawCOPPERPackerInfo.h:12
Belle2::PostRawCOPPERFormat_latest::GetMagicFPGATrailer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
Definition: PostRawCOPPERFormat_latest.h:234
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:275
Belle2::PostRawCOPPERFormat_latest::CheckCRC16
int CheckCRC16(int n, int finesse_num)
check magic words
Definition: PostRawCOPPERFormat_latest.cc:162
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::CheckCOPPERMagic
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
Definition: PostRawCOPPERFormat_latest.cc:113
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:59
Belle2::PostRawCOPPERFormat_latest
The Raw COPPER class ver.
Definition: PostRawCOPPERFormat_latest.h:37
Belle2::PostRawCOPPERFormat_latest::GetB2LFEE32bitEventNumber
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_latest.cc:41
Belle2::PostRawCOPPERFormat_latest::GetExpRunSubrunBuf
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PostRawCOPPERFormat_latest.h:184
Belle2::PostRawCOPPERFormat_latest::GetDriverChkSum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
Definition: PostRawCOPPERFormat_latest.h:195
Belle2::RawCOPPERFormat_latest::GetFINESSEBuffer
int * GetFINESSEBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to a FINESSE buffer.
Definition: RawCOPPERFormat_latest.h:406
Belle2::PostRawCOPPERFormat_latest::CalcDriverChkSum
unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17
calc COPPER driver's checksum value
Definition: PostRawCOPPERFormat_latest.cc:27
Belle2::RawTrailer_latest::GetTrlNwords
int GetTrlNwords()
Set magic word.
Definition: RawTrailer_latest.h:132
Belle2::RawCOPPERFormat_latest::tmp_header
RawHeader_latest tmp_header
header ( not recorded )
Definition: RawCOPPERFormat_latest.h:233
Belle2::PostRawCOPPERFormat_latest::GetDetectorBuffer
int * GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to detector buffer.
Definition: PostRawCOPPERFormat_latest.h:267
Belle2::PostRawCOPPERFormat_latest::CheckB2LHSLBMagicWords
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words
Definition: PostRawCOPPERFormat_latest.cc:152
Belle2::PostRawCOPPERFormat_latest::GetEventCRC16Value
int GetEventCRC16Value(int n, int finesse_num) OVERRIDE_CPP17
Get CRC16 value for an event.
Definition: PostRawCOPPERFormat_latest.h:256
Belle2::PostRawCOPPERFormat_latest::GetMagicDriverHeader
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Definition: PostRawCOPPERFormat_latest.h:213
Belle2::RawCOPPERFormat_latest::GetFINESSENwords
int GetFINESSENwords(int n, int finesse_num) OVERRIDE_CPP17
Get the size of a finesse buffer.
Definition: RawCOPPERFormat_latest.h:372
Belle2::PostRawCOPPERFormat_latest::PostRawCOPPERFormat_latest
PostRawCOPPERFormat_latest()
Default constructor.
Definition: PostRawCOPPERFormat_latest.cc:19
Belle2::PostRawCOPPERFormat_latest::GetMagicFPGAHeader
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
Definition: PostRawCOPPERFormat_latest.h:223
Belle2::PostRawCOPPERFormat_latest::GetTrailerChksum
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
Get checksum in RawTrailer.
Definition: PostRawCOPPERFormat_latest.h:250
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PostRawCOPPERFormat_latest::GetDetectorNwords
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
Definition: PostRawCOPPERFormat_latest.h:276
Belle2::PostRawCOPPERFormat_latest::CheckUtimeCtimeTRGType
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
Definition: PostRawCOPPERFormat_latest.cc:129
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:236
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:34
Belle2::PostRawCOPPERFormat_latest::~PostRawCOPPERFormat_latest
virtual ~PostRawCOPPERFormat_latest()
Constructor using existing pointer to raw data buffer.
Definition: PostRawCOPPERFormat_latest.cc:23
Belle2::PostRawCOPPERFormat_latest::GetMagicDriverTrailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
Definition: PostRawCOPPERFormat_latest.h:243
Belle2::PostRawCOPPERFormat_latest::GetCOPPERCounter
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
Definition: PostRawCOPPERFormat_latest.h:203
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:138