CMS 3D CMS Logo

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