CMS 3D CMS Logo

DCCFEBlock.cc

Go to the documentation of this file.
00001 #include "EventFilter/EcalRawToDigiDev/interface/DCCFEBlock.h"
00002 #include "EventFilter/EcalRawToDigiDev/interface/DCCEventBlock.h"
00003 #include "EventFilter/EcalRawToDigiDev/interface/DCCDataUnpacker.h"
00004 #include <stdio.h>
00005 #include "EventFilter/EcalRawToDigiDev/interface/EcalElectronicsMapper.h"
00006 
00007 
00008 
00009 DCCFEBlock::DCCFEBlock( DCCDataUnpacker * u, EcalElectronicsMapper * m, DCCEventBlock * e,bool unpack)
00010   : DCCDataBlockPrototype(u,m,e,unpack), checkFeId_(false) {
00011    
00012   expXtalTSamples_           = mapper_->numbXtalTSamples();
00013   numbDWInXtalBlock_         = (expXtalTSamples_-2)/4+1;
00014   unfilteredDataBlockLength_ = mapper_->getUnfilteredTowerBlockLength();
00015   xtalGains_                 = new short[expXtalTSamples_]; 
00016   
00017 }
00018 
00019 
00020 void DCCFEBlock::updateCollectors(){
00021 
00022   invalidBlockLengths_    = unpacker_->invalidBlockLengthsCollection();
00023   invalidTTIds_           = unpacker_->invalidTTIdsCollection();
00024 
00025 }
00026 
00027 
00028 
00029 int DCCFEBlock::unpack(uint64_t ** data, uint * dwToEnd, bool zs, uint expectedTowerID){
00030   
00031   zs_      = zs;  
00032   datap_   = data;
00033   data_    = *data;
00034   dwToEnd_ = dwToEnd;
00035   
00036  
00037   if( (*dwToEnd_)<1){
00038     if( ! DCCDataUnpacker::silentMode_ ){
00039       edm::LogWarning("EcalRawToDigiDevTowerSize")
00040         <<"\n Unable to unpack Tower block for event "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
00041         <<"\n The end of event was reached "
00042         <<"\n(or, previously, pointers intended to navigate outside of FedBlock (based on block sizes), and were stopped by setting dwToEnd_ to zero)"    ;
00043       //TODO : add this to a dcc event size collection error?
00044     }
00045     return STOP_EVENT_UNPACKING;
00046   }
00047   
00048   lastStripId_     = 0;
00049   lastXtalId_      = 0;
00050   expTowerID_      = expectedTowerID;
00051   
00052   
00053   //Point to begin of block
00054   data_++;
00055   
00056   towerId_           = ( *data_ )                   & TOWER_ID_MASK;
00057   nTSamples_         = ( *data_>>TOWER_NSAMP_B  )   & TOWER_NSAMP_MASK; 
00058   bx_                = ( *data_>>TOWER_BX_B     )   & TOWER_BX_MASK;
00059   l1_                = ( *data_>>TOWER_L1_B     )   & TOWER_L1_MASK;
00060   blockLength_       = ( *data_>>TOWER_LENGTH_B )   & TOWER_LENGTH_MASK;
00061 
00062   //debugging
00063   //display(cout);
00064 
00065 
00066   uint activeDCC = mapper_->getActiveSM();
00067   
00069   // check that expected fe_id==fe_expected is on
00070   if( checkFeId_              &&
00071       expTowerID_ != towerId_ &&
00072       expTowerID_ <= mapper_->getNumChannelsInDcc(activeDCC) ){ // fe_id must be within range foreseen in the FED 
00073     if( ! DCCDataUnpacker::silentMode_ ){
00074       edm::LogWarning("EcalRawToDigiDevTowerId")
00075         <<"\n For event "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()
00076         <<"\n Expected FE_id is "<<expTowerID_<<" while "<<towerId_<<" was found "
00077         <<"\n => Skipping to next FE block...";
00078      } 
00079 
00080      fillEcalElectronicsError(invalidTTIds_); 
00081     
00082     updateEventPointers();
00083     return SKIP_BLOCK_UNPACKING;
00084   }
00085 
00087   // check that expected fe_id==fe_expected is off
00088   // still, check the range (to avoid non-valid detId's)
00089   else if( (!checkFeId_) && 
00090            towerId_ > mapper_->getNumChannelsInDcc(activeDCC) ){ // fe_id must still be within range foreseen in the FED 
00091     if( ! DCCDataUnpacker::silentMode_ ){
00092       edm::LogWarning("EcalRawToDigiDevTowerId")
00093         <<"\n For event "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()<<" (there's no check fe_id==dcc_channel)"
00094         <<"\n the FE_id found: "<<towerId_<<" exceeds max number of FE foreseen in fed"
00095         <<"\n => Skipping to next FE block...";
00096     }
00097     
00098     updateEventPointers();
00099     return SKIP_BLOCK_UNPACKING;
00100   }
00101   
00102   
00103   
00104   // Check synchronization
00105   if(sync_){
00106 
00107     uint dccBx = (event_->bx())&TCC_BX_MASK;
00108     uint dccL1 = (event_->l1A())&TCC_L1_MASK; 
00109     // accounting for counters starting from 0 in ECAL FE, while from 1 in CSM
00110     if( dccBx != bx_ || dccL1 != (l1_+1) ){
00111       if( ! DCCDataUnpacker::silentMode_ ){
00112         edm::LogWarning("EcalRawToDigiDevNumTowerBlocks")
00113           <<"\n Synchronization error for Tower Block "<<towerId_<<" in event "<<event_->l1A()
00114           <<" with bx "<<event_->bx()<<" in fed "<<mapper_->getActiveDCC()
00115           <<"\n TCC local l1A is  "<<l1_<<" and local bx is "<<bx_
00116           <<"\n => Skipping to next tower block...";
00117        }
00118       //Note : add to error collection ?                 
00119       updateEventPointers();
00120       return SKIP_BLOCK_UNPACKING;
00121     }
00122   }
00123 
00124 
00125 
00126   // check number of samples
00127   if( nTSamples_ != expXtalTSamples_ ){
00128     if( ! DCCDataUnpacker::silentMode_ ){
00129       edm::LogWarning("EcalRawToDigiDevNumTowerBlocks")
00130         <<"EcalRawToDigi@SUB=DCCFEBlock::unpack"
00131         <<"\n Unable to unpack Tower Block "<<towerId_<<" for event L1A "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
00132         <<"\n Number of time samples "<<nTSamples_<<" is not the same as expected ("<<expXtalTSamples_<<")"
00133         <<"\n => Skipping to next tower block...";
00134      } 
00135     //Note : add to error collection ?           
00136     updateEventPointers();
00137     return SKIP_BLOCK_UNPACKING;
00138   }
00139 
00140   
00141   xtalBlockSize_     = numbDWInXtalBlock_*8;
00142   blockSize_           = blockLength_*8;  
00143   
00144   if((*dwToEnd_)<blockLength_){
00145     if( ! DCCDataUnpacker::silentMode_ ){
00146       edm::LogWarning("EcalRawToDigiDevNumTowerBlocks")
00147         <<"\n Unable to unpack Tower Block "<<towerId_<<" for event L1A "<<event_->l1A()<<" in fed "<<mapper_->getActiveDCC()
00148         <<"\n Only "<<((*dwToEnd_)*8)<<" bytes are available while "<<blockSize_<<" are needed!"
00149         <<"\n => Skipping to next fed block...";
00150     }
00151     //TODO : add to error collections
00152     return STOP_EVENT_UNPACKING;
00153   }
00154 
00155 
00156   if(!zs_){
00157          
00158     if ( unfilteredDataBlockLength_ != blockLength_ ){
00159       if( ! DCCDataUnpacker::silentMode_ ){ 
00160         edm::LogWarning("EcalRawToDigiDevNumTowerBlocks")
00161           <<"\n For event L1A "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00162           <<"\n Expected block size is "<<(unfilteredDataBlockLength_*8)<<" bytes while "<<(blockLength_*8)<<" was found"
00163           <<"\n => Skipping to next fed block...";
00164        }
00165 
00166       fillEcalElectronicsError(invalidBlockLengths_) ;
00167 
00168       //Safer approach...  - why pointers do not navigate in this case?
00169       return STOP_EVENT_UNPACKING;        
00170     }
00171 
00172     
00173   }else if( blockLength_ > unfilteredDataBlockLength_ || (blockLength_-1) < numbDWInXtalBlock_ ){
00174     if( ! DCCDataUnpacker::silentMode_ ){
00175       edm::LogWarning("EcalRawToDigiDevNumTowerBlocks")
00176         <<"\n For event L1A "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()
00177         <<"\n The tower "<<towerId_<<" has a wrong number of bytes : "<<(blockLength_*8)           
00178         <<"\n => Skipping to next fed block...";
00179      }
00180 
00181     fillEcalElectronicsError(invalidBlockLengths_) ;
00182 
00183     //Safer approach... - why pointers do not navigate in this case?
00184     return STOP_EVENT_UNPACKING;
00185   }
00186   
00187 
00188 
00189   uint numbOfXtalBlocks = (blockLength_-1)/numbDWInXtalBlock_; 
00190 
00191   // get XTAL Data
00192   uint expStripID(0), expXtalID(0);
00193   //point to xtal data
00194   data_++;
00195   
00196   int statusUnpackXtal =0;
00197 
00198   for(uint numbXtal=1; numbXtal <= numbOfXtalBlocks && statusUnpackXtal!= SKIP_BLOCK_UNPACKING; numbXtal++){
00199 
00200     // If zs is disabled we know the expected strip and xtal ids
00201     // Note : this is valid for the EB how about the EE ? -> retieve expected index from mapper
00202     
00203     if(!zs_){
00204       expStripID  = ( numbXtal-1)/5 + 1;        
00205       expXtalID   =  numbXtal - (expStripID-1)*5;
00206     }
00207     
00208     statusUnpackXtal = unpackXtalData(expStripID,expXtalID);
00209     if (statusUnpackXtal== SKIP_BLOCK_UNPACKING)
00210       {
00211         if( ! DCCDataUnpacker::silentMode_ ){
00212           edm::LogWarning("EcalRawToDigiDev")
00213             <<"\n For event L1A "<<event_->l1A()<<" and fed "<<mapper_->getActiveDCC()
00214             <<"\n The tower "<<towerId_<<" won't be unpacked further";
00215         }
00216       }
00217 
00218   }// end loop over xtals of given FE 
00219 
00220   updateEventPointers();
00221   return BLOCK_UNPACKED;                
00222   
00223 }
00224 
00225 
00226 
00227 
00228 void DCCFEBlock::display(std::ostream& o){
00229 
00230   o<<"\n Unpacked Info for DCC Tower Block"
00231   <<"\n DW1 ============================="
00232   <<"\n Tower Id "<<towerId_
00233   <<"\n Numb Samp "<<nTSamples_
00234   <<"\n Bx "<<bx_
00235   <<"\n L1 "<<l1_
00236   <<"\n blockLength "<<blockLength_;  
00237 } 
00238 
00239 

Generated on Tue Jun 9 17:34:37 2009 for CMSSW by  doxygen 1.5.4