Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "DQM/EcalMonitorDbModule/interface/EcalDQMStatusWriter.h"
0002 
0003 #include "DQM/EcalCommon/interface/StatusManager.h"
0004 
0005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 
0008 #include "FWCore/Utilities/interface/Exception.h"
0009 
0010 #include "FWCore/Framework/interface/MakerMacros.h"
0011 
0012 EcalDQMStatusWriter::EcalDQMStatusWriter(edm::ParameterSet const &_ps)
0013     : channelStatus_(),
0014       towerStatus_(),
0015       firstRun_(_ps.getUntrackedParameter<unsigned>("firstRun")),
0016       inputFile_(_ps.getUntrackedParameter<std::string>("inputFile")),
0017       electronicsMap_(nullptr),
0018       elecMapHandle_(esConsumes<edm::Transition::BeginRun>()) {
0019   if (!inputFile_.is_open())
0020     throw cms::Exception("Invalid input for EcalDQMStatusWriter");
0021 }
0022 
0023 void EcalDQMStatusWriter::beginRun(edm::Run const &_run, edm::EventSetup const &_es) {
0024   setElectronicsMap(_es);
0025 
0026   ecaldqm::StatusManager statusManager;
0027 
0028   statusManager.readFromStream(inputFile_, GetElectronicsMap());
0029   statusManager.writeToObj(channelStatus_, towerStatus_);
0030 }
0031 
0032 void EcalDQMStatusWriter::endRun(edm::Run const &_run, edm::EventSetup const &_es) {}
0033 
0034 void EcalDQMStatusWriter::analyze(edm::Event const &, edm::EventSetup const &_es) {
0035   cond::service::PoolDBOutputService &dbOutput(*edm::Service<cond::service::PoolDBOutputService>());
0036   if (firstRun_ == dbOutput.endOfTime())
0037     return;
0038 
0039   dbOutput.writeOneIOV(channelStatus_, firstRun_, "EcalDQMChannelStatusRcd");
0040   dbOutput.writeOneIOV(towerStatus_, firstRun_, "EcalDQMTowerStatusRcd");
0041 
0042   firstRun_ = dbOutput.endOfTime();  // avoid accidentally re-writing the conditions
0043 }
0044 
0045 void EcalDQMStatusWriter::setElectronicsMap(edm::EventSetup const &_es) {
0046   electronicsMap_ = &_es.getData(elecMapHandle_);
0047 }
0048 
0049 EcalElectronicsMapping const *EcalDQMStatusWriter::GetElectronicsMap() {
0050   if (!electronicsMap_)
0051     throw cms::Exception("InvalidCall") << "Electronics Mapping not initialized";
0052   return electronicsMap_;
0053 }
0054 
0055 DEFINE_FWK_MODULE(EcalDQMStatusWriter);