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 <cstring>
31 #include <iostream>
32 
33 using namespace edm;
34 using namespace reco;
35 // using namespace std;
36 
37 //--------------------------------------------------------------------------------------------------
39  : beamSpotOutputBase_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
40  .getUntrackedParameter<std::string>("BeamSpotOutputBase")),
41  outputrecordName_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
42  .getUntrackedParameter<std::string>("outputRecordName", "BeamSpotObjectsRcd")),
43  sigmaZValue_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
44  .getUntrackedParameter<double>("SigmaZValue")),
45  sigmaZCut_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
46  .getUntrackedParameter<double>("SigmaZCut")),
47  dumpTxt_(
48  iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters").getUntrackedParameter<bool>("DumpTxt")),
49  outTxtFileName_(iConfig.getParameter<ParameterSet>("AlcaBeamSpotHarvesterParameters")
50  .getUntrackedParameter<std::string>("TxtFileName")),
51  theAlcaBeamSpotManager_(iConfig, consumesCollector()) {}
52 
53 //--------------------------------------------------------------------------------------------------
55  // edm::LogInfo("AlcaBeamSpotHarvester")
56  // << "Lumi: " << iEvent.luminosityBlock()
57  // << " Time: " << iEvent.time().unixTime()
58  // << std::endl;
59 }
60 
61 //--------------------------------------------------------------------------------------------------
63 
64 //--------------------------------------------------------------------------------------------------
67  std::map<edm::LuminosityBlockNumber_t, std::pair<edm::Timestamp, reco::BeamSpot>> beamSpotMap =
70  // cond::ExportIOVUtilities utilities;
71 
72  std::string outTxt = Form("%s_Run%d.txt", outTxtFileName_.c_str(), iRun.id().run());
73  std::ofstream outFile;
74  outFile.open(outTxt.c_str(), std::ios::app);
75 
76  if (poolDbService.isAvailable()) {
77  for (AlcaBeamSpotManager::bsMap_iterator it = beamSpotMap.begin(); it != beamSpotMap.end(); it++) {
78  BeamSpotObjects aBeamSpot;
79  aBeamSpot.setType(it->second.second.type());
80  aBeamSpot.setPosition(it->second.second.x0(), it->second.second.y0(), it->second.second.z0());
81  if (sigmaZValue_ == -1) {
82  aBeamSpot.setSigmaZ(it->second.second.sigmaZ());
83  } else {
84  aBeamSpot.setSigmaZ(sigmaZValue_);
85  }
86  aBeamSpot.setdxdz(it->second.second.dxdz());
87  aBeamSpot.setdydz(it->second.second.dydz());
88  aBeamSpot.setBeamWidthX(it->second.second.BeamWidthX());
89  aBeamSpot.setBeamWidthY(it->second.second.BeamWidthY());
90  aBeamSpot.setEmittanceX(it->second.second.emittanceX());
91  aBeamSpot.setEmittanceY(it->second.second.emittanceY());
92  aBeamSpot.setBetaStar(it->second.second.betaStar());
93 
94  for (int i = 0; i < 7; ++i) {
95  for (int j = 0; j < 7; ++j) {
96  aBeamSpot.setCovariance(i, j, it->second.second.covariance(i, j));
97  }
98  }
99 
100  if (sigmaZValue_ > 0) {
101  aBeamSpot.setCovariance(3, 3, 0.000025);
102  }
103 
104  cond::Time_t thisIOV = 1;
105 
106  beamspot::BeamSpotContainer currentBS;
107 
108  // run based
109  if (beamSpotOutputBase_ == "runbased") {
110  thisIOV = (cond::Time_t)iRun.id().run();
111  }
112  // lumi based
113  else if (beamSpotOutputBase_ == "lumibased") {
114  edm::LuminosityBlockID lu(iRun.id().run(), it->first);
115  thisIOV = (cond::Time_t)(lu.value());
116 
117  currentBS.beamspot = it->second.second;
118  currentBS.run = iRun.id().run();
119  currentBS.beginLumiOfFit = it->first;
120  currentBS.endLumiOfFit = it->first; // endLumi = initLumi
121 
122  std::time_t lumi_t_begin = it->second.first.unixTime();
123  std::time_t lumi_t_end = it->second.first.unixTime(); // begin time == end time
124  strftime(
125  currentBS.beginTimeOfFit, sizeof currentBS.beginTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_begin));
126  strftime(currentBS.endTimeOfFit, sizeof currentBS.endTimeOfFit, "%Y.%m.%d %H:%M:%S GMT", gmtime(&lumi_t_end));
127 
128  currentBS.reftime[0] = lumi_t_begin;
129  currentBS.reftime[1] = lumi_t_end;
130  }
131  if (poolDbService->isNewTagRequest(outputrecordName_)) {
132  edm::LogInfo("AlcaBeamSpotHarvester") << "new tag requested" << std::endl;
133  poolDbService->writeOneIOV<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
134  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased") {
136 
138  if (jr.isAvailable()) {
139  std::map<std::string, std::string> jrInfo;
140  jrInfo["Source"] = std::string("AlcaHarvesting");
141  jrInfo["FileClass"] = std::string("ALCATXT");
142  jr->reportAnalysisFile(outTxt, jrInfo);
143  }
144  }
145  } else {
146  edm::LogInfo("AlcaBeamSpotHarvester") << "no new tag requested, appending IOV" << std::endl;
147  poolDbService->writeOneIOV<BeamSpotObjects>(aBeamSpot, thisIOV, outputrecordName_);
148  if (dumpTxt_ && beamSpotOutputBase_ == "lumibased") {
150  }
151  }
152 
153  /*
154  int argc = 15;
155  const char* argv[] = {"endRun"
156  ,"-d","sqlite_file:combined.db"
157  ,"-s","sqlite_file:testbs2.db"
158  ,"-l","sqlite_file:log.db"
159  ,"-i","TestLSBasedBS"
160  ,"-t","TestLSBasedBS"
161  ,"-b","1"
162  ,"-e","10"
163  };
164 
165  edm::LogInfo("AlcaBeamSpotHarvester")
166  << "Running utilities!"
167  << utilities.run(argc,(char**)argv);
168  edm::LogInfo("AlcaBeamSpotHarvester")
169  << "Run utilities!"
170  << std::endl;
171  */
172  }
173  }
174 
175  outFile.close();
176 }
177 
178 //--------------------------------------------------------------------------------------------------
180 
181 //--------------------------------------------------------------------------------------------------
184 }
185 
void setCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
void setEmittanceY(double val)
set emittance
void beginRun(const edm::Run &, const edm::EventSetup &) override
void setBetaStar(double val)
set beta star
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 setType(int type)
set beam type
AlcaBeamSpotHarvester(const edm::ParameterSet &)
Constructor.
void setEmittanceX(double val)
set emittance
int iEvent
Definition: GenABIO.cc:224
unsigned long long Time_t
Definition: Time.h:14
bool isNewTagRequest(const std::string &recordName)
void beginLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void setdydz(double val)
set dydz slope, crossing angle in XZ
Hash writeOneIOV(const T &payload, Time_t time, const std::string &recordName)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void endLuminosityBlock(const edm::LuminosityBlock &, const edm::EventSetup &) override
void setdxdz(double val)
set dxdz slope, crossing angle
RunID const & id() const
Definition: RunBase.h:39
Log< level::Info, false > LogInfo
void readLumi(const edm::LuminosityBlock &)
void setSigmaZ(double val)
set sigma Z, RMS bunch length
AlcaBeamSpotManager theAlcaBeamSpotManager_
fixed size matrix
HLT enums.
void reportAnalysisFile(std::string const &fileName, std::map< std::string, std::string > const &fileData)
Definition: JobReport.cc:509
void setPosition(double x, double y, double z)
set XYZ position
void setBeamWidthX(double val)
set average transverse beam width X
bool isAvailable() const
Definition: Service.h:40
void dumpBeamSpotTxt(std::ofstream &outFile, BeamSpotContainer const &bsContainer)
void setBeamWidthY(double val)
set average transverse beam width Y
RunNumber_t run() const
Definition: RunID.h:26
Definition: Run.h:45
const std::map< edm::LuminosityBlockNumber_t, std::pair< edm::Timestamp, reco::BeamSpot > > & getPayloads(void)