CMS 3D CMS Logo

EcalCondDBWriter.cc
Go to the documentation of this file.
1 #include <memory>
2 
4 
6 
12 
13 #include "TObjArray.h"
14 #include "TPRegexp.h"
15 #include "TString.h"
16 
17 void setBit(int &_bitArray, unsigned _iBit) { _bitArray |= (0x1 << _iBit); }
18 
19 bool getBit(int &_bitArray, unsigned _iBit) { return (_bitArray & (0x1 << _iBit)) != 0; }
20 
22  : runNumber_(0),
23  db_(nullptr),
24  location_(_ps.getUntrackedParameter<std::string>("location")),
25  runType_(_ps.getUntrackedParameter<std::string>("runType")),
26  runGeneralTag_(_ps.getUntrackedParameter<std::string>("runGeneralTag")),
27  monRunGeneralTag_(_ps.getUntrackedParameter<std::string>("monRunGeneralTag")),
28  summaryWriter_(_ps.getUntrackedParameterSet("workerParams")),
29  verbosity_(_ps.getUntrackedParameter<int>("verbosity")),
30  executed_(false) {
31  std::vector<std::string> inputRootFiles(_ps.getUntrackedParameter<std::vector<std::string>>("inputRootFiles"));
32 
33  if (inputRootFiles.empty())
34  throw cms::Exception("Configuration") << "No input ROOT file given";
35 
36  if (verbosity_ > 0)
37  edm::LogInfo("EcalDQM") << "Initializing DQMStore from input ROOT files";
38 
40 
41  for (unsigned iF(0); iF < inputRootFiles.size(); ++iF) {
43 
44  if (verbosity_ > 1)
45  edm::LogInfo("EcalDQM") << " " << fileName;
46 
47  TPRegexp pat("DQM_V[0-9]+(?:|_[0-9a-zA-Z]+)_R([0-9]+)");
48  std::unique_ptr<TObjArray> matches(pat.MatchS(fileName.c_str()));
49  if (matches->GetEntries() == 0)
50  throw cms::Exception("Configuration") << "Input file " << fileName << " is not an DQM output";
51 
52  if (iF == 0)
53  runNumber_ = TString(matches->At(1)->GetName()).Atoi();
54  else if (TString(matches->At(1)->GetName()).Atoi() != runNumber_)
55  throw cms::Exception("Configuration") << "Input files disagree in run number";
56 
57  dqmStore.open(fileName, false, "", "", DQMStore::StripRunDirs);
58  }
59 
62  int hostPort(_ps.getUntrackedParameter<int>("hostPort"));
65 
66  std::unique_ptr<EcalCondDBInterface> db(nullptr);
67 
68  if (verbosity_ > 0)
69  edm::LogInfo("EcalDQM") << "Establishing DB connection";
70 
71  try {
72  db = std::make_unique<EcalCondDBInterface>(DBName, userName, password);
73  } catch (std::runtime_error &re) {
74  if (!hostName.empty()) {
75  try {
76  db = std::make_unique<EcalCondDBInterface>(hostName, DBName, userName, password, hostPort);
77  } catch (std::runtime_error &re2) {
78  throw cms::Exception("DBError") << re2.what();
79  }
80  } else
81  throw cms::Exception("DBError") << re.what();
82  }
83 
84  db_ = db.release();
85 
86  if (verbosity_ > 0)
87  edm::LogInfo("EcalDQM") << " Done.";
88 
89  edm::ParameterSet const &workerParams(_ps.getUntrackedParameterSet("workerParams"));
90 
92  workers_[Cosmic] = nullptr;
97  workers_[BeamCalo] = nullptr;
98  workers_[BeamHodo] = nullptr;
99  workers_[TriggerPrimitives] = nullptr;
100  workers_[Cluster] = nullptr;
103  workers_[RawData] = nullptr;
105 
106  for (unsigned iC(0); iC < nTasks; ++iC)
107  if (workers_[iC])
109 }
110 
112  try {
113  delete db_;
114  } catch (std::runtime_error &e) {
115  throw cms::Exception("DBError") << e.what();
116  }
117 
118  for (unsigned iC(0); iC < nTasks; ++iC)
119  delete workers_[iC];
120 }
121 
122 void EcalCondDBWriter::beginRun(edm::Run const &_run, edm::EventSetup const &_es) {
123  for (unsigned iC(0); iC < nTasks; ++iC)
124  if (workers_[iC])
125  workers_[iC]->setSetupObjects(_es);
126 }
127 
129  if (executed_)
130  return;
131 
133 
134  if (verbosity_ > 1)
135  edm::LogInfo("EcalDQM") << " Searching event info";
136 
137  uint64_t timeStampInFile(0);
138  unsigned processedEvents(0);
139 
140  _igetter.cd();
141  std::vector<std::string> dirs(_igetter.getSubdirs());
142  for (unsigned iD(0); iD < dirs.size(); ++iD) {
143  if (!_igetter.dirExists(dirs[iD] + "/EventInfo"))
144  continue;
145 
146  MonitorElement *timeStampME(_igetter.get(dirs[iD] + "/EventInfo/runStartTimeStamp"));
147  if (timeStampME) {
148  double timeStampValue(timeStampME->getFloatValue());
149  uint64_t seconds(timeStampValue);
150  uint64_t microseconds((timeStampValue - seconds) * 1.e6);
151  timeStampInFile = (seconds << 32) | microseconds;
152  }
153 
154  MonitorElement *eventsME(_igetter.get(dirs[iD] + "/EventInfo/processedEvents"));
155  if (eventsME)
156  processedEvents = eventsME->getIntValue();
157 
158  if (timeStampInFile != 0 && processedEvents != 0) {
159  if (verbosity_ > 1)
160  edm::LogInfo("EcalDQM") << " Event info found; timestamp=" << timeStampInFile
161  << " processedEvents=" << processedEvents;
162  break;
163  }
164  }
165 
166  if (verbosity_ > 0)
167  edm::LogInfo("EcalDQM") << " Done.";
168 
170 
171  if (verbosity_ > 0)
172  edm::LogInfo("EcalDQM") << "Setting up source MonitorElements for given run type " << runType_;
173 
174  int taskList(0);
175  for (unsigned iC(0); iC < nTasks; ++iC) {
176  if (!workers_[iC] || !workers_[iC]->runsOn(runType_))
177  continue;
178 
179  workers_[iC]->retrieveSource(_igetter);
180 
181  setBit(taskList, iC);
182  }
183 
184  if (verbosity_ > 0)
185  edm::LogInfo("EcalDQM") << " Done.";
186 
188 
189  if (verbosity_ > 0)
190  edm::LogInfo("EcalDQM") << "Initializing DB entry";
191 
192  RunIOV runIOV;
193  RunTag runTag;
194  try {
195  runIOV = db_->fetchRunIOV(location_, runNumber_);
196  runTag = runIOV.getRunTag();
197  } catch (std::runtime_error &e) {
198  std::cerr << e.what();
199 
200  if (timeStampInFile == 0)
201  throw cms::Exception("Initialization") << "Time stamp for the run could not be found";
202 
203  LocationDef locationDef;
204  locationDef.setLocation(location_);
205  RunTypeDef runTypeDef;
206  runTypeDef.setRunType(runType_);
207  runTag.setLocationDef(locationDef);
208  runTag.setRunTypeDef(runTypeDef);
210 
211  runIOV.setRunStart(Tm(timeStampInFile));
212  runIOV.setRunNumber(runNumber_);
213  runIOV.setRunTag(runTag);
214 
215  try {
216  db_->insertRunIOV(&runIOV);
217  runIOV = db_->fetchRunIOV(&runTag, runNumber_);
218  } catch (std::runtime_error &e) {
219  throw cms::Exception("DBError") << e.what();
220  }
221  }
222 
223  // No filtering - DAQ definitions change time to time..
224  // if(runType_ != runIOV.getRunTag().getRunTypeDef().getRunType())
225  // throw cms::Exception("Configuration") << "Given run type " << runType_
226  // << " does not match the run type in DB " <<
227  // runIOV.getRunTag().getRunTypeDef().getRunType();
228 
229  MonVersionDef versionDef;
230  versionDef.setMonitoringVersion("test01"); // the only mon_ver in mon_version_def table as of September
231  // 2012
232  MonRunTag monTag;
233  monTag.setMonVersionDef(versionDef);
235 
236  MonRunIOV monIOV;
237 
238  try {
239  monIOV = db_->fetchMonRunIOV(&runTag, &monTag, runNumber_, 1);
240  } catch (std::runtime_error &e) {
241  std::cerr << e.what();
242 
243  monIOV.setRunIOV(runIOV);
244  monIOV.setSubRunNumber(1);
245  monIOV.setSubRunStart(runIOV.getRunStart());
246  monIOV.setSubRunEnd(runIOV.getRunEnd());
247  monIOV.setMonRunTag(monTag);
248 
249  try {
250  db_->insertMonRunIOV(&monIOV);
251  monIOV = db_->fetchMonRunIOV(&runTag, &monTag, runNumber_, 1);
252  } catch (std::runtime_error &e) {
253  throw cms::Exception("DBError") << e.what();
254  }
255  }
256 
257  if (verbosity_ > 0)
258  edm::LogInfo("EcalDQM") << " Done.";
259 
261 
262  if (verbosity_ > 0)
263  edm::LogInfo("EcalDQM") << "Writing to DB";
264 
265  int outcome(0);
266  for (unsigned iC(0); iC < nTasks; ++iC) {
267  if (!getBit(taskList, iC))
268  continue;
269 
270  if (verbosity_ > 1)
271  edm::LogInfo("EcalDQM") << " " << workers_[iC]->getName();
272 
273  if (workers_[iC]->isActive() && workers_[iC]->run(db_, monIOV))
274  setBit(outcome, iC);
275  }
276 
277  if (verbosity_ > 0)
278  edm::LogInfo("EcalDQM") << " Done.";
279 
280  if (verbosity_ > 0)
281  edm::LogInfo("EcalDQM") << "Registering the outcome of DB writing";
282 
283  summaryWriter_.setTaskList(taskList);
284  summaryWriter_.setOutcome(outcome);
285  summaryWriter_.setProcessedEvents(processedEvents);
286  summaryWriter_.run(db_, monIOV);
287 
288  if (verbosity_ > 0)
289  edm::LogInfo("EcalDQM") << " Done.";
290 
291  executed_ = true;
292 }
293 
LocationDef::setLocation
void setLocation(std::string loc)
Definition: LocationDef.cc:20
ecaldqm::PedestalWriter
Definition: DBWriterWorkers.h:62
EcalCondDBWriter::TestPulse
Definition: EcalCondDBWriter.h:26
EcalCondDBWriter::beginRun
void beginRun(edm::Run const &, edm::EventSetup const &) override
Definition: EcalCondDBWriter.cc:122
RunIOV
Definition: RunIOV.h:13
dqm::implementation::DQMStore::StripRunDirs
Definition: DQMStore.h:542
MonVersionDef::setMonitoringVersion
void setMonitoringVersion(std::string ver)
Definition: MonVersionDef.cc:21
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
EcalCondDBWriter::Occupancy
Definition: EcalCondDBWriter.h:34
edm::ParameterSet::getUntrackedParameterSet
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
Definition: ParameterSet.cc:2136
EcalCondDBWriter::TriggerPrimitives
Definition: EcalCondDBWriter.h:29
edm::Run
Definition: Run.h:45
EcalCondDBWriter_cfi.hostPort
hostPort
Definition: EcalCondDBWriter_cfi.py:60
EcalCondDBWriter::BeamHodo
Definition: EcalCondDBWriter.h:28
EcalCondDBWriter::Led
Definition: EcalCondDBWriter.h:32
heppy_check.dirs
dirs
Definition: heppy_check.py:26
RunTag
Definition: RunTag.h:13
ecaldqm::LaserWriter
Definition: DBWriterWorkers.h:51
oniaPATMuonsWithTrigger_cff.matches
matches
Definition: oniaPATMuonsWithTrigger_cff.py:77
EcalCondDBWriter::dqmEndJob
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
Definition: EcalCondDBWriter.cc:128
EcalCondDBWriter::Cluster
Definition: EcalCondDBWriter.h:30
ecaldqm::OccupancyWriter
Definition: DBWriterWorkers.h:113
LocationDef
Definition: LocationDef.h:12
EcalCondDBInterface::fetchMonRunIOV
MonRunIOV fetchMonRunIOV(RunTag *runtag, MonRunTag *montag, run_t run, subrun_t monrun) noexcept(false)
Definition: EcalCondDBInterface.cc:674
EcalCondDBWriter_cfi.DBName
DBName
Definition: EcalCondDBWriter_cfi.py:58
DQMStore.h
dqm::implementation::IGetter::getSubdirs
virtual DQM_DEPRECATED std::vector< std::string > getSubdirs() const
Definition: DQMStore.cc:678
EcalCondDBInterface::insertRunIOV
void insertRunIOV(RunIOV *iov) noexcept(false)
Definition: EcalCondDBInterface.cc:505
dqm::legacy::MonitorElement
Definition: MonitorElement.h:462
getBit
bool getBit(int &_bitArray, unsigned _iBit)
Definition: EcalCondDBWriter.cc:19
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
MillePedeFileConverter_cfg.fileName
fileName
Definition: MillePedeFileConverter_cfg.py:32
ecaldqm::IntegrityWriter
Definition: DBWriterWorkers.h:43
RunIOV::setRunStart
void setRunStart(const Tm &start)
Definition: RunIOV.cc:33
MonRunIOV::setRunIOV
void setRunIOV(const RunIOV &iov)
Definition: MonRunIOV.cc:36
MonRunIOV::setSubRunEnd
void setSubRunEnd(const Tm &end)
Definition: MonRunIOV.cc:63
MonRunTag::setGeneralTag
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:21
EcalCondDBWriter::db_
EcalCondDBInterface * db_
Definition: EcalCondDBWriter.h:39
EcalCondDBWriter_cfi.userName
userName
Definition: EcalCondDBWriter_cfi.py:61
ecaldqm::DBWriterWorker::getName
const std::string & getName() const
Definition: DBWriterWorkers.h:32
EcalCondDBWriter::runType_
std::string runType_
Definition: EcalCondDBWriter.h:41
dqmiodatasetharvest.db
db
Definition: dqmiodatasetharvest.py:119
ecaldqm::DQWorker::setSetupObjects
void setSetupObjects(edm::EventSetup const &)
Definition: DQWorker.cc:86
MakerMacros.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
RunTypeDef::setRunType
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:21
EcalCondDBWriter_cfi.password
password
Definition: EcalCondDBWriter_cfi.py:62
RunIOV::getRunEnd
Tm getRunEnd() const
Definition: RunIOV.cc:49
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
dqm::legacy::DQMStore
Definition: DQMStore.h:727
RunTag::setGeneralTag
void setGeneralTag(std::string tag)
Definition: RunTag.cc:24
Service.h
seconds
double seconds()
RunIOV::getRunTag
RunTag getRunTag() const
Definition: RunIOV.cc:58
setBit
void setBit(int &_bitArray, unsigned _iBit)
Definition: EcalCondDBWriter.cc:17
EcalCondDBWriter::location_
std::string location_
Definition: EcalCondDBWriter.h:40
EcalCondDBWriter::monRunGeneralTag_
std::string monRunGeneralTag_
Definition: EcalCondDBWriter.h:43
dqm::implementation::NavigatorBase::cd
virtual void cd()
Definition: DQMStore.cc:29
ecaldqm::SummaryWriter::setProcessedEvents
void setProcessedEvents(unsigned _n)
Definition: DBWriterWorkers.h:129
MonVersionDef
Definition: MonVersionDef.h:12
RunIOV::setRunTag
void setRunTag(const RunTag &tag)
Definition: RunIOV.cc:51
Tm
Definition: Tm.h:13
L1TBPTX_cfi.dqmStore
dqmStore
Definition: L1TBPTX_cfi.py:6
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RunTypeDef
Definition: RunTypeDef.h:12
ecaldqm::TestPulseWriter
Definition: DBWriterWorkers.h:82
EcalCondDBWriter::RawData
Definition: EcalCondDBWriter.h:33
EcalCondDBWriter::Timing
Definition: EcalCondDBWriter.h:31
ecaldqm::PresampleWriter
Definition: DBWriterWorkers.h:74
ecaldqm::SummaryWriter::setTaskList
void setTaskList(int _list)
Definition: DBWriterWorkers.h:127
EcalCondDBWriter_cfi.workerParams
workerParams
Definition: EcalCondDBWriter_cfi.py:68
edm::ParameterSet
Definition: ParameterSet.h:47
EcalCondDBWriter::verbosity_
int verbosity_
Definition: EcalCondDBWriter.h:48
EcalCondDBWriter_cfi.hostName
hostName
Definition: EcalCondDBWriter_cfi.py:59
RunIOV::setRunNumber
void setRunNumber(run_t run)
Definition: RunIOV.cc:22
ecaldqm::LedWriter
Definition: DBWriterWorkers.h:102
ecaldqm::DBWriterWorker::setVerbosity
void setVerbosity(int _v)
Definition: DBWriterWorkers.h:30
EcalCondDBWriter::nTasks
Definition: EcalCondDBWriter.h:35
EcalCondDBWriter::Pedestal
Definition: EcalCondDBWriter.h:24
EcalCondDBWriter::runNumber_
int runNumber_
Definition: EcalCondDBWriter.h:38
EcalCondDBWriter::~EcalCondDBWriter
~EcalCondDBWriter() override
Definition: EcalCondDBWriter.cc:111
edm::Service
Definition: Service.h:30
createfilelist.int
int
Definition: createfilelist.py:10
EcalCondDBWriter::workers_
ecaldqm::DBWriterWorker * workers_[nTasks]
Definition: EcalCondDBWriter.h:45
EcalCondDBWriter::BeamCalo
Definition: EcalCondDBWriter.h:27
EcalCondDBInterface::insertMonRunIOV
void insertMonRunIOV(MonRunIOV *iov) noexcept(false)
Definition: EcalCondDBInterface.cc:652
MonRunIOV
Definition: MonRunIOV.h:14
edm::EventSetup
Definition: EventSetup.h:58
pat
Definition: HeavyIon.h:7
MonRunIOV::setSubRunNumber
void setSubRunNumber(subrun_t subrun)
Definition: MonRunIOV.cc:45
MonRunTag
Definition: MonRunTag.h:13
MonRunIOV::setMonRunTag
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunIOV.cc:27
ecaldqm::DBWriterWorker::retrieveSource
void retrieveSource(DQMStore::IGetter &)
Definition: DBWriterWorkers.cc:79
EcalCondDBWriter::summaryWriter_
ecaldqm::SummaryWriter summaryWriter_
Definition: EcalCondDBWriter.h:46
EcalCondDBWriter::Presample
Definition: EcalCondDBWriter.h:25
EcalCondDBWriter.h
ecaldqm::SummaryWriter::setOutcome
void setOutcome(int _outcome)
Definition: DBWriterWorkers.h:128
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
RunTag::setLocationDef
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:33
EcalCondDBWriter::executed_
bool executed_
Definition: EcalCondDBWriter.h:49
dqm::implementation::IGetter
Definition: DQMStore.h:484
EcalCondDBWriter::EcalCondDBWriter
EcalCondDBWriter(edm::ParameterSet const &)
Definition: EcalCondDBWriter.cc:21
EcalCondDBWriter::Cosmic
Definition: EcalCondDBWriter.h:22
Exception
Definition: hltDiff.cc:245
dqm::implementation::IGetter::get
virtual MonitorElement * get(std::string const &fullpath) const
Definition: DQMStore.cc:651
Exception.h
EcalCondDBWriter::Integrity
Definition: EcalCondDBWriter.h:21
dqm::implementation::IBooker
Definition: DQMStore.h:43
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
RunTag::setRunTypeDef
void setRunTypeDef(const RunTypeDef &runTypeDef)
Definition: RunTag.cc:42
MonRunIOV::setSubRunStart
void setSubRunStart(const Tm &start)
Definition: MonRunIOV.cc:54
ecaldqm::TimingWriter
Definition: DBWriterWorkers.h:94
cms::Exception
Definition: Exception.h:70
EcalCondDBWriter
Definition: EcalCondDBWriter.h:10
EcalCondDBWriter_cfi.inputRootFiles
inputRootFiles
Definition: EcalCondDBWriter_cfi.py:67
MonRunTag::setMonVersionDef
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:30
ParameterSet.h
RunIOV::getRunStart
Tm getRunStart() const
Definition: RunIOV.cc:40
EcalCondDBWriter::runGeneralTag_
std::string runGeneralTag_
Definition: EcalCondDBWriter.h:42
EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.cerr
cerr
Definition: EcnaPython_AdcPeg12_S1_10_R170298_1_0_150_Dee0.py:8
EcalCondDBInterface::fetchRunIOV
RunIOV fetchRunIOV(RunTag *tag, run_t run) noexcept(false)
Definition: EcalCondDBInterface.cc:631
EcalCondDBWriter::Laser
Definition: EcalCondDBWriter.h:23
dqm::impl::MonitorElement::getIntValue
virtual int64_t getIntValue() const
Definition: MonitorElement.cc:924
sistrip::runNumber_
static const char runNumber_[]
Definition: ConstantsForDqm.h:33
dqm::implementation::IGetter::dirExists
virtual bool dirExists(std::string const &path) const
Definition: DQMStore.cc:708
ecaldqm::SummaryWriter::run
bool run(EcalCondDBInterface *, MonRunIOV &) override
Definition: DBWriterWorkers.cc:1340
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37