CMS 3D CMS Logo

Phase2TrackerFEDHeader.cc
Go to the documentation of this file.
5 
6 namespace Phase2Tracker {
7 
8  Phase2TrackerFEDHeader::Phase2TrackerFEDHeader(const uint8_t* headerPointer) : trackerHeader_(headerPointer) {
11  // decode the Tracker Header and store info
12  init();
13  }
14 
18  // WARNING: eventType must be called before
19  // readoutMode, conditionData and dataType
20  // as this info is stored in eventType
24  dataType_ = dataType();
25 
27  // numberOfCBC must be called before pointerToData
30 
31  LogTrace("Phase2TrackerFEDBuffer") << "[Phase2Tracker::Phase2TrackerFEDHeader::" << __func__ << "]: \n"
32  << " Tracker Header contents:\n"
33  << " -- Data Format Version : " << uint32_t(dataFormatVersion_) << "\n"
34  << " -- Debug Level : " << debugMode_ << "\n"
35  << " -- Operating Mode : " << readoutMode_ << "\n"
36  << " -- Condition Data : " << (conditionData_ ? "Present" : "Absent")
37  << "\n"
38  << " -- Data Type : " << (dataType_ ? "Real" : "Fake") << "\n"
39  << " -- Glib Stat registers : " << std::hex << std::setw(16) << glibStatusCode_
40  << "\n"
41  << " -- connected CBC : " << std::dec << numberOfCBC_ << "\n";
42  }
43 
45  uint8_t Version = static_cast<uint8_t>(extract64(VERSION_M, VERSION_S, header_first_word_));
46  if (Version != 1) {
47  std::ostringstream ss;
48  ss << "[Phase2Tracker::Phase2TrackerFEDHeader::" << __func__ << "] ";
49  ss << "Invalid Data Format Version in Traker Header : ";
51  throw cms::Exception("Phase2TrackerFEDBuffer") << ss.str();
52  }
53  return Version;
54  }
55 
57  // Read debugMode in Tracker Header
58  uint8_t mode = static_cast<uint8_t>(extract64(HEADER_FORMAT_M, HEADER_FORMAT_S, header_first_word_));
59 
60  switch (mode) { // check if it is one of correct modes
61  case SUMMARY:
62  return READ_MODE(SUMMARY);
63  case FULL_DEBUG:
64  return READ_MODE(FULL_DEBUG);
65  case CBC_ERROR:
66  return READ_MODE(CBC_ERROR);
67  default: // else create Exception
68  std::ostringstream ss;
69  ss << "[Phase2Tracker::Phase2TrackerFEDHeader::" << __func__ << "] ";
70  ss << "Invalid Header Format in Traker Header : ";
72  throw cms::Exception("Phase2TrackerFEDBuffer") << ss.str();
73  }
74 
76  }
77 
79  return static_cast<uint8_t>(extract64(EVENT_TYPE_M, EVENT_TYPE_S, header_first_word_));
80  }
81 
82  // decode eventType_. Read: readoutMode, conditionData and dataType
84  // readout mode is first bit of event type
85  uint8_t mode = static_cast<uint8_t>(eventType_ >> 2) & 0x3;
86 
87  switch (mode) { // check if it is one of correct modes
88  case 2:
90  case 1:
92  default: // else create Exception
93  std::ostringstream ss;
94  ss << "[Phase2Tracker::Phase2TrackerFEDHeader::" << __func__ << "] ";
95  ss << "Invalid Readout Mode in Traker Header : ";
97  throw cms::Exception("Phase2TrackerFEDBuffer") << ss.str();
98  }
99  }
100 
101  uint8_t Phase2TrackerFEDHeader::conditionData() const { return static_cast<uint8_t>(eventType_ >> 1) & 0x1; }
102 
103  uint8_t Phase2TrackerFEDHeader::dataType() const { return static_cast<uint8_t>(eventType_) & 0x1; }
104 
107  }
108 
109  std::vector<bool> Phase2TrackerFEDHeader::frontendStatus() const {
110  uint16_t FE_status = static_cast<uint16_t>(extract64(FRONTEND_STAT_M, FRONTEND_STAT_S, header_first_word_));
111  std::vector<bool> status(16, false);
112  for (int i = 0; i < 16; i++) {
113  status[i] = (FE_status >> i) & 0x1;
114  }
115  return status;
116  }
117 
119  if (debugMode_ != SUMMARY) {
120  return static_cast<uint16_t>(extract64(CBC_NUMBER_M, CBC_NUMBER_S, header_second_word_));
121  } else {
122  return 0;
123  }
124  }
125 
126  // pending too
127  std::vector<uint8_t> Phase2TrackerFEDHeader::CBCStatus() const {
128  // set offset and data to begining of second header 64 bit word
129  int offset = 8;
130  uint64_t data64 = header_second_word_;
131  // number of CBC:
132  uint16_t cbc_num = numberOfCBC();
133  // size of data per CBC (in bits)
134  int status_size = 0;
135  if (debugMode_ == FULL_DEBUG) {
136  status_size = 8;
137  } else if (debugMode_ == CBC_ERROR) {
138  status_size = 1;
139  }
140  // starting byte for CBC status bits
141  std::vector<uint8_t> cbc_status;
142  if (status_size == 8) {
143  int num_bytes = cbc_num;
144  int current_byte = 5;
145  while (num_bytes > 0) {
146  cbc_status.push_back(static_cast<uint8_t>((data64 >> current_byte * 8) & 0xFF));
147  if (current_byte == 0) {
148  current_byte = 8;
149  offset += 8;
150  data64 = read64(offset, trackerHeader_);
151  }
152  current_byte--;
153  num_bytes--;
154  }
155  } else if (status_size == 1) {
156  int current_bit = 47;
157  int num_bits = cbc_num;
158  while (num_bits > 0) {
159  cbc_status.push_back(static_cast<uint8_t>((data64 >> current_bit) & 0x1));
160  if (current_bit == 0) {
161  current_bit = 64;
162  offset += 8;
163  data64 = read64(offset, trackerHeader_);
164  }
165  current_bit--;
166  num_bits--;
167  }
168  }
169 
170  return cbc_status;
171  }
172 
174  int status_size = 0;
175  int cbc_num = numberOfCBC();
176  // CAUTION: we express all sizes in bits here
177  if (debugMode_ == FULL_DEBUG) {
178  status_size = 8;
179  } else if (debugMode_ == CBC_ERROR) {
180  status_size = 1;
181  }
182  // compute number of additional 64 bit words before payload
183  int num_add_words64 = (cbc_num * status_size - 48 + 64 - 1) / 64;
184  // back to bytes
185  trackerHeaderSize_ = (2 + num_add_words64) * 8;
187  }
188 
189 } // namespace Phase2Tracker
std::vector< uint8_t > CBCStatus() const
#define LogTrace(id)
FEDReadoutMode
Definition: utils.h:96
unsigned long long uint64_t
Definition: Time.h:13
void printHex(const void *pointer, const size_t lengthInBytes, std::ostream &os)
Definition: utils.h:59
uint64_t extract64(trackerHeader_m mask, trackerHeader_s shift, uint64_t data)
Definition: utils.h:192
uint64_t read64(int offset, const uint8_t *buffer)
Definition: utils.h:187