CMS 3D CMS Logo

TotemSampicFrame.h
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * This is a part of the TOTEM offline software.
4 * Authors:
5 * Nicola Minafra
6 *
7 ****************************************************************************/
8 
9 #ifndef EventFilter_CTPPSRawToDigi_TotemSampicFrame
10 #define EventFilter_CTPPSRawToDigi_TotemSampicFrame
11 
12 #include <vector>
13 #include <cstddef>
14 #include <cstdint>
15 #include <iomanip>
16 #include <bitset>
17 #include <iostream>
18 
21 
23  hwId_Position = 0, // hwId_Size = 1,
30  fpgaTime_Position = 7, // fpgaTime_Size = 5,
31  timestampA_Position = 12, // timestampA_Size = 2,
33  timestampB_Position = 14, // timestampB_Size = 2,
35  cellInfo_Position = 16, // cellInfo_Size = 2,
37  planeChannelId_Position = 18, // planeChannelId_Size = 1,
39  reserved_Position = 19, // reserved_Size = 5,
40 
41  boardId_Position = 0, // boardId_Size = 1,
42  l1ATimestamp_Position = 1, // l1ATimestamp_Size = 5,
43  bunchNumber_Position = 6, // bunchNumber_Size = 2,
45  orbitNumber_Position = 8, // orbitNumber_Size = 4,
47  eventNumber_Position = 12, // eventNumber_Size = 4,
49  channelMap_Position = 16, // channelMap_Size = 2,
51  l1ALatency_Position = 18, // l1ALatency_Size = 2,
53  numberOfSamples_Position = 20, // numberOfSamples_Size = 1,
55  offsetOfSamples_Position = 21, // offsetOfSamples_Size = 1,
56  fwVersion_Position = 22, // fwVersion_Size = 1,
57  pllInfo_Position = 23, // pllInfo_Size = 1,
58 
60  controlBits3 = 0x69,
61  cellInfo_Mask = 0x3F,
62 
63 };
64 
65 template <typename T>
66 T grayToBinary(const T& gcode_data) {
67  // assign b[0] = g[0]
68  T binary = gcode_data & (0x0001 << (8 * sizeof(T) - 1)); // MSB is the same
69 
70  // assign b[i] = g[i] xor b[i-1]
71  for (unsigned short int i = 1; i < 8 * sizeof(T); ++i)
72  binary |= (gcode_data ^ (binary >> 1)) & (0x0001 << (8 * sizeof(T) - i - 1));
73 
74  return binary;
75 }
76 
81 public:
82  TotemSampicFrame(const uint8_t* chInfoPtr, const uint8_t* chDataPtr, const uint8_t* eventInfoPtr)
83  : totemSampicInfoPtr_(chInfoPtr),
84  totemSampicDataPtr_(chDataPtr),
85  totemSampicEventInfoPtr_(eventInfoPtr),
86  status_(0) {
87  if (chInfoPtr != nullptr && chDataPtr != nullptr && eventInfoPtr != nullptr &&
89  status_ = 1;
90  }
92 
95  void printRaw(bool binary = false) const {
96  edm::LogInfo("TotemSampicFrame") << "Event Info: \n";
98 
99  edm::LogInfo("TotemSampicFrame") << "Channel Info: \n";
101 
102  edm::LogInfo("TotemSampicFrame") << "Channel Data: \n";
104  }
105 
106  void print() const {
107  std::bitset<16> bitsChannelMap(getChannelMap());
108  std::bitset<16> bitsPLLInfo(getPLLInfo());
109  edm::LogInfo("TotemSampicFrame") << "\nEvent:"
110  << "\nHardwareId (Event):\t" << std::hex << (unsigned int)getEventHardwareId()
111  << "\nL1A Timestamp:\t" << std::dec << getL1ATimestamp() << "\nL1A Latency:\t"
112  << std::dec << getL1ALatency() << "\nBunch Number:\t" << std::dec
113  << getBunchNumber() << "\nOrbit Number:\t" << std::dec << getOrbitNumber()
114  << "\nEvent Number:\t" << std::dec << getEventNumber() << "\nChannels fired:\t"
115  << std::hex << bitsChannelMap.to_string() << "\nNumber of Samples:\t" << std::dec
116  << getNumberOfSentSamples() << "\nOffset of Samples:\t" << std::dec
117  << (int)getOffsetOfSamples() << "\nFW Version:\t" << std::hex
118  << (int)getFWVersion() << "\nChannel:\nHardwareId:\t" << std::hex
119  << (unsigned int)getHardwareId() << "\nFPGATimestamp:\t" << std::dec
120  << getFPGATimestamp() << "\nTimestampA:\t" << std::dec << getTimestampA()
121  << "\nTimestampB:\t" << std::dec << getTimestampB() << "\nCellInfo:\t" << std::dec
122  << getCellInfo() << "\nPlane:\t" << std::dec << getDetPlane() << "\nChannel:\t"
123  << std::dec << getDetChannel() << "\nPLL Info:\t" << bitsPLLInfo.to_string()
124  << "\n\n";
125  }
126 
127  // All getters
128  inline uint8_t getHardwareId() const {
129  uint8_t tmp = 0;
130  if (status_)
132  return tmp;
133  }
134 
135  template <class T>
136  T extractDataFromBytesLSB(const uint8_t* array, int start, int size) const {
137  T result = 0;
138  for (int i = start + size - 1; i >= start; i--)
139  result = (result << 8) | array[i];
140  return result;
141  }
142 
143  inline uint64_t getFPGATimestamp() const {
144  uint64_t tmp = 0;
145  if (status_)
146  tmp =
147  extractDataFromBytesLSB<uint64_t>(totemSampicInfoPtr_, TotemSampicConstant::fpgaTime_Position, fpgaTime_Size);
148  return tmp;
149  }
150 
151  inline uint16_t getTimestampA() const {
152  uint16_t tmp = 0;
153  if (status_)
154  tmp = extractDataFromBytesLSB<uint16_t>(
156  tmp = 0xFFF - tmp;
157  return grayToBinary<uint16_t>(tmp);
158  }
159 
160  inline uint16_t getTimestampB() const {
161  uint16_t tmp = 0;
162  if (status_)
163  tmp = extractDataFromBytesLSB<uint16_t>(
165  return grayToBinary<uint16_t>(tmp);
166  }
167 
168  inline uint16_t getCellInfo() const {
169  uint16_t tmp = 0;
170  if (status_)
171  tmp =
172  extractDataFromBytesLSB<uint16_t>(totemSampicInfoPtr_, TotemSampicConstant::cellInfo_Position, cellInfo_Size);
174  }
175 
176  inline int getDetPlane() const {
177  int tmp = 0;
178  if (status_)
180  return tmp;
181  }
182 
183  inline int getDetChannel() const {
184  int tmp = 0;
185  if (status_)
187  return tmp;
188  }
189 
190  const std::vector<uint8_t> getSamples() const {
191  std::vector<uint8_t> samples;
192  if (status_) {
194  for (auto it = samples.begin(); it != samples.end(); ++it)
195  *it = grayToBinary<uint8_t>(*it);
196  }
197  return samples;
198  }
199 
200  inline unsigned int getNumberOfSamples() const { return status_ * TotemSampicConstant::numberOfSamples; }
201 
202  // Event Info
203  inline uint8_t getEventHardwareId() const {
204  uint8_t tmp = 0;
205  if (status_)
207  return tmp;
208  }
209 
210  inline uint64_t getL1ATimestamp() const {
211  uint64_t tmp = 0;
212  if (status_)
213  tmp = extractDataFromBytesLSB<uint64_t>(
215  return tmp;
216  }
217 
218  inline uint16_t getBunchNumber() const {
219  uint16_t tmp = 0;
220  if (status_)
221  tmp = extractDataFromBytesLSB<uint16_t>(
223  return tmp;
224  }
225 
226  inline uint32_t getOrbitNumber() const {
227  uint32_t tmp = 0;
228  if (status_)
229  tmp = extractDataFromBytesLSB<uint32_t>(
231  return tmp;
232  }
233 
234  inline uint32_t getEventNumber() const {
235  uint32_t tmp = 0;
236  if (status_)
237  tmp = extractDataFromBytesLSB<uint32_t>(
239  return tmp;
240  }
241 
242  inline uint16_t getChannelMap() const {
243  uint16_t tmp = 0;
244  if (status_)
245  tmp = extractDataFromBytesLSB<uint16_t>(
247  return tmp;
248  }
249 
250  inline uint16_t getL1ALatency() const {
251  uint16_t tmp = 0;
252  if (status_)
253  tmp = extractDataFromBytesLSB<uint16_t>(
255  return tmp;
256  }
257 
258  inline uint8_t getNumberOfSentSamples() const {
259  uint8_t tmp = 0;
260  if (status_)
262  return tmp;
263  }
264 
265  inline uint8_t getOffsetOfSamples() const {
266  uint8_t tmp = 0;
267  if (status_)
269  return tmp;
270  }
271 
272  inline uint8_t getPLLInfo() const {
273  uint8_t tmp = 0;
274  if (status_)
276  return tmp;
277  }
278 
279  inline uint8_t getFWVersion() const {
280  uint8_t tmp = 0;
281  if (status_)
283  return tmp;
284  }
285 
286  inline bool valid() const { return status_ != 0; }
287 
288 protected:
289  const uint8_t* totemSampicInfoPtr_;
290  const uint8_t* totemSampicDataPtr_;
291  const uint8_t* totemSampicEventInfoPtr_;
292 
293  int status_;
294 
295  inline void printRawBuffer(const uint16_t* buffer, const bool binary = false, const unsigned int size = 12) const {
296  for (unsigned int i = 0; i < size; i++) {
297  if (binary) {
298  std::bitset<16> bits(*(buffer++));
299  edm::LogInfo("TotemSampicFrame") << bits.to_string() << "\n";
300  } else
301  edm::LogInfo("TotemSampicFrame") << std::setfill('0') << std::setw(4) << std::hex << *(buffer++) << "\n";
302  }
303  }
304 };
305 
306 #endif
void print() const
size
Write out results.
Definition: start.py:1
unsigned int getNumberOfSamples() const
uint8_t getFWVersion() const
uint32_t getEventNumber() const
uint64_t getL1ATimestamp() const
uint8_t getEventHardwareId() const
const uint8_t * totemSampicInfoPtr_
uint16_t getBunchNumber() const
int getDetChannel() const
constexpr uint32_t bits
Definition: gpuClustering.h:25
int getDetPlane() const
uint16_t getL1ALatency() const
const uint8_t * totemSampicEventInfoPtr_
const uint8_t * totemSampicDataPtr_
uint32_t getOrbitNumber() const
uint16_t getCellInfo() const
uint16_t getChannelMap() const
uint8_t getOffsetOfSamples() const
void printRawBuffer(const uint16_t *buffer, const bool binary=false, const unsigned int size=12) const
void printRaw(bool binary=false) const
const std::vector< uint8_t > getSamples() const
Log< level::Info, false > LogInfo
TotemSampicFrame(const uint8_t *chInfoPtr, const uint8_t *chDataPtr, const uint8_t *eventInfoPtr)
unsigned long long uint64_t
Definition: Time.h:13
TotemSampicConstant
uint16_t getTimestampB() const
uint8_t getPLLInfo() const
uint8_t getNumberOfSentSamples() const
T grayToBinary(const T &gcode_data)
bool valid() const
tmp
align.sh
Definition: createJobs.py:716
long double T
uint16_t getTimestampA() const
T extractDataFromBytesLSB(const uint8_t *array, int start, int size) const
uint64_t getFPGATimestamp() const
uint8_t getHardwareId() const