CMS 3D CMS Logo

utils.h
Go to the documentation of this file.
1 #ifndef EventFilter_Phase2TrackerRawToDigi_utils_H // {
2 #define EventFilter_Phase2TrackerRawToDigi_utils_H
3 
4 // common tools
5 #include <iomanip>
6 #include <ostream>
7 #include <iostream>
9 
10 namespace Phase2Tracker {
11 
12  // TODO: set this in a common include file.
13  // see DataFormats/Phase2TrackerCommon/interface/Constants.h
14 
15  // -------------------- FED ids --------------------
16 
17  static const uint16_t FED_ID_MIN = static_cast<uint16_t>( FEDNumbering::MINSiStripFEDID);
18  static const uint16_t FED_ID_MAX = static_cast<uint16_t>( FEDNumbering::MAXSiStripFEDID);
19  static const uint16_t CMS_FED_ID_MAX = static_cast<uint16_t>( FEDNumbering::MAXFEDID);
20  static const uint16_t NUMBER_OF_FEDS = static_cast<uint16_t>( FED_ID_MAX - FED_ID_MIN + 1 );
21 
22  // Assumptions for phase 2
23 
24  static const int MAX_FE_PER_FED = 16;
25  static const int MAX_CBC_PER_FE = 16;
26  static const int STRIPS_PER_CBC = 254;
27  static const int STRIPS_PADDING = 2;
28  static const int TRIGGER_SIZE = 0;
29 
30  // definition
31 
32  static const uint8_t INVALID=0xFF;
33 
34  // utils
35 
36  inline void printNibbleValue(uint8_t value, std::ostream& os)
37  {
38  const std::ios_base::fmtflags originalFormatFlags = os.flags();
39  os << std::hex << std::setw(1) << value;
40  os.flags(originalFormatFlags);
41  }
42 
43  inline void printHexValue(const uint8_t value, std::ostream& os)
44  {
45  const std::ios_base::fmtflags originalFormatFlags = os.flags();
46  os << std::hex << std::setfill('0') << std::setw(2);
47  os << uint16_t(value);
48  os.flags(originalFormatFlags);
49  }
50 
51  inline void printHexWord(const uint8_t* pointer, const size_t lengthInBytes, std::ostream& os)
52  {
53  size_t i = lengthInBytes-1;
54  do{
55  printHexValue(pointer[i],os);
56  if (i != 0) os << " ";
57  } while (i-- != 0);
58  }
59 
60  inline void printHex(const void* pointer, const size_t lengthInBytes, std::ostream& os)
61  {
62  const uint8_t* bytePointer = reinterpret_cast<const uint8_t*>(pointer);
63  //if there is one 64 bit word or less, print it out
64  if (lengthInBytes <= 8) {
65  printHexWord(bytePointer,lengthInBytes,os);
66  }
67  //otherwise, print word numbers etc
68  else {
69  //header
70  os << "word\tbyte\t \t\tbyte" << std::endl;;
71  const size_t words = lengthInBytes/8;
72  const size_t extraBytes = lengthInBytes - 8*words;
73  //print full words
74  for (size_t w = 0; w < words; w++) {
75  const size_t startByte = w*8;
76  os << w << '\t' << startByte+8 << '\t';
77  printHexWord(bytePointer+startByte,8,os);
78  os << "\t\t" << startByte << std::endl;
79  }
80  //print part word, if any
81  if (extraBytes) {
82  const size_t startByte = words*8;
83  os << words << '\t' << startByte+8 << '\t';
84  //padding
85  size_t p = 8;
86  while (p-- > extraBytes) {
87  os << "00 ";
88  }
89  printHexWord(bytePointer+startByte,extraBytes,os);
90  os << "\t\t" << startByte << std::endl;
91  }
92  os << std::endl;
93  }
94  }
95 
96 
97  //enum values are values which appear in FED buffer. DO NOT CHANGE!
105  };
106 
107  //to make enums printable
108  std::ostream& operator<<(std::ostream& os, const FEDReadoutMode& value);
109  inline std::ostream& operator<<(std::ostream& os, const FEDReadoutMode& value)
110  {
111  switch (value) {
112  case READOUT_MODE_SCOPE:
113  os << "Scope mode";
114  break;
116  os << "Virgin raw";
117  break;
119  os << "Processed raw";
120  break;
122  os << "Zero suppressed";
123  break;
125  os << "Zero suppressed lite";
126  break;
127  case READOUT_MODE_SPY:
128  os << "Spy channel";
129  break;
131  os << "Invalid";
132  break;
133  default:
134  os << "Unrecognized";
135  os << " (";
136  printHexValue(value,os);
137  os << ")";
138  break;
139  }
140  return os;
141  }
142 
143  // tracker header read modes
145  {
147  SUMMARY = 0,
150  };
151 
152  //to make enums printable
153  std::ostream& operator<<(std::ostream& os, const READ_MODE& value);
154  inline std::ostream& operator<<(std::ostream& os, const READ_MODE& value)
155  {
156  switch (value) {
157  case SUMMARY:
158  os << "Summary mode";
159  break;
160  case FULL_DEBUG:
161  os << "Full debug mode";
162  break;
163  case CBC_ERROR:
164  os << "CBC error mode";
165  break;
166  default:
167  os << "Unrecognized mode";
168  os << " (";
169  printHexValue(value,os);
170  os << ")";
171  break;
172  }
173  return os;
174  }
175 
176 
177 
178  //enum values to parse tracker header
179  enum trackerHeader_m { VERSION_M = 0xF000000000000000,
180  HEADER_FORMAT_M = 0x0C00000000000000,
181  EVENT_TYPE_M = 0x03C0000000000000,
182  GLIB_STATUS_M = 0x003FFFFFFFFF0000,
183  FRONTEND_STAT_M = 0x000000000000FFFF,
184  CBC_NUMBER_M = 0xFFFF000000000000
185  };
186 
193  };
194 
195 
196  // get 64 bits word from data with given offset
197  inline uint64_t read64(int offset, const uint8_t* buffer)
198  {
199  return *reinterpret_cast<const uint64_t*>(buffer+offset);
200  }
201 
202  // extract data from a 64 bits word using mask and shift
204  {
205  // cout <<"IN "<< hex<< " " <<setfill('0') << setw(16) << data << "\n" ;
206  data = (data & mask) >> shift;
207  return data;
208  }
209 
210 } // end of Phase2Tracker namespace
211 
212 #endif // } end def utils
213 
const double w
Definition: UKUtility.cc:23
void printHexWord(const uint8_t *pointer, const size_t lengthInBytes, std::ostream &os)
Definition: utils.h:51
static const int TRIGGER_SIZE
Definition: utils.h:28
std::ostream & operator<<(std::ostream &os, const FEDDAQEventType &value)
static const uint8_t INVALID
Definition: utils.h:32
static const uint16_t CMS_FED_ID_MAX
Definition: utils.h:19
static const int MAX_CBC_PER_FE
Definition: utils.h:25
FEDReadoutMode
Definition: utils.h:98
Definition: value.py:1
void printHexValue(const uint8_t value, std::ostream &os)
Definition: utils.h:43
unsigned long long uint64_t
Definition: Time.h:15
void printNibbleValue(uint8_t value, std::ostream &os)
Definition: utils.h:36
static const uint16_t FED_ID_MAX
Definition: utils.h:18
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
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
static unsigned int const shift
static const int STRIPS_PER_CBC
Definition: utils.h:26
static const uint16_t FED_ID_MIN
Definition: utils.h:17
static const int MAX_FE_PER_FED
Definition: utils.h:24
static const int STRIPS_PADDING
Definition: utils.h:27
uint64_t read64(int offset, const uint8_t *buffer)
Definition: utils.h:197
static const uint16_t NUMBER_OF_FEDS
Definition: utils.h:20