CMS 3D CMS Logo

DCCSCBlock.cc

Go to the documentation of this file.
00001 #include "EventFilter/EcalRawToDigiDev/interface/DCCSCBlock.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 DCCSCBlock::DCCSCBlock( DCCDataUnpacker * u,EcalElectronicsMapper * m , DCCEventBlock * e, bool unpack)
00010 : DCCFEBlock(u,m,e,unpack){}
00011 
00012 
00013 void DCCSCBlock::updateCollectors(){
00014 
00015   DCCFEBlock::updateCollectors();
00016   
00017   // needs to be update for eb/ee
00018   digis_               = unpacker_->eeDigisCollection();
00019 
00020   invalidGains_        = unpacker_->invalidEEGainsCollection();
00021   invalidGainsSwitch_  = unpacker_->invalidEEGainsSwitchCollection();
00022   invalidChIds_        = unpacker_->invalidEEChIdsCollection();
00023 
00024 }
00025 
00026 
00027 
00028 
00029 int DCCSCBlock::unpackXtalData(uint expStripID, uint expXtalID){
00030   
00031   bool errorOnXtal(false);
00032  
00033   uint16_t * xData_= reinterpret_cast<uint16_t *>(data_);
00034 
00035  
00036   // Get xtal data ids
00037   uint stripId = (*xData_) & TOWER_STRIPID_MASK;
00038   uint xtalId  =((*xData_)>>TOWER_XTALID_B ) & TOWER_XTALID_MASK;
00039   
00040   // cout<<"\n DEBUG : unpacked xtal data for strip id "<<stripId<<" and xtal id "<<xtalId<<endl;
00041   // cout<<"\n DEBUG : expected strip id "<<expStripID<<" expected xtal id "<<expXtalID<<endl;
00042   
00043 
00044   if( !zs_ && (expStripID != stripId || expXtalID != xtalId)){ 
00045 
00046     if( ! DCCDataUnpacker::silentMode_ ){        
00047       edm::LogWarning("EcalRawToDigiDevChId")
00048         <<"\n For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00049         <<"\n The expected strip is "<<expStripID<<" and "<<stripId<<" was found"
00050         <<"\n The expected xtal  is "<<expXtalID <<" and "<<xtalId<<" was found";       
00051      }
00052     
00053     
00054     // using expected cry_di to raise warning about xtal_id problem
00055     pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,expStripID,expXtalID);
00056     (*invalidChIds_)->push_back(*pDetId_);
00057     
00058     stripId = expStripID;
00059     xtalId  = expXtalID;
00060     errorOnXtal = true;
00061     
00062     // return here, so to skip all following checks
00063     data_ += numbDWInXtalBlock_;
00064     return BLOCK_UNPACKED;
00065   }
00066 
00067 
00068   // check id in case of 0suppressed data
00069 
00070   else if(zs_){
00071 
00072     // Check for valid Ids 1) values out of range
00073 
00074     if(stripId == 0 || stripId > 5 || xtalId == 0 || xtalId > 5){
00075 
00076       if( ! DCCDataUnpacker::silentMode_ ){
00077         edm::LogWarning("EcalRawToDigiDevChId")
00078           <<"\n For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00079           <<"\n Invalid strip : "<<stripId<<" or xtal : "<<xtalId
00080           <<" ids ( last strip was: " << lastStripId_ << " last ch was: " << lastXtalId_ << ")";
00081        }
00082       
00083       int st = lastStripId_;
00084       int ch = lastXtalId_;
00085       ch++;
00086       if (ch > NUMB_XTAL)       {ch=1; st++;}
00087       if (st > NUMB_STRIP)      {ch=1; st=1;}
00088 
00089       // adding channel following the last valid
00090       pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,st,ch);
00091       (*invalidChIds_)->push_back(*pDetId_);
00092 
00093       errorOnXtal = true;
00094 
00095       lastStripId_ = st;
00096       lastXtalId_  = ch;
00097 
00098       // return here, so to skip all following checks
00099       return SKIP_BLOCK_UNPACKING;
00100 
00101     }else{
00102                   
00103       // Check for zs valid Ids 2) if channel-in-strip has increased wrt previous xtal
00104       //                        3) if strip has increased wrt previous xtal
00105       if( ( stripId == lastStripId_ && xtalId <= lastXtalId_ ) ||
00106           (stripId < lastStripId_))
00107         {
00108           if( ! DCCDataUnpacker::silentMode_ ){ 
00109             edm::LogWarning("EcalRawToDigiDevChId")
00110               <<"\n For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00111               <<"\n Xtal id was expected to increase but it didn't. "
00112               <<"\n Last unpacked xtal was "<<lastXtalId_<<" while current xtal is "<<xtalId<<".";
00113           }
00114 
00115           int st = lastStripId_;
00116           int ch = lastXtalId_;
00117           ch++;
00118           if (ch > NUMB_XTAL)   {ch=1; st++;}
00119           if (st > NUMB_STRIP)  {ch=1; st=1;}
00120           
00121           // adding channel following the last valid
00122            pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,stripId,xtalId);
00123            (*invalidChIds_)->push_back(*pDetId_);
00124            
00125            errorOnXtal = true;
00126            lastStripId_ = st;
00127            lastXtalId_  = ch;
00128            
00129            // return here, so to skip all following checks
00130            return SKIP_BLOCK_UNPACKING;
00131 
00132         }
00133         
00134       lastStripId_  = stripId;
00135       lastXtalId_   = xtalId;
00136     }// end else
00137   }// end if(zs_)
00138  
00139   bool frameAdded=false;
00140 
00141   // if there is an error on xtal id ignore next error checks  
00142   // otherwise, assume channel_id is valid and proceed with making and checking the data frame
00143   if(errorOnXtal) return SKIP_BLOCK_UNPACKING;
00144 
00145     pDetId_ = (EEDetId*) mapper_->getDetIdPointer(towerId_,stripId,xtalId);
00146     
00147     if(pDetId_){// checking that requested EEDetId exists
00148       
00149       (*digis_)->push_back(*pDetId_);
00150       EEDataFrame df( (*digis_)->back() );
00151       frameAdded=true;
00152       bool wrongGain(false);
00153          
00154       //set samples in the frame
00155       for(uint i =0; i< nTSamples_ ;i++){ 
00156         xData_++;
00157         uint data =  (*xData_) & TOWER_DIGI_MASK;
00158         uint gain =  data>>12;
00159         xtalGains_[i]=gain;
00160         if(gain == 0){    wrongGain = true; } 
00161         df.setSample(i,data);
00162       } 
00163     
00164       if(wrongGain){ 
00165         if( ! DCCDataUnpacker::silentMode_ ){
00166           edm::LogWarning("EcalRawToDigiDevGainZero")
00167           <<"\n For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00168           <<"\n Gain zero was found in strip "<<stripId<<" and xtal "<<xtalId;   
00169         }
00170         
00171         (*invalidGains_)->push_back(*pDetId_); 
00172         errorOnXtal = true;
00173         
00174         //return here, so to skip all the rest
00175         //make special collection for gain0 data frames (saturation)
00176         //Point to begin of next xtal Block
00177         data_ += numbDWInXtalBlock_;
00178         
00179         return BLOCK_UNPACKED;
00180 
00181       }
00182         
00183    
00184       short firstGainWrong=-1;
00185       short numGainWrong=0;
00186             
00187       for (uint i=0; i<nTSamples_; i++ ) {
00188         if (i>0 && xtalGains_[i-1]>xtalGains_[i]) {
00189           numGainWrong++;
00190           if (firstGainWrong == -1) { firstGainWrong=i;}
00191         }
00192       }
00193       
00194       if (numGainWrong>0) {
00195         if( ! DCCDataUnpacker::silentMode_ ){
00196           edm::LogWarning("EcalRawToDigiDevGainSwitch")
00197             <<"\n For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00198             <<"\n A wrong gain transition switch was found in strip "<<stripId<<" and xtal "<<xtalId;    
00199         }
00200         
00201         (*invalidGainsSwitch_)->push_back(*pDetId_);
00202         
00203         errorOnXtal = true;
00204       } 
00205 
00206       //Add frame to collection only if all data format and gain rules are respected
00207       if(errorOnXtal&&frameAdded) {
00208         (*digis_)->pop_back();
00209       }
00210 
00211     }// End 'if EE id exist'
00212     
00213     else{// in case EE did not exist
00214       if( ! DCCDataUnpacker::silentMode_ ){
00215         edm::LogWarning("EcalRawToDigiDevChId")
00216             <<"\n For event LV1: "<<event_->l1A()<<", fed "<<mapper_->getActiveDCC()<<" and tower "<<towerId_
00217             <<"\n An EEDetId was requested that does not exist";    
00218       }
00219     }
00220     
00221 
00222   //Point to begin of next xtal Block
00223   data_ += numbDWInXtalBlock_;
00224 
00225   return BLOCK_UNPACKED;
00226       
00227 }
00228 
00229 
00230 
00231 
00232 void DCCSCBlock::fillEcalElectronicsError( std::auto_ptr<EcalElectronicsIdCollection> * errorColection){
00233 
00234   int activeDCC = mapper_->getActiveSM();
00235 
00236   if ( (NUMB_SM_EE_MIN_MIN <=activeDCC && activeDCC<=NUMB_SM_EE_MIN_MAX) ||
00237          (NUMB_SM_EE_PLU_MIN <=activeDCC && activeDCC<=NUMB_SM_EE_PLU_MAX) ){
00238      EcalElectronicsId  *  eleTp = mapper_->getSCElectronicsPointer(activeDCC,expTowerID_);
00239      (*errorColection)->push_back(*eleTp);
00240   }else{
00241      if( ! DCCDataUnpacker::silentMode_ ){
00242        edm::LogWarning("EcalRawToDigiDevChId")
00243          <<"\n For event "<<event_->l1A()<<" there's fed: "<< activeDCC
00244          <<" activeDcc: "<<mapper_->getActiveSM()
00245          <<" but that activeDcc is not valid in EE.";
00246      }
00247   }
00248 
00249 }
00250 
00251 
00252 

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