Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-25 03:29:19

0001 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0002 #include "FWCore/ServiceRegistry/interface/Service.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0004 #include "FWCore/Framework/interface/Event.h"
0005 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ESTransientHandle.h"
0008 #include "FWCore/Framework/interface/ESHandle.h"
0009 #include "FWCore/Framework/interface/MakerMacros.h"
0010 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
0011 #include "Geometry/Records/interface/RPCRecoGeometryRcd.h"
0012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0013 #include "DetectorDescription/Core/interface/DDCompactView.h"
0014 #include "Geometry/Records/interface/MuonNumberingRecord.h"
0015 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0016 #include "Geometry/RPCGeometryBuilder/interface/RPCGeometryParsFromDD.h"
0017 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0018 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 
0021 class RPCRecoIdealDBLoader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0022 public:
0023   RPCRecoIdealDBLoader(const edm::ParameterSet&);
0024 
0025   void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override;
0026   void analyze(edm::Event const& iEvent, edm::EventSetup const&) override {}
0027   void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
0028 
0029 private:
0030   bool fromDD4hep_;
0031   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4HepCompactViewToken_;
0032   edm::ESGetToken<DDCompactView, IdealGeometryRecord> compactViewToken_;
0033   edm::ESGetToken<MuonGeometryConstants, IdealGeometryRecord> muonGeomConstantsToken_;
0034 };
0035 
0036 RPCRecoIdealDBLoader::RPCRecoIdealDBLoader(const edm::ParameterSet& iC) {
0037   fromDD4hep_ = iC.getUntrackedParameter<bool>("fromDD4hep", false);
0038   dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0039   compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0040   muonGeomConstantsToken_ = esConsumes<edm::Transition::BeginRun>();
0041 }
0042 
0043 void RPCRecoIdealDBLoader::beginRun(const edm::Run&, edm::EventSetup const& es) {
0044   RecoIdealGeometry rig;
0045   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0046   if (!mydbservice.isAvailable()) {
0047     edm::LogError("RPCRecoIdealDBLoader") << "PoolDBOutputService unavailable";
0048     return;
0049   }
0050 
0051   auto pMNDC = es.getHandle(muonGeomConstantsToken_);
0052   RPCGeometryParsFromDD rpcpd;
0053 
0054   if (fromDD4hep_) {
0055     auto pDD = es.getTransientHandle(dd4HepCompactViewToken_);
0056     const cms::DDCompactView& cpv = *pDD;
0057     rpcpd.build(&cpv, *pMNDC, rig);
0058   } else {
0059     auto pDD = es.getTransientHandle(compactViewToken_);
0060     const DDCompactView& cpv = *pDD;
0061     rpcpd.build(&cpv, *pMNDC, rig);
0062   }
0063   if (mydbservice->isNewTagRequest("RPCRecoGeometryRcd")) {
0064     mydbservice->createOneIOV(rig, mydbservice->beginOfTime(), "RPCRecoGeometryRcd");
0065   } else {
0066     edm::LogError("RPCRecoIdealDBLoader") << "RPCRecoGeometryRcd Tag is already present.";
0067   }
0068 }
0069 
0070 DEFINE_FWK_MODULE(RPCRecoIdealDBLoader);