CMS 3D CMS Logo

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