Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:07:18

0001 #include <memory>
0002 
0003 #include "DQM/EcalMonitorDbModule/interface/EcalCondDBReader.h"
0004 
0005 #include "DQM/EcalCommon/interface/MESetUtils.h"
0006 #include "DQMServices/Core/interface/DQMStore.h"
0007 
0008 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0009 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0010 #include "FWCore/ServiceRegistry/interface/Service.h"
0011 
0012 EcalCondDBReader::EcalCondDBReader(edm::ParameterSet const &_ps)
0013     : db_(nullptr),
0014       monIOV_(),
0015       worker_(nullptr),
0016       formula_(_ps.getUntrackedParameter<std::string>("formula")),
0017       meSet_(ecaldqm::createMESet(_ps.getUntrackedParameterSet("plot"))),
0018       verbosity_(_ps.getUntrackedParameter<int>("verbosity")),
0019       elecMapHandle(esConsumes<edm::Transition::EndRun>()) {
0020   std::string table(_ps.getUntrackedParameter<std::string>("table"));
0021   edm::ParameterSet const &workerParams(_ps.getUntrackedParameterSet("workerParams"));
0022 
0023   if (table == "CrystalConsistency")
0024     worker_ = new ecaldqm::CrystalConsistencyReader(workerParams);
0025   if (table == "TTConsistency")
0026     worker_ = new ecaldqm::TTConsistencyReader(workerParams);
0027   if (table == "MemChConsistency")
0028     worker_ = new ecaldqm::MemChConsistencyReader(workerParams);
0029   if (table == "MemTTConsistency")
0030     worker_ = new ecaldqm::MemTTConsistencyReader(workerParams);
0031   if (table == "LaserBlue")
0032     worker_ = new ecaldqm::LaserBlueReader(workerParams);
0033   if (table == "TimingLaserBlueCrystal")
0034     worker_ = new ecaldqm::TimingLaserBlueCrystalReader(workerParams);
0035   if (table == "PNBlue")
0036     worker_ = new ecaldqm::PNBlueReader(workerParams);
0037   if (table == "LaserGreen")
0038     worker_ = new ecaldqm::LaserGreenReader(workerParams);
0039   if (table == "TimingLaserGreenCrystal")
0040     worker_ = new ecaldqm::TimingLaserGreenCrystalReader(workerParams);
0041   if (table == "PNGreen")
0042     worker_ = new ecaldqm::PNGreenReader(workerParams);
0043   if (table == "LaserIRed")
0044     worker_ = new ecaldqm::LaserIRedReader(workerParams);
0045   if (table == "TimingLaserIRedCrystal")
0046     worker_ = new ecaldqm::TimingLaserIRedCrystalReader(workerParams);
0047   if (table == "PNIRed")
0048     worker_ = new ecaldqm::PNIRedReader(workerParams);
0049   if (table == "LaserRed")
0050     worker_ = new ecaldqm::LaserRedReader(workerParams);
0051   if (table == "TimingLaserRedCrystal")
0052     worker_ = new ecaldqm::TimingLaserRedCrystalReader(workerParams);
0053   if (table == "PNRed")
0054     worker_ = new ecaldqm::PNRedReader(workerParams);
0055   if (table == "Pedestals")
0056     worker_ = new ecaldqm::PedestalsReader(workerParams);
0057   if (table == "PNPed")
0058     worker_ = new ecaldqm::PNPedReader(workerParams);
0059   if (table == "PedestalsOnline")
0060     worker_ = new ecaldqm::PedestalsOnlineReader(workerParams);
0061   if (table == "TestPulse")
0062     worker_ = new ecaldqm::TestPulseReader(workerParams);
0063   if (table == "PulseShape")
0064     worker_ = new ecaldqm::PulseShapeReader(workerParams);
0065   if (table == "PNMGPA")
0066     worker_ = new ecaldqm::PNMGPAReader(workerParams);
0067   if (table == "TimingCrystal")
0068     worker_ = new ecaldqm::TimingCrystalReader(workerParams);
0069   if (table == "Led1")
0070     worker_ = new ecaldqm::Led1Reader(workerParams);
0071   if (table == "TimingLed1Crystal")
0072     worker_ = new ecaldqm::TimingLed1CrystalReader(workerParams);
0073   if (table == "Led2")
0074     worker_ = new ecaldqm::Led2Reader(workerParams);
0075   if (table == "TimingLed2Crystal")
0076     worker_ = new ecaldqm::TimingLed2CrystalReader(workerParams);
0077   if (table == "Occupancy")
0078     worker_ = new ecaldqm::OccupancyReader(workerParams);
0079 
0080   if (!worker_)
0081     throw cms::Exception("Configuration") << "Invalid worker type";
0082 
0083   std::string DBName(_ps.getUntrackedParameter<std::string>("DBName"));
0084   std::string hostName(_ps.getUntrackedParameter<std::string>("hostName"));
0085   int hostPort(_ps.getUntrackedParameter<int>("hostPort"));
0086   std::string userName(_ps.getUntrackedParameter<std::string>("userName"));
0087   std::string password(_ps.getUntrackedParameter<std::string>("password"));
0088 
0089   std::unique_ptr<EcalCondDBInterface> db(nullptr);
0090 
0091   if (verbosity_ > 0)
0092     edm::LogInfo("EcalDQM") << "Establishing DB connection";
0093 
0094   try {
0095     db = std::make_unique<EcalCondDBInterface>(DBName, userName, password);
0096   } catch (std::runtime_error &re) {
0097     if (!hostName.empty()) {
0098       try {
0099         db = std::make_unique<EcalCondDBInterface>(hostName, DBName, userName, password, hostPort);
0100       } catch (std::runtime_error &re2) {
0101         throw cms::Exception("DBError") << re2.what();
0102       }
0103     } else
0104       throw cms::Exception("DBError") << re.what();
0105   }
0106 
0107   db_ = db.release();
0108 
0109   std::string location(_ps.getUntrackedParameter<std::string>("location"));
0110   int runNumber(_ps.getUntrackedParameter<int>("runNumber"));
0111   std::string monRunGeneralTag(_ps.getUntrackedParameter<std::string>("monRunGeneralTag"));
0112 
0113   if (verbosity_ > 0)
0114     edm::LogInfo("EcalDQM") << "Initializing DB entry";
0115 
0116   RunTag runTag;
0117 
0118   try {
0119     runTag = db_->fetchRunIOV(location, runNumber).getRunTag();
0120   } catch (std::exception &) {
0121     edm::LogError("EcalDQM") << "Cannot fetch RunIOV for location=" << location << " runNumber=" << runNumber;
0122     throw;
0123   }
0124 
0125   MonVersionDef versionDef;
0126   versionDef.setMonitoringVersion("test01");  // the only mon_ver in mon_version_def table as of September
0127                                               // 2012
0128   MonRunTag monTag;
0129   monTag.setMonVersionDef(versionDef);
0130   monTag.setGeneralTag(monRunGeneralTag);
0131 
0132   try {
0133     monIOV_ = db_->fetchMonRunIOV(&runTag, &monTag, runNumber, 1);
0134   } catch (std::runtime_error &e) {
0135     edm::LogError("EcalDQM") << "Cannot fetch MonRunIOV for location=" << location << " runNumber=" << runNumber
0136                              << " monVersion=test01 monRunGeneralTag=" << monRunGeneralTag;
0137     throw;
0138   }
0139 
0140   if (verbosity_ > 0)
0141     edm::LogInfo("EcalDQM") << " Done.";
0142 }
0143 
0144 EcalCondDBReader::~EcalCondDBReader() {
0145   delete worker_;
0146   delete meSet_;
0147 }
0148 
0149 void EcalCondDBReader::dqmEndRun(DQMStore::IBooker &_ibooker,
0150                                  DQMStore::IGetter &,
0151                                  edm::Run const &,
0152                                  edm::EventSetup const &_es) {
0153   setElectronicsMap(_es);
0154   meSet_->book(_ibooker, GetElectronicsMap());
0155 
0156   std::map<DetId, double> values(worker_->run(db_, monIOV_, formula_));
0157   for (std::map<DetId, double>::const_iterator vItr(values.begin()); vItr != values.end(); ++vItr)
0158     meSet_->setBinContent(getEcalDQMSetupObjects(), vItr->first, vItr->second);
0159 }
0160 
0161 void EcalCondDBReader::setElectronicsMap(edm::EventSetup const &_es) { electronicsMap = &_es.getData(elecMapHandle); }
0162 
0163 EcalElectronicsMapping const *EcalCondDBReader::GetElectronicsMap() {
0164   if (!electronicsMap)
0165     throw cms::Exception("InvalidCall") << "Electronics Mapping not initialized";
0166   return electronicsMap;
0167 }
0168 
0169 ecaldqm::EcalDQMSetupObjects const EcalCondDBReader::getEcalDQMSetupObjects() {
0170   if (!electronicsMap)
0171     throw cms::Exception("InvalidCall") << "Electronics Mapping not initialized";
0172   ecaldqm::EcalDQMSetupObjects edso = {electronicsMap, nullptr, nullptr, nullptr};
0173   return edso;
0174 }