CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalCondDBWriter.cc
Go to the documentation of this file.
1 #include "../interface/EcalCondDBWriter.h"
2 
4 
9 
10 #include "TObjArray.h"
11 #include "TPRegexp.h"
12 #include "TString.h"
13 
14 void
15 setBit(int& _bitArray, unsigned _iBit)
16 {
17  _bitArray |= (0x1 << _iBit);
18 }
19 
20 bool
21 getBit(int& _bitArray, unsigned _iBit)
22 {
23  return (_bitArray & (0x1 << _iBit)) != 0;
24 }
25 
27  db_(0),
28  location_(_ps.getUntrackedParameter<std::string>("location")),
29  runType_(_ps.getUntrackedParameter<std::string>("runType")),
30  runGeneralTag_(_ps.getUntrackedParameter<std::string>("runGeneralTag")),
31  monRunGeneralTag_(_ps.getUntrackedParameter<std::string>("monRunGeneralTag")),
32  inputRootFiles_(_ps.getUntrackedParameter<std::vector<std::string> >("inputRootFiles")),
33  summaryWriter_(_ps.getUntrackedParameterSet("workerParams")),
34  verbosity_(_ps.getUntrackedParameter<int>("verbosity")),
35  executed_(false)
36 {
37  if(inputRootFiles_.size() == 0)
38  throw cms::Exception("Configuration") << "No input ROOT file given";
39 
40  std::string DBName(_ps.getUntrackedParameter<std::string>("DBName"));
41  std::string hostName(_ps.getUntrackedParameter<std::string>("hostName"));
42  int hostPort(_ps.getUntrackedParameter<int>("hostPort"));
43  std::string userName(_ps.getUntrackedParameter<std::string>("userName"));
44  std::string password(_ps.getUntrackedParameter<std::string>("password"));
45 
46  std::auto_ptr<EcalCondDBInterface> db(0);
47 
48  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Establishing DB connection";
49 
50  try{
51  db = std::auto_ptr<EcalCondDBInterface>(new EcalCondDBInterface(DBName, userName, password));
52  }
53  catch(std::runtime_error& re){
54  if(hostName != ""){
55  try{
56  db = std::auto_ptr<EcalCondDBInterface>(new EcalCondDBInterface(hostName, DBName, userName, password, hostPort));
57  }
58  catch(std::runtime_error& re2){
59  throw cms::Exception("DBError") << re2.what();
60  }
61  }
62  else
63  throw cms::Exception("DBError") << re.what();
64  }
65 
66  db_ = db.release();
67 
68  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
69 
70  edm::ParameterSet const& workerParams(_ps.getUntrackedParameterSet("workerParams"));
71 
72  workers_[Integrity] = new ecaldqm::IntegrityWriter(workerParams);
73  workers_[Cosmic] = 0;
74  workers_[Laser] = new ecaldqm::LaserWriter(workerParams);
75  workers_[Pedestal] = new ecaldqm::PedestalWriter(workerParams);
76  workers_[Presample] = new ecaldqm::PresampleWriter(workerParams);
77  workers_[TestPulse] = new ecaldqm::TestPulseWriter(workerParams);
78  workers_[BeamCalo] = 0;
79  workers_[BeamHodo] = 0;
80  workers_[TriggerPrimitives] = 0;
81  workers_[Cluster] = 0;
82  workers_[Timing] = new ecaldqm::TimingWriter(workerParams);
83  workers_[Led] = new ecaldqm::LedWriter(workerParams);
84  workers_[RawData] = 0;
85  workers_[Occupancy] = new ecaldqm::OccupancyWriter(workerParams);
86 
87  for(unsigned iC(0); iC < nTasks; ++iC)
88  if(workers_[iC]) workers_[iC]->setVerbosity(verbosity_);
89 }
90 
92 {
93  try{
94  delete db_;
95  }
96  catch(std::runtime_error& e){
97  throw cms::Exception("DBError") << e.what();
98  }
99 
100  for(unsigned iC(0); iC < nTasks; ++iC)
101  delete workers_[iC];
102 }
103 
104 void
106 {
107  if(executed_) return;
108 
110 
111  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Initializing DQMStore from input ROOT files";
112 
113  DQMStore& dqmStore(*edm::Service<DQMStore>());
114 
115  int runNumber(0);
116 
117  for(unsigned iF(0); iF < inputRootFiles_.size(); ++iF){
119 
120  if(verbosity_ > 1) edm::LogInfo("EcalDQM") << " " << fileName;
121 
122  TPRegexp pat("DQM_V[0-9]+(?:|_[0-9a-zA-Z]+)_R([0-9]+)");
123  std::auto_ptr<TObjArray> matches(pat.MatchS(fileName.c_str()));
124  if(matches->GetEntries() == 0)
125  throw cms::Exception("Configuration") << "Input file " << fileName << " is not an DQM output";
126 
127  if(iF == 0)
128  runNumber = TString(matches->At(1)->GetName()).Atoi();
129  else if(TString(matches->At(1)->GetName()).Atoi() != runNumber)
130  throw cms::Exception("Configuration") << "Input files disagree in run number";
131 
132  dqmStore.open(fileName, false, "", "", DQMStore::StripRunDirs);
133  }
134 
135  if(verbosity_ > 1) edm::LogInfo("EcalDQM") << " Searching event info";
136 
137  uint64_t timeStampInFile(0);
138  unsigned processedEvents(0);
139 
140  dqmStore.cd();
141  std::vector<std::string> dirs(dqmStore.getSubdirs());
142  for(unsigned iD(0); iD < dirs.size(); ++iD){
143  if(!dqmStore.dirExists(dirs[iD] + "/EventInfo")) continue;
144 
145  MonitorElement* timeStampME(dqmStore.get(dirs[iD] + "/EventInfo/runStartTimeStamp"));
146  if(timeStampME){
147  double timeStampValue(timeStampME->getFloatValue());
148  uint64_t seconds(timeStampValue);
149  uint64_t microseconds((timeStampValue - seconds) * 1.e6);
150  timeStampInFile = (seconds << 32) | microseconds;
151  }
152 
153  MonitorElement* eventsME(dqmStore.get(dirs[iD] + "/EventInfo/processedEvents"));
154  if(eventsME)
155  processedEvents = eventsME->getIntValue();
156 
157  if(timeStampInFile != 0 && processedEvents != 0){
158  if(verbosity_ > 1) edm::LogInfo("EcalDQM") << " Event info found; timestamp=" << timeStampInFile << " processedEvents=" << processedEvents;
159  break;
160  }
161  }
162 
163  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
164 
166 
167  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Setting up source MonitorElements for given run type " << runType_;
168 
169  int taskList(0);
170  for(unsigned iC(0); iC < nTasks; ++iC){
171  if(!workers_[iC] || !workers_[iC]->runsOn(runType_)) continue;
172 
173  workers_[iC]->retrieveSource(dqmStore);
174 
175  setBit(taskList, iC);
176  }
177 
178  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
179 
181 
182  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Initializing DB entry";
183 
184  RunIOV runIOV;
185  RunTag runTag;
186  try{
187  runIOV = db_->fetchRunIOV(location_, runNumber);
188  runTag = runIOV.getRunTag();
189  }
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  }
212  catch(std::runtime_error& e){
213  throw cms::Exception("DBError") << e.what();
214  }
215  }
216 
217  // No filtering - DAQ definitions change time to time..
218 // if(runType_ != runIOV.getRunTag().getRunTypeDef().getRunType())
219 // throw cms::Exception("Configuration") << "Given run type " << runType_ << " does not match the run type in DB " << runIOV.getRunTag().getRunTypeDef().getRunType();
220 
221  MonVersionDef versionDef;
222  versionDef.setMonitoringVersion("test01"); // the only mon_ver in mon_version_def table as of September 2012
223  MonRunTag monTag;
224  monTag.setMonVersionDef(versionDef);
226 
227  MonRunIOV monIOV;
228 
229  try{
230  monIOV = db_->fetchMonRunIOV(&runTag, &monTag, runNumber, 1);
231  }
232  catch(std::runtime_error& e){
233  std::cerr << e.what();
234 
235  monIOV.setRunIOV(runIOV);
236  monIOV.setSubRunNumber(1);
237  monIOV.setSubRunStart(runIOV.getRunStart());
238  monIOV.setSubRunEnd(runIOV.getRunEnd());
239  monIOV.setMonRunTag(monTag);
240 
241  try{
242  db_->insertMonRunIOV(&monIOV);
243  monIOV = db_->fetchMonRunIOV(&runTag, &monTag, runNumber, 1);
244  }
245  catch(std::runtime_error& e){
246  throw cms::Exception("DBError") << e.what();
247  }
248  }
249 
250  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
251 
253 
254  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Writing to DB";
255 
256  int outcome(0);
257  for(unsigned iC(0); iC < nTasks; ++iC){
258  if(!getBit(taskList, iC)) continue;
259 
260  if(verbosity_ > 1) edm::LogInfo("EcalDQM") << " " << workers_[iC]->getName();
261 
262  if(workers_[iC]->isActive() && workers_[iC]->run(db_, monIOV)) setBit(outcome, iC);
263  }
264 
265  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
266 
267  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Registering the outcome of DB writing";
268 
269  summaryWriter_.setTaskList(taskList);
270  summaryWriter_.setOutcome(outcome);
271  summaryWriter_.setProcessedEvents(processedEvents);
272  summaryWriter_.run(db_, monIOV);
273 
274  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
275 
276  executed_ = true;
277 }
278 
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
bool run(EcalCondDBInterface *, MonRunIOV &) override
double seconds()
void insertRunIOV(RunIOV *iov)
std::vector< std::string > getSubdirs(void) const
Definition: DQMStore.cc:1644
EcalCondDBWriter(edm::ParameterSet const &)
std::string location_
void cd(void)
go to top directory (ie. root)
Definition: DQMStore.cc:632
#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)
tuple db
Definition: EcalCondDB.py:151
RunIOV fetchRunIOV(RunTag *tag, run_t run)
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
virtual void retrieveSource(DQMStore const &)
void setRunNumber(run_t run)
Definition: RunIOV.cc:29
RunTag getRunTag() const
Definition: RunIOV.cc:96
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 analyze(edm::Event const &, edm::EventSetup const &)
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
void setSubRunStart(const Tm &start)
Definition: MonRunIOV.cc:84
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1693
void setLocationDef(const LocationDef &locDef)
Definition: RunTag.cc:53
void setBit(int &_bitArray, unsigned _iBit)
std::vector< std::string > inputRootFiles_
bool dirExists(const std::string &path) const
true if directory exists
Definition: DQMStore.cc:720
unsigned long long uint64_t
Definition: Time.h:15
void setRunType(std::string runtype)
Definition: RunTypeDef.cc:33
int64_t getIntValue(void) const
Tm getRunEnd() const
Definition: RunIOV.cc:79
void setMonRunTag(const MonRunTag &tag)
Definition: MonRunIOV.cc:36
MonRunIOV fetchMonRunIOV(RunTag *runtag, MonRunTag *montag, run_t run, subrun_t monrun)
void setMonitoringVersion(std::string ver)
std::string const & getName() const
void insertMonRunIOV(MonRunIOV *iov)
ecaldqm::DBWriterWorker * workers_[nTasks]
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:2840
void setLocation(std::string loc)
Definition: LocationDef.cc:33
ecaldqm::SummaryWriter summaryWriter_
volatile std::atomic< bool > shutdown_flag false
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_