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/EventSetup.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/ESHandle.h"
0005 #include "FWCore/Framework/interface/MakerMacros.h"
0006 #include "FWCore/ServiceRegistry/interface/Service.h"
0007 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
0008 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
0009 #include "CondFormats/GeometryObjects/interface/CSCRecoDigiParameters.h"
0010 #include "Geometry/Records/interface/CSCRecoGeometryRcd.h"
0011 #include "Geometry/Records/interface/CSCRecoDigiParametersRcd.h"
0012 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0013 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0014 #include "Geometry/CSCGeometryBuilder/interface/CSCGeometryParsFromDD.h"
0015 #include "DetectorDescription/Core/interface/DDCompactView.h"
0016 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0017 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0020 
0021 class CSCRecoIdealDBLoader : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
0022 public:
0023   CSCRecoIdealDBLoader(edm::ParameterSet const&);
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 CSCRecoIdealDBLoader::CSCRecoIdealDBLoader(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 CSCRecoIdealDBLoader::beginRun(const edm::Run&, edm::EventSetup const& es) {
0044   edm::LogInfo("CSCRecoIdealDBLoader") << "CSCRecoIdealDBLoader::beginRun";
0045 
0046   RecoIdealGeometry rig;
0047   CSCRecoDigiParameters rdp;
0048   edm::Service<cond::service::PoolDBOutputService> mydbservice;
0049   if (!mydbservice.isAvailable()) {
0050     edm::LogError("CSCRecoIdealDBLoader") << "PoolDBOutputService unavailable";
0051     return;
0052   }
0053 
0054   auto pMNDC = es.getHandle(muonGeomConstantsToken_);
0055   CSCGeometryParsFromDD cscgp;
0056 
0057   if (fromDD4hep_) {
0058     auto pDD = es.getTransientHandle(dd4HepCompactViewToken_);
0059     const cms::DDCompactView& cpv = *pDD;
0060     cscgp.build(&cpv, *pMNDC, rig, rdp);
0061   } else {
0062     auto pDD = es.getTransientHandle(compactViewToken_);
0063     const DDCompactView& cpv = *pDD;
0064     cscgp.build(&cpv, *pMNDC, rig, rdp);
0065   }
0066 
0067   if (mydbservice->isNewTagRequest("CSCRecoGeometryRcd")) {
0068     mydbservice->createOneIOV(rig, mydbservice->beginOfTime(), "CSCRecoGeometryRcd");
0069   } else {
0070     edm::LogError("CSCRecoIdealDBLoader") << "CSCRecoGeometryRcd Tag is already present.";
0071   }
0072   if (mydbservice->isNewTagRequest("CSCRecoDigiParametersRcd")) {
0073     mydbservice->createOneIOV(rdp, mydbservice->beginOfTime(), "CSCRecoDigiParametersRcd");
0074   } else {
0075     edm::LogError("CSCRecoIdealDBLoader") << "CSCRecoDigiParametersRcd Tag is already present.";
0076   }
0077 }
0078 
0079 DEFINE_FWK_MODULE(CSCRecoIdealDBLoader);