CMS 3D CMS Logo

MatacqRawEvent.h
Go to the documentation of this file.
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
2 
3 #ifndef MATACQRAWEVENT_H
4 #define MATACQRAWEVENT_H
5 
6 #include <cinttypes>
7 #include <cstddef>
8 #include <vector>
9 
10 //replace 1 by 0 to remove XDAQ dependency. In this case it is assumed the machine is little endian.
11 #if 0
12 #include "i2o/utils/endian.h" //from XDAQ
13 #define UINT32_FROM_LE i2odecodel
14 #define UINT16_FROM_LE i2odecodes
15 #define INT16_FROM_LE i2odecodes
16 
17 #else //assuming little endianness of the machine
18 
19 #define UINT32_FROM_LE
20 #define UINT16_FROM_LE
21 #define INT16_FROM_LE
22 
23 #endif
24 
25 #include <sys/time.h> //for timeval definition
26 
31  //typedefs, enums and static constants
32 public:
40  errorLength = 1 << 1,
43  errorWrongBoe = 1 << 2
44  };
45 
46  /* The following types are little-endian encoded types. Use of these types
47  * for the I20 data block should offer portability to big-endian platforms.
48  */
50  struct uint32le_t {
51  uint32_t littleEndianInt;
52  operator uint32_t() const { return UINT32_FROM_LE(littleEndianInt); }
53  };
54 
55  struct uint16le_t {
56  uint16_t littleEndianInt;
57  operator uint16_t() const { return UINT16_FROM_LE(littleEndianInt); }
58  };
59 
60  struct int16le_t {
61  int16_t littleEndianInt;
62  operator int16_t() const { return INT16_FROM_LE(littleEndianInt); }
63  };
65 
66  struct ChannelData {
69  int chId;
72  int nSamples;
76  };
77 
78 private:
81  // struct matacqHeader_t{
82  // uint16_t version;
83  // unsigned char freqGHz;
84  // unsigned char channelCount;
85  // uint32_t orbitId;
86  // unsigned char trigRec;
87  // uint16_t postTrig;
88  // uint16_t vernier[4];
89  // uint32_t timeStamp;
90  // };
91 
94  struct field32spec_t {
95  int offset;
96  unsigned int mask;
97  };
98 
100 
102  static const field32spec_t fov32;
103  static const field32spec_t fedId32;
104  static const field32spec_t bxId32;
105  static const field32spec_t lv132;
107  static const field32spec_t boeType32;
108  static const field32spec_t dccLen32;
110  static const field32spec_t runNum32;
111  static const field32spec_t h1Marker32;
113 
115 
118  static const field32spec_t freqGHz32;
121  static const field32spec_t tTrigPs32;
122  static const field32spec_t orbitId32;
123  static const field32spec_t trigRec32;
124  static const field32spec_t postTrig32;
130 
135  static const field32spec_t delayA32;
136  static const field32spec_t dccId32;
137  static const field32spec_t color32;
138  static const field32spec_t trigType32;
139  static const field32spec_t side32;
140 
142 
143  //constructors
144 public:
154  MatacqRawEvent(const unsigned char* dataBuffer, size_t bufferSize) : vernier(std::vector<int>(4)) {
155  setRawData(dataBuffer, bufferSize);
156  }
157  //methods
158 public:
165  int getFov() const { return read32(daqHeader, fov32); }
166 
170  int getFedId() const { return read32(daqHeader, fedId32); }
171 
175  int getBxId() const { return read32(daqHeader, bxId32); }
176 
180  unsigned getEventId() const { return read32(daqHeader, lv132); }
181 
185  int getTriggerType() const { return read32(daqHeader, triggerType32); }
186 
190  int getBoe() const { return read32(daqHeader, boeType32); }
191 
195  unsigned getDccLen() const { return read32(daqHeader, dccLen32); }
196 
203  static unsigned getDccLen(unsigned char* data, size_t size) {
204  if (size < (unsigned)(dccLen32.offset + 1) * 4)
205  return (unsigned)-1;
206  return read32((uint32le_t*)data, dccLen32);
207  }
208 
216  static unsigned getOrbitId(unsigned char* data, size_t size) {
217  if (size < (unsigned)(orbitId32.offset + 1) * 8)
218  return (unsigned)-1;
219  return read32((uint32le_t*)data, orbitId32);
220  }
221 
228  static unsigned getRunNum(unsigned char* data, size_t size) {
229  if (size < (unsigned)(runNum32.offset + 1) * 8)
230  return (unsigned)-1;
231  return read32((uint32le_t*)data, runNum32);
232  }
233 
237  unsigned getDaqLen() const { return fragLen; }
238 
242  int getDccErrors() const { return read32(daqHeader, dccErrors32); }
243 
247  unsigned getRunNum() const { return read32(daqHeader, runNum32); }
248 
252  int getH1Marker() const { return read32(daqHeader, h1Marker32); }
253 
258 
263  int32_t getStatus() const { return error; }
264 
268  int getFreqGHz() const { return /*matacqHeader->*/ freqGHz; }
269 
273  int getChannelCount() const { return /*matacqHeader->*/ channelCount; }
274 
280  const std::vector<ChannelData>& getChannelData() const { return channelData; }
281 
286  int getParsedLen() { return parsedLen; }
287 
293  time_t getTimeStamp() const { return /*matacqHeader->*/ timeStamp.tv_sec; }
294 
300  void getTimeStamp(struct timeval& t) const { t = timeStamp; }
301 
306  int getTTrigPs() const { return tTrigPs; }
307 
312  uint32_t getOrbitId() const { return orbitId; }
313 
318  int getTrigRec() const { return trigRec; }
319 
323  int getPostTrig() const { return postTrig; }
324 
328  std::vector<int> getVernier() const { return vernier; }
329 
332  int getDelayA() const { return delayA; }
333 
336  int getEmtcDelay() const { return emtcDelay; }
337 
340  int getEmtcPhase() const { return emtcPhase; }
341 
345  int getAttenuation_dB() const { return attenuation_dB; }
346 
349  int getLaserPower() const { return laserPower; }
350 
351 private:
360  static int read32(const uint32le_t* pData, field32spec_t spec, bool ovfTrans = false);
361 
362  // /** Help function to get the maximum value of a data field
363  // * @param spec32 data field specification
364  // * @return maximum value
365  // */
366  // int max32(field32spec_t spec32) const;
367 
375  void setRawData(const unsigned char* buffer, size_t bufferSize);
376 
377  //fields
378 private:
381  int boe;
382 
385  int bxId;
386 
390 
393  std::vector<ChannelData> channelData;
394 
398 
402 
405  unsigned dccLen;
406 
409  unsigned eventId;
410 
413  int32_t error;
414 
417  int fedId;
418 
421  int fov;
422 
425  int fragLen;
426 
429  int freqGHz;
430 
433  int h1Marker;
434 
437  // matacqHeader_t* matacqHeader;
438 
442 
446 
450 
453  unsigned runNum;
454 
457  struct timeval timeStamp;
458 
461  int tTrigPs;
462 
466 
467  /* LHC orbit ID
468  */
469  uint32_t orbitId;
470 
473  int trigRec;
474 
477  int postTrig;
478 
481  std::vector<int> vernier;
482 
485  int delayA;
486 
490 
494 
499 
503 };
504 
505 #endif //MATACQRAWEVENT_H not defined
size
Write out results.
static const field32spec_t vernier1_32
static const field32spec_t fedId32
static const field32spec_t boeType32
int getFreqGHz() const
static unsigned getRunNum(unsigned char *data, size_t size)
int getPostTrig() const
static int read32(const uint32le_t *pData, field32spec_t spec, bool ovfTrans=false)
time_t getTimeStamp() const
const int16le_t * samples
int getChannelCount() const
static unsigned getOrbitId(unsigned char *data, size_t size)
static const field32spec_t runNum32
unsigned getDccLen() const
static const field32spec_t timeStamp32
#define UINT32_FROM_LE
const uint32le_t * daqHeader
static const field32spec_t trigType32
static const field32spec_t tTrigPs32
int getDccErrors() const
std::vector< int > vernier
int getTTrigPs() const
static const field32spec_t channelCount32
const std::vector< ChannelData > & getChannelData() const
unsigned getDaqLen() const
#define UINT16_FROM_LE
static const field32spec_t emtcPhase32
int getH1Marker() const
void setRawData(const unsigned char *buffer, size_t bufferSize)
static const field32spec_t dccLen32
std::vector< int > getVernier() const
static const field32spec_t fov32
static const field32spec_t attenuation_dB32
static const field32spec_t lv132
static const field32spec_t vernier0_32
static const field32spec_t vernier3_32
static unsigned getDccLen(unsigned char *data, size_t size)
static const field32spec_t postTrig32
int getDelayA() const
int getFedId() const
int getEmtcPhase() const
uint16le_t * pSamples
int getLaserPower() const
static const field32spec_t timeStampMicroSec32
static const field32spec_t trigRec32
#define INT16_FROM_LE
static const field32spec_t vernier2_32
static const field32spec_t emtcDelay32
int getFov() const
static const field32spec_t side32
unsigned getEventId() const
static const field32spec_t dccId32
static const field32spec_t triggerType32
int getEmtcDelay() const
static const field32spec_t color32
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
MatacqRawEvent(const unsigned char *dataBuffer, size_t bufferSize)
int getBxId() const
static const field32spec_t delayA32
struct timeval timeStamp
int getTriggerType() const
void getTimeStamp(struct timeval &t) const
unsigned getRunNum() const
int getBoe() const
static const field32spec_t orbitId32
std::vector< ChannelData > channelData
uint32_t getOrbitId() const
int getTrigRec() const
static const field32spec_t formatVersion32
static const field32spec_t dccErrors32
static const field32spec_t h1Marker32
static const field32spec_t freqGHz32
static const field32spec_t laserPower32
int getMatacqDataFormatVersion() const
int32_t getStatus() const
int getAttenuation_dB() const
static const field32spec_t bxId32