CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/Calibration/TkAlCaRecoProducers/plugins/AlcaBeamSpotHarvester.cc

Go to the documentation of this file.
00001 
00002 /*
00003  *  See header file for a description of this class.
00004  *
00005  *  $Date: 2011/02/16 12:40:30 $
00006  *  $Revision: 1.10 $
00007  *  \author L. Uplegger F. Yumiceva - Fermilab
00008  */
00009 
00010 #include "Calibration/TkAlCaRecoProducers/interface/AlcaBeamSpotHarvester.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/Run.h"
00013 #include "FWCore/Framework/interface/LuminosityBlock.h"
00014 #include "FWCore/Framework/interface/FileBlock.h"
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "DataFormats/Common/interface/Handle.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 #include "FWCore/Framework/interface/MakerMacros.h"
00019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 
00022 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00023 
00024 #include "CondFormats/BeamSpotObjects/interface/BeamSpotObjects.h"
00025 #include "FWCore/ServiceRegistry/interface/Service.h"
00026 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00027 //#include "CondCore/Utilities/bin/cmscond_export_iov.cpp"
00028 //#include "CondCore/Utilities/interface/Utilities.h"
00029 // #include "FWCore/MessageLogger/interface/JobReport.h"
00030 
00031 #include <iostream> 
00032 
00033 using namespace edm;
00034 using namespace reco;
00035 //using namespace std;
00036 
00037 //--------------------------------------------------------------------------------------------------
00038 AlcaBeamSpotHarvester::AlcaBeamSpotHarvester(const edm::ParameterSet& iConfig) :
00039   beamSpotOutputBase_    (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("BeamSpotOutputBase")),
00040   outputrecordName_      (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
00041   sigmaZValue_           (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>("SigmaZValue")),
00042   theAlcaBeamSpotManager_(iConfig) {  
00043 }
00044 
00045 //--------------------------------------------------------------------------------------------------
00046 AlcaBeamSpotHarvester::~AlcaBeamSpotHarvester(){}
00047 
00048 //--------------------------------------------------------------------------------------------------
00049 void AlcaBeamSpotHarvester::beginJob() {}
00050 
00051 //--------------------------------------------------------------------------------------------------
00052 void AlcaBeamSpotHarvester::endJob() {}  
00053 
00054 //--------------------------------------------------------------------------------------------------
00055 void AlcaBeamSpotHarvester::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
00056 //  edm::LogInfo("AlcaBeamSpotHarvester")
00057 //      << "Lumi: " << iEvent.luminosityBlock() 
00058 //      << " Time: " << iEvent.time().unixTime() 
00059 //      << std::endl;
00060 }
00061 
00062 //--------------------------------------------------------------------------------------------------
00063 void AlcaBeamSpotHarvester::beginRun(const edm::Run&, const edm::EventSetup&){
00064   theAlcaBeamSpotManager_.reset();
00065 }
00066 
00067 //--------------------------------------------------------------------------------------------------
00068 void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&){
00069   theAlcaBeamSpotManager_.createWeightedPayloads();
00070   std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
00071   Service<cond::service::PoolDBOutputService> poolDbService;
00072 //  cond::ExportIOVUtilities utilities;
00073   if(poolDbService.isAvailable() ) {
00074     for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
00075       BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
00076       aBeamSpot->SetType(it->second.type());
00077       aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
00078       if(sigmaZValue_ == -1){
00079         aBeamSpot->SetSigmaZ(it->second.sigmaZ());
00080       }
00081       else{
00082         aBeamSpot->SetSigmaZ(sigmaZValue_);
00083       }
00084       aBeamSpot->Setdxdz(it->second.dxdz());
00085       aBeamSpot->Setdydz(it->second.dydz());
00086       aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
00087       aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
00088       aBeamSpot->SetEmittanceX(it->second.emittanceX());
00089       aBeamSpot->SetEmittanceY(it->second.emittanceY());
00090       aBeamSpot->SetBetaStar(it->second.betaStar() );
00091         
00092       for (int i=0; i<7; ++i) {
00093         for (int j=0; j<7; ++j) {
00094           aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
00095         }
00096       }
00097 
00098       if(sigmaZValue_ > 0){
00099         aBeamSpot->SetCovariance(3,3,0.000025);
00100       }
00101 
00102       cond::Time_t thisIOV = 1;
00103 
00104 
00105 
00106       // run based      
00107       if (beamSpotOutputBase_ == "runbased" ) {
00108         thisIOV = (cond::Time_t) iRun.id().run();
00109       }
00110       // lumi based
00111       else if (beamSpotOutputBase_ == "lumibased" ) {
00112         edm::LuminosityBlockID lu(iRun.id().run(),it->first);
00113         thisIOV = (cond::Time_t)(lu.value()); 
00114       }
00115       if (poolDbService->isNewTagRequest(outputrecordName_) ) {
00116           edm::LogInfo("AlcaBeamSpotHarvester")
00117               << "new tag requested" << std::endl;
00118           //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
00119           
00120           //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(), poolDbService->endOfTime(),"BeamSpotObjectsRcd");
00121           poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00122       } 
00123       else {
00124         edm::LogInfo("AlcaBeamSpotHarvester")
00125             << "no new tag requested, appending IOV" << std::endl;
00126         //poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(),"BeamSpotObjectsRcd");
00127         poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00128       }
00129 
00130 
00131 
00132 
00133 /*
00134       int         argc = 15;
00135       const char* argv[] = {"endRun"
00136                            ,"-d","sqlite_file:combined.db"
00137                            ,"-s","sqlite_file:testbs2.db"
00138                            ,"-l","sqlite_file:log.db"
00139                            ,"-i","TestLSBasedBS"
00140                            ,"-t","TestLSBasedBS"
00141                            ,"-b","1"
00142                            ,"-e","10"
00143                            };
00144       
00145       edm::LogInfo("AlcaBeamSpotHarvester")
00146         << "Running utilities!" 
00147         << utilities.run(argc,(char**)argv);
00148       edm::LogInfo("AlcaBeamSpotHarvester")
00149         << "Run utilities!" 
00150         << std::endl;
00151 */
00152     }
00153 
00154 
00155 
00156 
00157   }
00158 }
00159 
00160 //--------------------------------------------------------------------------------------------------
00161 void AlcaBeamSpotHarvester::beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) {}
00162 
00163 //--------------------------------------------------------------------------------------------------
00164 void AlcaBeamSpotHarvester::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup&) {
00165   theAlcaBeamSpotManager_.readLumi(iLumi);
00166 }
00167 
00168 
00169 DEFINE_FWK_MODULE(AlcaBeamSpotHarvester);