CMS 3D CMS Logo

BeamSpotOnlineLegacyRcdWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: CondTools/BeamSpot
4 // Class: BeamSpotOnlineLegacyRcdWriter
5 //
13 //
14 // Original Author: Francesco Brivio
15 // Created: Tue, 11 Feb 2020 11:10:12 GMT
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 #include <string>
22 #include <fstream>
23 #include <iostream>
24 
25 // user include files
30 
34 
37 
39 
40 //
41 // class declaration
42 //
43 
45 public:
48 
49  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
50  cond::Time_t pack(uint32_t, uint32_t);
51 
52 private:
53  void beginJob() override;
54  void analyze(const edm::Event&, const edm::EventSetup&) override;
55  void endJob() override;
56 
57  std::ifstream fasciiFile;
59  uint32_t fIOVStartRun;
60  uint32_t fIOVStartLumi;
63 
64  // ----------member data ---------------------------
65 };
66 
67 //
68 // constructors and destructor
69 //
71  //now do what ever initialization is needed
72  fasciiFileName = iConfig.getUntrackedParameter<std::string>("InputFileName");
73  fasciiFile.open(fasciiFileName.c_str());
74  if (iConfig.exists("IOVStartRun") && iConfig.exists("IOVStartLumi")) {
75  fIOVStartRun = iConfig.getUntrackedParameter<uint32_t>("IOVStartRun");
76  fIOVStartLumi = iConfig.getUntrackedParameter<uint32_t>("IOVStartLumi");
78  fuseNewSince = true;
79  } else {
80  fuseNewSince = false;
81  }
82 }
83 
85  // do anything here that needs to be done at desctruction time
86  // (e.g. close files, deallocate resources etc.)
87 }
88 
89 //
90 // member functions
91 //
92 
93 // ------------ Create a since object (cond::Time_t) by packing Run and LS (both uint32_t) ------------
94 cond::Time_t BeamSpotOnlineLegacyRcdWriter::pack(uint32_t fIOVStartRun, uint32_t fIOVStartLumi) {
95  return ((uint64_t)fIOVStartRun << 32 | fIOVStartLumi);
96 }
97 
98 // ------------ method called for each event ------------
100 
101 // ------------ method called once each job just before starting event loop ------------
103 
104 // ------------ method called once each job just after ending the event loop ------------
106  std::cout << "Reading BeamSpotOnlineLegacyObjectsRcd data from text file: " << fasciiFileName << std::endl;
107 
108  // extract from file
109  double x, y, z, sigmaZ, dxdz, dydz, beamWidthX, beamWidthY, emittanceX, emittanceY, betastar;
110  double cov[7][7];
111  int type, lastAnalyzedLumi, firstAnalyzedLumi, lastAnalyzedRun, lastAnalyzedFill;
113 
114  fasciiFile >> tag >> lastAnalyzedRun;
115  fasciiFile >> tag >> tag >> tag >> tag >> tag; // BeginTimeOfFit parsing (not used in payload)
116  fasciiFile >> tag >> tag >> tag >> tag >> tag; // EndTimeOfFit parsing (not used in payload)
117  fasciiFile >> tag >> firstAnalyzedLumi;
118  fasciiFile >> tag >> lastAnalyzedLumi;
119  fasciiFile >> tag >> type;
120  fasciiFile >> tag >> x;
121  fasciiFile >> tag >> y;
122  fasciiFile >> tag >> z;
123  fasciiFile >> tag >> sigmaZ;
124  fasciiFile >> tag >> dxdz;
125  fasciiFile >> tag >> dydz;
126  fasciiFile >> tag >> beamWidthX;
127  fasciiFile >> tag >> beamWidthY;
128  fasciiFile >> tag >> cov[0][0] >> cov[0][1] >> cov[0][2] >> cov[0][3] >> cov[0][4] >> cov[0][5] >> cov[0][6];
129  fasciiFile >> tag >> cov[1][0] >> cov[1][1] >> cov[1][2] >> cov[1][3] >> cov[1][4] >> cov[1][5] >> cov[1][6];
130  fasciiFile >> tag >> cov[2][0] >> cov[2][1] >> cov[2][2] >> cov[2][3] >> cov[2][4] >> cov[2][5] >> cov[2][6];
131  fasciiFile >> tag >> cov[3][0] >> cov[3][1] >> cov[3][2] >> cov[3][3] >> cov[3][4] >> cov[3][5] >> cov[3][6];
132  fasciiFile >> tag >> cov[4][0] >> cov[4][1] >> cov[4][2] >> cov[4][3] >> cov[4][4] >> cov[4][5] >> cov[4][6];
133  fasciiFile >> tag >> cov[5][0] >> cov[5][1] >> cov[5][2] >> cov[5][3] >> cov[5][4] >> cov[5][5] >> cov[5][6];
134  fasciiFile >> tag >> cov[6][0] >> cov[6][1] >> cov[6][2] >> cov[6][3] >> cov[6][4] >> cov[6][5] >> cov[6][6];
135  fasciiFile >> tag >> emittanceX;
136  fasciiFile >> tag >> emittanceY;
137  fasciiFile >> tag >> betastar;
138 
139  lastAnalyzedFill = -999;
140 
141  std::cout << "---- Parsed these parameters from input txt file ----" << std::endl;
142  std::cout << " lastAnalyzedRun : " << lastAnalyzedRun << std::endl;
143  std::cout << " lastAnalyzedFill : " << lastAnalyzedFill << std::endl;
144  std::cout << " firstAnalyzedLumi : " << firstAnalyzedLumi << std::endl;
145  std::cout << " lastAnalyzedLumi : " << lastAnalyzedLumi << std::endl;
146  std::cout << " type : " << type << std::endl;
147  std::cout << " x : " << x << std::endl;
148  std::cout << " y : " << y << std::endl;
149  std::cout << " z : " << z << std::endl;
150  std::cout << " sigmaZ : " << sigmaZ << std::endl;
151  std::cout << " dxdz : " << dxdz << std::endl;
152  std::cout << " dydz : " << dydz << std::endl;
153  std::cout << " beamWidthX : " << beamWidthX << std::endl;
154  std::cout << " beamWidthY : " << beamWidthY << std::endl;
155  std::cout << " Cov(0,j) : " << cov[0][0] << " " << cov[0][1] << " " << cov[0][2] << " " << cov[0][3] << " "
156  << cov[0][4] << " " << cov[0][5] << " " << cov[0][6] << std::endl;
157  std::cout << " Cov(1,j) : " << cov[1][0] << " " << cov[1][1] << " " << cov[1][2] << " " << cov[1][3] << " "
158  << cov[1][4] << " " << cov[1][5] << " " << cov[1][6] << std::endl;
159  std::cout << " Cov(2,j) : " << cov[2][0] << " " << cov[2][1] << " " << cov[2][2] << " " << cov[2][3] << " "
160  << cov[2][4] << " " << cov[2][5] << " " << cov[2][6] << std::endl;
161  std::cout << " Cov(3,j) : " << cov[3][0] << " " << cov[3][1] << " " << cov[3][2] << " " << cov[3][3] << " "
162  << cov[3][4] << " " << cov[3][5] << " " << cov[3][6] << std::endl;
163  std::cout << " Cov(4,j) : " << cov[4][0] << " " << cov[4][1] << " " << cov[4][2] << " " << cov[4][3] << " "
164  << cov[4][4] << " " << cov[4][5] << " " << cov[4][6] << std::endl;
165  std::cout << " Cov(5,j) : " << cov[5][0] << " " << cov[5][1] << " " << cov[5][2] << " " << cov[5][3] << " "
166  << cov[5][4] << " " << cov[5][5] << " " << cov[5][6] << std::endl;
167  std::cout << " Cov(6,j) : " << cov[6][0] << " " << cov[6][1] << " " << cov[6][2] << " " << cov[6][3] << " "
168  << cov[6][4] << " " << cov[6][5] << " " << cov[6][6] << std::endl;
169  std::cout << " emittanceX : " << emittanceX << std::endl;
170  std::cout << " emittanceY : " << emittanceY << std::endl;
171  std::cout << " betastar : " << betastar << std::endl;
172  std::cout << "-----------------------------------------------------" << std::endl;
173 
175 
176  abeam->SetLastAnalyzedLumi(lastAnalyzedLumi);
177  abeam->SetLastAnalyzedRun(lastAnalyzedRun);
178  abeam->SetLastAnalyzedFill(lastAnalyzedFill);
179  abeam->SetType(type);
180  abeam->SetPosition(x, y, z);
181  abeam->SetSigmaZ(sigmaZ);
182  abeam->Setdxdz(dxdz);
183  abeam->Setdydz(dydz);
184  abeam->SetBeamWidthX(beamWidthX);
185  abeam->SetBeamWidthY(beamWidthY);
186  abeam->SetEmittanceX(emittanceX);
187  abeam->SetEmittanceY(emittanceY);
188  abeam->SetBetaStar(betastar);
189 
190  for (int i = 0; i < 7; ++i) {
191  for (int j = 0; j < 7; ++j) {
192  abeam->SetCovariance(i, j, cov[i][j]);
193  }
194  }
195 
196  std::cout << " Writing results to DB..." << std::endl;
197 
199  if (poolDbService.isAvailable()) {
200  std::cout << "poolDBService available" << std::endl;
201  if (poolDbService->isNewTagRequest("BeamSpotOnlineLegacyObjectsRcd")) {
202  std::cout << "new tag requested" << std::endl;
203  if (fuseNewSince) {
204  std::cout << "Using a new Since: " << fnewSince << std::endl;
205  poolDbService->createNewIOV<BeamSpotOnlineObjects>(
206  abeam, fnewSince, poolDbService->endOfTime(), "BeamSpotOnlineLegacyObjectsRcd");
207  } else
208  poolDbService->createNewIOV<BeamSpotOnlineObjects>(
209  abeam, poolDbService->beginOfTime(), poolDbService->endOfTime(), "BeamSpotOnlineLegacyObjectsRcd");
210  } else {
211  std::cout << "no new tag requested" << std::endl;
212  if (fuseNewSince) {
213  std::cout << "Using a new Since: " << fnewSince << std::endl;
214  poolDbService->appendSinceTime<BeamSpotOnlineObjects>(abeam, fnewSince, "BeamSpotOnlineLegacyObjectsRcd");
215  } else
216  poolDbService->appendSinceTime<BeamSpotOnlineObjects>(
217  abeam, poolDbService->currentTime(), "BeamSpotOnlineLegacyObjectsRcd");
218  }
219  }
220 
221  std::cout << "[BeamSpotOnlineLegacyRcdWriter] endJob done \n" << std::endl;
222 }
223 
224 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
226  //The following says we do not know what parameters are allowed so do no validation
227  // Please change this to state exactly what you do use, even if it is no parameters
229  desc.setUnknown();
230  descriptions.addDefault(desc);
231 }
232 
233 //define this as a plug-in
DDAxes::y
EDAnalyzer.h
mps_fire.i
i
Definition: mps_fire.py:428
BeamSpotObjects::SetBetaStar
void SetBetaStar(double val)
set beta star
Definition: BeamSpotObjects.h:64
BeamSpotPI::sigmaZ
Definition: BeamSpotPayloadInspectorHelper.h:36
cond::service::PoolDBOutputService::beginOfTime
cond::Time_t beginOfTime() const
Definition: PoolDBOutputService.cc:215
BeamSpotOnlineLegacyRcdWriter
Definition: BeamSpotOnlineLegacyRcdWriter.cc:44
gather_cfg.cout
cout
Definition: gather_cfg.py:144
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
cond::service::PoolDBOutputService::appendSinceTime
void appendSinceTime(const T *payloadObj, cond::Time_t sinceTime, const std::string &recordName)
Definition: PoolDBOutputService.h:141
BeamSpotOnlineLegacyRcdWriter::fasciiFileName
std::string fasciiFileName
Definition: BeamSpotOnlineLegacyRcdWriter.cc:58
BeamSpotObjects::SetBeamWidthY
void SetBeamWidthY(double val)
set average transverse beam width Y
Definition: BeamSpotObjects.h:50
BeamSpotOnlineLegacyObjectsRcd.h
BeamSpotOnlineLegacyRcdWriter::BeamSpotOnlineLegacyRcdWriter
BeamSpotOnlineLegacyRcdWriter(const edm::ParameterSet &)
Definition: BeamSpotOnlineLegacyRcdWriter.cc:70
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
DDAxes::x
edm::one::EDAnalyzer
Definition: EDAnalyzer.h:30
BeamSpotOnlineLegacyRcdWriter::fIOVStartRun
uint32_t fIOVStartRun
Definition: BeamSpotOnlineLegacyRcdWriter.cc:59
edm::Service::isAvailable
bool isAvailable() const
Definition: Service.h:40
BeamSpotOnlineLegacyRcdWriter::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: BeamSpotOnlineLegacyRcdWriter.cc:225
BeamSpotObjects::SetSigmaZ
void SetSigmaZ(double val)
set sigma Z, RMS bunch length
Definition: BeamSpotObjects.h:42
MakerMacros.h
BeamSpotOnlineLegacyRcdWriter::fuseNewSince
bool fuseNewSince
Definition: BeamSpotOnlineLegacyRcdWriter.cc:62
PoolDBOutputService.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
BeamSpotFakeParameters_cfi.emittanceX
emittanceX
Definition: BeamSpotFakeParameters_cfi.py:17
cond::service::PoolDBOutputService::createNewIOV
void createNewIOV(const T *firstPayloadObj, cond::Time_t firstSinceTime, cond::Time_t, const std::string &recordName)
Definition: PoolDBOutputService.h:116
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
BeamSpotOnlineLegacyRcdWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: BeamSpotOnlineLegacyRcdWriter.cc:99
Service.h
DDAxes::z
BeamSpotPI::dxdz
Definition: BeamSpotPayloadInspectorHelper.h:37
BeamSpotObjects::SetEmittanceY
void SetEmittanceY(double val)
set emittance
Definition: BeamSpotObjects.h:62
BeamSpotFakeParameters_cfi.emittanceY
emittanceY
Definition: BeamSpotFakeParameters_cfi.py:18
BeamSpotObjects::SetPosition
void SetPosition(double x, double y, double z)
set XYZ position
Definition: BeamSpotObjects.h:36
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
BeamSpotObjects::SetType
void SetType(int type)
set beam type
Definition: BeamSpotObjects.h:58
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
BeamSpotOnlineLegacyRcdWriter::fIOVStartLumi
uint32_t fIOVStartLumi
Definition: BeamSpotOnlineLegacyRcdWriter.cc:60
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
BeamSpotObjects::SetEmittanceX
void SetEmittanceX(double val)
set emittance
Definition: BeamSpotObjects.h:60
BeamSpotObjects::SetCovariance
void SetCovariance(int i, int j, double val)
set i,j element of the full covariance matrix 7x7
Definition: BeamSpotObjects.h:56
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
BeamSpotPI::dydz
Definition: BeamSpotPayloadInspectorHelper.h:38
edm::Service< cond::service::PoolDBOutputService >
iEvent
int iEvent
Definition: GenABIO.cc:224
BeamSpotOnlineLegacyRcdWriter::fnewSince
cond::Time_t fnewSince
Definition: BeamSpotOnlineLegacyRcdWriter.cc:61
edm::EventSetup
Definition: EventSetup.h:58
BeamSpotObjects::Setdxdz
void Setdxdz(double val)
set dxdz slope, crossing angle
Definition: BeamSpotObjects.h:44
BeamSpotOnlineObjects::SetLastAnalyzedFill
void SetLastAnalyzedFill(int val)
Definition: BeamSpotOnlineObjects.h:50
InputTag.h
cond::service::PoolDBOutputService::endOfTime
cond::Time_t endOfTime() const
Definition: PoolDBOutputService.cc:213
BeamSpotOnlineLegacyRcdWriter::fasciiFile
std::ifstream fasciiFile
Definition: BeamSpotOnlineLegacyRcdWriter.cc:57
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
Frameworkfwd.h
BeamSpotOnlineObjects::SetLastAnalyzedLumi
void SetLastAnalyzedLumi(int val)
Setters Methods.
Definition: BeamSpotOnlineObjects.h:44
BeamSpotOnlineObjects
Definition: BeamSpotOnlineObjects.h:25
BeamSpotObjects::SetBeamWidthX
void SetBeamWidthX(double val)
set average transverse beam width X
Definition: BeamSpotObjects.h:48
BeamSpotOnlineLegacyRcdWriter::endJob
void endJob() override
Definition: BeamSpotOnlineLegacyRcdWriter.cc:105
BeamSpotOnlineLegacyRcdWriter::pack
cond::Time_t pack(uint32_t, uint32_t)
Definition: BeamSpotOnlineLegacyRcdWriter.cc:94
cond::service::PoolDBOutputService::isNewTagRequest
bool isNewTagRequest(const std::string &recordName)
Definition: PoolDBOutputService.cc:128
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
BeamSpotOnlineObjects::SetLastAnalyzedRun
void SetLastAnalyzedRun(int val)
Definition: BeamSpotOnlineObjects.h:47
BeamSpotOnlineObjects.h
ParameterSet.h
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
edm::Event
Definition: Event.h:73
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
BeamSpotObjects::Setdydz
void Setdydz(double val)
set dydz slope, crossing angle in XZ
Definition: BeamSpotObjects.h:46
BeamSpotOnlineLegacyRcdWriter::~BeamSpotOnlineLegacyRcdWriter
~BeamSpotOnlineLegacyRcdWriter() override
Definition: BeamSpotOnlineLegacyRcdWriter.cc:84
cond::service::PoolDBOutputService::currentTime
cond::Time_t currentTime() const
Definition: PoolDBOutputService.cc:217
BeamSpotOnlineLegacyRcdWriter::beginJob
void beginJob() override
Definition: BeamSpotOnlineLegacyRcdWriter.cc:102