CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondTools/SiStrip/plugins/SiStripDetVOffFakeBuilder.cc

Go to the documentation of this file.
00001 // system include files
00002 #include <memory>
00003 
00004 // user include files
00005 
00006 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00007 
00008 
00009 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
00010 
00011 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h" 
00012 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00013 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00014 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00015 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00016 
00017 
00018 #include "CondTools/SiStrip/plugins/SiStripDetVOffFakeBuilder.h"
00019 
00020 using namespace std;
00021 using namespace cms;
00022 
00023 SiStripDetVOffFakeBuilder::SiStripDetVOffFakeBuilder( const edm::ParameterSet& iConfig ):
00024   printdebug_(iConfig.getUntrackedParameter<bool>("printDebug",false)){}
00025 
00026 SiStripDetVOffFakeBuilder::~SiStripDetVOffFakeBuilder(){}
00027 
00028 
00029 void SiStripDetVOffFakeBuilder::initialize( const edm::EventSetup& iSetup ) {
00030 
00031   edm::ESHandle<TrackerGeometry> pDD;
00032   iSetup.get<TrackerDigiGeometryRecord>().get( pDD );
00033   edm::LogInfo("SiStripDetVOffFakeBuilder") <<" There are "<<pDD->detUnits().size() <<" detectors"<<std::endl;
00034   
00035   for(TrackerGeometry::DetUnitContainer::const_iterator it = pDD->detUnits().begin(); it != pDD->detUnits().end(); it++){
00036   
00037     if( dynamic_cast<StripGeomDetUnit*>((*it))!=0){
00038       uint32_t detid=((*it)->geographicalId()).rawId();            
00039       const StripTopology& p = dynamic_cast<StripGeomDetUnit*>((*it))->specificTopology();
00040       unsigned short Nstrips = p.nstrips();
00041       if(Nstrips<1 || Nstrips>768 ) {
00042         edm::LogError("SiStripDetVOffFakeBuilder")<<" Problem with Number of strips in detector.. "<< p.nstrips() <<" Exiting program"<<endl;
00043         exit(1);
00044       }
00045       detids.push_back(detid);
00046       if (printdebug_)
00047         edm::LogInfo("SiStripDetVOffFakeBuilder")<< "detid " << detid;
00048     }
00049   }
00050 }
00051 
00052 void SiStripDetVOffFakeBuilder::analyze(const edm::Event& evt, const edm::EventSetup& iSetup)
00053 {
00054   initialize(iSetup);
00055 
00056   unsigned int run=evt.id().run();
00057 
00058   edm::LogInfo("SiStripDetVOffFakeBuilder") << "... creating dummy SiStripDetVOff Data for Run " << run << "\n " << std::endl;
00059 
00060 
00061 
00062   SiStripDetVOff* SiStripDetVOff_ = new SiStripDetVOff();
00063 
00064    // std::vector<uint32_t> TheDetIdHVVector;
00065 
00066     for(std::vector<uint32_t>::const_iterator it = detids.begin(); it != detids.end(); it++){
00067 
00068     //Generate HV and LV for each channel, if at least one of the two is off fill the value
00069     int hv=rand() % 20;
00070     int lv=rand() % 20;
00071     if( hv<=2 ) {
00072       edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " <<  *it << " HV\t OFF" << std::endl;
00073       SiStripDetVOff_->put( *it, 1, -1 );
00074       // TheDetIdHVVector.push_back(*it);
00075     }
00076     if( lv<=2 ) {
00077       edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " <<  *it << " LV\t OFF" << std::endl;
00078       SiStripDetVOff_->put( *it, -1, 1 );
00079       // TheDetIdHVVector.push_back(*it);
00080     }
00081     if( lv<=2 || hv<=2 ) edm::LogInfo("SiStripDetVOffFakeBuilder") << "detid: " <<  *it << " V\t OFF" << std::endl;
00082   }
00083 
00084   // SiStripDetVOff_->put(TheDetIdHVVector);
00085 
00086 
00087 
00088   //End now write DetVOff data in DB
00089   edm::Service<cond::service::PoolDBOutputService> mydbservice;
00090   
00091   if( mydbservice.isAvailable() ){
00092     try{
00093       if( mydbservice->isNewTagRequest("SiStripDetVOffRcd") ){
00094         mydbservice->createNewIOV<SiStripDetVOff>(SiStripDetVOff_,mydbservice->beginOfTime(),mydbservice->endOfTime(),"SiStripDetVOffRcd");      
00095       } else {
00096         mydbservice->appendSinceTime<SiStripDetVOff>(SiStripDetVOff_,mydbservice->currentTime(),"SiStripDetVOffRcd");      
00097       }
00098     }catch(const cond::Exception& er){
00099       edm::LogError("SiStripDetVOffFakeBuilder")<<er.what()<<std::endl;
00100     }catch(const std::exception& er){
00101       edm::LogError("SiStripDetVOffFakeBuilder")<<"caught std::exception "<<er.what()<<std::endl;
00102     }catch(...){
00103       edm::LogError("SiStripDetVOffFakeBuilder")<<"Funny error"<<std::endl;
00104     }
00105   }else{
00106     edm::LogError("SiStripDetVOffFakeBuilder")<<"Service is unavailable"<<std::endl;
00107   }
00108 }