CMS 3D CMS Logo

Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

DCCTBDataParser Class Reference

#include <DCCDataParser.h>

List of all members.

Public Types

enum  DCCDataParserGlobalFields { EMPTYEVENTSIZE = 32 }

Public Member Functions

std::pair< uint32_t, uint32_t > checkEventLength (uint32_t *pointerToEvent, uint32_t bytesToEnd, bool singleEvent=false)
std::vector< DCCTBEventBlock * > & dccEvents ()
uint32_t dccId ()
 DCCTBDataParser (std::vector< uint32_t > parserParameters, bool parseInternalData=true, bool debug=true)
bool debug ()
std::map< std::string, uint32_t > & errorCounters ()
std::vector< std::pair
< uint32_t, std::pair
< uint32_t *, uint32_t > > > 
events ()
uint32_t * getBuffer ()
std::string getDecString (uint32_t data)
std::string getHexString (uint32_t data)
std::string getIndexedData (uint32_t indexed, uint32_t *pointer)
std::string index (uint32_t position)
DCCTBDataMappermapper ()
uint32_t numbSRF ()
uint32_t numbTriggerSamples ()
uint32_t numbTTs ()
uint32_t numbXtalSamples ()
void parseBuffer (uint32_t *buffer, uint32_t bufferSize, bool singleEvent=false)
void parseFile (std::string fileName, bool singleEvent=false)
std::vector< uint32_t > parserParameters ()
void resetErrorCounters ()
void setParameters (std::vector< uint32_t > newParameters)
uint32_t srpBlockSize ()
uint32_t srpId ()
uint32_t tcc1Id ()
uint32_t tcc2Id ()
uint32_t tcc3Id ()
uint32_t tcc4Id ()
uint32_t tccBlockSize ()
 ~DCCTBDataParser ()

Protected Types

enum  DCCTBDataParserFields {
  EVENTLENGTHMASK = 0xFFFFFF, BOEBEGIN = 28, BOEMASK = 0xF, BOE = 0x5,
  EOEBEGIN = 28, EOEMASK = 0xF, EOE = 0xA
}

Protected Member Functions

void computeBlockSizes ()

Protected Attributes

uint32_t * buffer_
uint32_t bufferSize_
std::vector< DCCTBEventBlock * > dccEvents_
bool debug_
std::map< std::string, uint32_t > errors_
std::string eventErrors_
std::vector< std::pair
< uint32_t, std::pair
< uint32_t *, uint32_t > > > 
events_
DCCTBDataMappermapper_
std::vector< uint32_t > parameters
bool parseInternalData_
uint32_t processedEvent_
uint32_t srpBlockSize_
uint32_t tccBlockSize_

Detailed Description

Definition at line 27 of file DCCDataParser.h.


Member Enumeration Documentation

Enumerator:
EMPTYEVENTSIZE 

Definition at line 138 of file DCCDataParser.h.

                                {
    EMPTYEVENTSIZE = 32                   //bytes
  };
Enumerator:
EVENTLENGTHMASK 
BOEBEGIN 
BOEMASK 
BOE 
EOEBEGIN 
EOEMASK 
EOE 

Definition at line 165 of file DCCDataParser.h.

                            {
    EVENTLENGTHMASK = 0xFFFFFF,
    
    BOEBEGIN = 28,                  //begin of event (on 32 bit string starts at bit 28)
    BOEMASK = 0xF,                  //mask is 4 bits (F)
    BOE =0x5,                       //B'0101'

    EOEBEGIN = 28,                  //end of event
    EOEMASK = 0xF,                  //4 bits
    EOE =0xA                        //B'1010'
  };

Constructor & Destructor Documentation

DCCTBDataParser::DCCTBDataParser ( std::vector< uint32_t >  parserParameters,
bool  parseInternalData = true,
bool  debug = true 
)

Class constructor: takes a vector of 10 parameters and flags for parseInternalData and debug Parameters are: 0 - crystal samples (default is 10) 1 - number of trigger time samples (default is 1) 2 - number of TT (default is 68) 3 - number of SR Flags (default is 68) 4 - DCC id 5 - SR id [6-9] - TCC[6-9] id

Definition at line 9 of file DCCDataParser.cc.

References computeBlockSizes(), mapper_, and resetErrorCounters().

                                                                                                       :
  buffer_(0),parseInternalData_(parseInternalData),debug_(debug), parameters(parserParameters){
        
  mapper_ = new DCCTBDataMapper(this);       //build a new data mapper
  resetErrorCounters();                    //restart error counters
  computeBlockSizes();                     //calculate block sizes
  
}
DCCTBDataParser::~DCCTBDataParser ( )

Class destructor

Definition at line 347 of file DCCDataParser.cc.

References dccEvents_, and mapper_.

                                 {
  
  // delete DCCTBEvents if any...
  std::vector<DCCTBEventBlock *>::iterator it;
  for(it=dccEvents_.begin();it!=dccEvents_.end();it++){delete *it;}
  dccEvents_.clear();
    
  delete mapper_;
}

Member Function Documentation

std::pair< uint32_t, uint32_t > DCCTBDataParser::checkEventLength ( uint32_t *  pointerToEvent,
uint32_t  bytesToEnd,
bool  singleEvent = false 
)

Check if EVENT LENGTH is coeherent and if BOE/EOE are correctly written returns 3 bits code with the error found + event length

Definition at line 218 of file DCCDataParser.cc.

References BOE, BOEBEGIN, BOEMASK, EMPTYEVENTSIZE, EOEBEGIN, EOEMASK, errors_, EVENTLENGTHMASK, events_, getDecString(), and query::result.

Referenced by parseBuffer().

                                                                                                                           {
        
  std::pair<uint32_t,uint32_t> result;    //returns error mask and event length 
  uint32_t errorMask(0);          //error mask to return

  //check begin of event (BOE bits field) 
  //(Note: we have to add one to read the 2nd 32 bit word where BOE is written)
  uint32_t *boePointer = pointerToEvent + 1;
  if( (  ((*boePointer)>>BOEBEGIN)& BOEMASK  )  != BOE ) { 
    (errors_["DCC::BOE"])++; errorMask = 1; 
  }
        
        
  //get Event Length from buffer (Note: we have to add two to read the 3rd 32 bit word where EVENT LENGTH is written)
  uint32_t * myPointer = pointerToEvent + 2; 
  uint32_t eventLength = (*myPointer)&EVENTLENGTHMASK;

  // std::cout << " Event Length(from decoding) = " << dec << eventLength << "... bytes to end... " << bytesToEnd << ", event numb : " << processedEvent_ << std::endl;
  
  bool eoeError = false;

  //check if event is empty but but EVENT LENGTH is not corresponding to it
  if( singleEvent && eventLength != bytesToEnd/8 ){
    eventLength = bytesToEnd/8;
    (errors_["DCC::EVENT LENGTH"])++; 
    errorMask = errorMask | (1<<1);
  }
  //check if event length mismatches the number of words written as data
  else if( eventLength == 0 || eventLength > (bytesToEnd / 8) || eventLength < (EMPTYEVENTSIZE/8) ){  
    // How to handle bad event length in multiple event buffers
    // First approach : Send an exception       
    // Second aproach : Try to find the EOE (To be done? If yes check dataDecoder tBeam implementation)
    std::string fatalError;
                
    fatalError +="\n ======================================================================";           
    fatalError +="\n Fatal error at event = " + getDecString(events_.size()+1);
    fatalError +="\n Decoded event length = " + getDecString(eventLength);
    fatalError +="\n bytes to buffer end  = " + getDecString(bytesToEnd);
    fatalError +="\n Unable to procead the data decoding ...";

    if(eventLength > (bytesToEnd / 8)){ fatalError +=" (eventLength > (bytesToEnd / 8)";}
    else{ fatalError += "\n event length not big enough heaven to build an empty event ( 4x8 bytes)";}

    fatalError +="\n ======================================================================";

    throw ECALTBParserException(fatalError);
  }

  //check end of event (EOE bits field) 
  //(Note: event length is multiplied by 2 because its written as 32 bit words and not 64 bit words)
  uint32_t *endOfEventPointer = pointerToEvent + eventLength*2 -1;
  if ( (  ((*endOfEventPointer) >> EOEBEGIN & EOEMASK )  != EOEMASK) && !eoeError ){ 
    (errors_["DCC::EOE"])++; 
    errorMask = errorMask | (1<<2); 
  }
  
  //build result to return
  result.first  = errorMask;
  result.second = eventLength;
  
  return result;
}
void DCCTBDataParser::computeBlockSizes ( ) [protected]

Definition at line 35 of file DCCDataParser.cc.

References nTT, numbSRF(), numbTriggerSamples(), numbTTs(), srpBlockSize_, tccBlockSize_, and tests::test_DownloadDQM::tf.

Referenced by DCCTBDataParser(), and setParameters().

                                       {
  uint32_t nTT = numbTTs();                                      //gets the number of the trigger towers (default:68)  
  uint32_t tSamples = numbTriggerSamples();                      //gets the number of trigger time samples (default: 1)
  uint32_t nSr = numbSRF();                                      //gests the number of SR flags (default:68)

  uint32_t tf(0), srf(0);
        
  if( (nTT*tSamples)<4 || (nTT*tSamples)%4 ) tf=1;            //test is there is no TTC primitives or if it's a multiple of 4?
  else tf=0;
  

  if( srf<16 || srf%16 ) srf=1;                               //??? by default srf=0 why do we make this test ?????
  else srf=0;
  
  //TTC block size: header (8 bytes) + 17 words with 4 trigger primitives (17*8bytes)
  tccBlockSize_ = 8 + ((nTT*tSamples)/4)*8 + tf*8 ;          

  //SR block size: header (8 bytes) + 4 words with 16 SR flags + 1 word with 4 SR flags (5*8bytes)
  srpBlockSize_ = 8 + (nSr/16)*8 + srf*8;
}
std::vector< DCCTBEventBlock * > & DCCTBDataParser::dccEvents ( ) [inline]

Get method for DCCEventBlocks vector

Definition at line 199 of file DCCDataParser.h.

References dccEvents_.

Referenced by EcalTB07DaqFormatter::interpretRawData(), and EcalTBDaqFormatter::interpretRawData().

{ return dccEvents_;    }
uint32_t DCCTBDataParser::dccId ( ) [inline]

Definition at line 186 of file DCCDataParser.h.

References parameters.

{ return parameters[4]; }
bool DCCTBDataParser::debug ( ) [inline]
std::map< std::string, uint32_t > & DCCTBDataParser::errorCounters ( ) [inline]

Get method for error counters map

Definition at line 200 of file DCCDataParser.h.

References errors_.

{ return errors_;       }
std::vector< std::pair< uint32_t, std::pair< uint32_t *, uint32_t > > > DCCTBDataParser::events ( ) [inline]

Get method for events

Definition at line 201 of file DCCDataParser.h.

References events_.

{ return events_;   }
uint32_t* DCCTBDataParser::getBuffer ( ) [inline]

Retrieves a pointer to the data buffer

Definition at line 131 of file DCCDataParser.h.

References buffer_.

{ return buffer_;}
std::string DCCTBDataParser::getDecString ( uint32_t  data)
std::string DCCTBDataParser::getHexString ( uint32_t  data)

Definition at line 315 of file DCCDataParser.cc.

Referenced by getIndexedData().

                                                    {
        
  char buffer[10];
  sprintf(buffer,"0x%08x",(uint16_t)(data));

  return std::string(buffer);   
}
std::string DCCTBDataParser::getIndexedData ( uint32_t  indexed,
uint32_t *  pointer 
)

Definition at line 328 of file DCCDataParser.cc.

References getHexString(), index(), and runTheMatrix::ret.

                                                                             {
  std::string ret;
  
  //char indexBuffer[20];
  //char dataBuffer[20];
  //sprintf(indexBuffer,"W[%08u] = ",position);
  //sprintf(dataBuffer,"0x%08x",*pointer);
  //ret = std::string(indexBuffer)+std::string(dataBuffer);

  ret = index(position) + getHexString(*pointer);
  
  return ret;   
}
std::string DCCTBDataParser::index ( uint32_t  position)

Definition at line 287 of file DCCDataParser.cc.

References pos, and position.

Referenced by getIndexedData().

                                                 {

  char indexBuffer[20];
  long unsigned int pos = position;
  sprintf(indexBuffer,"W[%08lu]",pos);        //build an index string for display purposes, p.e.  W[15] 

  return std::string(indexBuffer);      
}
DCCTBDataMapper * DCCTBDataParser::mapper ( ) [inline]
uint32_t DCCTBDataParser::numbSRF ( ) [inline]

Definition at line 185 of file DCCDataParser.h.

References parameters.

Referenced by computeBlockSizes(), and DCCTBSRPBlock::DCCTBSRPBlock().

{ return parameters[3]; }
uint32_t DCCTBDataParser::numbTriggerSamples ( ) [inline]

Definition at line 183 of file DCCDataParser.h.

References parameters.

Referenced by DCCTBDataMapper::buildTCCFields(), and computeBlockSizes().

{ return parameters[1]; }
uint32_t DCCTBDataParser::numbTTs ( ) [inline]
uint32_t DCCTBDataParser::numbXtalSamples ( ) [inline]
void DCCTBDataParser::parseBuffer ( uint32_t *  buffer,
uint32_t  bufferSize,
bool  singleEvent = false 
)

Parse data from a buffer

Definition at line 114 of file DCCDataParser.cc.

References buffer_, checkEventLength(), dccEvents_, EMPTYEVENTSIZE, eventErrors_, events_, getDecString(), parseInternalData_, processedEvent_, and resetErrorCounters().

Referenced by EcalTB07DaqFormatter::interpretRawData(), EcalTBDaqFormatter::interpretRawData(), and parseFile().

                                                                                         {
        
  resetErrorCounters();                           //reset error counters
        
  buffer_ = buffer;                               //set class buffer
  
  //clear stored data
  processedEvent_ = 0;
  events_.clear();
  std::vector<DCCTBEventBlock *>::iterator it;
  for( it = dccEvents_.begin(); it!=dccEvents_.end(); it++ ) { delete *it; }
  dccEvents_.clear();
  eventErrors_ = "";
        
  //for debug purposes
  //std::cout << std::endl << "Now in DCCTBDataParser::parseBuffer" << std::endl;
  //std::cout << std::endl << "Buffer Size:" << dec << bufferSize << std::endl;
        
  //check if we have a coherent buffer size
  if( bufferSize%8  ){
    std::string fatalError ;
    fatalError += "\n ======================================================================";          
    fatalError += "\n Fatal error at event = " + getDecString(events_.size()+1);
    fatalError += "\n Buffer Size of = "+ getDecString(bufferSize) + "[bytes] is not divisible by 8 ... ";
    fatalError += "\n ======================================================================";
    throw ECALTBParserException(fatalError);
  }
  if ( bufferSize < EMPTYEVENTSIZE ){
    std::string fatalError ;
    fatalError += "\n ======================================================================";          
    fatalError += "\n Fatal error at event = " + getDecString(events_.size()+1);
    fatalError += "\n Buffer Size of = "+ getDecString(bufferSize) + "[bytes] is less than an empty event ... ";
    fatalError += "\n ======================================================================";
    throw ECALTBParserException(fatalError);
  }

  uint32_t *myPointer =  buffer_;                        
  
  //  uint32_t processedBytes(0), wordIndex(0), lastEvIndex(0),eventSize(0), eventLength(0), errorMask(0);
  uint32_t processedBytes(0), wordIndex(0), eventLength(0), errorMask(0);
  
  //parse until there are no more events
  while( processedBytes + EMPTYEVENTSIZE <= bufferSize ){

    //for debug purposes
    //std::cout << "-> processedBytes.  =   " << dec << processedBytes << std::endl;
    //std::cout << " -> Processed Event index =   " << dec << processedEvent_ << std::endl;
    //std::cout << "-> First ev.word    = 0x" << hex << (*myPointer) << std::endl;
    //std::cout << "-> word index       =   " << dec << wordIndex << std::endl;
    
    //check if Event Length is coherent /////////////////////////////////////////
    uint32_t bytesToEnd         = bufferSize - processedBytes;
    std::pair<uint32_t,uint32_t> eventD = checkEventLength(myPointer,bytesToEnd,singleEvent);
    eventLength              = eventD.second; 
    errorMask                = eventD.first;
     
    //for debug purposes
    //std::cout <<" -> EventSizeBytes        =   " << dec << eventLength*8 << std::endl;
   
          
             
    //for debug purposes debug 
    //std::cout<<std::endl;
    //std::cout<<" out... Bytes To End.... =   "<<dec<<bytesToEnd<<std::endl;
    //std::cout<<" out... Processed Event  =   "<<dec<<processedEvent_<<std::endl;      
    //std::cout<<" out... Event Length     =   "<<dec<<eventLength<<std::endl;
    //std::cout<<" out... LastWord         = 0x"<<hex<<*(myPointer+eventLength*2-1)<<std::endl;
    
    if (parseInternalData_){ 
      //build a new event block from buffer
      DCCTBEventBlock *myBlock = new DCCTBEventBlock(this,myPointer,eventLength*8, eventLength*2 -1 ,wordIndex,0);
      
      //add event to dccEvents vector
      dccEvents_.push_back(myBlock);
    }
    
    //build the event pointer with error mask and add it to the events vector
    std::pair<uint32_t *, uint32_t> eventPointer(myPointer,eventLength);
    std::pair<uint32_t, std::pair<uint32_t*, uint32_t> > eventPointerWithErrorMask(errorMask,eventPointer);
    events_.push_back(eventPointerWithErrorMask);
                
    //update processed buffer size 
    processedEvent_++;
    processedBytes += eventLength*8;
    //std::cout << std::endl << "Processed Bytes = " << dec << processedBytes << std::endl;
    
    //go to next event
    myPointer     += eventLength*2;
    wordIndex     += eventLength*2;
  } 
}
void DCCTBDataParser::parseFile ( std::string  fileName,
bool  singleEvent = false 
)

Parse data from file

Definition at line 61 of file DCCDataParser.cc.

References buffer_, bufferSize_, convertXMLtoSQLite_cfg::fileName, i, analyzePatCleaning_cfg::inputFile, parseBuffer(), and resetErrorCounters().

                                                                   {
        
  std::ifstream inputFile;                            //open file as input
  inputFile.open(fileName.c_str());
        
  resetErrorCounters();                          //reset error counters

  //for debug purposes
  //std::cout << "Now in DCCTBDataParser::parseFile " << std::endl;

        
  //if file opened correctly read data to a buffer and parse it
  //else throw an exception
  if( !inputFile.fail() ){ 
        
    std::string myWord;                               //word read from line
    std::vector<std::string> dataVector;                   //data vector
    
    //until the end of file read each line as a string and add it to the data vector
    while( inputFile >> myWord ){ 
      dataVector.push_back( myWord ); 
    }
    
    bufferSize_ = (dataVector.size() ) * 4 ;      //buffer size in bytes (note:each char is an hex number)
    if( buffer_ ){ delete [] buffer_; }           //delete current vector if any
    buffer_ = new uint32_t[dataVector.size()];       //allocate memory for new data buffer

    uint32_t *myData_ = (uint32_t *) buffer_;         
    
    //fill buffer data with data from file lines
    for(uint32_t i = 1; i <= dataVector.size() ; i++, myData_++ ){
      sscanf((dataVector[i-1]).c_str(),"%x",(unsigned int *)myData_);
      
      //for debug purposes
      //std::cout << std::endl << "Data position: " << dec << i << " val = " << getHexString(*myData_);
    }
    
    inputFile.close();                              //close file
    
    parseBuffer( buffer_,bufferSize_,singleEvent);  //parse data from buffer
    
  }
  else{ 
    std::string errorMessage = std::string(" Error::Unable to open file :") + fileName;
    throw ECALTBParserException(errorMessage);
  }
}
std::vector< uint32_t > DCCTBDataParser::parserParameters ( ) [inline]

Get methods for parser parameters;

Definition at line 181 of file DCCDataParser.h.

References parameters.

{ return parameters; }
void DCCTBDataParser::resetErrorCounters ( )

Reset Error Counters

Definition at line 23 of file DCCDataParser.cc.

References errors_.

Referenced by DCCTBDataParser(), parseBuffer(), and parseFile().

                                        {
  //set error counters to 0
  errors_["DCC::BOE"] = 0;               //begin of event (header B[60-63])
  errors_["DCC::EOE"] = 0;               //end of event (trailer B[60-63])
  errors_["DCC::EVENT LENGTH"] = 0;      //event length (trailer B[32-55])
}
void DCCTBDataParser::setParameters ( std::vector< uint32_t >  newParameters) [inline]

Set method for parser parameters

Definition at line 193 of file DCCDataParser.h.

References computeBlockSizes(), and parameters.

{ parameters = newParameters; computeBlockSizes();}
uint32_t DCCTBDataParser::srpBlockSize ( ) [inline]

Get methods for block sizes

Definition at line 195 of file DCCDataParser.h.

References srpBlockSize_.

Referenced by DCCTBEventBlock::DCCTBEventBlock().

{ return srpBlockSize_; } 
uint32_t DCCTBDataParser::srpId ( ) [inline]

Definition at line 187 of file DCCDataParser.h.

References parameters.

Referenced by DCCTBSRPBlock::dataCheck().

{ return parameters[5]; }
uint32_t DCCTBDataParser::tcc1Id ( ) [inline]

Definition at line 188 of file DCCDataParser.h.

References parameters.

Referenced by DCCTBEventBlock::DCCTBEventBlock().

{ return parameters[6]; } 
uint32_t DCCTBDataParser::tcc2Id ( ) [inline]

Definition at line 189 of file DCCDataParser.h.

References parameters.

Referenced by DCCTBEventBlock::DCCTBEventBlock().

{ return parameters[7]; } 
uint32_t DCCTBDataParser::tcc3Id ( ) [inline]

Definition at line 190 of file DCCDataParser.h.

References parameters.

Referenced by DCCTBEventBlock::DCCTBEventBlock().

{ return parameters[8]; } 
uint32_t DCCTBDataParser::tcc4Id ( ) [inline]

Definition at line 191 of file DCCDataParser.h.

References parameters.

Referenced by DCCTBEventBlock::DCCTBEventBlock().

{ return parameters[9]; }
uint32_t DCCTBDataParser::tccBlockSize ( ) [inline]

Definition at line 196 of file DCCDataParser.h.

References tccBlockSize_.

Referenced by DCCTBEventBlock::DCCTBEventBlock().

{ return tccBlockSize_; } 

Member Data Documentation

uint32_t* DCCTBDataParser::buffer_ [protected]

Definition at line 145 of file DCCDataParser.h.

Referenced by getBuffer(), parseBuffer(), and parseFile().

uint32_t DCCTBDataParser::bufferSize_ [protected]

Definition at line 146 of file DCCDataParser.h.

Referenced by parseFile().

std::vector<DCCTBEventBlock *> DCCTBDataParser::dccEvents_ [protected]

Definition at line 155 of file DCCDataParser.h.

Referenced by dccEvents(), parseBuffer(), and ~DCCTBDataParser().

bool DCCTBDataParser::debug_ [protected]

Definition at line 161 of file DCCDataParser.h.

Referenced by debug().

std::map<std::string,uint32_t> DCCTBDataParser::errors_ [protected]

Definition at line 162 of file DCCDataParser.h.

Referenced by checkEventLength(), errorCounters(), and resetErrorCounters().

std::string DCCTBDataParser::eventErrors_ [protected]

Definition at line 152 of file DCCDataParser.h.

Referenced by parseBuffer().

std::vector< std::pair< uint32_t, std::pair<uint32_t *, uint32_t> > > DCCTBDataParser::events_ [protected]

Definition at line 158 of file DCCDataParser.h.

Referenced by checkEventLength(), events(), and parseBuffer().

Definition at line 153 of file DCCDataParser.h.

Referenced by DCCTBDataParser(), mapper(), and ~DCCTBDataParser().

std::vector<uint32_t> DCCTBDataParser::parameters [protected]

Definition at line 160 of file DCCDataParser.h.

Referenced by parseBuffer().

uint32_t DCCTBDataParser::processedEvent_ [protected]

Definition at line 151 of file DCCDataParser.h.

Referenced by parseBuffer().

uint32_t DCCTBDataParser::srpBlockSize_ [protected]

Definition at line 148 of file DCCDataParser.h.

Referenced by computeBlockSizes(), and srpBlockSize().

uint32_t DCCTBDataParser::tccBlockSize_ [protected]

Definition at line 149 of file DCCDataParser.h.

Referenced by computeBlockSizes(), and tccBlockSize().