pxar
 All Classes Namespaces Functions Variables Typedefs Friends
datatypes.cc
1 #include "datatypes.h"
2 #include "log.h"
3 #include "exceptions.h"
4 #include "constants.h"
5 
6 namespace pxar {
7 
8 
9  void pixel::decodeRaw(uint32_t raw, bool invert) {
10  // Get the pulse height:
11  setValue(static_cast<double>((raw & 0x0f) + ((raw >> 1) & 0xf0)));
12  if((raw & 0x10) > 0) {
13  LOG(logDEBUGAPI) << "invalid pulse-height fill bit from raw value of "<< std::hex << raw << std::dec << ": " << *this;
14  throw DataInvalidPulseheightError("Error decoding pixel raw value");
15  }
16 
17  // Decode the pixel address
18  int r2 = (raw >> 15) & 7;
19  if(invert) { r2 ^= 0x7; }
20  int r1 = (raw >> 12) & 7;
21  if(invert) { r1 ^= 0x7; }
22  int r0 = (raw >> 9) & 7;
23  if(invert) { r0 ^= 0x7; }
24  int r = r2*36 + r1*6 + r0;
25  _row = 80 - r/2;
26  _column = 2*(((raw >> 21) & 7)*6 + ((raw >> 18) & 7)) + (r&1);
27 
28  // Perform range checks:
29  if(_row >= ROC_NUMROWS || _column >= ROC_NUMCOLS) {
30  LOG(logDEBUGAPI) << "Invalid pixel from raw value of "<< std::hex << raw << std::dec << ": " << *this;
31  if(_row == ROC_NUMROWS) throw DataCorruptBufferError("Error decoding pixel raw value");
32  else throw DataInvalidAddressError("Error decoding pixel raw value");
33  }
34  }
35 
36  void statistics::dump() {
37  // Print out the full statistics:
38  LOG(logINFO) << "Decoding statistics:";
39  LOG(logINFO) << " General information:";
40  LOG(logINFO) << "\t 16bit words read: " << this->info_words_read();
41  LOG(logINFO) << "\t valid pixel hits: " << this->info_pixels_valid();
42  LOG(logINFO) << " Event errors: \t " << this->errors_event();
43  LOG(logINFO) << "\t start marker: " << this->errors_event_start();
44  LOG(logINFO) << "\t stop marker: " << this->errors_event_stop();
45  LOG(logINFO) << "\t overflow: " << this->errors_event_overflow();
46  LOG(logINFO) << "\t invalid 5bit words: " << this->errors_event_invalid_words();
47  LOG(logINFO) << "\t invalid XOR eye diagram: " << this->errors_event_invalid_xor();
48  LOG(logINFO) << " TBM errors: \t\t " << this->errors_tbm();
49  LOG(logINFO) << "\t flawed TBM headers: " << this->errors_tbm_header();
50  LOG(logINFO) << "\t flawed TBM trailers: " << this->errors_tbm_trailer();
51  LOG(logINFO) << "\t event ID mismatches: " << this->errors_tbm_eventid_mismatch();
52  LOG(logINFO) << " ROC errors: \t\t " << this->errors_roc();
53  LOG(logINFO) << "\t missing ROC header(s): " << this->errors_roc_missing();
54  LOG(logINFO) << "\t misplaced readback start: " << this->errors_roc_readback();
55  LOG(logINFO) << " Pixel decoding errors:\t " << this->errors_pixel();
56  LOG(logINFO) << "\t pixel data incomplete: " << this->errors_pixel_incomplete();
57  LOG(logINFO) << "\t pixel address: " << this->errors_pixel_address();
58  LOG(logINFO) << "\t pulse height fill bit: " << this->errors_pixel_pulseheight();
59  LOG(logINFO) << "\t buffer corruption: " << this->errors_pixel_buffer_corrupt();
60  }
61 
62  void statistics::clear() {
63  m_info_words_read = 0;
64  m_info_pixels_valid = 0;
65 
66  m_errors_event_start = 0;
67  m_errors_event_stop = 0;
68  m_errors_event_overflow = 0;
69  m_errors_event_invalid_words = 0;
70  m_errors_event_invalid_xor = 0;
71 
72  m_errors_tbm_header = 0;
73  m_errors_tbm_trailer = 0;
74  m_errors_tbm_eventid_mismatch = 0;
75 
76  m_errors_roc_missing = 0;
77  m_errors_roc_readback = 0;
78 
79  m_errors_pixel_incomplete = 0;
80  m_errors_pixel_address = 0;
81  m_errors_pixel_pulseheight = 0;
82  m_errors_pixel_buffer_corrupt = 0;
83  }
84 
85  statistics& operator+=(statistics &lhs, const statistics &rhs) {
86  // Informational bits:
87  lhs.m_info_words_read += rhs.m_info_words_read;
88  lhs.m_info_pixels_valid += rhs.m_info_pixels_valid;
89 
90  // Event errors:
91  lhs.m_errors_event_start += rhs.m_errors_event_start;
92  lhs.m_errors_event_stop += rhs.m_errors_event_stop;
93  lhs.m_errors_event_overflow += rhs.m_errors_event_overflow;
94  lhs.m_errors_event_invalid_words += rhs.m_errors_event_invalid_words;
95  lhs.m_errors_event_invalid_xor += rhs.m_errors_event_invalid_xor;
96 
97  // TBM errors:
98  lhs.m_errors_tbm_header += rhs.m_errors_tbm_header;
99  lhs.m_errors_tbm_trailer += rhs.m_errors_tbm_trailer;
100  lhs.m_errors_tbm_eventid_mismatch += rhs.m_errors_tbm_eventid_mismatch;
101 
102  // ROC errors:
103  lhs.m_errors_roc_missing += rhs.m_errors_roc_missing;
104  lhs.m_errors_roc_readback += rhs.m_errors_roc_readback;
105 
106  // Pixel decoding errors:
107  lhs.m_errors_pixel_incomplete += rhs.m_errors_pixel_incomplete;
108  lhs.m_errors_pixel_address += rhs.m_errors_pixel_address;
109  lhs.m_errors_pixel_pulseheight += rhs.m_errors_pixel_pulseheight;
110  lhs.m_errors_pixel_buffer_corrupt += rhs.m_errors_pixel_buffer_corrupt;
111 
112  return lhs;
113  }
114 
115 } // namespace pxar
void setValue(double val)
Definition: datatypes.h:85