CMS 3D CMS Logo

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  sigmaZCut_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<double>("SigmaZCut")),
42  dumpTxt_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<bool>("DumpTxt")),
43  outTxtFileName_ (iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<std::string>("TxtFileName")),
44  theAlcaBeamSpotManager_(iConfig, consumesCollector()) {
45 }
46 
47 //--------------------------------------------------------------------------------------------------
49 
50 //--------------------------------------------------------------------------------------------------
52 
53 //--------------------------------------------------------------------------------------------------
55 
56 //--------------------------------------------------------------------------------------------------
58 // edm::LogInfo("AlcaBeamSpotHarvester")
59 // << "Lumi: " << iEvent.luminosityBlock()
60 // << " Time: " << iEvent.time().unixTime()
61 // << std::endl;
62 }
63 
64 //--------------------------------------------------------------------------------------------------
67 }
68 
69 //--------------------------------------------------------------------------------------------------
72  std::map<edm::LuminosityBlockNumber_t,reco::BeamSpot> beamSpotMap = theAlcaBeamSpotManager_.getPayloads();
74 // cond::ExportIOVUtilities utilities;
75 
76  std::string outTxt = Form("%s_Run%d.txt", outTxtFileName_.c_str(), iRun.id().run());
77  std::ofstream outFile;
78  outFile.open(outTxt.c_str());
79 
80  if(poolDbService.isAvailable() ) {
81  for(AlcaBeamSpotManager::bsMap_iterator it=beamSpotMap.begin(); it!=beamSpotMap.end();it++){
82  BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
83  aBeamSpot->SetType(it->second.type());
84  aBeamSpot->SetPosition(it->second.x0(),it->second.y0(),it->second.z0());
85  if(sigmaZValue_ == -1){
86  aBeamSpot->SetSigmaZ(it->second.sigmaZ());
87  }
88  else{
89  aBeamSpot->SetSigmaZ(sigmaZValue_);
90  }
91  aBeamSpot->Setdxdz(it->second.dxdz());
92  aBeamSpot->Setdydz(it->second.dydz());
93  aBeamSpot->SetBeamWidthX(it->second.BeamWidthX());
94  aBeamSpot->SetBeamWidthY(it->second.BeamWidthY());
95  aBeamSpot->SetEmittanceX(it->second.emittanceX());
96  aBeamSpot->SetEmittanceY(it->second.emittanceY());
97  aBeamSpot->SetBetaStar(it->second.betaStar() );
98 
99  for (int i=0; i<7; ++i) {
100  for (int j=0; j<7; ++j) {
101  aBeamSpot->SetCovariance(i,j,it->second.covariance(i,j));
102  }
103  }
104 
105  if(sigmaZValue_ > 0){
106  aBeamSpot->SetCovariance(3,3,0.000025);
107  }
108 
109  cond::Time_t thisIOV = 1;
110 
111  beamspot::BeamSpotContainer currentBS;
112 
113 
114  // run based
115  if (beamSpotOutputBase_ == "runbased" ) {
116  thisIOV = (cond::Time_t) iRun.id().run();
117  }
118  // lumi based
119  else if (beamSpotOutputBase_ == "lumibased" ) {
120  edm::LuminosityBlockID lu(iRun.id().run(),it->first);
121  thisIOV = (cond::Time_t)(lu.value());
122 
123  currentBS.beamspot = it -> second ;
124  currentBS.run = iRun.id().run() ;
125  currentBS.beginLumiOfFit = it->first;
126  currentBS.endLumiOfFit = it->first;// to fix, for now endLumi = initLumi
127 
128  std::time_t lumi_t_begin = thisIOV; // to fix: meaningless value
129  std::time_t lumi_t_end = thisIOV; // to fix: meaningless value
130  char ts[] = "yyyy.mn.dd hh:mm:ss zzz ";
131  char* fbeginTime = ts;
132  strftime(fbeginTime, sizeof(ts), "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_begin));
133  std::copy(fbeginTime, fbeginTime+32, currentBS.beginTimeOfFit);
134 
135  char* fendTime = ts;
136  strftime(fendTime, sizeof(ts), "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));
137  std::copy(fendTime, fendTime+32, currentBS.endTimeOfFit);
138 
139  currentBS.reftime[0] = lumi_t_begin;
140  currentBS.reftime[1] = lumi_t_end;
141 
142  }
143  if (poolDbService->isNewTagRequest(outputrecordName_) ) {
144  edm::LogInfo("AlcaBeamSpotHarvester")
145  << "new tag requested" << std::endl;
146  //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
147 
148  //poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(), poolDbService->endOfTime(),"BeamSpotObjectsRcd");
149  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
150  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased"){
151  beamspot::dumpBeamSpotTxt(outFile, currentBS);
152  }
153  }
154  else {
155  edm::LogInfo("AlcaBeamSpotHarvester")
156  << "no new tag requested, appending IOV" << std::endl;
157  //poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot, poolDbService->currentTime(),"BeamSpotObjectsRcd");
158  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
159  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased"){
160  beamspot::dumpBeamSpotTxt(outFile, currentBS);
161  }
162  }
163 
164 
165 
166 
167 /*
168  int argc = 15;
169  const char* argv[] = {"endRun"
170  ,"-d","sqlite_file:combined.db"
171  ,"-s","sqlite_file:testbs2.db"
172  ,"-l","sqlite_file:log.db"
173  ,"-i","TestLSBasedBS"
174  ,"-t","TestLSBasedBS"
175  ,"-b","1"
176  ,"-e","10"
177  };
178 
179  edm::LogInfo("AlcaBeamSpotHarvester")
180  << "Running utilities!"
181  << utilities.run(argc,(char**)argv);
182  edm::LogInfo("AlcaBeamSpotHarvester")
183  << "Run utilities!"
184  << std::endl;
185 */
186  }
187 
188 
189 
190 
191  }
192 
193  outFile.close();
194 
195 }
196 
197 //--------------------------------------------------------------------------------------------------
199 
200 //--------------------------------------------------------------------------------------------------
203 }
204 
205 
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunID.h:39
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void beginRun(const edm::Run &, const edm::EventSetup &) override
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
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
AlcaBeamSpotHarvester(const edm::ParameterSet &)
Constructor.
const std::map< edm::LuminosityBlockNumber_t, reco::BeamSpot > & getPayloads(void)
U second(std::pair< T, U > const &p)
void endJob(void) override
int iEvent
Definition: GenABIO.cc:230
unsigned long long Time_t
Definition: Time.h:16
bool isNewTagRequest(const std::string &recordName)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void SetEmittanceX(double val)
set emittance
~AlcaBeamSpotHarvester() override
Destructor.
bool isAvailable() const
Definition: Service.h:46
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void Setdxdz(double val)
set dxdz slope, crossing angle
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void SetBetaStar(double val)
set beta star
void readLumi(const edm::LuminosityBlock &)
void SetType(int type)
set beam type
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
void beginJob(void) override
AlcaBeamSpotManager theAlcaBeamSpotManager_
fixed size matrix
HLT enums.
void dumpBeamSpotTxt(std::ofstream &outFile, BeamSpotContainer const &bsContainer)
Definition: Run.h:43
void SetPosition(double x, double y, double z)
set XYZ position