Belle II Software  release-05-02-19
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 
55  // virtual int GetBufferPos(int n);
56 
57  //
58  // Get information from 13words "COPPER header" attached by COPPER board
59  //
61  unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17;
62 
63  //
64  // Get information from "B2link(attached by FEE and HLSB) header"
65  //
67  // virtual int* GetFTSW2Words(int n);
68 
70  virtual int* GetExpRunSubrunBuf(int n) OVERRIDE_CPP17;
71 
73  virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17;
74 
75  //
76  // read magic word to check data
77  //
79  unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17;
80 
82  unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17;
83 
85  unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17;
86 
88  unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17;
89 
91  unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17;
92 
94  bool CheckCOPPERMagic(int n) OVERRIDE_CPP17;
95 
97  unsigned int FillTopBlockRawHeader(unsigned int m_node_id,
98  unsigned int prev_eve32, unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
99 
101  unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17;
102 
104  unsigned int CalcDriverChkSum(int n) OVERRIDE_CPP17;
105 
107  void CheckData(int n,
108  unsigned int prev_evenum, unsigned int* cur_evenum,
109  unsigned int prev_copper_ctr, unsigned int* cur_copper_ctr,
110  unsigned int prev_exprunsubrun_no, unsigned int* cur_exprunsubrun_no) OVERRIDE_CPP17;
111 
113  void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17;
114 
116  int CheckB2LHSLBMagicWords(int* finesse_buf, int finesse_nwords);
117 
119  int CalcReducedDataSize(int* bufin, int nwords, int num_events, int num_nodes);
120  // int CalcReducedDataSize(RawDataBlock* raw_datablk);
121 
123  void CopyReducedData(int* bufin, int nwords, int num_events, int num_nodes, int* buf_to, int* nwords_to);
124  // void CopyReducedData(RawDataBlock* raw_datablk, int* buf_to, int delete_flag_from);
125 
127  int CalcReducedNwords(int n);
128 
130  int CopyReducedBuffer(int n, int* buf_to);
131 
133  int CheckCRC16(int n, int finesse_num);
134 
136  int* PackDetectorBuf(int* packed_buf_nwords,
137  int* detector_buf_1st, int nwords_1st,
138  int* detector_buf_2nd, int nwords_2nd,
139  int* detector_buf_3rd, int nwords_3rd,
140  int* detector_buf_4th, int nwords_4th,
141  RawCOPPERPackerInfo rawcprpacker_info) OVERRIDE_CPP17;
142 
144  /* cppcheck-suppress missingOverride */
145  int* PackDetectorBuf(int* packed_buf_nwords,
146  int* const(&detector_buf_ch)[MAX_PCIE40_CH],
147  int const(&nwords_ch)[MAX_PCIE40_CH],
148  RawCOPPERPackerInfo rawcpr_info) OVERRIDE_CPP17;
149 
151  /* cppcheck-suppress missingOverride */
152  int* GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17;
153 
154  //
155  // Data Format : "B2Link HSLB Header"
156  //
157  enum {
158  POS_MAGIC_B2LHSLB = 0,
159  // POS_EVE_CNT_B2LHSLB = 1,
160  SIZE_B2LHSLB_HEADER = 1
161  };
162 
163  // Data Format : "B2Link FEE Header"
164  // modified by Nov. 21, 2013, Nakao-san's New firmware?
165  enum {
166  POS_TT_CTIME_TYPE = 0,
167  POS_TT_TAG = 1,
168  POS_TT_UTIME = 2,
169  POS_EXP_RUN = 3,
170  POS_B2L_CTIME = 4,
171  SIZE_B2LFEE_HEADER = 5
172  };
173 
174 
175  //
176  // Data Format : B2Link FEE Trailer
177  //
178  enum {
179  POS_TT_CTIME_B2LFEE = 0,
180  POS_CHKSUM_B2LFEE = 1,
181  SIZE_B2LFEE_TRAILER = 2
182  };
183 
184 
185  //
186  // Data Format : "B2Link HSLB Trailer"
187  //
188  enum {
189  POS_CHKSUM_B2LHSLB = 0,
190  SIZE_B2LHSLB_TRAILER = 1
191  };
192 
193  //
194  // magic words attached by HSLB
195  //
196  enum {
197  B2LHSLB_HEADER_MAGIC = 0xFFAA0000,
198  B2LHSLB_TRAILER_MAGIC = 0xFF550000
199  };
200 
203 
204  protected :
206  // ClassDefOverride(PreRawCOPPERFormat_latest, 2);
207 
208  };
209 
210 
212  {
213 #ifdef USE_B2LFEE_FORMAT_BOTH_VER1_AND_2
214  CheckB2LFEEHeaderVersion(n);
215 #endif
216  int pos_nwords = GetOffset1stFINESSE(n) + SIZE_B2LHSLB_HEADER + POS_EXP_RUN;
217  return &(m_buffer[ pos_nwords ]);
218  }
219 
220 
221 
222  inline unsigned int PreRawCOPPERFormat_latest::GetMagicDriverHeader(int/* n */)
223  {
224  char err_buf[500];
225  sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
226  __FILE__, __PRETTY_FUNCTION__, __LINE__);
227  printf("[DEBUG] %s\n", err_buf);
228  B2FATAL(err_buf);
229  return 0;
230  }
231 
232  inline unsigned int PreRawCOPPERFormat_latest::GetMagicFPGAHeader(int/* n */)
233  {
234  char err_buf[500];
235  sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
236  __FILE__, __PRETTY_FUNCTION__, __LINE__);
237  printf("[DEBUG] %s\n", err_buf);
238  B2FATAL(err_buf);
239  return 0;
240  }
241 
243  {
244  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 3;
245 
246  // printf( "[DEBUG] 1 %d 2 %d 3 %d\n", GetBufferPos(n), GetBlockNwords(n), trl.GetTrlNwords());
247 
248  return (unsigned int)(m_buffer[ pos_nwords ]);
249  }
250 
252  {
253  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() - 1;
254  return (unsigned int)(m_buffer[ pos_nwords ]);
255  }
256 
257 
259  {
260  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n)
261  - tmp_trailer.RAWTRAILER_NWORDS - SIZE_COPPER_DRIVER_TRAILER;
262  return m_buffer[ pos_nwords ];
263  }
264 
265 
266  inline unsigned int PreRawCOPPERFormat_latest::GetCOPPERCounter(int/* n */)
267  {
268  char err_buf[500];
269  sprintf(err_buf, "[FATAL] This function is not supported. Exiting...: \n%s %s %d\n",
270  __FILE__, __PRETTY_FUNCTION__, __LINE__);
271  printf("[DEBUG] %s\n", err_buf);
272  B2FATAL(err_buf);
273  return 0;
274  }
275 
277  {
278  int pos_nwords = GetBufferPos(n) + GetBlockNwords(n) - tmp_trailer.GetTrlNwords() + tmp_trailer.POS_CHKSUM;
279  return (unsigned int)(m_buffer[ pos_nwords ]);
280  }
281 
282  inline int* PreRawCOPPERFormat_latest::GetDetectorBuffer(int n, int finesse_num)
283  {
284  if (GetFINESSENwords(n, finesse_num) > 0) {
285  return (GetFINESSEBuffer(n, finesse_num) + SIZE_B2LHSLB_HEADER + SIZE_B2LFEE_HEADER);
286  }
287  return NULL;
288  }
289 
290  inline int PreRawCOPPERFormat_latest::GetDetectorNwords(int n, int finesse_num)
291  {
292  int nwords = 0;
293  if (GetFINESSENwords(n, finesse_num) > 0) {
294  nwords = GetFINESSENwords(n, finesse_num)
295  - (SIZE_B2LHSLB_HEADER + SIZE_B2LHSLB_TRAILER + SIZE_B2LFEE_HEADER + SIZE_B2LFEE_TRAILER);
296  }
297  return nwords;
298  }
299 
300 
302 }
303 #endif
Belle2::RawCOPPERPackerInfo
struct to contain header information used by RawCOPPERFormat::Packer()
Definition: RawCOPPERPackerInfo.h:12
Belle2::RawCOPPERFormat_latest::GetOffset1stFINESSE
int GetOffset1stFINESSE(int n) OVERRIDE_CPP17 FINAL_CPP17
get # of offset words for FINESSE slot A buffer position
Definition: RawCOPPERFormat_latest.cc:213
Belle2::PreRawCOPPERFormat_latest::CheckUtimeCtimeTRGType
void CheckUtimeCtimeTRGType(int n) OVERRIDE_CPP17
check data contents
Definition: PreRawCOPPERFormat_latest.cc:292
Belle2::PreRawCOPPERFormat_latest::GetMagicFPGATrailer
unsigned int GetMagicFPGATrailer(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA trailer
Definition: PreRawCOPPERFormat_latest.h:242
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::PostRawCOPPERFormat_latest
The Raw COPPER class ver.
Definition: PostRawCOPPERFormat_latest.h:37
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:124
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:451
Belle2::PreRawCOPPERFormat_latest::GetB2LFEE32bitEventNumber
virtual unsigned int GetB2LFEE32bitEventNumber(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PreRawCOPPERFormat_latest.cc:40
Belle2::PreRawCOPPERFormat_latest::GetExpRunSubrunBuf
virtual int * GetExpRunSubrunBuf(int n) OVERRIDE_CPP17
get b2l block from "FEE b2link header"
Definition: PreRawCOPPERFormat_latest.h:211
Belle2::PreRawCOPPERFormat_latest::GetDriverChkSum
unsigned int GetDriverChkSum(int n) OVERRIDE_CPP17
read COPPER driver's checksum value
Definition: PreRawCOPPERFormat_latest.h:258
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:612
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::PreRawCOPPERFormat_latest::CheckCRC16
int CheckCRC16(int n, int finesse_num)
check CRC16 in B2LFEE trailer
Definition: PreRawCOPPERFormat_latest.cc:568
Belle2::RawTrailer_latest::GetTrlNwords
int GetTrlNwords()
Set magic word.
Definition: RawTrailer_latest.h:132
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:383
Belle2::PreRawCOPPERFormat_latest::GetDetectorBuffer
int * GetDetectorBuffer(int n, int finesse_num) OVERRIDE_CPP17
Get a pointer to detector buffer.
Definition: PreRawCOPPERFormat_latest.h:282
Belle2::PreRawCOPPERFormat_latest::CheckCOPPERMagic
bool CheckCOPPERMagic(int n) OVERRIDE_CPP17
Check if COPPER Magic words are correct.
Definition: PreRawCOPPERFormat_latest.cc:282
Belle2::PreRawCOPPERFormat_latest::GetMagicDriverHeader
unsigned int GetMagicDriverHeader(int n) OVERRIDE_CPP17
get magic word of COPPER driver header
Definition: PreRawCOPPERFormat_latest.h:222
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::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:486
Belle2::PreRawCOPPERFormat_latest::CopyReducedBuffer
int CopyReducedBuffer(int n, int *buf_to)
copy data to reduced buffer
Definition: PreRawCOPPERFormat_latest.cc:533
Belle2::PreRawCOPPERFormat_latest::m_reduced_rawcpr
PostRawCOPPERFormat_latest m_reduced_rawcpr
data fromat after size reduction
Definition: PreRawCOPPERFormat_latest.h:202
Belle2::PreRawCOPPERFormat_latest::GetMagicFPGAHeader
unsigned int GetMagicFPGAHeader(int n) OVERRIDE_CPP17
get magic word of COPPER FPGA header
Definition: PreRawCOPPERFormat_latest.h:232
Belle2::PreRawCOPPERFormat_latest::GetTrailerChksum
unsigned int GetTrailerChksum(int n) OVERRIDE_CPP17
get a checksum on trailer
Definition: PreRawCOPPERFormat_latest.h:276
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::PreRawCOPPERFormat_latest::GetDetectorNwords
int GetDetectorNwords(int n, int finesse_num) OVERRIDE_CPP17
get Detector buffer length
Definition: PreRawCOPPERFormat_latest.h:290
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::PreRawCOPPERFormat_latest::GetMagicDriverTrailer
unsigned int GetMagicDriverTrailer(int n) OVERRIDE_CPP17
get magic word of COPPER driver trailer
Definition: PreRawCOPPERFormat_latest.h:251
Belle2::PreRawCOPPERFormat_latest::CalcReducedNwords
int CalcReducedNwords(int n)
calculate reduced data size
Definition: PreRawCOPPERFormat_latest.cc:522
Belle2::PreRawCOPPERFormat_latest::GetCOPPERCounter
unsigned int GetCOPPERCounter(int n) OVERRIDE_CPP17
get posistion of COPPER block in unit of word
Definition: PreRawCOPPERFormat_latest.h:266
Belle2::PreRawCOPPERFormat_latest::CheckB2LHSLBMagicWords
int CheckB2LHSLBMagicWords(int *finesse_buf, int finesse_nwords)
check magic words of B2link HSLB header/trailer
Definition: PreRawCOPPERFormat_latest.cc:544