Classes | Public Member Functions | Private Attributes | List of all members
CRT::Fragment Class Reference

#include <CRTFragment.hh>

Classes

struct  header_t
 
struct  hit_t
 

Public Member Functions

struct CRT::Fragment::header_t __attribute__ ((packed))
 
struct CRT::Fragment::hit_t __attribute__ ((packed))
 
uint16_t module_num () const
 
size_t num_hits () const
 
uint64_t raw_backend_time () const
 
uint64_t fifty_mhz_time () const
 
uint8_t channel (const int i) const
 
int16_t adc (const int i) const
 
void print_header () const
 
void print_hit (const int i) const
 
void print_hits () const
 
bool good_header () const
 
bool good_hit (const int i) const
 
unsigned int size () const
 
bool good_size () const
 
bool good_event () const
 
const hit_thit (const int i) const
 
const header_theader () const
 
 Fragment (artdaq::Fragment const &f)
 

Private Attributes

artdaq::Fragment const & thefrag
 

Detailed Description

Definition at line 15 of file CRTFragment.hh.

Constructor & Destructor Documentation

CRT::Fragment::Fragment ( artdaq::Fragment const &  f)
inlineexplicit

Definition at line 105 of file CRTFragment.hh.

105 : thefrag(f) {}
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108

Member Function Documentation

struct CRT::Fragment::header_t CRT::Fragment::__attribute__ ( (packed)  )
struct CRT::Fragment::hit_t CRT::Fragment::__attribute__ ( (packed)  )
int16_t Fragment::adc ( const int  i) const

Definition at line 41 of file CRTFragment.cc.

42  {
43  return hit(i)->adc;
44  }
const hit_t * hit(const int i) const
Definition: CRTFragment.cc:192
uint8_t Fragment::channel ( const int  i) const

Definition at line 35 of file CRTFragment.cc.

36  {
37  return hit(i)->channel;
38  }
const hit_t * hit(const int i) const
Definition: CRTFragment.cc:192
uint64_t Fragment::fifty_mhz_time ( ) const

Definition at line 29 of file CRTFragment.cc.

30  {
31  return header()->fifty_mhz_time;
32  }
const header_t * header() const
Definition: CRTFragment.cc:199
bool Fragment::good_event ( ) const

Definition at line 178 of file CRTFragment.cc.

179  {
180  if(!good_size()) return false;
181 
182  if(!good_header()) return false;
183 
184  for(unsigned int i = 0; i < header()->nhit; i++)
185  if(!good_hit(i))
186  return false;
187 
188  return true;
189  }
bool good_hit(const int i) const
Definition: CRTFragment.cc:114
const header_t * header() const
Definition: CRTFragment.cc:199
bool good_size() const
Definition: CRTFragment.cc:145
bool good_header() const
Definition: CRTFragment.cc:93
bool Fragment::good_header ( ) const

Definition at line 93 of file CRTFragment.cc.

94  {
95  const header_t * const h = header();
96  if(h->magic != 'M'){
97  std::cerr << "CRT header has wrong magic: " << h->magic << "\n";
98  return false;
99  }
100  if(h->nhit == 0){
101  std::cerr << "CRT event has no hits\n";
102  return false;
103  }
104  if(h->nhit > 64){
105  std::cerr << "CRT event has more hits (" << h->nhit << ") than channels (64)\n";
106  return false;
107  }
108  return true;
109  }
const header_t * header() const
Definition: CRTFragment.cc:199
bool Fragment::good_hit ( const int  i) const

Definition at line 114 of file CRTFragment.cc.

115  {
116  const hit_t * const h = hit(i);
117  if(h->magic != 'H'){
118  std::cerr << "CRT hit has wrong magic: " << h->magic << "\n";
119  return false;
120  }
121  if(h->channel >= 64){
122  std::cerr << "CRT hit has bad channel " << h->channel << " >= 64\n";
123  return false;
124  }
125  if(h->adc >= 4096){
126  // It is a 12-bit ADC. This number probably represents the raw
127  // ADC value before pedestal subtraction, but in any case, the
128  // pedestal is positive, so the value still can't exceed 4095.
129  std::cerr << "CRT hit has bad ADC value " << h->adc << " >= 4096\n";
130  return false;
131  }
132  return true;
133  }
const hit_t * hit(const int i) const
Definition: CRTFragment.cc:192
bool Fragment::good_size ( ) const

Definition at line 145 of file CRTFragment.cc.

146  {
147  if(size() < sizeof(header_t)){
148  std::cerr << "CRT fragment isn't as big (" << size() << "B) as header (" << sizeof(header_t) << "B)\n";
149  return false;
150  }
151 
152  const unsigned int expect_size =
153  (sizeof(header_t) + header()->nhit * sizeof(hit_t)
154  + sizeof(artdaq::RawDataType) - 1)
155  /sizeof(artdaq::RawDataType)
156  *sizeof(artdaq::RawDataType);
157 
158  if(size() != expect_size){
159  std::cerr << "CRT fragment: N hit (" << header()->nhit << " -> " << expect_size << "B) mismatches size "
160  << size() << "B\n";
161  for(char * c = (char *) thefrag.dataBeginBytes();
162  c < (char *)thefrag.dataEndBytes();
163  c++){
164  std::cerr << (unsigned char)*c << "/"
165  << (isprint((unsigned char)*c)?(unsigned char)*c:'.');
166  if((c - (char*)thefrag.dataBeginBytes())%0x08 == 0x07)
167  std::cerr << " ";
168  if((c - (char*)thefrag.dataBeginBytes())%0x10 == 0x0f)
169  std::cerr << "\n";
170  }
171  std::cerr << "\n";
172  return false;
173  }
174  return true;
175  }
unsigned int size() const
Definition: CRTFragment.cc:136
const header_t * header() const
Definition: CRTFragment.cc:199
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108
const CRT::Fragment::header_t * Fragment::header ( ) const

Definition at line 199 of file CRTFragment.cc.

200  {
201  return reinterpret_cast<const header_t *>(thefrag.dataBeginBytes());
202  }
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108
const CRT::Fragment::hit_t * Fragment::hit ( const int  i) const

Definition at line 192 of file CRTFragment.cc.

193  {
194  return reinterpret_cast<const hit_t *>
195  (thefrag.dataBeginBytes() + sizeof(header_t) + i*sizeof(hit_t));
196  }
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108
uint16_t Fragment::module_num ( ) const

Definition at line 11 of file CRTFragment.cc.

12  {
13  return header()->module_num;
14  }
const header_t * header() const
Definition: CRTFragment.cc:199
size_t Fragment::num_hits ( ) const

Definition at line 17 of file CRTFragment.cc.

18  {
19  return header()->nhit;
20  }
const header_t * header() const
Definition: CRTFragment.cc:199
void Fragment::print_header ( ) const

Definition at line 48 of file CRTFragment.cc.

49  {
50  if(size() < sizeof(header_t)){
51  std::cerr << "CRT fragment smaller (" << size() << "B) than header ("
52  << sizeof(header_t) << "B), can't print\n";
53  return;
54  }
55 
56  std::cout << "CRT header: Magic = '" << header()->magic << "'\n"
57  << " n hit = " << +(header()->nhit) << "\n"
58  << " module = " << header()->module_num << "\n"
59  << " 50Mhz time = " << header()->fifty_mhz_time
60  << " (0x" << std::hex << header()->fifty_mhz_time << std::dec << ")\n"
61  << " raw time = " << header()->raw_backend_time << " (0x"
62  << std::hex << header()->raw_backend_time << std::dec << ")\n";
63  }
unsigned int size() const
Definition: CRTFragment.cc:136
QTextStream & hex(QTextStream &s)
QTextStream & dec(QTextStream &s)
const header_t * header() const
Definition: CRTFragment.cc:199
void Fragment::print_hit ( const int  i) const

Definition at line 67 of file CRTFragment.cc.

68  {
69  // Is pointer arithmetic valid in the case that we're checking for? Not
70  // sure what the standard says, but I think that practically this should
71  // work.
72  if((uint8_t *)hit(i) + sizeof(hit_t) > thefrag.dataEndBytes()){
73  std::cerr << "Hit " << i << " would be past end of fragment, can't print\n";
74  return;
75  }
76 
77  std::cout << "CRT hit " << i << ": Magic = '" << hit(i)->magic << "'\n"
78  << " channel = " << +(hit(i)->channel) << "\n"
79  << " ADC = " << hit(i)->adc << "\n";
80  }
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108
const hit_t * hit(const int i) const
Definition: CRTFragment.cc:192
void Fragment::print_hits ( ) const

Definition at line 83 of file CRTFragment.cc.

84  {
85  for(int i = 0; i < header()->nhit; i++)
86  print_hit(i);
87  puts("");
88  }
void print_hit(const int i) const
Definition: CRTFragment.cc:67
const header_t * header() const
Definition: CRTFragment.cc:199
uint64_t Fragment::raw_backend_time ( ) const

Definition at line 23 of file CRTFragment.cc.

24  {
25  return header()->raw_backend_time;
26  }
const header_t * header() const
Definition: CRTFragment.cc:199
unsigned int Fragment::size ( ) const

Definition at line 136 of file CRTFragment.cc.

137  {
138  return thefrag.dataEndBytes() - thefrag.dataBeginBytes();
139  }
artdaq::Fragment const & thefrag
Definition: CRTFragment.hh:108

Member Data Documentation

artdaq::Fragment const& CRT::Fragment::thefrag
private

Definition at line 108 of file CRTFragment.hh.


The documentation for this class was generated from the following files: