CMS 3D CMS Logo

EcalCondDBReader.cc
Go to the documentation of this file.
1 #include "../interface/EcalCondDBReader.h"
2 
5 
9 
11  db_(nullptr),
12  monIOV_(),
13  worker_(nullptr),
14  formula_(_ps.getUntrackedParameter<std::string>("formula")),
15  meSet_(ecaldqm::createMESet(_ps.getUntrackedParameterSet("plot"))),
16  verbosity_(_ps.getUntrackedParameter<int>("verbosity"))
17 {
18  std::string table(_ps.getUntrackedParameter<std::string>("table"));
19  edm::ParameterSet const& workerParams(_ps.getUntrackedParameterSet("workerParams"));
20 
21  if(table == "CrystalConsistency") worker_ = new ecaldqm::CrystalConsistencyReader(workerParams);
22  if(table == "TTConsistency") worker_ = new ecaldqm::TTConsistencyReader(workerParams);
23  if(table == "MemChConsistency") worker_ = new ecaldqm::MemChConsistencyReader(workerParams);
24  if(table == "MemTTConsistency") worker_ = new ecaldqm::MemTTConsistencyReader(workerParams);
25  if(table == "LaserBlue") worker_ = new ecaldqm::LaserBlueReader(workerParams);
26  if(table == "TimingLaserBlueCrystal") worker_ = new ecaldqm::TimingLaserBlueCrystalReader(workerParams);
27  if(table == "PNBlue") worker_ = new ecaldqm::PNBlueReader(workerParams);
28  if(table == "LaserGreen") worker_ = new ecaldqm::LaserGreenReader(workerParams);
29  if(table == "TimingLaserGreenCrystal") worker_ = new ecaldqm::TimingLaserGreenCrystalReader(workerParams);
30  if(table == "PNGreen") worker_ = new ecaldqm::PNGreenReader(workerParams);
31  if(table == "LaserIRed") worker_ = new ecaldqm::LaserIRedReader(workerParams);
32  if(table == "TimingLaserIRedCrystal") worker_ = new ecaldqm::TimingLaserIRedCrystalReader(workerParams);
33  if(table == "PNIRed") worker_ = new ecaldqm::PNIRedReader(workerParams);
34  if(table == "LaserRed") worker_ = new ecaldqm::LaserRedReader(workerParams);
35  if(table == "TimingLaserRedCrystal") worker_ = new ecaldqm::TimingLaserRedCrystalReader(workerParams);
36  if(table == "PNRed") worker_ = new ecaldqm::PNRedReader(workerParams);
37  if(table == "Pedestals") worker_ = new ecaldqm::PedestalsReader(workerParams);
38  if(table == "PNPed") worker_ = new ecaldqm::PNPedReader(workerParams);
39  if(table == "PedestalsOnline") worker_ = new ecaldqm::PedestalsOnlineReader(workerParams);
40  if(table == "TestPulse") worker_ = new ecaldqm::TestPulseReader(workerParams);
41  if(table == "PulseShape") worker_ = new ecaldqm::PulseShapeReader(workerParams);
42  if(table == "PNMGPA") worker_ = new ecaldqm::PNMGPAReader(workerParams);
43  if(table == "TimingCrystal") worker_ = new ecaldqm::TimingCrystalReader(workerParams);
44  if(table == "Led1") worker_ = new ecaldqm::Led1Reader(workerParams);
45  if(table == "TimingLed1Crystal") worker_ = new ecaldqm::TimingLed1CrystalReader(workerParams);
46  if(table == "Led2") worker_ = new ecaldqm::Led2Reader(workerParams);
47  if(table == "TimingLed2Crystal") worker_ = new ecaldqm::TimingLed2CrystalReader(workerParams);
48  if(table == "Occupancy") worker_ = new ecaldqm::OccupancyReader(workerParams);
49 
50  if(!worker_)
51  throw cms::Exception("Configuration") << "Invalid worker type";
52 
53  std::string DBName(_ps.getUntrackedParameter<std::string>("DBName"));
54  std::string hostName(_ps.getUntrackedParameter<std::string>("hostName"));
55  int hostPort(_ps.getUntrackedParameter<int>("hostPort"));
56  std::string userName(_ps.getUntrackedParameter<std::string>("userName"));
57  std::string password(_ps.getUntrackedParameter<std::string>("password"));
58 
59  std::auto_ptr<EcalCondDBInterface> db(nullptr);
60 
61  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Establishing DB connection";
62 
63  try{
64  db = std::auto_ptr<EcalCondDBInterface>(new EcalCondDBInterface(DBName, userName, password));
65  }
66  catch(std::runtime_error& re){
67  if(hostName != ""){
68  try{
69  db = std::auto_ptr<EcalCondDBInterface>(new EcalCondDBInterface(hostName, DBName, userName, password, hostPort));
70  }
71  catch(std::runtime_error& re2){
72  throw cms::Exception("DBError") << re2.what();
73  }
74  }
75  else
76  throw cms::Exception("DBError") << re.what();
77  }
78 
79  db_ = db.release();
80 
81  std::string location(_ps.getUntrackedParameter<std::string>("location"));
82  int runNumber(_ps.getUntrackedParameter<int>("runNumber"));
83  std::string monRunGeneralTag(_ps.getUntrackedParameter<std::string>("monRunGeneralTag"));
84 
85  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Initializing DB entry";
86 
87  RunTag runTag;
88 
89  try{
90  runTag = db_->fetchRunIOV(location, runNumber).getRunTag();
91  }
92  catch(std::exception&){
93  edm::LogError("EcalDQM") << "Cannot fetch RunIOV for location=" << location << " runNumber=" << runNumber;
94  throw;
95  }
96 
97  MonVersionDef versionDef;
98  versionDef.setMonitoringVersion("test01"); // the only mon_ver in mon_version_def table as of September 2012
99  MonRunTag monTag;
100  monTag.setMonVersionDef(versionDef);
101  monTag.setGeneralTag(monRunGeneralTag);
102 
103  try{
104  monIOV_ = db_->fetchMonRunIOV(&runTag, &monTag, runNumber, 1);
105  }
106  catch(std::runtime_error& e){
107  edm::LogError("EcalDQM") << "Cannot fetch MonRunIOV for location=" << location << " runNumber=" << runNumber << " monVersion=test01 monRunGeneralTag=" << monRunGeneralTag;
108  throw;
109  }
110 
111  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
112 }
113 
115 {
116  delete worker_;
117  delete meSet_;
118 }
119 
120 void
122 {
123  meSet_->book(_ibooker);
124 
125  std::map<DetId, double> values(worker_->run(db_, monIOV_, formula_));
126  for(std::map<DetId, double>::const_iterator vItr(values.begin()); vItr != values.end(); ++vItr)
127  meSet_->setBinContent(vItr->first, vItr->second);
128 }
T getUntrackedParameter(std::string const &, T const &) const
ecaldqm::MESet * meSet_
MonRunIOV fetchMonRunIOV(RunTag *runtag, MonRunTag *montag, run_t run, subrun_t monrun) noexcept(false)
virtual void book(DQMStore::IBooker &)
Definition: MESet.h:42
ecaldqm::DBReaderWorker * worker_
Definition: RunTag.h:13
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
#define nullptr
EcalCondDBInterface * db_
virtual void setBinContent(DetId const &, double)
Definition: MESet.h:51
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
void dqmEndJob(DQMStore::IBooker &, DQMStore::IGetter &) override
RunTag getRunTag() const
Definition: RunIOV.cc:96
RunIOV fetchRunIOV(RunTag *tag, run_t run) noexcept(false)
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
std::string formula_
void setMonitoringVersion(std::string ver)
EcalCondDBReader(edm::ParameterSet const &)
virtual std::map< DetId, double > run(EcalCondDBInterface *, MonRunIOV &, std::string const &)=0
MESet * createMESet(edm::ParameterSet const &)
Definition: MESetUtils.cc:19