CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalCondDBReader.cc
Go to the documentation of this file.
1 #include "../interface/EcalCondDBReader.h"
2 
5 
8 
10  db_(0),
11  monIOV_(),
12  worker_(0),
13  formula_(_ps.getUntrackedParameter<std::string>("formula")),
14  meSet_(ecaldqm::createMESet(_ps.getUntrackedParameterSet("plot"))),
15  verbosity_(_ps.getUntrackedParameter<int>("verbosity")),
16  executed_(false)
17 {
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 
54 
55  std::string DBName(_ps.getUntrackedParameter<std::string>("DBName"));
56  std::string hostName(_ps.getUntrackedParameter<std::string>("hostName"));
57  int hostPort(_ps.getUntrackedParameter<int>("hostPort"));
58  std::string userName(_ps.getUntrackedParameter<std::string>("userName"));
59  std::string password(_ps.getUntrackedParameter<std::string>("password"));
60 
61  std::auto_ptr<EcalCondDBInterface> db(0);
62 
63  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Establishing DB connection";
64 
65  try{
66  db = std::auto_ptr<EcalCondDBInterface>(new EcalCondDBInterface(DBName, userName, password));
67  }
68  catch(std::runtime_error& re){
69  if(hostName != ""){
70  try{
71  db = std::auto_ptr<EcalCondDBInterface>(new EcalCondDBInterface(hostName, DBName, userName, password, hostPort));
72  }
73  catch(std::runtime_error& re2){
74  throw cms::Exception("DBError") << re2.what();
75  }
76  }
77  else
78  throw cms::Exception("DBError") << re.what();
79  }
80 
81  db_ = db.release();
82 
83  std::string location(_ps.getUntrackedParameter<std::string>("location"));
84  int runNumber(_ps.getUntrackedParameter<int>("runNumber"));
85  std::string monRunGeneralTag(_ps.getUntrackedParameter<std::string>("monRunGeneralTag"));
86 
87  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << "Initializing DB entry";
88 
89  RunTag runTag;
90 
91  try{
92  runTag = db_->fetchRunIOV(location, runNumber).getRunTag();
93  }
94  catch(std::exception&){
95  edm::LogError("EcalDQM") << "Cannot fetch RunIOV for location=" << location << " runNumber=" << runNumber;
96  throw;
97  }
98 
99  MonVersionDef versionDef;
100  versionDef.setMonitoringVersion("test01"); // the only mon_ver in mon_version_def table as of September 2012
101  MonRunTag monTag;
102  monTag.setMonVersionDef(versionDef);
103  monTag.setGeneralTag(monRunGeneralTag);
104 
105  try{
106  monIOV_ = db_->fetchMonRunIOV(&runTag, &monTag, runNumber, 1);
107  }
108  catch(std::runtime_error& e){
109  edm::LogError("EcalDQM") << "Cannot fetch MonRunIOV for location=" << location << " runNumber=" << runNumber << " monVersion=test01 monRunGeneralTag=" << monRunGeneralTag;
110  throw;
111  }
112 
113  if(verbosity_ > 0) edm::LogInfo("EcalDQM") << " Done.";
114 }
115 
117 {
118  delete worker_;
119  delete meSet_;
120 }
121 
122 void
124 {
125  if(executed_) return;
126 
127  std::map<DetId, double> values(worker_->run(db_, monIOV_, formula_));
128  for(std::map<DetId, double>::const_iterator vItr(values.begin()); vItr != values.end(); ++vItr)
129  meSet_->setBinContent(vItr->first, vItr->second);
130 
131  executed_ = true;
132 }
T getUntrackedParameter(std::string const &, T const &) const
ecaldqm::MESet * meSet_
ecaldqm::DBReaderWorker * worker_
Definition: RunTag.h:13
tuple db
Definition: EcalCondDB.py:151
RunIOV fetchRunIOV(RunTag *tag, run_t run)
ParameterSet getUntrackedParameterSet(std::string const &name, ParameterSet const &defaultValue) const
EcalCondDBInterface * db_
virtual void setBinContent(DetId const &, double)
Definition: MESet.h:52
void setGeneralTag(std::string tag)
Definition: MonRunTag.cc:33
RunTag getRunTag() const
Definition: RunIOV.cc:96
virtual void book(DQMStore &)
Definition: MESet.h:42
void analyze(edm::Event const &, edm::EventSetup const &)
void setMonVersionDef(const MonVersionDef &ver)
Definition: MonRunTag.cc:49
#define table(NAME)
Definition: DbCore.h:49
std::string formula_
MonRunIOV fetchMonRunIOV(RunTag *runtag, MonRunTag *montag, run_t run, subrun_t monrun)
void setMonitoringVersion(std::string ver)
EcalCondDBReader(edm::ParameterSet const &)
volatile std::atomic< bool > shutdown_flag false
virtual std::map< DetId, double > run(EcalCondDBInterface *, MonRunIOV &, std::string const &)=0
MESet * createMESet(edm::ParameterSet const &)
Definition: MESetUtils.cc:19