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,
32  timestampB_Position = 14, // timestampB_Size = 2,
33  cellInfo_Position = 16, // cellInfo_Size = 2,
34  planeChannelId_Position = 18, // planeChannelId_Size = 1,
35  reserved_Position = 19, // reserved_Size = 5,
36 
37  boardId_Position = 0, // boardId_Size = 1,
38  l1ATimestamp_Position = 1, // l1ATimestamp_Size = 5,
39  bunchNumber_Position = 6, // bunchNumber_Size = 2,
40  orbitNumber_Position = 8, // orbitNumber_Size = 4,
41  eventNumber_Position = 12, // eventNumber_Size = 4,
42  channelMap_Position = 16, // channelMap_Size = 2,
43  l1ALatency_Position = 18, // l1ALatency_Size = 2,
44  numberOfSamples_Position = 20, // numberOfSamples_Size = 1,
45  offsetOfSamples_Position = 21, // offsetOfSamples_Size = 1,
46  fwVersion_Position = 22, // fwVersion_Size = 1,
47  pllInfo_Position = 23, // pllInfo_Size = 1,
48 
50  controlBits3 = 0x69,
51  cellInfo_Mask = 0x3F,
52 
53 };
54 
55 template <typename T>
56 T grayToBinary(const T& gcode_data) {
57  // assign b[0] = g[0]
58  T binary = gcode_data & (0x0001 << (8 * sizeof(T) - 1)); // MSB is the same
59 
60  // assign b[i] = g[i] xor b[i-1]
61  for (unsigned short int i = 1; i < 8 * sizeof(T); ++i)
62  binary |= (gcode_data ^ (binary >> 1)) & (0x0001 << (8 * sizeof(T) - i - 1));
63 
64  return binary;
65 }
66 
71 public:
72  TotemSampicFrame(const uint8_t* chInfoPtr, const uint8_t* chDataPtr, const uint8_t* eventInfoPtr)
73  : totemSampicInfoPtr_(chInfoPtr),
74  totemSampicDataPtr_(chDataPtr),
75  totemSampicEventInfoPtr_(eventInfoPtr),
76  status_(0) {
77  if (chInfoPtr != nullptr && chDataPtr != nullptr && eventInfoPtr != nullptr &&
79  status_ = 1;
80  }
82 
85  void printRaw(bool binary = false) const {
86  edm::LogInfo("TotemSampicFrame") << "Event Info: \n";
88 
89  edm::LogInfo("TotemSampicFrame") << "Channel Info: \n";
91 
92  edm::LogInfo("TotemSampicFrame") << "Channel Data: \n";
94  }
95 
96  void print() const {
97  std::bitset<16> bitsChannelMap(getChannelMap());
98  std::bitset<16> bitsPLLInfo(getPLLInfo());
99  edm::LogInfo("TotemSampicFrame") << "\nEvent:"
100  << "\nHardwareId (Event):\t" << std::hex << (unsigned int)getEventHardwareId()
101  << "\nL1A Timestamp:\t" << std::dec << getL1ATimestamp() << "\nL1A Latency:\t"
102  << std::dec << getL1ALatency() << "\nBunch Number:\t" << std::dec
103  << getBunchNumber() << "\nOrbit Number:\t" << std::dec << getOrbitNumber()
104  << "\nEvent Number:\t" << std::dec << getEventNumber() << "\nChannels fired:\t"
105  << std::hex << bitsChannelMap.to_string() << "\nNumber of Samples:\t" << std::dec
106  << getNumberOfSentSamples() << "\nOffset of Samples:\t" << std::dec
107  << (int)getOffsetOfSamples() << "\nFW Version:\t" << std::hex
108  << (int)getFWVersion() << "\nChannel:\nHardwareId:\t" << std::hex
109  << (unsigned int)getHardwareId() << "\nFPGATimestamp:\t" << std::dec
110  << getFPGATimestamp() << "\nTimestampA:\t" << std::dec << getTimestampA()
111  << "\nTimestampB:\t" << std::dec << getTimestampB() << "\nCellInfo:\t" << std::dec
112  << getCellInfo() << "\nPlane:\t" << std::dec << getDetPlane() << "\nChannel:\t"
113  << std::dec << getDetChannel() << "\nPLL Info:\t" << bitsPLLInfo.to_string()
114  << "\n\n";
115  }
116 
117  // All getters
118  inline uint8_t getHardwareId() const {
119  uint8_t tmp = 0;
120  if (status_)
122  return tmp;
123  }
124 
125  inline uint64_t getFPGATimestamp() const {
126  uint64_t tmp = 0;
127  if (status_) {
128  tmp = *((const uint64_t*)(totemSampicInfoPtr_ + TotemSampicConstant::fpgaTime_Position)) & 0xFFFFFFFFFF;
129  }
130  return tmp;
131  }
132 
133  inline uint16_t getTimestampA() const {
134  uint16_t tmp = 0;
135  if (status_) {
137  }
138  tmp = 0xFFF - tmp;
139  return grayToBinary<uint16_t>(tmp);
140  }
141 
142  inline uint16_t getTimestampB() const {
143  uint16_t tmp = 0;
144  if (status_) {
146  }
147  return grayToBinary<uint16_t>(tmp);
148  }
149 
150  inline uint16_t getCellInfo() const {
151  uint16_t tmp = 0;
152  if (status_)
153  tmp = *((const uint16_t*)(totemSampicInfoPtr_ + TotemSampicConstant::cellInfo_Position));
155  }
156 
157  inline int getDetPlane() const {
158  int tmp = 0;
159  if (status_)
160  tmp = (totemSampicInfoPtr_[planeChannelId_Position] & 0xF0) >> 4;
161  return tmp;
162  }
163 
164  inline int getDetChannel() const {
165  int tmp = 0;
166  if (status_)
168  return tmp;
169  }
170 
171  const std::vector<uint8_t> getSamples() const {
172  std::vector<uint8_t> samples;
173  if (status_) {
175  for (auto it = samples.begin(); it != samples.end(); ++it)
176  *it = grayToBinary<uint8_t>(*it);
177  }
178  return samples;
179  }
180 
181  inline unsigned int getNumberOfSamples() const { return status_ * TotemSampicConstant::numberOfSamples; }
182 
183  // Event Info
184  inline uint8_t getEventHardwareId() const {
185  uint8_t tmp = 0;
186  if (status_)
188  return tmp;
189  }
190 
191  inline uint64_t getL1ATimestamp() const {
192  uint64_t tmp = 0;
193  if (status_) {
195  }
196  return tmp;
197  }
198 
199  inline uint16_t getBunchNumber() const {
200  uint16_t tmp = 0;
201  if (status_)
203  return tmp;
204  }
205 
206  inline uint32_t getOrbitNumber() const {
207  uint32_t tmp = 0;
208  if (status_)
210  return tmp;
211  }
212 
213  inline uint32_t getEventNumber() const {
214  uint32_t tmp = 0;
215  if (status_)
217  return tmp;
218  }
219 
220  inline uint16_t getChannelMap() const {
221  uint16_t tmp = 0;
222  if (status_)
224  return tmp;
225  }
226 
227  inline uint16_t getL1ALatency() const {
228  uint16_t tmp = 0;
229  if (status_)
231  return tmp;
232  }
233 
234  inline uint8_t getNumberOfSentSamples() const {
235  uint8_t tmp = 0;
236  if (status_)
238  return tmp;
239  }
240 
241  inline uint8_t getOffsetOfSamples() const {
242  uint8_t tmp = 0;
243  if (status_)
245  return tmp;
246  }
247 
248  inline uint8_t getPLLInfo() const {
249  uint8_t tmp = 0;
250  if (status_)
252  return tmp;
253  }
254 
255  inline uint8_t getFWVersion() const {
256  uint8_t tmp = 0;
257  if (status_)
259  return tmp;
260  }
261 
262  inline bool valid() const { return status_ != 0; }
263 
264 protected:
265  const uint8_t* totemSampicInfoPtr_;
266  const uint8_t* totemSampicDataPtr_;
267  const uint8_t* totemSampicEventInfoPtr_;
268 
269  int status_;
270 
271  inline void printRawBuffer(const uint16_t* buffer, const bool binary = false, const unsigned int size = 12) const {
272  for (unsigned int i = 0; i < size; i++) {
273  if (binary) {
274  std::bitset<16> bits(*(buffer++));
275  edm::LogInfo("TotemSampicFrame") << bits.to_string() << "\n";
276  } else
277  edm::LogInfo("TotemSampicFrame") << std::setfill('0') << std::setw(4) << std::hex << *(buffer++) << "\n";
278  }
279  }
280 };
281 
282 #endif
size
Write out results.
const std::vector< uint8_t > getSamples() const
uint16_t getTimestampB() const
const uint8_t * totemSampicInfoPtr_
uint16_t getChannelMap() const
int getDetPlane() const
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision bits
uint8_t getEventHardwareId() const
uint8_t getPLLInfo() const
unsigned int getNumberOfSamples() const
void print() const
void printRaw(bool binary=false) const
const uint8_t * totemSampicEventInfoPtr_
const uint8_t * totemSampicDataPtr_
uint8_t getHardwareId() const
uint32_t getEventNumber() const
uint16_t getTimestampA() const
uint64_t getL1ATimestamp() const
uint8_t getOffsetOfSamples() const
uint8_t getFWVersion() const
int getDetChannel() const
TotemSampicFrame(const uint8_t *chInfoPtr, const uint8_t *chDataPtr, const uint8_t *eventInfoPtr)
unsigned long long uint64_t
Definition: Time.h:13
uint16_t getBunchNumber() const
TotemSampicConstant
void printRawBuffer(const uint16_t *buffer, const bool binary=false, const unsigned int size=12) const
uint8_t getNumberOfSentSamples() const
T grayToBinary(const T &gcode_data)
tmp
align.sh
Definition: createJobs.py:716
long double T
bool valid() const
uint16_t getCellInfo() const
uint64_t getFPGATimestamp() const
uint16_t getL1ALatency() const
uint32_t getOrbitNumber() const