CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/EcalRawToDigi/interface/MatacqRawEvent.h

Go to the documentation of this file.
00001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
00002 //$Id: MatacqRawEvent.h,v 1.2 2012/06/11 08:57:01 davidlt Exp $
00003 
00004 #ifndef MATACQRAWEVENT_H
00005 #define MATACQRAWEVENT_H
00006 
00007 #include <inttypes.h>
00008 #include <vector>
00009 
00010 #if 0 //replace 1 by 0 to remove XDAQ dependency. In this case it is assumed the
00011       //machine is little endian.
00012 #include "i2o/utils/endian.h" //from XDAQ
00013 #define UINT32_FROM_LE i2odecodel
00014 #define UINT16_FROM_LE i2odecodes
00015 #define INT16_FROM_LE i2odecodes
00016 
00017 #else //assuming little endianness of the machine
00018 
00019 #define UINT32_FROM_LE
00020 #define UINT16_FROM_LE
00021 #define INT16_FROM_LE
00022 
00023 #endif
00024 
00025 #include <sys/time.h> //for timeval definition
00026 
00030 class MatacqRawEvent{
00031   //typedefs, enums and static constants
00032 public:
00033   enum matacqError_t {
00037     errorLengthConsistency = 1<<0,
00040     errorLength = 1<<1,
00043     errorWrongBoe = 1<<2
00044   };
00045 
00046   /* The following types are little-endian encoded types. Use of these types
00047    * for the I20 data block should offer portability to big-endian platforms.
00048    */
00050   struct uint32le_t{
00051     uint32_t littleEndianInt;
00052     operator uint32_t() const{
00053       return UINT32_FROM_LE(littleEndianInt);
00054     }
00055   };
00056   
00057   struct uint16le_t{
00058     uint16_t littleEndianInt;
00059     operator uint16_t() const{
00060       return UINT16_FROM_LE(littleEndianInt);
00061     }
00062   };
00063   
00064   struct int16le_t{
00065     int16_t littleEndianInt;
00066     operator int16_t() const{
00067       return INT16_FROM_LE(littleEndianInt);
00068     }
00069   };
00071   
00072   struct ChannelData{
00075     int chId;
00078     int nSamples;
00081     const int16le_t* samples;
00082   };
00083 
00084 private:  
00087 //   struct matacqHeader_t{              
00088 //     uint16_t version;         
00089 //     unsigned char freqGHz;    
00090 //     unsigned char channelCount; 
00091 //     uint32_t orbitId;
00092 //     unsigned char trigRec;
00093 //     uint16_t postTrig;
00094 //     uint16_t vernier[4];
00095 //     uint32_t timeStamp;
00096 //   };                                          
00097 
00100   struct field32spec_t{
00101     int offset;
00102     unsigned int mask;
00103   };
00104   
00106 
00108   static const field32spec_t fov32;
00109   static const field32spec_t fedId32;
00110   static const field32spec_t bxId32;
00111   static const field32spec_t lv132;
00112   static const field32spec_t triggerType32;
00113   static const field32spec_t boeType32;
00114   static const field32spec_t dccLen32;
00115   static const field32spec_t dccErrors32;
00116   static const field32spec_t runNum32;
00117   static const field32spec_t h1Marker32;
00119   
00121 
00123   static const field32spec_t formatVersion32;
00124   static const field32spec_t freqGHz32;
00125   static const field32spec_t channelCount32;
00126   static const field32spec_t timeStamp32;
00127   static const field32spec_t tTrigPs32;
00128   static const field32spec_t orbitId32;
00129   static const field32spec_t trigRec32;
00130   static const field32spec_t postTrig32;
00131   static const field32spec_t vernier0_32;
00132   static const field32spec_t vernier1_32;
00133   static const field32spec_t vernier2_32;
00134   static const field32spec_t vernier3_32;
00135   static const field32spec_t timeStampMicroSec32;
00136   
00137   static const field32spec_t laserPower32;
00138   static const field32spec_t attenuation_dB32;
00139   static const field32spec_t emtcPhase32;
00140   static const field32spec_t emtcDelay32;
00141   static const field32spec_t delayA32;
00142   static const field32spec_t dccId32;
00143   static const field32spec_t color32;
00144   static const field32spec_t trigType32;
00145   static const field32spec_t side32;
00146 
00148   
00149   //constructors
00150 public:
00160   MatacqRawEvent(const unsigned char* dataBuffer, size_t bufferSize): vernier(std::vector<int>(4)){
00161     setRawData(dataBuffer, bufferSize);
00162   }
00163   //methods
00164 public:
00171   int getFov() const { return read32(daqHeader, fov32);}
00172   
00176   int getFedId() const { return read32(daqHeader, fedId32);}
00177 
00181   int getBxId() const { return read32(daqHeader, bxId32);}
00182 
00186   unsigned getEventId() const { return read32(daqHeader, lv132);}
00187 
00191   int getTriggerType() const { return read32(daqHeader, triggerType32);}
00192 
00196   int getBoe() const { return read32(daqHeader, boeType32);}
00197 
00201   unsigned getDccLen() const { return read32(daqHeader, dccLen32);}
00202 
00209    static unsigned getDccLen(unsigned char* data, size_t size){
00210      if(size<(unsigned)(dccLen32.offset+1)*4) return (unsigned)-1;
00211      return read32((uint32le_t*) data, dccLen32);
00212    }
00213 
00221    static unsigned getOrbitId(unsigned char* data, size_t size){
00222      if(size<(unsigned)(orbitId32.offset+1)*8) return (unsigned)-1;
00223      return read32((uint32le_t*) data, orbitId32);
00224    }
00225 
00232    static unsigned getRunNum(unsigned char* data, size_t size){
00233      if(size<(unsigned)(runNum32.offset+1)*8) return (unsigned)-1;
00234      return read32((uint32le_t*) data, runNum32);
00235    }
00236 
00237   
00241   unsigned getDaqLen() const { return fragLen;}
00242 
00243 
00247   int getDccErrors() const { return read32(daqHeader, dccErrors32);}
00248 
00252   unsigned getRunNum() const { return read32(daqHeader, runNum32);}
00253 
00257   int getH1Marker() const { return read32(daqHeader, h1Marker32);}
00258   
00259 
00263   int getMatacqDataFormatVersion() const { return matacqDataFormatVersion;}
00264 
00269   int32_t getStatus() const { return error;}
00270 
00274   int getFreqGHz() const { return /*matacqHeader->*/freqGHz;}
00275 
00279   int getChannelCount() const { return /*matacqHeader->*/channelCount;}
00280 
00286   const std::vector<ChannelData>& getChannelData() const{
00287     return channelData;
00288   }
00289 
00294   int getParsedLen() {  return parsedLen; }
00295   
00301   time_t getTimeStamp() const { return /*matacqHeader->*/timeStamp.tv_sec; }
00302 
00308   void getTimeStamp(struct timeval& t) const { t = timeStamp; }
00309 
00314   int getTTrigPs() const { return tTrigPs; }
00315 
00320   uint32_t getOrbitId() const { return orbitId; }
00321 
00326   int getTrigRec() const { return trigRec; }
00327 
00331   int getPostTrig() const { return postTrig; }
00332 
00336   std::vector<int> getVernier() const { return vernier; }
00337 
00340   int getDelayA() const { return delayA; }
00341 
00344   int getEmtcDelay() const { return emtcDelay; }
00345   
00348   int getEmtcPhase() const { return emtcPhase; }
00349 
00353   int getAttenuation_dB() const { return attenuation_dB; }
00354 
00357   int getLaserPower() const { return laserPower; }
00358   
00359 private:
00368   static int read32(uint32le_t* pData, field32spec_t spec, bool ovfTrans = false);
00369   
00370 //   /** Help function to get the maximum value of a data field
00371 //    * @param spec32 data field specification
00372 //    * @return maximum value
00373 //    */
00374 //   int max32(field32spec_t spec32) const;
00375 
00383   void setRawData(const unsigned char* buffer, size_t bufferSize);
00384 
00385   //fields
00386 private:
00389   int boe;
00390 
00393   int bxId;
00394 
00397   int channelCount;
00398   
00401   std::vector<ChannelData> channelData;
00402 
00405   uint32le_t* daqHeader;
00406 
00409   int dccErrors;
00410 
00413   unsigned dccLen;
00414 
00417   unsigned eventId;
00418 
00421   int32_t error;
00422 
00425   int fedId;
00426 
00429   int fov;
00430 
00433   int fragLen;
00434 
00437   int freqGHz;
00438 
00441   int h1Marker;
00442 
00445   //  matacqHeader_t* matacqHeader;
00446   
00449   int matacqDataFormatVersion;
00450 
00453   int parsedLen;
00454 
00457   uint16le_t* pSamples;
00458 
00461   unsigned runNum;
00462 
00465   struct timeval timeStamp;
00466 
00469   int tTrigPs;
00470   
00473   int triggerType;
00474 
00475   /* LHC orbit ID
00476    */
00477   uint32_t orbitId;
00478 
00481   int trigRec;
00482 
00485   int postTrig;
00486 
00489   std::vector<int> vernier;
00490 
00493   int delayA;
00494 
00497   int emtcDelay;    
00498   
00501   int emtcPhase;
00502 
00506   int attenuation_dB;
00507 
00510   int laserPower;
00511 };
00512 
00513 #endif //MATACQRAWEVENT_H not defined