Belle II Software  release-08-01-10
PXDRawDataStructs.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <pxd/dataobjects/PXDErrorFlags.h>
12 
13 #include <boost/endian/arithmetic.hpp>
14 
15 
19 
20 namespace Belle2 {
26  namespace PXD {
27 
29  using ulittle16_t = boost::endian::little_uint16_t;
31  using ulittle32_t = boost::endian::little_uint32_t;
33  using ubig16_t = boost::endian::big_uint16_t;
35  using ubig32_t = boost::endian::big_uint32_t;
36 
37  using Belle2::PXD::PXDError::PXDErrorFlags;
38 
45  const ubig16_t data;
46 
48  inline ubig16_t getData(void) const
49  {
50  return data;
51  };
53  inline unsigned short getFrameType(void) const
54  {
55  return (data & 0x7800) >> 11;
56  };
58  inline unsigned short getErrorFlag(void) const
59  {
60  return (data & 0x8000) >> 15;
61  };
63  inline unsigned short getMisc(void) const
64  {
65  return data & 0x7FF;
66  };
68  void print(void) const;
69  };
70 
75  struct dhc_start_frame {
83  const ubig16_t exp_run;
84  const unsigned int crc32;
85  // fixed length, only for reading
86 
88  inline unsigned short getRunSubrun(void) const
89  {
90  return run_subrun;
91  };
93  inline unsigned short getExpRun(void) const
94  {
95  return exp_run;
96  };
98  inline unsigned short getEventNrLo(void) const
99  {
100  return trigger_nr_lo;
101  };
103  inline unsigned short getEventNrHi(void) const
104  {
105  return trigger_nr_hi;
106  };
107 
109  bool isFakedData(void) const;
111  inline unsigned int getFixedSize(void) const
112  {
113  return 20;
114  };
116  void print(void) const;
118  inline unsigned short get_active_dhe_mask(void) const
119  {
120  return word0.getMisc() & 0x1F;
121  };
123  inline unsigned short get_dhc_id(void) const
124  {
125  return (word0.getMisc() >> 5) & 0xF;
126  };
128  inline unsigned short get_subrun(void) const
129  {
130  return run_subrun & 0x00FF;
131  };
133  inline unsigned short get_run(void) const
134  {
135  return (((run_subrun & 0xFF00) >> 8) | ((exp_run & 0x003F) << 8));
136  };
138  inline unsigned short get_experiment(void) const
139  {
140  return (exp_run & 0xFFC0) >> 6;
141  };
143  inline unsigned short get_gated_flag(void) const
144  {
145  return (word0.getMisc() & 0x200) != 0;
146  };
148  inline unsigned short get_gated_isher(void) const
149  {
150  return (word0.getMisc() & 0x400) != 0;
151  };
152  };
153 
165  const unsigned int crc32;
166  // fixed length
167 
169  inline unsigned short getEventNrLo(void) const
170  {
171  return trigger_nr_lo;
172  };
174  inline unsigned short getEventNrHi(void) const
175  {
176  return trigger_nr_hi;
177  };
179  inline unsigned short getStartFrameNr(void) const
180  {
181  return (sfnr_offset & 0xFC00) >> 10;
182  };
184  inline unsigned short getTriggerGate(void) const
185  {
186  return sfnr_offset & 0xFF;
187  };
189  inline unsigned int getFixedSize(void) const
190  {
191  return 16;
192  };
194  void print(void) const;
196  inline unsigned int getActiveDHPMask(void) const
197  {
198  return word0.getMisc() & 0xF;
199  };
201  inline unsigned int getDHEId(void) const
202  {
203  return (word0.getMisc() >> 4) & 0x3F;
204  };
205  };
206 
215  const ubig16_t data[96];
216  const unsigned int crc32;
217  // fixed length
218 
220  inline unsigned short getEventNrLo(void) const
221  {
222  return trigger_nr_lo;
223  };
225  inline unsigned int getFixedSize(void) const
226  {
227  return (4 + 96) * 2;
228  };
230  inline unsigned int getDHEId(void) const
231  {
232  return (word0.getMisc() >> 4) & 0x3F;
233  };
234  };
235 
243  // an unbelievable amount of words may follow
244  // and finally a 32 bit checksum
245 
247  inline unsigned short getEventNrLo(void) const
248  {
249  return trigger_nr_lo;
250  };
252  void print(void) const;
254  inline unsigned short getDHEId(void) const
255  {
256  return (word0.getMisc() >> 4) & 0x3F;
257  };
259  inline unsigned short getDHPPort(void) const
260  {
261  return (word0.getMisc()) & 0x3;
262  };
264  inline bool getDataReformattedFlag(void) const
265  {
266  return (word0.getMisc() >> 3) & 0x1;
267  };
268  };
269 
275  };
276 
282  };
283 
291  const ubig32_t magic1;
294  const ubig32_t magic2;
297  const unsigned int crc32;
298 
300  inline unsigned int getFixedSize(void) const
301  {
302  return 32;
303  };
305  inline unsigned short get_trig_nr0(void) const
306  {
307  return trignr0;
308  };
310  inline unsigned int get_trig_nr1(void) const
311  {
312  return trignr1;
313  };
315  inline unsigned int get_trig_nr2(void) const
316  {
317  return trignr2;
318  };
320  inline unsigned int get_trig_tag1(void) const
321  {
322  return trigtag1;
323  };
325  inline unsigned int get_trig_tag2(void) const
326  {
327  return trigtag2;
328  };
330  inline unsigned short get_subrun1(void) const
331  {
332  return trigtag1 & 0xFF;
333  };
335  inline unsigned short get_run1(void) const
336  {
337  return ((trigtag1 & 0x003FFF00) >> 8);
338  };
340  inline unsigned short get_experiment1(void) const
341  {
342  return (trigtag1 & 0xFFC00000) >> 22;
343  };
345  inline unsigned short get_subrun2(void) const
346  {
347  return trigtag2 & 0xFF;
348  };
350  inline unsigned short get_run2(void) const
351  {
352  return ((trigtag2 & 0x003FFF00) >> 8);
353  };
355  inline unsigned short get_experiment2(void) const
356  {
357  return (trigtag2 & 0xFFC00000) >> 22;
358  };
360  void print(void) const;
361 
363  void check_error(
364  PXDErrorFlags& errormask,
365  bool ignore_datcon_flag = false,
366  bool ignore_hltroi_magic_flag = false,
367  bool ignore_merger_mm_flag = false
368  ) const;
369 
371  inline bool is_fake_datcon(void) const
372  {
373  return (magic2 == 0xCAFE0000 && trignr2 == 0x00000000 && trigtag2 == 0x00000000);
374  };
376  inline bool is_Accepted(void) const
377  {
378  return (magic1 & 0x8000) != 0;
379  };
381  inline bool is_SendROIs(void) const
382  {
383  return (magic1 & 0x2000) != 0;
384  };
386  inline bool is_SendUnfiltered(void) const
387  {
388  return (magic1 & 0x4000) != 0;
389  };
390  };
391 
399  // plus n* ROIs (64 bit)
400  // plus inner checksum 32bit
401  // plus checksum 32bit
402 
404  inline unsigned short get_trig_nr0(void) const
405  {
406  return trignr0;
407  };
409  void check_error(
410  PXDErrorFlags& errormask,
411  int length,
412  bool ignore_inv_size_flag = false
413  ) const;
415  void print(void) const;
417  inline int getMinSize(void) const {return 4 + 4 + 4;};
419  unsigned int check_inner_crc(PXDErrorFlags& /*errormask*/, unsigned int /*length*/) const
420  {
421  // Parts of the data are now in the ONSEN Trigger frame,
422  // therefore the inner CRC cannot be checked that easily!
423  // TODO can be re-implemented if needed
424  return 0;
425  };
426  };
427 
435  const unsigned int crc32;
437 
439  inline unsigned int getFixedSize(void) const
440  {
441  return 8;
442  };
444  void print(void) const;
446  inline unsigned short getDHEId(void) const
447  {
448  return (word0.getMisc() >> 4) & 0x3F;
449  };
451  inline unsigned short getDHPPort(void) const
452  {
453  return (word0.getMisc()) & 0x3;
454  };
456  unsigned short getErrorBits(void) const;
457  };
458 
463  struct dhc_end_frame {
468  const unsigned int crc32;
469  // fixed length
470 
472  unsigned int get_words(void) const
473  {
474  return wordsinevent;
475  }
477  inline unsigned int getFixedSize(void) const
478  {
479  return 16;
480  };
482  bool isFakedData(void) const;
484  void print(void) const;
486  inline unsigned int get_dhc_id(void) const
487  {
488  return (word0.getMisc() >> 5) & 0xF;
489  };
491  inline unsigned int getErrorInfo(void) const
492  {
493  return errorinfo;
494  };
495  };
496 
507  const unsigned int crc32;
508  // fixed length
509 
511  unsigned int get_words(void) const
512  {
513  return wordsineventlo | ((unsigned int)wordsineventhi << 16);
514  }
516  inline unsigned int getFixedSize(void) const
517  {
518  return 16;
519  };
521  void print(void) const;
523  inline unsigned int getDHEId(void) const
524  {
525  return (word0.getMisc() >> 4) & 0x3F;
526  };
528  inline unsigned int getErrorInfo(void) const
529  {
530  return errorinfo;
531  };
533  unsigned int getErrorStateMachineDHP(int dhpid) const;
535  unsigned int getErrorStateMachineStartDHP(int dhpid) const;
537  unsigned int getErrorStateMachineEndDHP(int dhpid) const;
538  };
539 
540 
544 
550  class dhc_frames {
551  public:
552  union {
553  const void* data;
565  };
566  unsigned int datasize;
567  int type;
568  int length;
569 
572  {
573  data = 0;
574  datasize = 0;
575  type = -1;
576  length = 0;
577  };
579  int getFrameType(void)
580  {
581  return type;
582  };
587  void set(const void* d, unsigned int t)
588  {
589  data = d;
590  type = t;
591  length = 0;
592  };
598  void set(const void* d, unsigned int t, unsigned int l)
599  {
600  data = d;
601  type = t;
602  length = l;
603  };
607  void set(const void* d)
608  {
609  data = d;
610  type = reinterpret_cast <const dhc_frame_header_word0*>(data)->getFrameType();
611  length = 0;
612  };
614  inline unsigned int getEventNrLo(void) const
615  {
616  return ((ubig16_t*)data)[1];
617  };
619  void check_padding(PXDErrorFlags& errormask);
621  void check_crc(PXDErrorFlags& errormask, bool ignore_crc_flag = false);
622 
624  unsigned int getFixedSize(void);
625 
626  };
627  };
629 };
DHC frame wrapper class.
const dhc_ghost_frame * data_ghost_frame
data_ghost_frame
void set(const void *d, unsigned int t, unsigned int l)
set data, type and length
const dhc_direct_readout_frame_zsd * data_direct_readout_frame_zsd
data_direct_readout_frame_zsd
unsigned int getEventNrLo(void) const
get event nr lo (from data)
const dhc_end_frame * data_dhc_end_frame
data_dhc_end_frame
const void * data
no type
void set(const void *d)
set data (get type from dhc_frame_header_word0 and set length to 0)
unsigned int getFixedSize(void)
get fixed size
int getFrameType(void)
get type of frame
const dhc_dhe_start_frame * data_dhe_start_frame
data_dhe_start_frame
void set(const void *d, unsigned int t)
set data and type (and length to 0)
const dhc_start_frame * data_dhc_start_frame
data_dhc_start_frame
const dhc_direct_readout_frame * data_direct_readout_frame
data_direct_readout_frame
const dhc_dhe_end_frame * data_dhe_end_frame
data_dhe_end_frame
void check_padding(PXDErrorFlags &errormask)
check padding and return it
const dhc_onsen_roi_frame * data_onsen_roi_frame
data_onsen_roi_frame
const dhc_direct_readout_frame_raw * data_direct_readout_frame_raw
data_direct_readout_frame_raw
const dhc_commode_frame * data_commode_frame
data_commode_frame
void check_crc(PXDErrorFlags &errormask, bool ignore_crc_flag=false)
check crc and return it
unsigned int datasize
datasize
dhc_frames(void)
set default values
const dhc_onsen_trigger_frame * data_onsen_trigger_frame
data_onsen_trigger_frame
boost::endian::little_uint16_t ulittle16_t
define alias ulittle16_t
boost::endian::big_uint32_t ubig32_t
define alias ubig32_t
boost::endian::little_uint32_t ulittle32_t
define alias ulittle32_t
boost::endian::big_uint16_t ubig16_t
define alias ubig16_t
Abstract base class for different kinds of events.
DHH common mode frame data struct.
const dhc_frame_header_word0 word0
word0
unsigned int getFixedSize(void) const
100 words
const unsigned int crc32
crc32
const ubig16_t trigger_nr_lo
trigger_nr_lo
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned short getEventNrLo(void) const
get trigger_nr_lo
DHE End frame data struct.
const dhc_frame_header_word0 word0
word0
unsigned int getFixedSize(void) const
get fixed size
const unsigned int crc32
crc32
unsigned int get_words(void) const
get words
const ubig16_t trigger_nr_lo
trigger_nr_lo
unsigned int getDHEId(void) const
get DHE Id
unsigned int getErrorStateMachineStartDHP(int dhpid) const
get error state machine start DHP
const ubig16_t wordsineventhi
wordsineventhi
unsigned int getErrorStateMachineDHP(int dhpid) const
get error state machine DHP
const ubig16_t wordsineventlo
words swapped... because of DHE 16 bit handling
unsigned int getErrorInfo(void) const
get error info
unsigned int getErrorStateMachineEndDHP(int dhpid) const
get error state machine end DHP
const ubig32_t errorinfo
not well defined yet
DHH start frame data struct.
const ubig16_t dhe_time_tag_hi
dhe_time_tag_hi
const ubig16_t trigger_nr_hi
trigger_nr_hi
const dhc_frame_header_word0 word0
word0
const ubig16_t dhe_time_tag_lo
dhe_time_tag_lo
unsigned int getFixedSize(void) const
8 words
const ubig16_t trigger_nr_lo
trigger_nr_lo
unsigned int getDHEId(void) const
get DHE Id (from word0)
unsigned short getEventNrLo(void) const
get trigger_nr_lo
const ubig16_t sfnr_offset
sfnr_offset
unsigned short getTriggerGate(void) const
trigger gate (updated to 8 bit, before 10!)
unsigned short getStartFrameNr(void) const
last DHP frame before trigger
unsigned short getEventNrHi(void) const
get trigger_nr_hi
unsigned int getActiveDHPMask(void) const
get Active DHP Mask (from word0)
DHC RAW direct readout frame data struct.
DHC Zero supressed direct readout frame data struct.
DHC direct readout frame data struct.
const dhc_frame_header_word0 word0
word0
const ubig16_t trigger_nr_lo
trigger_nr_lo
unsigned short getEventNrLo(void) const
get trigger_nr_lo
bool getDataReformattedFlag(void) const
get DataReformattedFlag (from word0)
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DHP Port (from word0)
DHC End frame data struct.
void print(void) const
print
const dhc_frame_header_word0 word0
word0
unsigned int getFixedSize(void) const
get fixed size
const unsigned int crc32
crc32
unsigned int get_words(void) const
get words
const ubig16_t trigger_nr_lo
trigger_nr_lo
bool isFakedData(void) const
is faked data
unsigned int get_dhc_id(void) const
get dhc id (from word0)
unsigned int getErrorInfo(void) const
get error info
const ubig32_t wordsinevent
wordsinevent
const ubig32_t errorinfo
errorinfo
DHC frame header word data struct.
unsigned short getMisc(void) const
get misc
ubig16_t getData(void) const
get the data
unsigned short getFrameType(void) const
get type of frame
unsigned short getErrorFlag(void) const
get error flag
DHC Ghost frame data struct.
const dhc_frame_header_word0 word0
word0
unsigned int getFixedSize(void) const
fixed length
const unsigned int crc32
crc32
const ubig16_t trigger_nr_lo
trigger_nr_lo
unsigned short getErrorBits(void) const
get Error Bits
unsigned short getDHEId(void) const
get DHE Id (from word0)
unsigned short getDHPPort(void) const
get DDHP port (from word0)
ONSEN (debug) ROI frame data struct.
const dhc_frame_header_word0 word0
mainly empty
unsigned short get_trig_nr0(void) const
get trignr0
unsigned int check_inner_crc(PXDErrorFlags &, unsigned int) const
check inner crc (currently not implemented/needed)
void check_error(PXDErrorFlags &errormask, int length, bool ignore_inv_size_flag=false) const
check error and return error mask
int getMinSize(void) const
4 byte header, ROIS (n*8), 4 byte copy of inner CRC, 4 byte outer CRC
ONSEN Trigger frame data struct.
unsigned short get_subrun1(void) const
get subrun1 (from trigtag1)
const dhc_frame_header_word0 word0
word0
unsigned int getFixedSize(void) const
8*4 bytes might still be changed
unsigned int get_trig_nr1(void) const
get trignr1
bool is_SendUnfiltered(void) const
is sendUnfiltered
const ubig32_t trignr2
redundant, DATCON Trigger/Tag part 1
const ubig32_t magic1
CAFExxxx , redundant.
const ubig32_t trigtag2
redundant, DATCON Trigger/Tag part 2
bool is_SendROIs(void) const
is sendROIs
void check_error(PXDErrorFlags &errormask, bool ignore_datcon_flag=false, bool ignore_hltroi_magic_flag=false, bool ignore_merger_mm_flag=false) const
check error and return error mask
const ubig32_t trignr1
HLT Trigger/Tag part 1.
unsigned int get_trig_tag2(void) const
get trigtag2
unsigned int get_trig_tag1(void) const
get trigtag1
unsigned short get_run2(void) const
get run2 (from trigtag2)
bool is_fake_datcon(void) const
is fake datcon
const ubig32_t magic2
CAFExxxx, redundant.
unsigned short get_experiment1(void) const
get experiment1 (from trigtag1)
unsigned int get_trig_nr2(void) const
get trignr2
unsigned short get_experiment2(void) const
get experiment2
unsigned short get_trig_nr0(void) const
get trignr0
unsigned short get_subrun2(void) const
get subrun2 (from trigtag2)
bool is_Accepted(void) const
is accepted
unsigned short get_run1(void) const
get run1 (from trigtag1)
const ubig32_t trigtag1
HLT Trigger/Tag part 2.
DHC start frame data struct.
void print(void) const
print
const ubig16_t trigger_nr_hi
trigger_nr_hi
const dhc_frame_header_word0 word0
word0
unsigned int getFixedSize(void) const
get fixed size (byte)
const ubig16_t exp_run
exp_run
const unsigned int crc32
crc32
unsigned short get_gated_isher(void) const
get gated_isher (from word0)
const ubig16_t trigger_nr_lo
trigger_nr_lo
unsigned short get_subrun(void) const
get subrun (from run_subrun)
unsigned short getRunSubrun(void) const
get run_subrun
unsigned short get_run(void) const
get run (from run_subrun)
unsigned short get_dhc_id(void) const
get dhc_id (from word0)
const ubig16_t time_tag_hi
time_tag_hi
const ubig16_t time_tag_mid
time_tag_mid
bool isFakedData(void) const
isFakedData
unsigned short getEventNrLo(void) const
get trigger_nr_lo
unsigned short getExpRun(void) const
get exp_run
unsigned short get_experiment(void) const
get experiment (from exp_run)
unsigned short get_gated_flag(void) const
get gated_flag (from word0)
unsigned short get_active_dhe_mask(void) const
get active_dhe_mask (from word0)
const ubig16_t run_subrun
run_subrun
const ubig16_t time_tag_lo_and_type
time_tag_lo_and_type
unsigned short getEventNrHi(void) const
get trigger_nr_hi