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 
21 
23 
27 //#include "CondCore/Utilities/bin/cmscond_export_iov.cpp"
28 //#include "CondCore/Utilities/interface/Utilities.h"
29 // #include "FWCore/MessageLogger/interface/JobReport.h"
30 
31 #include <cstring>
32 #include <iostream>
33 
34 using namespace edm;
35 using namespace reco;
36 // using namespace std;
37 
38 //--------------------------------------------------------------------------------------------------
40  : beamSpotOutputBase_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
41  .getUntrackedParameter<std::string>("BeamSpotOutputBase")),
42  outputrecordName_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
43  .getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
44  sigmaZValue_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
45  .getUntrackedParameter<double>("SigmaZValue")),
46  sigmaZCut_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
47  .getUntrackedParameter<double>("SigmaZCut")),
48  dumpTxt_(
49  iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<bool>("DumpTxt")),
50  outTxtFileName_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
51  .getUntrackedParameter<std::string>("TxtFileName")),
52  theAlcaBeamSpotManager_(iConfig, consumesCollector()) {}
53 
54 //--------------------------------------------------------------------------------------------------
56 
57 //--------------------------------------------------------------------------------------------------
59 
60 //--------------------------------------------------------------------------------------------------
62 
63 //--------------------------------------------------------------------------------------------------
65  // edm::LogInfo("AlcaBeamSpotHarvester")
66  // << "Lumi: " << iEvent.luminosityBlock()
67  // << " Time: " << iEvent.time().unixTime()
68  // << std::endl;
69 }
70 
71 //--------------------------------------------------------------------------------------------------
73 
74 //--------------------------------------------------------------------------------------------------
77  std::map<edm::LuminosityBlockNumber_t, std::pair<edm::Timestamp, reco::BeamSpot>> beamSpotMap =
80  // cond::ExportIOVUtilities utilities;
81 
82  std::string outTxt = Form("%s_Run%d.txt", outTxtFileName_.c_str(), iRun.id().run());
83  std::ofstream outFile;
84  outFile.open(outTxt.c_str(), std::ios::app);
85 
86  if (poolDbService.isAvailable()) {
87  for (AlcaBeamSpotManager::bsMap_iterator it = beamSpotMap.begin(); it != beamSpotMap.end(); it++) {
88  BeamSpotObjects *aBeamSpot = new BeamSpotObjects();
89  aBeamSpot->SetType(it->second.second.type());
90  aBeamSpot->SetPosition(it->second.second.x0(), it->second.second.y0(), it->second.second.z0());
91  if (sigmaZValue_ == -1) {
92  aBeamSpot->SetSigmaZ(it->second.second.sigmaZ());
93  } else {
94  aBeamSpot->SetSigmaZ(sigmaZValue_);
95  }
96  aBeamSpot->Setdxdz(it->second.second.dxdz());
97  aBeamSpot->Setdydz(it->second.second.dydz());
98  aBeamSpot->SetBeamWidthX(it->second.second.BeamWidthX());
99  aBeamSpot->SetBeamWidthY(it->second.second.BeamWidthY());
100  aBeamSpot->SetEmittanceX(it->second.second.emittanceX());
101  aBeamSpot->SetEmittanceY(it->second.second.emittanceY());
102  aBeamSpot->SetBetaStar(it->second.second.betaStar());
103 
104  for (int i = 0; i < 7; ++i) {
105  for (int j = 0; j < 7; ++j) {
106  aBeamSpot->SetCovariance(i, j, it->second.second.covariance(i, j));
107  }
108  }
109 
110  if (sigmaZValue_ > 0) {
111  aBeamSpot->SetCovariance(3, 3, 0.000025);
112  }
113 
114  cond::Time_t thisIOV = 1;
115 
116  beamspot::BeamSpotContainer currentBS;
117 
118  // run based
119  if (beamSpotOutputBase_ == "runbased") {
120  thisIOV = (cond::Time_t)iRun.id().run();
121  }
122  // lumi based
123  else if (beamSpotOutputBase_ == "lumibased") {
124  edm::LuminosityBlockID lu(iRun.id().run(), it->first);
125  thisIOV = (cond::Time_t)(lu.value());
126 
127  currentBS.beamspot = it->second.second;
128  currentBS.run = iRun.id().run();
129  currentBS.beginLumiOfFit = it->first;
130  currentBS.endLumiOfFit = it->first; // endLumi = initLumi
131 
132  std::time_t lumi_t_begin = it->second.first.unixTime();
133  std::time_t lumi_t_end = it->second.first.unixTime(); // begin time == end time
134  strftime(
135  currentBS.beginTimeOfFit, sizeof currentBS.beginTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_begin));
136  strftime(currentBS.endTimeOfFit, sizeof currentBS.endTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));
137 
138  currentBS.reftime[0] = lumi_t_begin;
139  currentBS.reftime[1] = lumi_t_end;
140  }
141  if (poolDbService->isNewTagRequest(outputrecordName_)) {
142  edm::LogInfo("AlcaBeamSpotHarvester") << "new tag requested" << std::endl;
143  // poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot,
144  // poolDbService->beginOfTime(),poolDbService->endOfTime(),"BeamSpotObjectsRcd");
145  // poolDbService->createNewIOV<BeamSpotObjects>(aBeamSpot,
146  // poolDbService->currentTime(),
147  // poolDbService->endOfTime(),"BeamSpotObjectsRcd");
148  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
149  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased") {
150  beamspot::dumpBeamSpotTxt(outFile, currentBS);
151 
153  if (jr.isAvailable()) {
154  std::map<std::string, std::string> jrInfo;
155  jrInfo["Source"] = std::string("AlcaHarvesting");
156  jrInfo["FileClass"] = std::string("ALCATXT");
157  jr->reportAnalysisFile(outTxt, jrInfo);
158  }
159  }
160  } else {
161  edm::LogInfo("AlcaBeamSpotHarvester") << "no new tag requested, appending IOV" << std::endl;
162  // poolDbService->appendSinceTime<BeamSpotObjects>(aBeamSpot,
163  // poolDbService->currentTime(),"BeamSpotObjectsRcd");
164  poolDbService->writeOne<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
165  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased") {
166  beamspot::dumpBeamSpotTxt(outFile, currentBS);
167  }
168  }
169 
170  /*
171  int argc = 15;
172  const char* argv[] = {"endRun"
173  ,"-d","sqlite_file:combined.db"
174  ,"-s","sqlite_file:testbs2.db"
175  ,"-l","sqlite_file:log.db"
176  ,"-i","TestLSBasedBS"
177  ,"-t","TestLSBasedBS"
178  ,"-b","1"
179  ,"-e","10"
180  };
181 
182  edm::LogInfo("AlcaBeamSpotHarvester")
183  << "Running utilities!"
184  << utilities.run(argc,(char**)argv);
185  edm::LogInfo("AlcaBeamSpotHarvester")
186  << "Run utilities!"
187  << std::endl;
188  */
189  }
190  }
191 
192  outFile.close();
193 }
194 
195 //--------------------------------------------------------------------------------------------------
197 
198 //--------------------------------------------------------------------------------------------------
201 }
202 
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunID.h:39
void beginRun(const edm::Run &, const edm::EventSetup &) override
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > >::iterator bsMap_iterator
void analyze(const edm::Event &, const edm::EventSetup &) override
void endRun(const edm::Run &, const edm::EventSetup &) override
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.
void endJob(void) override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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:40
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 reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:473
void dumpBeamSpotTxt(std::ofstream &outFile, BeamSpotContainer const &bsContainer)
Definition: Run.h:45
const std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > > & getPayloads(void)
void SetPosition(double x, double y, double z)
set XYZ position