CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CalibTracker/SiPixelLorentzAngle/src/SiPixelLorentzAngleDB.cc

Go to the documentation of this file.
00001 #include <memory>
00002 #include <string>
00003 #include <iostream>
00004 #include <fstream>
00005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00006 #include "CalibTracker/SiPixelLorentzAngle/interface/SiPixelLorentzAngleDB.h"
00007 #include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00010 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00011 #include "FWCore/ServiceRegistry/interface/Service.h"
00012 
00013 
00014 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementPoint.h"
00015 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
00016 #include "DataFormats/GeometrySurface/interface/GloballyPositioned.h"
00017 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00018 
00019 using namespace std;
00020 using namespace edm;
00021 
00022   //Constructor
00023 
00024 SiPixelLorentzAngleDB::SiPixelLorentzAngleDB(edm::ParameterSet const& conf) : 
00025   conf_(conf){
00026         magneticField_ = conf_.getParameter<double>("magneticField");
00027         recordName_ = conf_.getUntrackedParameter<std::string>("record","SiPixelLorentzAngleRcd");
00028         bPixLorentzAnglePerTesla_ = (float)conf_.getParameter<double>("bPixLorentzAnglePerTesla");
00029         fPixLorentzAnglePerTesla_ = (float)conf_.getParameter<double>("fPixLorentzAnglePerTesla");
00030         useFile_ = conf_.getParameter<bool>("useFile");         
00031         fileName_ = conf_.getParameter<string>("fileName");
00032 
00033 }
00034 
00035   //BeginJob
00036 
00037 void SiPixelLorentzAngleDB::beginJob(){
00038   
00039 }
00040 // Virtual destructor needed.
00041 
00042 SiPixelLorentzAngleDB::~SiPixelLorentzAngleDB() {  
00043 
00044 }  
00045 
00046 // Analyzer: Functions that gets called by framework every event
00047 
00048 void SiPixelLorentzAngleDB::analyze(const edm::Event& e, const edm::EventSetup& es)
00049 {
00050 
00051         SiPixelLorentzAngle* LorentzAngle = new SiPixelLorentzAngle();
00052            
00053         
00054         edm::ESHandle<TrackerGeometry> pDD;
00055         es.get<TrackerDigiGeometryRecord>().get( pDD );
00056         edm::LogInfo("SiPixelLorentzAngle") <<" There are "<<pDD->detUnits().size() <<" detectors"<<std::endl;
00057         
00058         for(TrackerGeometry::DetUnitContainer::const_iterator it = pDD->detUnits().begin(); it != pDD->detUnits().end(); it++){
00059     
00060                 if( dynamic_cast<PixelGeomDetUnit*>((*it))!=0){
00061                         DetId detid=(*it)->geographicalId();
00062                         
00063                         // fill bpix values for LA 
00064                         if(detid.subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel)) {
00065                                 
00066                                 if(!useFile_){
00067                                         if ( ! LorentzAngle->putLorentzAngle(detid.rawId(),bPixLorentzAnglePerTesla_) )
00068                                         edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] detid already exists"<<std::endl;
00069                                 } else {
00070                                         cout << "method for reading file not implemented yet" << endl;
00071                                 }
00072                                 
00073                         
00074                         // fill bpix values for LA 
00075                         } else if(detid.subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap)) {
00076                                 
00077                                 if ( ! LorentzAngle->putLorentzAngle(detid.rawId(),fPixLorentzAnglePerTesla_) )
00078                                         edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] detid already exists"<<std::endl;
00079                         } else {
00080                                 edm::LogError("SiPixelLorentzAngleDB")<<"[SiPixelLorentzAngleDB::analyze] detid is Pixel but neither bpix nor fpix"<<std::endl;
00081                         }
00082                 
00083                 }
00084                         
00085         }      
00086         
00087 
00088         edm::Service<cond::service::PoolDBOutputService> mydbservice;
00089         if( mydbservice.isAvailable() ){
00090                 try{
00091                         if( mydbservice->isNewTagRequest(recordName_) ){
00092                                 mydbservice->createNewIOV<SiPixelLorentzAngle>(LorentzAngle,
00093                                                                                mydbservice->beginOfTime(),
00094                                                                                mydbservice->endOfTime(),
00095                                                                                recordName_);
00096                         } else {
00097                                 mydbservice->appendSinceTime<SiPixelLorentzAngle>(LorentzAngle,
00098                                                                                   mydbservice->currentTime(),
00099                                                                                   recordName_);
00100                         }
00101                 }catch(const cond::Exception& er){
00102                         edm::LogError("SiPixelLorentzAngleDB")<<er.what()<<std::endl;
00103                 }catch(const std::exception& er){
00104                         edm::LogError("SiPixelLorentzAngleDB")<<"caught std::exception "<<er.what()<<std::endl;
00105                 }catch(...){
00106                         edm::LogError("SiPixelLorentzAngleDB")<<"Funny error"<<std::endl;
00107                 }
00108         }else{
00109                 edm::LogError("SiPixelLorentzAngleDB")<<"Service is unavailable"<<std::endl;
00110         }
00111    
00112 
00113 }
00114 
00115 void SiPixelLorentzAngleDB::endJob(){
00116 
00117 
00118 }