CRTFragment.hh
Go to the documentation of this file.
1 /* Author: Matthew Strait <mstrait@fnal.gov> */
2 
3 #ifndef artdaq_demo_Overlays_CRTFragment_hh
4 #define artdaq_demo_Overlays_CRTFragment_hh
5 
6 #include "artdaq-core/Data/Fragment.hh"
7 
8 #include <ostream>
9 
10 namespace CRT
11 {
12  class Fragment;
13 }
14 
16 {
17 public:
18 
19  struct header_t{
20  uint8_t magic; // must be 'M'
21  uint8_t nhit;
22  uint16_t module_num;
23 
24  // The global ProtoDUNE-SP timestamp
25  uint64_t fifty_mhz_time;
26 
27  // The raw timestamp held by the CRT's internal 32-bit counter. You don't
28  // want to look at this unless you are a CRT expert. Should start at zero
29  // at the start of the run, increment one-to-one with fifty_mhz_time, and
30  // roll over every 86 seconds.
31  uint32_t raw_backend_time;
32 
33  // Must tell GCC not to add padding, even at the cost of performance,
34  // because this struct is describing exactly how the input data is
35  // laid out.
36  } __attribute__((packed));
37 
38  struct hit_t{
39  uint8_t magic; // must be 'H'
40  uint8_t channel;
41  int16_t adc;
42 
43  // This time, disabling padding doesn't make a difference in struct
44  // layout, but I am including it for consistency.
45  } __attribute__((packed));
46 
47  // Return the module number for this fragment. A CRT fragment consists
48  // of a set of hits sharing a time stamp from one module.
49  uint16_t module_num() const;
50 
51  // Return the number of hits claimed in the header of this fragment
52  size_t num_hits() const;
53 
54  // Return the value of the 50MHz counter that holds the raw internal CRT time
55  uint64_t raw_backend_time() const;
56 
57  // Return the value of the 50MHz counter that holds the global ProtoDUNE time
58  uint64_t fifty_mhz_time() const;
59 
60  // Return the channel number of the ith hit. That hit must exist.
61  uint8_t channel(const int i) const;
62 
63  // Return the ADC value of the ith hit. That hit must exist.
64  int16_t adc(const int i) const;
65 
66  // Print the header to stdout, even if it is bad, but not if it
67  // isn't all there.
68  void print_header() const;
69 
70  // Print the given hit to stdout, even if it is bad, but not if it
71  // isn't all there.
72  void print_hit(const int i) const;
73 
74  // Print all the hits
75  void print_hits() const;
76 
77  // Returns true if the header contains sensible values. Otherwise,
78  // prints a complaint and returns false. Assumes header is complete
79  // (check good_size() first).
80  bool good_header() const;
81 
82  // Returns true if the hit contains sensible values. Otherwise,
83  // prints a complaint and returns false. Assumes hit exists and
84  // is complete (check good_size() first).
85  bool good_hit(const int i) const;
86 
87  // Return the size of the CRT fragment in bytes.
88  unsigned int size() const;
89 
90  // Returns true if the fragment is as big as the header says it is,
91  // and false if it isn't, or it doesn't even have a full header.
92  // i.e. if this is false, you're going to seg fault (or wish you had)
93  // if you read the fragment.
94  bool good_size() const;
95 
96  // Return true if the fragment contains a complete and sensible event.
97  bool good_event() const;
98 
99  // Return a pointer to hit 'i'. Not range checked.
100  const hit_t * hit(const int i) const;
101 
102  // Return a pointer to the header
103  const header_t * header() const;
104 
105  explicit Fragment(artdaq::Fragment const& f) : thefrag(f) {}
106 
107 private:
108  artdaq::Fragment const& thefrag;
109 };
110 
111 #endif /* artdaq_demo_Overlays_CRTFragment_hh */
void print_hit(const int i) const
Definition: CRTFragment.cc:67
unsigned int size() const
Definition: CRTFragment.cc:136
void print_header() const
Definition: CRTFragment.cc:48
int16_t adc(const int i) const
Definition: CRTFragment.cc:41
size_t num_hits() const
Definition: CRTFragment.cc:17
bool good_hit(const int i) const
Definition: CRTFragment.cc:114
bool good_event() const
Definition: CRTFragment.cc:178
Fragment(artdaq::Fragment const &f)
Definition: CRTFragment.hh:105
struct CRT::Fragment::header_t __attribute__((packed))
uint8_t channel(const int i) const
Definition: CRTFragment.cc:35
const header_t * header() const
Definition: CRTFragment.cc:199
bool good_size() const
Definition: CRTFragment.cc:145
void print_hits() const
Definition: CRTFragment.cc:83
bool good_header() const
Definition: CRTFragment.cc:93
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108
const hit_t * hit(const int i) const
Definition: CRTFragment.cc:192