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 
70 class TotemSampicFrame {
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_) {
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_)
155  }
156 
157  inline int getDetPlane() const {
158  int tmp = 0;
159  if (status_)
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
mps_fire.i
i
Definition: mps_fire.py:355
MessageLogger.h
numberOfSamples_Position
Definition: TotemSampicFrame.h:48
TotemSampicFrame::getOffsetOfSamples
uint8_t getOffsetOfSamples() const
Definition: TotemSampicFrame.h:240
grayToBinary
T grayToBinary(const T &gcode_data)
Definition: TotemSampicFrame.h:55
l1ALatency_Position
Definition: TotemSampicFrame.h:47
TotemSampicFrame::totemSampicEventInfoPtr_
const uint8_t * totemSampicEventInfoPtr_
Definition: TotemSampicFrame.h:266
boardId_Position
Definition: TotemSampicFrame.h:41
TotemSampicFrame::getTimestampB
uint16_t getTimestampB() const
Definition: TotemSampicFrame.h:141
orbitNumber_Position
Definition: TotemSampicFrame.h:44
fpgaTime_Position
Definition: TotemSampicFrame.h:34
TotemSampicFrame::getPLLInfo
uint8_t getPLLInfo() const
Definition: TotemSampicFrame.h:247
edm::LogInfo
Definition: MessageLogger.h:254
TotemSampicFrame::getTimestampA
uint16_t getTimestampA() const
Definition: TotemSampicFrame.h:132
TotemSampicFrame::getFPGATimestamp
uint64_t getFPGATimestamp() const
Definition: TotemSampicFrame.h:124
eventNumber_Position
Definition: TotemSampicFrame.h:45
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
TotemSampicFrame::~TotemSampicFrame
~TotemSampicFrame()
Definition: TotemSampicFrame.h:80
EgammaValidation_cff.samples
samples
Definition: EgammaValidation_cff.py:19
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
TotemSampicFrame::TotemSampicFrame
TotemSampicFrame(const uint8_t *chInfoPtr, const uint8_t *chDataPtr, const uint8_t *eventInfoPtr)
Definition: TotemSampicFrame.h:71
TotemSampicFrame::getFWVersion
uint8_t getFWVersion() const
Definition: TotemSampicFrame.h:254
TotemSampicFrame::getSamples
const std::vector< uint8_t > getSamples() const
Definition: TotemSampicFrame.h:170
timestampB_Position
Definition: TotemSampicFrame.h:36
TotemSampicFrame::getEventHardwareId
uint8_t getEventHardwareId() const
Definition: TotemSampicFrame.h:183
TotemSampicFrame::getL1ATimestamp
uint64_t getL1ATimestamp() const
Definition: TotemSampicFrame.h:190
controlBits5_Position
Definition: TotemSampicFrame.h:33
l1ATimestamp_Position
Definition: TotemSampicFrame.h:42
TotemSampicFrame::getNumberOfSamples
unsigned int getNumberOfSamples() const
Definition: TotemSampicFrame.h:180
controlBits2_Position
Definition: TotemSampicFrame.h:30
TotemSampicFrame::getNumberOfSentSamples
uint8_t getNumberOfSentSamples() const
Definition: TotemSampicFrame.h:233
TotemSampicConstant
TotemSampicConstant
Definition: TotemSampicFrame.h:21
reserved_Position
Definition: TotemSampicFrame.h:39
TotemSampicFrame
Definition: TotemSampicFrame.h:69
bunchNumber_Position
Definition: TotemSampicFrame.h:43
timestampA_Position
Definition: TotemSampicFrame.h:35
hwId_Position
Definition: TotemSampicFrame.h:27
TotemSampicFrame::valid
bool valid() const
Definition: TotemSampicFrame.h:261
TotemSampicFrame::getDetChannel
int getDetChannel() const
Definition: TotemSampicFrame.h:163
fwVersion_Position
Definition: TotemSampicFrame.h:50
TotemSampicFrame::getL1ALatency
uint16_t getL1ALatency() const
Definition: TotemSampicFrame.h:226
VFATFrame.h
cellInfo_Mask
Definition: TotemSampicFrame.h:55
createfilelist.int
int
Definition: createfilelist.py:10
TotemSampicFrame::getOrbitNumber
uint32_t getOrbitNumber() const
Definition: TotemSampicFrame.h:205
TotemSampicFrame::print
void print() const
Definition: TotemSampicFrame.h:95
pllInfo_Position
Definition: TotemSampicFrame.h:51
TotemSampicFrame::getHardwareId
uint8_t getHardwareId() const
Definition: TotemSampicFrame.h:117
controlBits0_Position
Definition: TotemSampicFrame.h:28
controlBits4_Position
Definition: TotemSampicFrame.h:32
TotemSampicFrame::printRawBuffer
void printRawBuffer(const uint16_t *buffer, const bool binary=false, const unsigned int size=12) const
Definition: TotemSampicFrame.h:270
TotemSampicFrame::getCellInfo
uint16_t getCellInfo() const
Definition: TotemSampicFrame.h:149
bits
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
Definition: EventSelector-behavior.doc:35
TotemSampicFrame::getEventNumber
uint32_t getEventNumber() const
Definition: TotemSampicFrame.h:212
controlBits1_Position
Definition: TotemSampicFrame.h:29
TotemSampicFrame::getChannelMap
uint16_t getChannelMap() const
Definition: TotemSampicFrame.h:219
T
long double T
Definition: Basic3DVectorLD.h:48
TotemSampicFrame::getBunchNumber
uint16_t getBunchNumber() const
Definition: TotemSampicFrame.h:198
offsetOfSamples_Position
Definition: TotemSampicFrame.h:49
TotemSampicFrame::totemSampicInfoPtr_
const uint8_t * totemSampicInfoPtr_
Definition: TotemSampicFrame.h:264
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
channelMap_Position
Definition: TotemSampicFrame.h:46
TotemSampicFrame::status_
int status_
Definition: TotemSampicFrame.h:268
TotemSampicFrame::printRaw
void printRaw(bool binary=false) const
Definition: TotemSampicFrame.h:84
controlBits3
Definition: TotemSampicFrame.h:54
controlBits3_Position
Definition: TotemSampicFrame.h:31
planeChannelId_Position
Definition: TotemSampicFrame.h:38
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
numberOfSamples
Definition: TotemSampicFrame.h:53
cellInfo_Position
Definition: TotemSampicFrame.h:37
TotemSampicFrame::getDetPlane
int getDetPlane() const
Definition: TotemSampicFrame.h:156
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
TotemSampicFrame::totemSampicDataPtr_
const uint8_t * totemSampicDataPtr_
Definition: TotemSampicFrame.h:265