CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/EventFilter/EcalRawToDigi/src/DCCEETCCBlock.cc

Go to the documentation of this file.
00001 #include "EventFilter/EcalRawToDigi/interface/DCCEETCCBlock.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "EventFilter/EcalRawToDigi/interface/EcalElectronicsMapper.h"
00004 #include "EventFilter/EcalRawToDigi/interface/DCCDataUnpacker.h"
00005 
00006 
00007 DCCEETCCBlock::DCCEETCCBlock ( DCCDataUnpacker  * u,EcalElectronicsMapper * m, DCCEventBlock * e, bool unpack) : 
00008 DCCTCCBlock(u,m,e,unpack)
00009 {
00010    blockLength_ = 0;
00011   
00012 }
00013 
00014 void DCCEETCCBlock::updateCollectors(){
00015   tps_ = unpacker_->ecalTpsCollection();
00016   pss_ = unpacker_->ecalPSsCollection();
00017 }
00018 
00019 void DCCEETCCBlock::addTriggerPrimitivesToCollection(){
00020   
00021   //point to trigger data
00022   data_++;
00023 
00024   bool processTPG2(true) ;
00025   unsigned int psInputCounter(0);
00026   
00027   const uint16_t * tccP_= reinterpret_cast<const uint16_t * >(data_);
00028   
00029   
00030   int dccFOV =  event_->fov();
00031   if (! (dccFOV==dcc_FOV_0 || dccFOV==dcc_FOV_1 || dccFOV==dcc_FOV_2) ){
00032     if( ! DCCDataUnpacker::silentMode_ ){
00033       edm::LogWarning("IncorrectEvent") 
00034         <<"\n FOV value in data is: " << dccFOV <<
00035         "At event: "  <<event_->l1A()<<" with bx "<<event_->bx()<<" in fed <<"<<mapper_->getActiveDCC()
00036         <<"\n TCC id "<<tccId_<<" FOV "<< dccFOV << " which is not a foreseen value. Setting it to: " << dcc_FOV_2;
00037     }
00038     dccFOV=dcc_FOV_2;
00039   }
00040   
00041   
00043   // MC raw data based on CMS NOTE 2005/021 
00044   // (and raw data when FOV was unassigned, earlier than mid 2008)   
00045     if (dccFOV == dcc_FOV_0)
00046       {
00047 
00048         // Unpack TPG1 pseudostrip input block
00049         if(ps_){ 
00050           for(unsigned int i = 1; i<= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++){
00051             pPS_= mapper_->getPSInputDigiPointer(tccId_,psInputCounter);
00052             if(!pPS_) continue;
00053             pPS_->setSampleValue(0, *tccP_ );
00054             (*pss_)->push_back(*pPS_);
00055           }
00056         }
00057   
00058         // Unpack TPG1 trigger primitive block
00059         // loop over tp_counter=i and navigate forward in raw (tccP_)
00060         for(unsigned int i = 1; i<= NUMB_TTS_TPG1; i++, tccP_++){//16
00061           
00062           if( i<= nTTs_){
00063             pTP_ = mapper_->getTPPointer(tccId_,i);  // pointer to tp digi container
00064             if(pTP_) pTP_->setSample(0, *tccP_ );    // fill it
00065           }else {
00066             processTPG2 = false;
00067             break;
00068           }
00069           // adding trigger primitive digi to the collection
00070           (*tps_)->push_back(*pTP_);
00071         }
00072         
00073         
00074         if(processTPG2){
00075           
00076           // Unpack TPG2 pseudostrip input block
00077           if(ps_){ 
00078             for(unsigned int i = 1; i<= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++){
00079               if (i<=NUMB_TTS_TPG2_DUPL) continue;
00080               //fill pseudostrip container
00081               pPS_= mapper_->getPSInputDigiPointer(tccId_,psInputCounter);
00082               if(!pPS_) continue;
00083               pPS_->setSampleValue(0, *tccP_ );
00084               (*pss_)->push_back(*pPS_);
00085             }
00086           }
00087           
00088           
00089           // Unpack TPG2 trigger primitive block
00090           for(unsigned int i = 1; i<= NUMB_TTS_TPG2; i++, tccP_++){//12
00091             unsigned int tt = i+NUMB_TTS_TPG1;
00092             
00093             if( tt <= nTTs_){
00094               pTP_ = mapper_->getTPPointer(tccId_,tt);
00095               if(pTP_) pTP_->setSample(0, *tccP_ ); 
00096             }
00097             else break;
00098             // adding trigger primitive digi to the collection
00099             (*tps_)->push_back(*pTP_);
00100           }
00101           
00102         }// end if(processTPG2)
00103         
00104       }// end FOV==0
00105     
00107       // real data since ever FOV was initialized; only 2 used >= June 09  
00108     else if (dccFOV == dcc_FOV_1  || dccFOV == dcc_FOV_2) 
00109       {
00110         
00111         // Unpack TPG1 pseudostrip input block
00112         if(ps_){ 
00113           for(unsigned int i = 1; i<= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++){
00114             pPS_= mapper_->getPSInputDigiPointer(tccId_,psInputCounter);
00115             if(!pPS_) continue;
00116             pPS_->setSampleValue(0, *tccP_ );
00117             (*pss_)->push_back(*pPS_);
00118           }
00119         }
00120         
00121         int offset(0);
00122         // Unpack TPG1 trigger primitive block
00123         // loop over tp_counter=i and navigate forward in raw (tccP_)
00124         for(unsigned int i = 1; i<= NUMB_TTS_TPG1; i++, tccP_++){//16
00125           
00126           if( i<= nTTs_){
00127             if(mapper_->isTCCExternal(tccId_)){
00128               if(i>8 && i<=16 ) continue;   // skip blank tp's [9,16]
00129               if(i>8  )         offset=8;   // 
00130               if(i>24 )         continue;   // skip blank tp's [25, 28]
00131             }
00132             
00133             pTP_ = mapper_->getTPPointer(tccId_,i-offset);  // pointer to tp digi container
00134             if(pTP_) pTP_->setSample(0, *tccP_ );    // fill it
00135             
00136           }else {
00137             processTPG2 = false;
00138             break;
00139           }
00140           // adding trigger primitive digi to the collection
00141           (*tps_)->push_back(*pTP_);
00142         }
00143         
00144         if(processTPG2){
00145           
00146           // Unpack TPG2 pseudostrip input block
00147           if(ps_){ 
00148             for(unsigned int i = 1; i<= NUMB_PSEUDOSTRIPS; i++, tccP_++, psInputCounter++){
00149               if (i<=NUMB_TTS_TPG2_DUPL) continue;
00150               //fill pseudostrip container
00151               pPS_= mapper_->getPSInputDigiPointer(tccId_,psInputCounter);
00152               if(!pPS_) continue;
00153               pPS_->setSampleValue(0, *tccP_ );
00154               (*pss_)->push_back(*pPS_);
00155             }
00156           }
00157           
00158           
00159           // Unpack TPG2 trigger primitive block
00160           for(unsigned int i = 1; i<= NUMB_TTS_TPG2; i++, tccP_++){//12
00161             unsigned int tt = i+NUMB_TTS_TPG1;
00162             
00163             if( i<= nTTs_){
00164               if(mapper_->isTCCExternal(tccId_)){
00165                 if(tt>8 && tt<=16 ) continue;   // skip blank tp's [9,16]
00166                 if(tt>8  )          offset=8;    // 
00167                 if(tt>24 )          continue;    // skip blank tp's [25, 28]
00168               }
00169               
00170               pTP_ = mapper_->getTPPointer(tccId_,tt-offset);
00171               if(pTP_) pTP_->setSample(0, *tccP_ ); 
00172             }
00173             else break;
00174             // adding trigger primitive digi to the collection
00175             (*tps_)->push_back(*pTP_);
00176           }
00177         }// end if(processTPG2)
00178       }// end FOV==1 or 2
00179 }
00180 
00181 
00182 bool DCCEETCCBlock::checkTccIdAndNumbTTs(){
00183   
00184         
00185   bool tccFound(false);
00186   bool errorOnNumbOfTTs(false);
00187   const int  activeDCC =  mapper_->getActiveSM();
00188   std::vector<unsigned int> * m = mapper_->getTccs(activeDCC);
00189   std::vector<unsigned int>::iterator it;
00190   for(it= m->begin();it!=m->end();it++){
00191     if((*it) == tccId_){
00192       tccFound=true;
00193      
00194           /*
00195             expNumbTTs_= 28; //separate from inner and outer tcc 
00196             For inner TCCs you expect 28 TTs (4 in phi, 7 in eta).
00197             For outer TCCs you expect 16 TTs (4 in phi, 4 in eta).
00198             to implement : map tccid-> number of tts
00199 
00200             Pascal P.: For outer board, only 16 TPs are meaningful but 28 are sent.
00201             - [1,8] are meaningful 
00202             - [9,16] are empty ie should be skipped by unpacker 
00203             - [17, 24] are meaningful 
00204             - [25, 28] are empty ie should be skipped by unpacker 
00205           */
00206 
00207           if( nTTs_ != 28 && nTTs_ !=16 ){
00208             if( ! DCCDataUnpacker::silentMode_ ){
00209           edm::LogWarning("IncorrectBlock") 
00210             <<"Error on event "<<event_->l1A()<<" with bx "<<event_->bx()<<" in fed <<"<<mapper_->getActiveDCC()
00211            <<"\n TCC id "<<tccId_<<" has "<<nTTs_<<" Trigger Towers (only 28 or 16 are the expected values in EE)"
00212            <<"\n => Skipping to next fed block...";
00213           errorOnNumbOfTTs = true; 
00214           //todo : add to error collection   
00215             }
00216           }
00217     }
00218   }
00219         
00220   if(!tccFound){
00221 
00222     if( ! DCCDataUnpacker::silentMode_ ){
00223       edm::LogWarning("IncorrectBlock") 
00224         <<"Error on event "<<event_->l1A()<<" with bx "<<event_->bx()<<" in fed <<"<<mapper_->getActiveDCC()
00225         <<"\n TCC id "<<tccId_<<" is not valid for this dcc "
00226         <<"\n => Skipping to next fed block...";
00227        //todo : add to error collection   
00228      }
00229   }
00230   
00231 
00232  return (tccFound || errorOnNumbOfTTs);
00233 
00234 }
00235 
00236 
00237 unsigned int DCCEETCCBlock::getLength(){
00238 
00239   const uint64_t * temp = data_;
00240   temp++;
00241 
00242   ps_       = ( *temp>>TCC_PS_B ) & B_MASK;   
00243    
00244   unsigned int numbTps = (NUMB_TTS_TPG1 + NUMB_TTS_TPG2);
00245   if(ps_){ numbTps += 2*NUMB_PSEUDOSTRIPS;}
00246   
00247   unsigned int length = numbTps/4 + 2; //header and trailer
00248   if(numbTps%4) length++ ;
00249   
00250   
00251   return length;
00252 
00253 }
00254 
00255