CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/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/03/17 11:22:14 $
00006  *  $Revision: 1.9.2.1 $
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   metadataForOfflineDropBox_(iConfig.getParameter<ParameterSet>("metadataOfflineDropBox"))
00044 {  
00045 }
00046 
00047 //--------------------------------------------------------------------------------------------------
00048 AlcaBeamSpotHarvester::~AlcaBeamSpotHarvester(){}
00049 
00050 //--------------------------------------------------------------------------------------------------
00051 void AlcaBeamSpotHarvester::beginJob() {}
00052 
00053 //--------------------------------------------------------------------------------------------------
00054 void AlcaBeamSpotHarvester::endJob() {}  
00055 
00056 //--------------------------------------------------------------------------------------------------
00057 void AlcaBeamSpotHarvester::analyze(const edm::Event& iEvent, const edm::EventSetup&) {
00058 //  edm::LogInfo("AlcaBeamSpotHarvester")
00059 //      << "Lumi: " << iEvent.luminosityBlock() 
00060 //      << " Time: " << iEvent.time().unixTime() 
00061 //      << std::endl;
00062 }
00063 
00064 //--------------------------------------------------------------------------------------------------
00065 void AlcaBeamSpotHarvester::beginRun(const edm::Run&, const edm::EventSetup&){
00066   theAlcaBeamSpotManager_.reset();
00067 }
00068 
00069 //--------------------------------------------------------------------------------------------------
00070 void AlcaBeamSpotHarvester::endRun(const edm::Run& iRun, const edm::EventSetup&){
00071   theAlcaBeamSpotManager_.createWeightedPayloads();
00072   std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
00073   Service<cond::service::PoolDBOutputService> poolDbService;
00074 //  cond::ExportIOVUtilities utilities;
00075   if(poolDbService.isAvailable() ) {
00076     for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
00077       BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
00078       aBeamSpot->SetType(it->second.type());
00079       aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
00080       if(sigmaZValue_ == -1){
00081         aBeamSpot->SetSigmaZ(it->second.sigmaZ());
00082       }
00083       else{
00084         aBeamSpot->SetSigmaZ(sigmaZValue_);
00085       }
00086       aBeamSpot->Setdxdz(it->second.dxdz());
00087       aBeamSpot->Setdydz(it->second.dydz());
00088       aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
00089       aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
00090       aBeamSpot->SetEmittanceX(it->second.emittanceX());
00091       aBeamSpot->SetEmittanceY(it->second.emittanceY());
00092       aBeamSpot->SetBetaStar(it->second.betaStar() );
00093         
00094       for (int i=0; i<7; ++i) {
00095         for (int j=0; j<7; ++j) {
00096           aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
00097         }
00098       }
00099 
00100       if(sigmaZValue_ > 0){
00101         aBeamSpot->SetCovariance(3,3,0.000025);
00102       }
00103 
00104       cond::Time_t thisIOV = 1;
00105 
00106 
00107 
00108       // run based      
00109       if (beamSpotOutputBase_ == "runbased" ) {
00110         thisIOV = (cond::Time_t) iRun.id().run();
00111       }
00112       // lumi based
00113       else if (beamSpotOutputBase_ == "lumibased" ) {
00114         edm::LuminosityBlockID lu(iRun.id().run(),it->first);
00115         thisIOV = (cond::Time_t)(lu.value()); 
00116       }
00117       if (poolDbService->isNewTagRequest(outputrecordName_) ) {
00118           edm::LogInfo("AlcaBeamSpotHarvester")
00119               << "new tag requested" << std::endl;
00120           //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
00121           
00122           //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(), poolDbService->endOfTime(),"BeamSpotObjectsRcd");
00123           poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00124       } 
00125       else {
00126         edm::LogInfo("AlcaBeamSpotHarvester")
00127             << "no new tag requested, appending IOV" << std::endl;
00128         //poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(),"BeamSpotObjectsRcd");
00129         poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
00130       }
00131 
00132 
00133 
00134 
00135 /*
00136       int         argc = 15;
00137       const char* argv[] = {"endRun"
00138                            ,"-d","sqlite_file:combined.db"
00139                            ,"-s","sqlite_file:testbs2.db"
00140                            ,"-l","sqlite_file:log.db"
00141                            ,"-i","TestLSBasedBS"
00142                            ,"-t","TestLSBasedBS"
00143                            ,"-b","1"
00144                            ,"-e","10"
00145                            };
00146       
00147       edm::LogInfo("AlcaBeamSpotHarvester")
00148         << "Running utilities!" 
00149         << utilities.run(argc,(char**)argv);
00150       edm::LogInfo("AlcaBeamSpotHarvester")
00151         << "Run utilities!" 
00152         << std::endl;
00153 */
00154     }
00155 
00156 
00157 
00158     edm::Service<edm::JobReport> jr;
00159     if (jr.isAvailable()) {
00160       std::map<std::string, std::string> jrInfo;
00161       jrInfo["Source"] = "AlcaHarvesting";
00162       jrInfo["FileClass"] = "ALCA";
00163 
00164 
00165       jrInfo["inputtag"] = poolDbService->tag(outputrecordName_);
00166       if(beamSpotOutputBase_ == "runbased") {
00167         jrInfo["Timetype"] = "runnumber";
00168       } else if(beamSpotOutputBase_ == "lumibased") {
00169         jrInfo["Timetype"] = "lumiid";
00170       }
00171       std::vector<std::string> paramKeys = metadataForOfflineDropBox_.getParameterNames();
00172       for(std::vector<std::string>::const_iterator key = paramKeys.begin();
00173           key != paramKeys.end();
00174           ++key) {
00175         jrInfo[*key] = metadataForOfflineDropBox_.getUntrackedParameter<std::string>(*key);
00176       }
00177       std::string filename = poolDbService->session().connectionString();
00178       jr->reportAnalysisFile(filename, jrInfo);
00179     }
00180 
00181 
00182   }
00183 }
00184 
00185 //--------------------------------------------------------------------------------------------------
00186 void AlcaBeamSpotHarvester::beginLuminosityBlock(const edm::LuminosityBlock&, const edm::EventSetup&) {}
00187 
00188 //--------------------------------------------------------------------------------------------------
00189 void AlcaBeamSpotHarvester::endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup&) {
00190   theAlcaBeamSpotManager_.readLumi(iLumi);
00191 }
00192 
00193 
00194 DEFINE_FWK_MODULE(AlcaBeamSpotHarvester);