CMS 3D CMS Logo

SiStripQualityConfigurableFakeESSource.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    SiStripQualityFakeESSource
00004 // Class:      SiStripQualityFakeESSource
00005 // 
00013 //
00014 // Original Author:  Domenico GIORDANO
00015 //         Created:  Wed Oct  3 11:46:09 CEST 2007
00016 // $Id: SiStripQualityConfigurableFakeESSource.cc,v 1.2 2008/09/11 16:26:56 giordano Exp $
00017 //
00018 //
00019 
00020 #include "CalibTracker/SiStripESProducers/plugins/fake/SiStripQualityConfigurableFakeESSource.h"
00021 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00022 
00023 SiStripQualityConfigurableFakeESSource::SiStripQualityConfigurableFakeESSource(const edm::ParameterSet& iConfig):
00024   iConfig_(iConfig){
00025   setWhatProduced(this);
00026   findingRecord<SiStripBadModuleRcd>();
00027 
00028   edm::LogInfo("SiStripQualityConfigurableFakeESSource") << " ctor ";
00029   fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
00030   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug",false);
00031   BadComponentList_ =  iConfig.getUntrackedParameter<Parameters>("BadComponentList");
00032 
00033 }
00034 
00035 
00036 std::auto_ptr<SiStripBadStrip> SiStripQualityConfigurableFakeESSource::produce(const SiStripBadModuleRcd& iRecord)
00037 {
00038 
00039   SiStripQuality* obj = new SiStripQuality();
00040 
00041   SiStripDetInfoFileReader reader(fp_.fullPath());   
00042   const std::vector<uint32_t>& DetIds= reader.getAllDetIds();
00043   std::vector<uint32_t> selDetIds;
00044   selectDetectors(DetIds,selDetIds);
00045 
00046   edm::LogInfo("SiStripQualityConfigurableFakeESSource")<<"[produce] number of selected dets to be removed " << selDetIds.size() <<std::endl;
00047 
00048   std::stringstream ss;  
00049   std::vector<uint32_t>::const_iterator iter=selDetIds.begin();
00050   std::vector<uint32_t>::const_iterator iterEnd=selDetIds.end();
00051   for(;iter!=iterEnd;++iter){
00052     
00053     SiStripQuality::InputVector theSiStripVector;
00054     
00055     unsigned short firstBadStrip=0, NconsecutiveBadStrips=reader.getNumberOfApvsAndStripLength(*iter).first * 128;
00056     unsigned int theBadStripRange;
00057     
00058     theBadStripRange = obj->encode(firstBadStrip,NconsecutiveBadStrips);
00059     
00060     if (printdebug_)
00061       ss << "detid " << *iter << " \t"
00062          << " firstBadStrip " << firstBadStrip << "\t "
00063          << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
00064          << " packed integer " << std::hex << theBadStripRange  << std::dec
00065          << std::endl;      
00066     
00067     theSiStripVector.push_back(theBadStripRange);
00068     
00069     SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00070     if ( ! obj->put(*iter,range) )
00071       edm::LogError("SiStripQualityConfigurableFakeESSource")<<"[produce] detid already exists"<<std::endl;
00072   }
00073   if (printdebug_)
00074     edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss.str();
00075   
00076   obj->cleanUp();
00077   //obj->fillBadComponents();
00078 
00079   std::stringstream ss1;
00080   if (printdebug_){
00081     for (std::vector<SiStripQuality::BadComponent>::const_iterator iter=obj->getBadComponentList().begin();iter!=obj->getBadComponentList().end();++iter)
00082       ss1 << "bad module " << iter->detid << " " << iter->BadModule <<  "\n";
00083     edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss1.str();
00084   }
00085   std::auto_ptr<SiStripBadStrip> ptr( dynamic_cast<SiStripBadStrip*> (obj) );
00086   return ptr;
00087 }
00088 
00089 void SiStripQualityConfigurableFakeESSource::setIntervalFor( const edm::eventsetup::EventSetupRecordKey&,
00090                                                          const edm::IOVSyncValue& iov,
00091                                                          edm::ValidityInterval& iValidity){
00092   edm::ValidityInterval infinity( iov.beginOfTime(), iov.endOfTime() );
00093   iValidity = infinity;
00094 }
00095 
00096 
00097 void SiStripQualityConfigurableFakeESSource::selectDetectors(const std::vector<uint32_t>& DetIds, std::vector<uint32_t>& list){
00098 
00099   SiStripSubStructure siStripSubStructure;
00100   std::stringstream ss;
00101 
00102   for(Parameters::iterator iBadComponent = BadComponentList_.begin(); iBadComponent != BadComponentList_.end(); ++iBadComponent ) {
00103     
00104     if (printdebug_)
00105       ss << "Bad SubDet " << iBadComponent->getParameter<std::string>("SubDet") << " \t";
00106 
00107     SiStripDetId::SubDetector subDet=SiStripDetId::UNKNOWN;
00108     if (iBadComponent->getParameter<std::string>("SubDet")=="TIB")
00109       subDet=SiStripDetId::TIB;
00110     else if (iBadComponent->getParameter<std::string>("SubDet")=="TID")
00111       subDet=SiStripDetId::TID;
00112     else if (iBadComponent->getParameter<std::string>("SubDet")=="TOB")
00113       subDet=SiStripDetId::TOB;
00114     else if (iBadComponent->getParameter<std::string>("SubDet")=="TEC")
00115       subDet=SiStripDetId::TEC;
00116     
00117     uint32_t startDet=DetId(DetId::Tracker,subDet).rawId();
00118     uint32_t stopDet=DetId(DetId::Tracker,subDet+1).rawId();
00119     
00120     std::vector<uint32_t>::const_iterator iter=lower_bound(DetIds.begin(),DetIds.end(),startDet);
00121     std::vector<uint32_t>::const_iterator iterEnd=lower_bound(DetIds.begin(),DetIds.end(),stopDet);
00122 
00123     bool resp;
00124     for ( ;iter!=iterEnd;++iter){
00125 
00126       resp=false;
00127       if (iBadComponent->getParameter<std::string>("SubDet")=="TIB")
00128         resp=isTIBDetector(*iter,
00129                            iBadComponent->getParameter<uint32_t>("layer"),
00130                            iBadComponent->getParameter<uint32_t>("bkw_frw"),
00131                            iBadComponent->getParameter<uint32_t>("int_ext"),
00132                            iBadComponent->getParameter<uint32_t>("ster"),
00133                            iBadComponent->getParameter<uint32_t>("string_"),
00134                            iBadComponent->getParameter<uint32_t>("detid")
00135                            );
00136       else if (iBadComponent->getParameter<std::string>("SubDet")=="TID")
00137         resp=isTIDDetector(*iter,
00138                            iBadComponent->getParameter<uint32_t>("side"),
00139                            iBadComponent->getParameter<uint32_t>("wheel"),
00140                            iBadComponent->getParameter<uint32_t>("ring"),
00141                            iBadComponent->getParameter<uint32_t>("ster"),
00142                            iBadComponent->getParameter<uint32_t>("detid")
00143                            );
00144       else if (iBadComponent->getParameter<std::string>("SubDet")=="TOB")
00145         resp=isTOBDetector(*iter,
00146                            iBadComponent->getParameter<uint32_t>("layer"),
00147                            iBadComponent->getParameter<uint32_t>("bkw_frw"),
00148                            iBadComponent->getParameter<uint32_t>("rod"),
00149                            iBadComponent->getParameter<uint32_t>("ster"),
00150                            iBadComponent->getParameter<uint32_t>("detid")
00151                            );
00152       else if (iBadComponent->getParameter<std::string>("SubDet")=="TEC")
00153         resp=isTECDetector(*iter,
00154                            iBadComponent->getParameter<uint32_t>("side"),
00155                            iBadComponent->getParameter<uint32_t>("wheel"),
00156                            iBadComponent->getParameter<uint32_t>("petal_bkw_frw"),
00157                            iBadComponent->getParameter<uint32_t>("petal"),
00158                            iBadComponent->getParameter<uint32_t>("ring"),
00159                            iBadComponent->getParameter<uint32_t>("ster"),
00160                            iBadComponent->getParameter<uint32_t>("detid")
00161                            );
00162       
00163       if(resp)
00164         list.push_back(*iter);      
00165     }
00166   }
00167   if (printdebug_)
00168     edm::LogInfo("SiStripQualityConfigurableFakeESSource") << ss.str();
00169 }
00170 
00171 
00172 bool SiStripQualityConfigurableFakeESSource::isTIBDetector(const uint32_t & therawid,
00173                                                            uint32_t requested_layer,
00174                                                            uint32_t requested_bkw_frw,
00175                                                            uint32_t requested_int_ext,
00176                                                            uint32_t requested_string,
00177                                                            uint32_t requested_ster,
00178                                                            uint32_t requested_detid) const{
00179   TIBDetId potentialDet = TIBDetId(therawid); // build TIBDetId, at this point is just DetId, but do not want to cast twice
00180   if( potentialDet.subDetector() ==  SiStripDetId::TIB ){ // check if subdetector field is a TIB, both tested numbers are int
00181     if( // check if TIB is from the ones requested
00182        (    (potentialDet.layerNumber()==requested_layer) || requested_layer==0 )  // take everything if default value is 0
00183        &&
00184        ( (potentialDet.isZPlusSide() && requested_bkw_frw==2) || (!potentialDet.isZPlusSide() && requested_bkw_frw==1) || requested_bkw_frw==0)
00185        &&
00186        ( (potentialDet.isInternalString() && requested_int_ext==1) || (!potentialDet.isInternalString() && requested_int_ext==2) || requested_int_ext==0 )
00187        && 
00188        ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00189        && 
00190        ( (potentialDet.stringNumber()==requested_string) || requested_string==0 )
00191        &&
00192        ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00193        )
00194       return 1;
00195   }
00196   return 0;
00197 }
00198 
00199 bool SiStripQualityConfigurableFakeESSource::isTOBDetector(const uint32_t & therawid,
00200                                                            uint32_t requested_layer,
00201                                                            uint32_t requested_bkw_frw,
00202                                                            uint32_t requested_rod,
00203                                                            uint32_t requested_ster,
00204                                                            uint32_t requested_detid) const{
00205   TOBDetId potentialDet = TOBDetId(therawid); // build TOBDetId, at this point is just DetId, but do not want to cast twice
00206   if( potentialDet.subDetector() ==  SiStripDetId::TOB ){ // check if subdetector field is a TOB, both tested numbers are int
00207     if( // check if TOB is from the ones requested
00208        (    (potentialDet.layerNumber()==requested_layer) || requested_layer==0 )  // take everything if default value is 0
00209        &&
00210        ( (potentialDet.isZPlusSide() && requested_bkw_frw==2) || (!potentialDet.isZPlusSide() && requested_bkw_frw==1) || requested_bkw_frw==0)
00211        &&
00212        ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00213        && 
00214        ( (potentialDet.rodNumber()==requested_rod) || requested_rod==0 )
00215        &&
00216        ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )   
00217        )
00218       return 1;
00219   }
00220   return 0;
00221 }
00222 
00223 
00224 bool SiStripQualityConfigurableFakeESSource::isTIDDetector(const uint32_t & therawid,
00225                                                            uint32_t requested_side,
00226                                                            uint32_t requested_wheel,
00227                                                            uint32_t requested_ring,
00228                                                            uint32_t requested_ster,
00229                                                            uint32_t requested_detid) const{
00230   TIDDetId potentialDet = TIDDetId(therawid); // build TIDDetId, at this point is just DetId, but do not want to cast twice
00231   if( potentialDet.subDetector() ==  SiStripDetId::TID ){ // check if subdetector field is a TID, both tested numbers are int 
00232     if( // check if TID is from the ones requested 
00233      (    (potentialDet.diskNumber()==requested_wheel) || requested_wheel==0 )  // take everything if default value is 0 
00234      &&
00235      ( (potentialDet.isZPlusSide() && requested_side==2) || (!potentialDet.isZPlusSide() && requested_side==1) || requested_side==0)
00236      &&
00237      ( (potentialDet.isStereo() && requested_ster==1) || (potentialDet.isRPhi() && requested_ster==2) || requested_ster==0 )
00238      &&
00239      ( (potentialDet.ringNumber()==requested_ring) || requested_ring==0 )
00240      &&
00241      ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00242      )
00243      return 1;
00244      }
00245   return 0;
00246 }
00247   
00248 
00249 bool SiStripQualityConfigurableFakeESSource::isTECDetector(const uint32_t & therawid,
00250                                                            uint32_t requested_side,
00251                                                            uint32_t requested_wheel,
00252                                                            uint32_t requested_petal_bkw_frw,
00253                                                            uint32_t requested_petal,                    
00254                                                            uint32_t requested_ring,
00255                                                            uint32_t requested_ster,
00256                                                            uint32_t requested_detid) const{
00257   TECDetId potentialDet = TECDetId(therawid); // build TECDetId, at this point is just DetId, but do not want to cast twice
00258   if( potentialDet.subDetector() ==  SiStripDetId::TEC ){ // check if subdetector field is a TEC, both tested numbers are int 
00259     if( // check if TEC is from the ones requested 
00260        (    (potentialDet.wheelNumber()==requested_wheel) || requested_wheel==0 )  // take everything if default value is 0 
00261        &&
00262        ( (potentialDet.isZPlusSide() && requested_side==2) || (!potentialDet.isZPlusSide() && requested_side==1) || requested_side==0)
00263        &&
00264        ( (potentialDet.isStereo() && requested_ster==1) || (!potentialDet.isStereo() && requested_ster==2) || requested_ster==0 )
00265        &&
00266        ( (potentialDet.isFrontPetal() && requested_petal_bkw_frw==2) || (!potentialDet.isFrontPetal() && requested_petal_bkw_frw==2) || requested_petal_bkw_frw==0 )
00267        &&
00268        ( (potentialDet.petalNumber()==requested_petal) || requested_petal==0 )
00269        &&
00270        ( (potentialDet.ringNumber()==requested_ring) || requested_ring==0 )
00271        &&
00272        ( (potentialDet.rawId()==requested_detid) || requested_detid==0 )
00273        )
00274       return 1;
00275   }
00276   return 0;
00277 }
00278 

Generated on Tue Jun 9 17:25:50 2009 for CMSSW by  doxygen 1.5.4