CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
AlcaBeamSpotHarvester.cc
Go to the documentation of this file.
1 
2 /*
3  * See header file for a description of this class.
4  *
5  * \author L. Uplegger F. Yumiceva - Fermilab
6  */
7 
20 
22 
26 //#include "CondCore/Utilities/bin/cmscond_export_iov.cpp"
27 //#include "CondCore/Utilities/interface/Utilities.h"
28 // #include "FWCore/MessageLogger/interface/JobReport.h"
29 
30 #include <iostream>
31 
32 using namespace edm;
33 using namespace reco;
34 //using namespace std;
35 
36 //--------------------------------------------------------------------------------------------------
38  beamSpotOutputBase_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("BeamSpotOutputBase")),
39  outputrecordName_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
40  sigmaZValue_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>("SigmaZValue")),
41  theAlcaBeamSpotManager_(iConfig, consumesCollector()) {
42 }
43 
44 //--------------------------------------------------------------------------------------------------
46 
47 //--------------------------------------------------------------------------------------------------
49 
50 //--------------------------------------------------------------------------------------------------
52 
53 //--------------------------------------------------------------------------------------------------
55 // edm::LogInfo("AlcaBeamSpotHarvester")
56 // << "Lumi: " << iEvent.luminosityBlock()
57 // << " Time: " << iEvent.time().unixTime()
58 // << std::endl;
59 }
60 
61 //--------------------------------------------------------------------------------------------------
64 }
65 
66 //--------------------------------------------------------------------------------------------------
69  std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
71 // cond::ExportIOVUtilities utilities;
72  if(poolDbService.isAvailable() ) {
73  for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
74  BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
75  aBeamSpot->SetType(it->second.type());
76  aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
77  if(sigmaZValue_ == -1){
78  aBeamSpot->SetSigmaZ(it->second.sigmaZ());
79  }
80  else{
81  aBeamSpot->SetSigmaZ(sigmaZValue_);
82  }
83  aBeamSpot->Setdxdz(it->second.dxdz());
84  aBeamSpot->Setdydz(it->second.dydz());
85  aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
86  aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
87  aBeamSpot->SetEmittanceX(it->second.emittanceX());
88  aBeamSpot->SetEmittanceY(it->second.emittanceY());
89  aBeamSpot->SetBetaStar(it->second.betaStar() );
90 
91  for (int i=0; i<7; ++i) {
92  for (int j=0; j<7; ++j) {
93  aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
94  }
95  }
96 
97  if(sigmaZValue_ > 0){
98  aBeamSpot->SetCovariance(3,3,0.000025);
99  }
100 
101  cond::Time_t thisIOV = 1;
102 
103 
104 
105  // run based
106  if (beamSpotOutputBase_ == "runbased" ) {
107  thisIOV = (cond::Time_t) iRun.id().run();
108  }
109  // lumi based
110  else if (beamSpotOutputBase_ == "lumibased" ) {
111  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
112  thisIOV = (cond::Time_t)(lu.value());
113  }
114  if (poolDbService->isNewTagRequest(outputrecordName_) ) {
115  edm::LogInfo("AlcaBeamSpotHarvester")
116  << "new tag requested" << std::endl;
117  //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
118 
119  //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(), poolDbService->endOfTime(),"BeamSpotObjectsRcd");
120  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
121  }
122  else {
123  edm::LogInfo("AlcaBeamSpotHarvester")
124  << "no new tag requested, appending IOV" << std::endl;
125  //poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(),"BeamSpotObjectsRcd");
126  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
127  }
128 
129 
130 
131 
132 /*
133  int argc = 15;
134  const char* argv[] = {"endRun"
135  ,"-d","sqlite_file:combined.db"
136  ,"-s","sqlite_file:testbs2.db"
137  ,"-l","sqlite_file:log.db"
138  ,"-i","TestLSBasedBS"
139  ,"-t","TestLSBasedBS"
140  ,"-b","1"
141  ,"-e","10"
142  };
143 
144  edm::LogInfo("AlcaBeamSpotHarvester")
145  << "Running utilities!"
146  << utilities.run(argc,(char**)argv);
147  edm::LogInfo("AlcaBeamSpotHarvester")
148  << "Run utilities!"
149  << std::endl;
150 */
151  }
152 
153 
154 
155 
156  }
157 }
158 
159 //--------------------------------------------------------------------------------------------------
161 
162 //--------------------------------------------------------------------------------------------------
165 }
166 
167 
int i
Definition: DBlmapReader.cc:9
RunID const & id() const
Definition: RunBase.h:41
RunNumber_t run() const
Definition: RunID.h:39
virtual void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
std::map< edm::LuminosityBlockNumber_t, reco::BeamSpot >::iterator bsMap_iterator
void SetCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
void Setdydz(double val)
set dydz slope, crossing angle in XZ
virtual void beginJob(void)
AlcaBeamSpotHarvester(const edm::ParameterSet &)
Constructor.
const std::map< edm::LuminosityBlockNumber_t, reco::BeamSpot > & getPayloads(void)
int iEvent
Definition: GenABIO.cc:230
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
void SetEmittanceX(double val)
set emittance
bool isAvailable() const
Definition: Service.h:46
int j
Definition: DBlmapReader.cc:9
virtual void endRun(const edm::Run &, const edm::EventSetup &)
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void Setdxdz(double val)
set dxdz slope, crossing angle
void SetBetaStar(double val)
set beta star
virtual void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &)
void readLumi(const edm::LuminosityBlock &)
void SetType(int type)
set beam type
virtual ~AlcaBeamSpotHarvester()
Destructor.
void SetEmittanceY(double val)
set emittance
void SetBeamWidthX(double val)
set average transverse beam width X
void SetBeamWidthY(double val)
set average transverse beam width Y
AlcaBeamSpotManager theAlcaBeamSpotManager_
Definition: Run.h:41
virtual void analyze(const edm::Event &, const edm::EventSetup &)
void SetPosition(double x, double y, double z)
set XYZ position