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