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