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 
19 
21 {
22  hwId_Position = 0, // hwId_Size = 1,
29  fpgaTime_Position = 7, // fpgaTime_Size = 5,
30  timestampA_Position = 12, // timestampA_Size = 2,
31  timestampB_Position = 14, // timestampB_Size = 2,
32  cellInfo_Position = 16, // cellInfo_Size = 2,
33  planeChannelId_Position = 18, // planeChannelId_Size = 1,
34  reserved_Position = 19, // reserved_Size = 5,
35 
36  boardId_Position = 0, // boardId_Size = 1,
37  l1ATimestamp_Position = 1, // l1ATimestamp_Size = 5,
38  bunchNumber_Position = 6, // bunchNumber_Size = 2,
39  orbitNumber_Position = 8, // orbitNumber_Size = 4,
40  eventNumber_Position = 12, // eventNumber_Size = 4,
41  channelMap_Position = 16, // channelMap_Size = 2,
42  l1ALatency_Position = 18, // l1ALatency_Size = 2,
43  numberOfSamples_Position = 20, // numberOfSamples_Size = 1,
44  offsetOfSamples_Position = 21, // offsetOfSamples_Size = 1,
45  fwVersion_Position = 22, // fwVersion_Size = 1,
46  pllInfo_Position = 23, // pllInfo_Size = 1,
47 
49  controlBits3 = 0x69,
50  cellInfo_Mask = 0x3F,
51 
52 };
53 
54 template <typename T>
55 T grayToBinary( const T& gcode_data )
56 {
57  //b[0] = g[0]
58  T binary = gcode_data & ( 0x0001 << ( 8*sizeof(T) - 1 ) ); // MSB is the same
59 
60  //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 {
72  public:
73  TotemSampicFrame( const uint8_t* chInfoPtr, const uint8_t* chDataPtr, const uint8_t* eventInfoPtr ) :
74  totemSampicInfoPtr_( chInfoPtr ), totemSampicDataPtr_( chDataPtr ), totemSampicEventInfoPtr_( eventInfoPtr ),
75  status_( 0 ) {
76  if ( chInfoPtr != nullptr && chDataPtr != nullptr && eventInfoPtr != nullptr && totemSampicInfoPtr_[ TotemSampicConstant::controlBits3_Position ] == TotemSampicConstant::controlBits3 )
77  status_ = 1;
78  }
80 
83  void printRaw( bool binary = false ) const {
84  std::cout << "Event Info: " << std::endl;
86 
87  std::cout << "Channel Info: " << std::endl;
88  printRawBuffer( (uint16_t*) totemSampicInfoPtr_ );
89 
90  std::cout << "Channel Data: " << std::endl;
91  printRawBuffer( (uint16_t*) totemSampicDataPtr_ );
92  }
93 
94  void print() const {
95  std::bitset<16> bitsChannelMap( getChannelMap() );
96  std::bitset<16> bitsPLLInfo( getPLLInfo() );
97  std::cout << "TotemSampicFrame:\nEvent:"
98  << "\nHardwareId (Event):\t" << std::hex << (unsigned int) getEventHardwareId()
99  << "\nL1A Timestamp:\t" << std::dec << getL1ATimestamp()
100  << "\nL1A Latency:\t" << std::dec << getL1ALatency()
101  << "\nBunch Number:\t" << std::dec << getBunchNumber()
102  << "\nOrbit Number:\t" << std::dec << getOrbitNumber()
103  << "\nEvent Number:\t" << std::dec << getEventNumber()
104  << "\nChannels fired:\t" << std::hex << bitsChannelMap.to_string()
105  << "\nNumber of Samples:\t" << std::dec << getNumberOfSentSamples()
106  << "\nOffset of Samples:\t" << std::dec << (int) getOffsetOfSamples()
107  << "\nFW Version:\t" << std::hex << (int) getFWVersion()
108  << "\nChannel:\nHardwareId:\t" << std::hex << (unsigned int) getHardwareId()
109  << "\nFPGATimestamp:\t" << std::dec << getFPGATimestamp()
110  << "\nTimestampA:\t" << std::dec << getTimestampA()
111  << "\nTimestampB:\t" << std::dec << getTimestampB()
112  << "\nCellInfo:\t" << std::dec << getCellInfo()
113  << "\nPlane:\t" << std::dec << getDetPlane()
114  << "\nChannel:\t" << std::dec << getDetChannel()
115  << "\nPLL Info:\t" << bitsPLLInfo.to_string()
116  << std::endl << std::endl;
117  }
118 
119  // All getters
120  inline uint8_t getHardwareId() const {
121  uint8_t tmp = 0;
123  return tmp;
124  }
125 
126  inline uint64_t getFPGATimestamp() const {
127  uint64_t tmp = 0;
128  if ( status_ ) {
129  tmp = *( ( const uint64_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::fpgaTime_Position ) ) & 0xFFFFFFFFFF;
130  }
131  return tmp;
132  }
133 
134  inline uint16_t getTimestampA() const {
135  uint16_t tmp = 0;
136  if ( status_ ) {
137  tmp = *( ( const uint16_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::timestampA_Position ) );
138  }
139  tmp = 0xFFF - tmp;
140  return grayToBinary<uint16_t> ( tmp );
141  }
142 
143  inline uint16_t getTimestampB() const {
144  uint16_t tmp = 0;
145  if ( status_ ) {
146  tmp = *( ( const uint16_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::timestampB_Position ) );
147  }
148  return grayToBinary<uint16_t> ( tmp );
149  }
150 
151  inline uint16_t getCellInfo() const {
152  uint16_t tmp = 0;
153  if ( status_ )
154  tmp = *( ( const uint16_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::cellInfo_Position ) );
156  }
157 
158  inline int getDetPlane() const {
159  int tmp = 0;
160  if ( status_ )
161  tmp = ( totemSampicInfoPtr_[ planeChannelId_Position ] & 0xF0 ) >> 4;
162  return tmp;
163  }
164 
165  inline int getDetChannel() const {
166  int tmp = 0;
167  if ( status_ )
169  return tmp;
170  }
171 
172  const std::vector<uint8_t> getSamples() const {
173  std::vector<uint8_t> samples;
174  if ( status_ ) {
176  for ( auto it = samples.begin(); it != samples.end(); ++it )
177  *it = grayToBinary<uint8_t>( *it );
178  }
179  return samples;
180  }
181 
182  inline unsigned int getNumberOfSamples() const {
184  }
185 
186  // Event Info
187  inline uint8_t getEventHardwareId() const {
188  uint8_t tmp = 0;
189  if ( status_ )
191  return tmp;
192  }
193 
194  inline uint64_t getL1ATimestamp() const {
195  uint64_t tmp = 0;
196  if ( status_ ) {
197  tmp = *( ( const uint64_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::l1ATimestamp_Position ) ) & 0xFFFFFFFFFF;
198  }
199  return tmp;
200  }
201 
202  inline uint16_t getBunchNumber() const
203  {
204  uint16_t tmp = 0;
205  if ( status_ )
206  tmp = *( ( const uint16_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::bunchNumber_Position ) );
207  return tmp;
208  }
209 
210  inline uint32_t getOrbitNumber() const
211  {
212  uint32_t tmp = 0;
213  if ( status_ )
214  tmp = *( ( const uint32_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::orbitNumber_Position ) );
215  return tmp;
216  }
217 
218  inline uint32_t getEventNumber() const
219  {
220  uint32_t tmp = 0;
221  if ( status_ )
222  tmp = *( ( const uint32_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::eventNumber_Position ) );
223  return tmp;
224  }
225 
226  inline uint16_t getChannelMap() const
227  {
228  uint16_t tmp = 0;
229  if ( status_ )
230  tmp = *( ( const uint16_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::channelMap_Position ) );
231  return tmp;
232  }
233 
234  inline uint16_t getL1ALatency() const
235  {
236  uint16_t tmp = 0;
237  if ( status_ )
238  tmp = *( ( const uint16_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::l1ALatency_Position ) );
239  return tmp;
240  }
241 
242  inline uint8_t getNumberOfSentSamples() const
243  {
244  uint8_t tmp = 0;
246  return tmp;
247  }
248 
249  inline uint8_t getOffsetOfSamples() const
250  {
251  uint8_t tmp = 0;
253  return tmp;
254  }
255 
256  inline uint8_t getPLLInfo() const {
257  uint8_t tmp = 0;
259  return tmp;
260  }
261 
262  inline uint8_t getFWVersion() const {
263  uint8_t tmp = 0;
265  return tmp;
266  }
267 
268  inline bool valid() const {
269  return status_ != 0;
270  }
271 
272  protected:
273  const uint8_t* totemSampicInfoPtr_;
274  const uint8_t* totemSampicDataPtr_;
275  const uint8_t* totemSampicEventInfoPtr_;
276 
277  int status_;
278 
279  inline void printRawBuffer( const uint16_t* buffer, const bool binary = false, const unsigned int size = 12 ) const {
280  for ( unsigned int i = 0; i < size; i++ ) {
281  if ( binary ) {
282  std::bitset<16> bits( *( buffer++ ) );
283  std::cout << bits.to_string() << std::endl;
284  }
285  else
286  std::cout << std::setfill( '0' ) << std::setw( 4 ) << std::hex << *( buffer++ ) << std::endl;
287  }
288  std::cout << std::endl;
289  }
290 
291 };
292 
293 
294 #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:15
uint16_t getBunchNumber() const
TotemSampicConstant
void printRawBuffer(const uint16_t *buffer, const bool binary=false, const unsigned int size=12) const
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
uint8_t getNumberOfSentSamples() const
T grayToBinary(const T &gcode_data)
long double T
bool valid() const
uint16_t getCellInfo() const
uint64_t getFPGATimestamp() const
uint16_t getL1ALatency() const
uint32_t getOrbitNumber() const