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 "Geometry/Records/interface/IdealGeometryRecord.h"
0012 #include "DetectorDescription/Core/interface/DDCompactView.h"
0013 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0014 #include "Geometry/GEMGeometryBuilder/interface/ME0GeometryParsFromDD.h"
0015 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0016 #include "Geometry/Records/interface/ME0RecoGeometryRcd.h"
0017 #include "Geometry/Records/interface/MuonNumberingRecord.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0020 
0021 class ME0RecoIdealDBLoader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0022 public:
0023   ME0RecoIdealDBLoader(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 ME0RecoIdealDBLoader::ME0RecoIdealDBLoader(const edm::ParameterSet& iC) {
0037   fromDD4hep_ = iC.getUntrackedParameter<bool>("fromDD4hep", false);  // set true for DD4hep
0038   dd4HepCompactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0039   compactViewToken_ = esConsumes<edm::Transition::BeginRun>();
0040   muonGeomConstantsToken_ = esConsumes<edm::Transition::BeginRun>();
0041 }
0042 
0043 void ME0RecoIdealDBLoader::beginRun(const edm::Run&, edm::EventSetup const& es) {
0044   edm::LogInfo("ME0RecoIdealDBLoader") << "ME0RecoIdealDBLoader::beginRun";
0045 
0046   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0047   if (!mydbservice.isAvailable()) {
0048     edm::LogError("ME0RecoIdealDBLoader") << "PoolDBOutputService unavailable";
0049     return;
0050   }
0051 
0052   if (mydbservice->isNewTagRequest("ME0RecoGeometryRcd")) {
0053     auto pMNDC = es.getHandle(muonGeomConstantsToken_);
0054     ME0GeometryParsFromDD me0pd;
0055     RecoIdealGeometry rig;
0056     if (fromDD4hep_) {
0057       edm::LogVerbatim("ME0RecoIdealDBLoader") << "(0) ME0RecoIdealDBLoader - DD4hep ";
0058       auto pDD = es.getTransientHandle(dd4HepCompactViewToken_);
0059       const cms::DDCompactView& cpv = *pDD;
0060       me0pd.build(&cpv, *pMNDC, rig);
0061     } else {
0062       edm::LogVerbatim("ME0RecoIdealDBLoader") << "(0) ME0RecoIdealDBLoader - DDD ";
0063       auto pDD = es.getTransientHandle(compactViewToken_);
0064       const DDCompactView& cpv = *pDD;
0065       me0pd.build(&cpv, *pMNDC, rig);
0066     }
0067     mydbservice->createOneIOV(rig, mydbservice->beginOfTime(), "ME0RecoGeometryRcd");
0068   } else {
0069     edm::LogError("ME0RecoIdealDBLoader") << "ME0RecoGeometryRcd Tag is already present";
0070   }
0071 }
0072 
0073 DEFINE_FWK_MODULE(ME0RecoIdealDBLoader);