CMS 3D CMS Logo

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