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 
20 
22 {
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 {
58  //b[0] = g[0]
59  T binary = gcode_data & ( 0x0001 << ( 8*sizeof(T) - 1 ) ); // MSB is the same
60 
61  //b[i] = g[i] xor b[i-1]
62  for (unsigned short int i = 1; i < 8*sizeof(T); ++i)
63  binary |= ( gcode_data ^ ( binary >> 1 ) ) & (0x0001 << ( 8*sizeof(T) - i - 1 ) );
64 
65  return binary;
66 }
67 
72 {
73  public:
74  TotemSampicFrame( const uint8_t* chInfoPtr, const uint8_t* chDataPtr, const uint8_t* eventInfoPtr ) :
75  totemSampicInfoPtr_( chInfoPtr ), totemSampicDataPtr_( chDataPtr ), totemSampicEventInfoPtr_( eventInfoPtr ),
76  status_( 0 ) {
77  if ( chInfoPtr != nullptr && chDataPtr != nullptr && eventInfoPtr != nullptr && totemSampicInfoPtr_[ TotemSampicConstant::controlBits3_Position ] == TotemSampicConstant::controlBits3 )
78  status_ = 1;
79  }
81 
84  void printRaw( bool binary = false ) const {
85  std::cout << "Event Info: " << std::endl;
87 
88  std::cout << "Channel Info: " << std::endl;
89  printRawBuffer( (uint16_t*) totemSampicInfoPtr_ );
90 
91  std::cout << "Channel Data: " << std::endl;
92  printRawBuffer( (uint16_t*) totemSampicDataPtr_ );
93  }
94 
95  void print() const {
96  std::bitset<16> bitsChannelMap( getChannelMap() );
97  std::bitset<16> bitsPLLInfo( getPLLInfo() );
98  std::cout << "TotemSampicFrame:\nEvent:"
99  << "\nHardwareId (Event):\t" << std::hex << (unsigned int) getEventHardwareId()
100  << "\nL1A Timestamp:\t" << std::dec << getL1ATimestamp()
101  << "\nL1A Latency:\t" << std::dec << getL1ALatency()
102  << "\nBunch Number:\t" << std::dec << getBunchNumber()
103  << "\nOrbit Number:\t" << std::dec << getOrbitNumber()
104  << "\nEvent Number:\t" << std::dec << getEventNumber()
105  << "\nChannels fired:\t" << std::hex << bitsChannelMap.to_string()
106  << "\nNumber of Samples:\t" << std::dec << getNumberOfSentSamples()
107  << "\nOffset of Samples:\t" << std::dec << (int) getOffsetOfSamples()
108  << "\nFW Version:\t" << std::hex << (int) getFWVersion()
109  << "\nChannel:\nHardwareId:\t" << std::hex << (unsigned int) getHardwareId()
110  << "\nFPGATimestamp:\t" << std::dec << getFPGATimestamp()
111  << "\nTimestampA:\t" << std::dec << getTimestampA()
112  << "\nTimestampB:\t" << std::dec << getTimestampB()
113  << "\nCellInfo:\t" << std::dec << getCellInfo()
114  << "\nPlane:\t" << std::dec << getDetPlane()
115  << "\nChannel:\t" << std::dec << getDetChannel()
116  << "\nPLL Info:\t" << bitsPLLInfo.to_string()
117  << std::endl << std::endl;
118  }
119 
120  // All getters
121  inline uint8_t getHardwareId() const {
122  uint8_t tmp = 0;
124  return tmp;
125  }
126 
127  inline uint64_t getFPGATimestamp() const {
128  uint64_t tmp = 0;
129  if ( status_ ) {
130  tmp = *( ( const uint64_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::fpgaTime_Position ) ) & 0xFFFFFFFFFF;
131  }
132  return tmp;
133  }
134 
135  inline uint16_t getTimestampA() const {
136  uint16_t tmp = 0;
137  if ( status_ ) {
138  tmp = *( ( const uint16_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::timestampA_Position ) );
139  }
140  tmp = 0xFFF - tmp;
141  return grayToBinary<uint16_t> ( tmp );
142  }
143 
144  inline uint16_t getTimestampB() const {
145  uint16_t tmp = 0;
146  if ( status_ ) {
147  tmp = *( ( const uint16_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::timestampB_Position ) );
148  }
149  return grayToBinary<uint16_t> ( tmp );
150  }
151 
152  inline uint16_t getCellInfo() const {
153  uint16_t tmp = 0;
154  if ( status_ )
155  tmp = *( ( const uint16_t* ) ( totemSampicInfoPtr_ + TotemSampicConstant::cellInfo_Position ) );
157  }
158 
159  inline int getDetPlane() const {
160  int tmp = 0;
161  if ( status_ )
162  tmp = ( totemSampicInfoPtr_[ planeChannelId_Position ] & 0xF0 ) >> 4;
163  return tmp;
164  }
165 
166  inline int getDetChannel() const {
167  int tmp = 0;
168  if ( status_ )
170  return tmp;
171  }
172 
173  const std::vector<uint8_t> getSamples() const {
174  std::vector<uint8_t> samples;
175  if ( status_ ) {
177  for ( auto it = samples.begin(); it != samples.end(); ++it )
178  *it = grayToBinary<uint8_t>( *it );
179  }
180  return samples;
181  }
182 
183  inline unsigned int getNumberOfSamples() const {
185  }
186 
187  // Event Info
188  inline uint8_t getEventHardwareId() const {
189  uint8_t tmp = 0;
190  if ( status_ )
192  return tmp;
193  }
194 
195  inline uint64_t getL1ATimestamp() const {
196  uint64_t tmp = 0;
197  if ( status_ ) {
198  tmp = *( ( const uint64_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::l1ATimestamp_Position ) ) & 0xFFFFFFFFFF;
199  }
200  return tmp;
201  }
202 
203  inline uint16_t getBunchNumber() const
204  {
205  uint16_t tmp = 0;
206  if ( status_ )
207  tmp = *( ( const uint16_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::bunchNumber_Position ) );
208  return tmp;
209  }
210 
211  inline uint32_t getOrbitNumber() const
212  {
213  uint32_t tmp = 0;
214  if ( status_ )
215  tmp = *( ( const uint32_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::orbitNumber_Position ) );
216  return tmp;
217  }
218 
219  inline uint32_t getEventNumber() const
220  {
221  uint32_t tmp = 0;
222  if ( status_ )
223  tmp = *( ( const uint32_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::eventNumber_Position ) );
224  return tmp;
225  }
226 
227  inline uint16_t getChannelMap() const
228  {
229  uint16_t tmp = 0;
230  if ( status_ )
231  tmp = *( ( const uint16_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::channelMap_Position ) );
232  return tmp;
233  }
234 
235  inline uint16_t getL1ALatency() const
236  {
237  uint16_t tmp = 0;
238  if ( status_ )
239  tmp = *( ( const uint16_t* ) ( totemSampicEventInfoPtr_ + TotemSampicConstant::l1ALatency_Position ) );
240  return tmp;
241  }
242 
243  inline uint8_t getNumberOfSentSamples() const
244  {
245  uint8_t tmp = 0;
247  return tmp;
248  }
249 
250  inline uint8_t getOffsetOfSamples() const
251  {
252  uint8_t tmp = 0;
254  return tmp;
255  }
256 
257  inline uint8_t getPLLInfo() const {
258  uint8_t tmp = 0;
260  return tmp;
261  }
262 
263  inline uint8_t getFWVersion() const {
264  uint8_t tmp = 0;
266  return tmp;
267  }
268 
269  inline bool valid() const {
270  return status_ != 0;
271  }
272 
273  protected:
274  const uint8_t* totemSampicInfoPtr_;
275  const uint8_t* totemSampicDataPtr_;
276  const uint8_t* totemSampicEventInfoPtr_;
277 
278  int status_;
279 
280  inline void printRawBuffer( const uint16_t* buffer, const bool binary = false, const unsigned int size = 12 ) const {
281  for ( unsigned int i = 0; i < size; i++ ) {
282  if ( binary ) {
283  std::bitset<16> bits( *( buffer++ ) );
284  std::cout << bits.to_string() << std::endl;
285  }
286  else
287  std::cout << std::setfill( '0' ) << std::setw( 4 ) << std::hex << *( buffer++ ) << std::endl;
288  }
289  std::cout << std::endl;
290  }
291 
292 };
293 
294 
295 #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