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
Phase2Tracker::Phase2TrackerFEDHeader::trackerHeaderSize_
uint8_t trackerHeaderSize_
Definition: Phase2TrackerFEDHeader.h:67
Phase2Tracker::CBC_NUMBER_M
Definition: utils.h:173
Phase2Tracker::EVENT_TYPE_M
Definition: utils.h:170
Phase2Tracker::FULL_DEBUG
Definition: utils.h:141
Phase2Tracker::Phase2TrackerFEDHeader::CBCStatus
std::vector< uint8_t > CBCStatus() const
Definition: Phase2TrackerFEDHeader.cc:127
Phase2Tracker::Phase2TrackerFEDHeader::conditionData_
uint8_t conditionData_
Definition: Phase2TrackerFEDHeader.h:74
mps_fire.i
i
Definition: mps_fire.py:428
MessageLogger.h
Phase2Tracker::VERSION_S
Definition: utils.h:177
Phase2Tracker::Phase2TrackerFEDHeader::numberOfCBC_
uint16_t numberOfCBC_
Definition: Phase2TrackerFEDHeader.h:77
Phase2Tracker::Phase2TrackerFEDHeader::dataType
uint8_t dataType() const
Definition: Phase2TrackerFEDHeader.cc:103
mps_update.status
status
Definition: mps_update.py:68
Phase2Tracker::Phase2TrackerFEDHeader::Phase2TrackerFEDHeader
Phase2TrackerFEDHeader()
Definition: Phase2TrackerFEDHeader.h:14
Phase2Tracker::GLIB_STATUS_S
Definition: utils.h:180
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
utils.h
Phase2Tracker::Phase2TrackerFEDHeader::trackerHeader_
const uint8_t * trackerHeader_
Definition: Phase2TrackerFEDHeader.h:65
Phase2Tracker::Phase2TrackerFEDHeader::dataFormatVersion_
uint8_t dataFormatVersion_
Definition: Phase2TrackerFEDHeader.h:70
Phase2Tracker::READOUT_MODE_ZERO_SUPPRESSED
Definition: utils.h:100
Phase2Tracker::HEADER_FORMAT_S
Definition: utils.h:178
Phase2Tracker::VERSION_M
Definition: utils.h:168
Phase2Tracker::GLIB_STATUS_M
Definition: utils.h:171
Phase2Tracker::Phase2TrackerFEDHeader::numberOfCBC
uint16_t numberOfCBC() const
Definition: Phase2TrackerFEDHeader.cc:118
Phase2Tracker::READOUT_MODE_PROC_RAW
Definition: utils.h:99
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
Phase2Tracker::Phase2TrackerFEDHeader::init
void init()
Definition: Phase2TrackerFEDHeader.cc:15
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
Phase2Tracker::FEDReadoutMode
FEDReadoutMode
Definition: utils.h:95
Phase2Tracker::Phase2TrackerFEDHeader::debugMode_
READ_MODE debugMode_
Definition: Phase2TrackerFEDHeader.h:71
Phase2Tracker::READ_MODE
READ_MODE
Definition: utils.h:141
Phase2Tracker::Phase2TrackerFEDHeader::header_first_word_
uint64_t header_first_word_
Definition: Phase2TrackerFEDHeader.h:68
Phase2Tracker::Phase2TrackerFEDHeader::pointerToData_
const uint8_t * pointerToData_
Definition: Phase2TrackerFEDHeader.h:66
Phase2Tracker::Phase2TrackerFEDHeader::dataType_
uint8_t dataType_
Definition: Phase2TrackerFEDHeader.h:75
Phase2Tracker::Phase2TrackerFEDHeader::eventType_
uint8_t eventType_
Definition: Phase2TrackerFEDHeader.h:72
Phase2Tracker::CBC_NUMBER_S
Definition: utils.h:182
Phase2Tracker::SUMMARY
Definition: utils.h:141
Phase2Tracker::FRONTEND_STAT_M
Definition: utils.h:172
Phase2Tracker::HEADER_FORMAT_M
Definition: utils.h:169
Phase2Tracker::FRONTEND_STAT_S
Definition: utils.h:181
Phase2Tracker::READ_MODE_INVALID
Definition: utils.h:141
Phase2Tracker::Phase2TrackerFEDHeader::readoutMode
FEDReadoutMode readoutMode() const
Definition: Phase2TrackerFEDHeader.cc:83
Phase2Tracker::Phase2TrackerFEDHeader::glibStatusCode
uint64_t glibStatusCode() const
Definition: Phase2TrackerFEDHeader.cc:105
Phase2Tracker::printHex
void printHex(const void *pointer, const size_t lengthInBytes, std::ostream &os)
Definition: utils.h:58
Phase2Tracker::Phase2TrackerFEDHeader::debugMode
READ_MODE debugMode() const
Definition: Phase2TrackerFEDHeader.cc:56
Phase2Tracker::Phase2TrackerFEDHeader::pointerToData
const uint8_t * pointerToData()
Definition: Phase2TrackerFEDHeader.cc:173
Phase2Tracker::extract64
uint64_t extract64(trackerHeader_m mask, trackerHeader_s shift, uint64_t data)
Definition: utils.h:191
Phase2Tracker::EVENT_TYPE_S
Definition: utils.h:179
Phase2Tracker::Phase2TrackerFEDHeader::conditionData
uint8_t conditionData() const
Definition: Phase2TrackerFEDHeader.cc:101
Exception
Definition: hltDiff.cc:245
Phase2TrackerFEDHeader.h
Phase2Tracker::read64
uint64_t read64(int offset, const uint8_t *buffer)
Definition: utils.h:186
Exception.h
Phase2Tracker::CBC_ERROR
Definition: utils.h:141
Phase2Tracker::Phase2TrackerFEDHeader::glibStatusCode_
uint64_t glibStatusCode_
Definition: Phase2TrackerFEDHeader.h:76
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
Phase2Tracker::Phase2TrackerFEDHeader::frontendStatus
std::vector< bool > frontendStatus() const
Definition: Phase2TrackerFEDHeader.cc:109
Phase2Tracker::Phase2TrackerFEDHeader::header_second_word_
uint64_t header_second_word_
Definition: Phase2TrackerFEDHeader.h:69
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
hltrates_dqm_sourceclient-live_cfg.offset
offset
Definition: hltrates_dqm_sourceclient-live_cfg.py:82
Phase2Tracker::Phase2TrackerFEDHeader::readoutMode_
FEDReadoutMode readoutMode_
Definition: Phase2TrackerFEDHeader.h:73
Version
Definition: InitMessage.h:39
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
Phase2Tracker
Definition: Phase2TrackerFEDBuffer.h:12
Phase2Tracker::Phase2TrackerFEDHeader::eventType
uint8_t eventType() const
Definition: Phase2TrackerFEDHeader.cc:78
Phase2Tracker::Phase2TrackerFEDHeader::dataFormatVersion
uint8_t dataFormatVersion() const
Definition: Phase2TrackerFEDHeader.cc:44