CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/CondTools/SiStrip/plugins/SiStripBadChannelBuilder.cc

Go to the documentation of this file.
00001 #include "CondTools/SiStrip/plugins/SiStripBadChannelBuilder.h"
00002 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00003 
00004 #include <iostream>
00005 #include <fstream>
00006 
00007 
00008 SiStripBadChannelBuilder::SiStripBadChannelBuilder(const edm::ParameterSet& iConfig) : ConditionDBWriter<SiStripBadStrip>(iConfig){
00009 
00010   fp_ = iConfig.getUntrackedParameter<edm::FileInPath>("file",edm::FileInPath("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat"));
00011   printdebug_ = iConfig.getUntrackedParameter<bool>("printDebug",false);
00012   BadComponentList_ =  iConfig.getUntrackedParameter<Parameters>("BadComponentList");
00013 }
00014 
00015 
00016 SiStripBadChannelBuilder::~SiStripBadChannelBuilder(){
00017 }
00018 
00019 void SiStripBadChannelBuilder::algoAnalyze(const edm::Event & event, const edm::EventSetup& iSetup){
00020   
00021   unsigned int run=event.id().run();
00022 
00023   edm::LogInfo("SiStripBadChannelBuilder") << "... creating dummy SiStripBadStrip Data for Run " << run << "\n " << std::endl;
00024   
00025   SiStripBadStrip* obj = new SiStripBadStrip();
00026 
00027   SiStripDetInfoFileReader reader(fp_.fullPath());
00028   
00029   const std::vector<uint32_t> DetIds = reader.getAllDetIds();
00030   
00031   for(Parameters::iterator iBadComponent = BadComponentList_.begin(); iBadComponent != BadComponentList_.end(); ++iBadComponent ) {
00032     
00033     uint32_t BadModule_ = iBadComponent->getParameter<uint32_t>("BadModule");
00034     std::vector<uint32_t> BadChannelList_ = iBadComponent->getParameter<std::vector<uint32_t> >("BadChannelList");
00035 
00036     std::vector<unsigned int> theSiStripVector;
00037     unsigned int NStrips=reader.getNumberOfApvsAndStripLength(BadModule_).first*128;   
00038     
00039     uint32_t lastBad=999;
00040     unsigned short firstBadStrip=0, NconsecutiveBadStrips=0;
00041     unsigned int theBadStripRange;
00042 
00043     for(std::vector<uint32_t>::const_iterator is=BadChannelList_.begin(); is!=BadChannelList_.end(); ++is){
00044       if (*is>NStrips-1)
00045         break;
00046       if (*is!=lastBad+1){
00047         //new set 
00048 
00049         if ( lastBad!=999 ){
00050           //save previous set
00051           theBadStripRange = obj->encode(firstBadStrip,NconsecutiveBadStrips);
00052 
00053           if (printdebug_)
00054             edm::LogInfo("SiStripBadChannelBuilder") << "detid " << BadModule_ << " \t"
00055                                                    << " firstBadStrip " << firstBadStrip << "\t "
00056                                                    << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
00057                                                    << " packed integer " << std::hex << theBadStripRange  << std::dec
00058                                                    << std::endl;            
00059           
00060           theSiStripVector.push_back(theBadStripRange);
00061         }
00062         
00063         firstBadStrip=*is;
00064         NconsecutiveBadStrips=0;
00065       }         
00066       NconsecutiveBadStrips++;
00067       lastBad=*is;
00068     }
00069 
00070     theBadStripRange = obj->encode(firstBadStrip,NconsecutiveBadStrips);
00071     if (printdebug_)
00072       edm::LogInfo("SiStripBadChannelBuilder") << "detid " << BadModule_ << " \t"
00073                                              << " firstBadStrip " << firstBadStrip << "\t "
00074                                              << " NconsecutiveBadStrips " << NconsecutiveBadStrips << "\t "
00075                                              << " packed integer " << std::hex << theBadStripRange  << std::dec
00076                                              << std::endl;          
00077           
00078     theSiStripVector.push_back(theBadStripRange);
00079         
00080     SiStripBadStrip::Range range(theSiStripVector.begin(),theSiStripVector.end());
00081     if ( ! obj->put(BadModule_,range) )
00082     edm::LogError("SiStripBadChannelBuilder")<<"[SiStripBadChannelBuilder::analyze] detid already exists"<<std::endl;
00083   }
00084  //End now write sistripbadChannel data in DB
00085   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00086 
00087   if( mydbservice.isAvailable() ){
00088     if ( mydbservice->isNewTagRequest("SiStripBadStripRcd") ){
00089       mydbservice->createNewIOV<SiStripBadStrip>(obj,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripBadStripRcd");
00090     } else {
00091       //mydbservice->createNewIOV<SiStripBadStrip>(obj,mydbservice->currentTime(),"SiStripBadStripRcd");
00092       mydbservice->appendSinceTime<SiStripBadStrip>(obj,mydbservice->currentTime(),"SiStripBadStripRcd");
00093     }
00094   }else{
00095     edm::LogError("SiStripBadStripBuilder")<<"Service is unavailable"<<std::endl;
00096   }
00097 
00098 }
00099 
00100