CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/EventFilter/EcalTBRawToDigi/src/DCCDataParser.h

Go to the documentation of this file.
00001 /*----------------------------------------------------------*/
00002 /* DCC DATA PARSER                                          */
00003 /*                                                          */
00004 /* Author : N.Almeida (LIP)         Date   : 30/05/2004     */
00005 /*----------------------------------------------------------*/
00006 
00007 #ifndef DCCTBDATAPARSER_HH
00008 #define DCCTBDATAPARSER_HH
00009 
00010 #include <fstream>                   //STL
00011 #include <iostream>
00012 #include <string>
00013 #include <vector>
00014 #include <map>
00015 
00016 #include <stdio.h>                     //C
00017 
00018 #include "ECALParserException.h"      //DATA DECODER
00019 #include "DCCEventBlock.h"
00020 #include "DCCDataMapper.h"
00021 
00022 
00023 class DCCTBDataMapper;
00024 class DCCTBEventBlock;
00025 
00026 
00027 class DCCTBDataParser{
00028 
00029 public : 
00030   
00042   DCCTBDataParser( std::vector<uint32_t> parserParameters , bool parseInternalData = true, bool debug = true);
00043   
00047   void parseFile( std::string fileName, bool singleEvent = false);
00048         
00052   void parseBuffer( uint32_t * buffer, uint32_t bufferSize, bool singleEvent = false);
00053 
00057   DCCTBDataMapper *mapper();
00058                 
00063   std::pair<uint32_t,uint32_t> checkEventLength(uint32_t * pointerToEvent, uint32_t bytesToEnd, bool singleEvent = false);
00064   
00068   std::vector<uint32_t> parserParameters(); 
00069   uint32_t numbXtalSamples();
00070   uint32_t numbTriggerSamples();
00071   uint32_t numbTTs();
00072   uint32_t numbSRF();
00073   uint32_t dccId();
00074   uint32_t srpId();
00075   uint32_t tcc1Id();
00076   uint32_t tcc2Id();
00077   uint32_t tcc3Id();
00078   uint32_t tcc4Id();
00079   
00080 
00084   void  setParameters( std::vector<uint32_t> newParameters );
00085 
00086 
00090   uint32_t srpBlockSize();
00091   uint32_t tccBlockSize();
00092 
00096   bool  debug();
00097 
00101   std::vector<DCCTBEventBlock *> & dccEvents();
00102 
00106   std::map<std::string,uint32_t> & errorCounters();
00107 
00111   std::vector< std::pair< uint32_t, std::pair<uint32_t *, uint32_t> > > events();
00112 
00113 
00117   void resetErrorCounters();
00118                 
00119 
00123   std::string getDecString(uint32_t data);              
00124   std::string getHexString(uint32_t data);
00125   std::string index(uint32_t position);
00126   std::string getIndexedData( uint32_t indexed, uint32_t * pointer);
00127 
00131   uint32_t *getBuffer() { return buffer_;}
00132   
00136   ~DCCTBDataParser();
00137 
00138   enum DCCDataParserGlobalFields{
00139     EMPTYEVENTSIZE = 32                   //bytes
00140   };
00141  
00142 protected :
00143   void computeBlockSizes();
00144 
00145   uint32_t *buffer_;                //data buffer
00146   uint32_t bufferSize_;             //buffer size
00147 
00148   uint32_t srpBlockSize_;           //SR block size
00149   uint32_t tccBlockSize_;           //TCC block size
00150 
00151   uint32_t processedEvent_;
00152   std::string eventErrors_;
00153   DCCTBDataMapper *mapper_;
00154   
00155   std::vector<DCCTBEventBlock *> dccEvents_;
00156   
00157   // std::pair< errorMask, std::pair< pointer to event, event size (number of DW)> >
00158   std::vector< std::pair< uint32_t, std::pair<uint32_t *, uint32_t> > > events_;
00159   
00160   bool parseInternalData_;          //parse internal data flag
00161   bool debug_;                      //debug flag
00162   std::map<std::string,uint32_t> errors_;        //errors map
00163   std::vector<uint32_t> parameters;         //parameters vector
00164 
00165   enum DCCTBDataParserFields{
00166     EVENTLENGTHMASK = 0xFFFFFF,
00167     
00168     BOEBEGIN = 28,                  //begin of event (on 32 bit string starts at bit 28)
00169     BOEMASK = 0xF,                  //mask is 4 bits (F)
00170     BOE =0x5,                       //B'0101'
00171 
00172     EOEBEGIN = 28,                  //end of event
00173     EOEMASK = 0xF,                  //4 bits
00174     EOE =0xA                        //B'1010'
00175   };
00176                 
00177 };
00178 
00179 inline DCCTBDataMapper *DCCTBDataParser::mapper() { return mapper_;}
00180 
00181 inline std::vector<uint32_t> DCCTBDataParser::parserParameters() { return parameters; }
00182 inline uint32_t DCCTBDataParser::numbXtalSamples()     { return parameters[0]; }
00183 inline uint32_t DCCTBDataParser::numbTriggerSamples()  { return parameters[1]; }
00184 inline uint32_t DCCTBDataParser::numbTTs()             { return parameters[2]; }
00185 inline uint32_t DCCTBDataParser::numbSRF()             { return parameters[3]; }
00186 inline uint32_t DCCTBDataParser::dccId()               { return parameters[4]; }
00187 inline uint32_t DCCTBDataParser::srpId()               { return parameters[5]; }
00188 inline uint32_t DCCTBDataParser::tcc1Id()              { return parameters[6]; } 
00189 inline uint32_t DCCTBDataParser::tcc2Id()              { return parameters[7]; } 
00190 inline uint32_t DCCTBDataParser::tcc3Id()              { return parameters[8]; } 
00191 inline uint32_t DCCTBDataParser::tcc4Id()              { return parameters[9]; }
00192 
00193 inline void  DCCTBDataParser::setParameters( std::vector<uint32_t> newParameters ){ parameters = newParameters; computeBlockSizes();}
00194 
00195 inline uint32_t DCCTBDataParser::srpBlockSize()        { return srpBlockSize_; } 
00196 inline uint32_t DCCTBDataParser::tccBlockSize()        { return tccBlockSize_; } 
00197 
00198 inline bool DCCTBDataParser::debug()                          { return debug_;     }
00199 inline std::vector<DCCTBEventBlock *> &DCCTBDataParser::dccEvents()  { return dccEvents_;    }
00200 inline std::map<std::string,uint32_t> &DCCTBDataParser::errorCounters()    { return errors_;       }
00201 inline std::vector< std::pair< uint32_t, std::pair<uint32_t *, uint32_t> > > DCCTBDataParser::events() { return events_;   }
00202 
00203 
00204 #endif
00205