CMS 3D CMS Logo

Public Member Functions | Protected Member Functions | Protected Attributes

DCCFEBlock Class Reference

#include <DCCFEBlock.h>

Inheritance diagram for DCCFEBlock:
DCCDataBlockPrototype DCCSCBlock DCCTowerBlock

List of all members.

Public Member Functions

 DCCFEBlock (DCCDataUnpacker *u, EcalElectronicsMapper *m, DCCEventBlock *e, bool unpack, bool forceToKeepFRdata)
void display (std::ostream &o)
void enableFeIdChecks ()
unsigned int getLength ()
int unpack (const uint64_t **data, unsigned int *dwToEnd, bool zs, unsigned int expectedTowerID)
virtual void updateCollectors ()
void zsFlag (bool zs)
virtual ~DCCFEBlock ()

Protected Member Functions

virtual void fillEcalElectronicsError (std::auto_ptr< EcalElectronicsIdCollection > *)
virtual int unpackXtalData (unsigned int stripID, unsigned int xtalID)

Protected Attributes

unsigned int blockSize_
unsigned int bx_
bool checkFeId_
unsigned int expTowerID_
unsigned int expXtalTSamples_
bool forceToKeepFRdata_
std::auto_ptr
< EcalElectronicsIdCollection > * 
invalidBlockLengths_
std::auto_ptr
< EcalElectronicsIdCollection > * 
invalidTTIds_
std::auto_ptr
< EcalElectronicsIdCollection > * 
invalidZSXtalIds_
unsigned int l1_
unsigned int lastStripId_
unsigned int lastXtalId_
unsigned int nTSamples_
unsigned int numbDWInXtalBlock_
unsigned int towerId_
unsigned int unfilteredDataBlockLength_
unsigned int xtalBlockSize_
short * xtalGains_
bool zs_

Detailed Description

Definition at line 22 of file DCCFEBlock.h.


Constructor & Destructor Documentation

DCCFEBlock::DCCFEBlock ( DCCDataUnpacker u,
EcalElectronicsMapper m,
DCCEventBlock e,
bool  unpack,
bool  forceToKeepFRdata 
)
virtual DCCFEBlock::~DCCFEBlock ( ) [inline, virtual]

Definition at line 28 of file DCCFEBlock.h.

References xtalGains_.

{ delete [] xtalGains_;}

Member Function Documentation

void DCCFEBlock::display ( std::ostream &  o) [virtual]

Reimplemented from DCCDataBlockPrototype.

Definition at line 254 of file DCCFEBlock.cc.

References DCCDataBlockPrototype::blockLength_, bx_, l1_, nTSamples_, and towerId_.

                                     {

  o<<"\n Unpacked Info for DCC Tower Block"
  <<"\n DW1 ============================="
  <<"\n Tower Id "<<towerId_
  <<"\n Numb Samp "<<nTSamples_
  <<"\n Bx "<<bx_
  <<"\n L1 "<<l1_
  <<"\n blockLength "<<blockLength_;  
} 
void DCCFEBlock::enableFeIdChecks ( ) [inline]

Definition at line 32 of file DCCFEBlock.h.

References checkFeId_.

Referenced by DCCEventBlock::enableFeIdChecks().

{checkFeId_= true;}
virtual void DCCFEBlock::fillEcalElectronicsError ( std::auto_ptr< EcalElectronicsIdCollection > *  ) [inline, protected, virtual]

Reimplemented in DCCSCBlock, and DCCTowerBlock.

Definition at line 45 of file DCCFEBlock.h.

Referenced by unpack().

{};
unsigned int DCCFEBlock::getLength ( ) [inline, virtual]

Reimplemented from DCCDataBlockPrototype.

Definition at line 40 of file DCCFEBlock.h.

References DCCDataBlockPrototype::blockLength_.

{return blockLength_; }
int DCCFEBlock::unpack ( const uint64_t **  data,
unsigned int *  dwToEnd,
bool  zs,
unsigned int  expectedTowerID 
)

Definition at line 29 of file DCCFEBlock.cc.

References BLOCK_UNPACKED, DCCDataBlockPrototype::blockLength_, blockSize_, DCCEventBlock::bx(), bx_, checkFeId_, data, DCCDataBlockPrototype::data_, DCCDataBlockPrototype::datap_, DCCDataBlockPrototype::dwToEnd_, DCCDataBlockPrototype::event_, expTowerID_, expXtalTSamples_, FE_MEM, fillEcalElectronicsError(), forceToKeepFRdata_, DCCEventBlock::fov(), EcalElectronicsMapper::getActiveDCC(), EcalElectronicsMapper::getActiveSM(), DCCEventBlock::getHLTChannel(), EcalElectronicsMapper::getNumChannelsInDcc(), H_FOV_MASK, invalidBlockLengths_, invalidTTIds_, isSynced(), l1_, DCCEventBlock::l1A(), lastStripId_, lastXtalId_, DCCDataBlockPrototype::mapper_, nTSamples_, numbDWInXtalBlock_, DCCEventBlock::setFESyncNumbers(), DCCDataUnpacker::silentMode_, SKIP_BLOCK_UNPACKING, STOP_EVENT_UNPACKING, DCCDataBlockPrototype::sync_, TCC_BX_MASK, TCC_L1_MASK, TOWER_BX_B, TOWER_BX_MASK, TOWER_ID_MASK, TOWER_L1_B, TOWER_L1_MASK, TOWER_LENGTH_B, TOWER_LENGTH_MASK, TOWER_NSAMP_B, TOWER_NSAMP_MASK, towerId_, unfilteredDataBlockLength_, unpackXtalData(), DCCDataBlockPrototype::updateEventPointers(), xtalBlockSize_, and zs_.

Referenced by DCCEBEventBlock::unpack(), and DCCEEEventBlock::unpack().

                                                                                                           {
  
  zs_      = zs;  
  datap_   = data;
  data_    = *data;
  dwToEnd_ = dwToEnd;
  
  const unsigned int activeDCC = mapper_->getActiveSM();

  if( (*dwToEnd_)<1){
    if( ! DCCDataUnpacker::silentMode_ ){
      edm::LogWarning("IncorrectEvent")
        <<"\n Unable to unpack Tower block for event "<<event_->l1A()<<" in fed "<<activeDCC
        <<"\n The end of event was reached "
        <<"\n(or, previously, pointers intended to navigate outside of FedBlock (based on block sizes), and were stopped by setting dwToEnd_ to zero)"    ;
      //TODO : add this to a dcc event size collection error?
    }
    return STOP_EVENT_UNPACKING;
  }
  
  lastStripId_     = 0;
  lastXtalId_      = 0;
  expTowerID_      = expectedTowerID;
  
  
  //Point to begin of block
  data_++;
  
  towerId_           = ( *data_ )                   & TOWER_ID_MASK;
  nTSamples_         = ( *data_>>TOWER_NSAMP_B  )   & TOWER_NSAMP_MASK; 
  bx_                = ( *data_>>TOWER_BX_B     )   & TOWER_BX_MASK;
  l1_                = ( *data_>>TOWER_L1_B     )   & TOWER_L1_MASK;
  blockLength_       = ( *data_>>TOWER_LENGTH_B )   & TOWER_LENGTH_MASK;
  
  event_->setFESyncNumbers(l1_,bx_, (short)(expTowerID_-1));

  //debugging
  //display(cout);


  
  // check that expected fe_id==fe_expected is on
  if (checkFeId_              &&
      expTowerID_ != towerId_ &&
      expTowerID_ <= mapper_->getNumChannelsInDcc(activeDCC) ){ // fe_id must be within range foreseen in the FED 
    if (! DCCDataUnpacker::silentMode_) {
      edm::LogWarning("IncorrectBlock")
        << "Expected tower ID is " << expTowerID_ << " while " << towerId_ << " was found"
        << " (L1A " << event_->l1A() << " fed " << mapper_->getActiveDCC() << ")\n"
        << "  => Skipping to next FE block...";
    }
    
    fillEcalElectronicsError(invalidTTIds_); 
    
    updateEventPointers();
    return SKIP_BLOCK_UNPACKING;
  }

  // check that expected fe_id==fe_expected is off
  else if( (!checkFeId_) && 
           towerId_ > mapper_->getNumChannelsInDcc(activeDCC) ){ // fe_id must still be within range foreseen in the FED 
    if( ! DCCDataUnpacker::silentMode_ ){
      edm::LogWarning("IncorrectBlock")
        <<"For event "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()<<" (there's no check fe_id==dcc_channel)"
        <<"\n the FE_id found: "<<towerId_<<" exceeds max number of FE foreseen in fed"
        <<"\n => Skipping to next FE block...";
    }
    
    updateEventPointers();
    return SKIP_BLOCK_UNPACKING;
  }
  
  // Check synchronization
  if (sync_) {
    const unsigned int dccBx = (event_->bx())  & TCC_BX_MASK;
    const unsigned int dccL1 = (event_->l1A()) & TCC_L1_MASK;
    const unsigned int fov   = (event_->fov()) & H_FOV_MASK;
    
    if (! isSynced(dccBx, bx_, dccL1, l1_, FE_MEM, fov)) {
      if (! DCCDataUnpacker::silentMode_) {
        // TODO: add check for status from Channel Status DB
        
        edm::LogWarning("IncorrectBlock")
          << "Synchronization error for Tower Block"
          << " (L1A " << event_->l1A() << " bx " << event_->bx() << " fed " << mapper_->getActiveDCC() << " tower " << towerId_ << ")\n"
          << "  dccBx = " << dccBx << " bx_ = " << bx_ << " dccL1 = " << dccL1 << " l1_ = " << l1_ << "\n"
          << "  => Skipping to next tower block";
      }
      
      //Note : add to error collection ?
      updateEventPointers();
      return SKIP_BLOCK_UNPACKING;
    }
  }
  
  // check number of samples
  if( nTSamples_ != expXtalTSamples_ ){
    if( ! DCCDataUnpacker::silentMode_ ){
      edm::LogWarning("IncorrectBlock")
        <<"Unable to unpack Tower Block "<<towerId_<<" for event L1A "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
        <<"\n Number of time samples "<<nTSamples_<<" is not the same as expected ("<<expXtalTSamples_<<")"
        <<"\n => Skipping to next tower block...";
     } 
    //Note : add to error collection ?                 
    updateEventPointers();
    return SKIP_BLOCK_UNPACKING;
  }

  
  xtalBlockSize_     = numbDWInXtalBlock_*8;
  blockSize_           = blockLength_*8;  
  
  if((*dwToEnd_)<blockLength_){
    if( ! DCCDataUnpacker::silentMode_ ){
      edm::LogWarning("IncorrectEvent")
        <<"\n Unable to unpack Tower Block "<<towerId_<<" for event L1A "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
        <<"\n Only "<<((*dwToEnd_)*8)<<" bytes are available while "<<blockSize_<<" are needed!"
        <<"\n => Skipping to next fed block...";
    }
    //TODO : add to error collections
    return STOP_EVENT_UNPACKING;
  }


  if(!zs_ && !forceToKeepFRdata_){
         
    if ( unfilteredDataBlockLength_ != blockLength_ ){
      if( ! DCCDataUnpacker::silentMode_ ){ 
        edm::LogWarning("IncorrectEvent")
          <<"\n For event L1A "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
          <<"\n Expected block size is "<<(unfilteredDataBlockLength_*8)<<" bytes while "<<(blockLength_*8)<<" was found"
          <<"\n => Skipping to next fed block...";
       }

      fillEcalElectronicsError(invalidBlockLengths_) ;

      //Safer approach...  - why pointers do not navigate in this case?
      return STOP_EVENT_UNPACKING;          

      
    }

    
  }
  else if (!zs && forceToKeepFRdata_){

     if ( unfilteredDataBlockLength_ != blockLength_ ){
      if( ! DCCDataUnpacker::silentMode_ ){ 
        edm::LogWarning("IncorrectBlock")
          <<"For event L1A "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
          <<"\n Expected block size is "<<(unfilteredDataBlockLength_*8)<<" bytes while "<<(blockLength_*8)<<" was found"
          <<"\n => Keeps unpacking as the unpacker was forced to keep FR data (by configuration) ...";
       }

      fillEcalElectronicsError(invalidBlockLengths_) ;
     }

  }
  else if( blockLength_ > unfilteredDataBlockLength_ || (blockLength_-1) < numbDWInXtalBlock_ ){
    if( ! DCCDataUnpacker::silentMode_ ){
      edm::LogWarning("IncorrectEvent")
        <<"\n For event L1A "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()
        <<"\n The tower "<<towerId_<<" has a wrong number of bytes : "<<(blockLength_*8)           
        <<"\n => Skipping to next fed block...";
     }

     fillEcalElectronicsError(invalidBlockLengths_) ;


    //Safer approach... - why pointers do not navigate in this case?
    return STOP_EVENT_UNPACKING;
  }
  


  // If the HLT says to skip this tower we skip it...
  if( ! event_->getHLTChannel(towerId_) ){
    updateEventPointers();
    return SKIP_BLOCK_UNPACKING;
  }





  unsigned int numbOfXtalBlocks = (blockLength_-1)/numbDWInXtalBlock_; 

  // get XTAL Data
  unsigned int expStripID(0), expXtalID(0);
  //point to xtal data
  data_++;
  
  int statusUnpackXtal =0;

  for(unsigned int numbXtal=1; numbXtal <= numbOfXtalBlocks && statusUnpackXtal!= SKIP_BLOCK_UNPACKING; numbXtal++){

    
    if(!zs_ && ! forceToKeepFRdata_){
      expStripID  = ( numbXtal-1)/5 + 1;        
      expXtalID   =  numbXtal - (expStripID-1)*5;
    }
    
    statusUnpackXtal = unpackXtalData(expStripID,expXtalID);
    if (statusUnpackXtal== SKIP_BLOCK_UNPACKING)
      {
        if( ! DCCDataUnpacker::silentMode_ ){
            edm::LogWarning("IncorrectBlock")
            <<"For event L1A "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()
            <<"\n The tower "<<towerId_<<" won't be unpacked further";
        }
      }

  }// end loop over xtals of given FE 

  updateEventPointers();
  return BLOCK_UNPACKED;                
  
}
virtual int DCCFEBlock::unpackXtalData ( unsigned int  stripID,
unsigned int  xtalID 
) [inline, protected, virtual]

Reimplemented in DCCSCBlock, and DCCTowerBlock.

Definition at line 44 of file DCCFEBlock.h.

References BLOCK_UNPACKED.

Referenced by unpack().

{      return BLOCK_UNPACKED;};
void DCCFEBlock::updateCollectors ( ) [virtual]
void DCCFEBlock::zsFlag ( bool  zs) [inline]

Definition at line 30 of file DCCFEBlock.h.

References zs_.

{ zs_ = zs;}

Member Data Documentation

unsigned int DCCFEBlock::blockSize_ [protected]

Definition at line 62 of file DCCFEBlock.h.

Referenced by unpack().

unsigned int DCCFEBlock::bx_ [protected]

Definition at line 63 of file DCCFEBlock.h.

Referenced by display(), and unpack().

bool DCCFEBlock::checkFeId_ [protected]

Definition at line 49 of file DCCFEBlock.h.

Referenced by enableFeIdChecks(), and unpack().

unsigned int DCCFEBlock::expTowerID_ [protected]
unsigned int DCCFEBlock::expXtalTSamples_ [protected]

Definition at line 52 of file DCCFEBlock.h.

Referenced by DCCFEBlock(), and unpack().

Definition at line 51 of file DCCFEBlock.h.

Referenced by unpack().

Definition at line 69 of file DCCFEBlock.h.

Referenced by unpack(), and updateCollectors().

Definition at line 67 of file DCCFEBlock.h.

Referenced by unpack(), and updateCollectors().

unsigned int DCCFEBlock::l1_ [protected]

Definition at line 64 of file DCCFEBlock.h.

Referenced by display(), and unpack().

unsigned int DCCFEBlock::lastStripId_ [protected]

Definition at line 54 of file DCCFEBlock.h.

Referenced by unpack(), DCCTowerBlock::unpackXtalData(), and DCCSCBlock::unpackXtalData().

unsigned int DCCFEBlock::lastXtalId_ [protected]

Definition at line 55 of file DCCFEBlock.h.

Referenced by unpack(), DCCTowerBlock::unpackXtalData(), and DCCSCBlock::unpackXtalData().

unsigned int DCCFEBlock::nTSamples_ [protected]
unsigned int DCCFEBlock::numbDWInXtalBlock_ [protected]
unsigned int DCCFEBlock::towerId_ [protected]
unsigned int DCCFEBlock::unfilteredDataBlockLength_ [protected]

Definition at line 53 of file DCCFEBlock.h.

Referenced by DCCFEBlock(), and unpack().

unsigned int DCCFEBlock::xtalBlockSize_ [protected]

Definition at line 59 of file DCCFEBlock.h.

Referenced by unpack().

short* DCCFEBlock::xtalGains_ [protected]
bool DCCFEBlock::zs_ [protected]