test
CMS 3D CMS Logo

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