Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-09 23:32:01

0001 /*
0002 //\class RPCGeometryESModule
0003 
0004 Description: RPC GeometryESModule from DD & DD4hep
0005 DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
0006 //
0007 // Author:  Sergio Lo Meo (sergio.lo.meo@cern.ch) following what Ianna Osborne made for DTs (DD4hep migration)
0008 //          Created:  Fri, 20 Sep 2019 
0009 //          Modified: Fri, 29 May 2020, following what Sunanda Banerjee made in PR #29842 PR #29943 and Ianna Osborne in PR #29954      
0010 */
0011 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
0012 #include "DetectorDescription/Core/interface/DDCompactView.h"
0013 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0014 #include "FWCore/Framework/interface/ESProducer.h"
0015 #include "FWCore/Framework/interface/EventSetup.h"
0016 #include "FWCore/Framework/interface/ESTransientHandle.h"
0017 #include "FWCore/Framework/interface/ModuleFactory.h"
0018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0020 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0021 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0022 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0023 #include "Geometry/Records/interface/RPCRecoGeometryRcd.h"
0024 #include "Geometry/RPCGeometryBuilder/src/RPCGeometryBuilder.h"
0025 #include "Geometry/RPCGeometryBuilder/src/RPCGeometryBuilderFromCondDB.h"
0026 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
0027 #include <unordered_map>
0028 #include <memory>
0029 
0030 class RPCGeometryESModule : public edm::ESProducer {
0031 public:
0032   RPCGeometryESModule(const edm::ParameterSet& p);
0033 
0034   static void fillDescriptions(edm::ConfigurationDescriptions&);
0035 
0036   std::unique_ptr<RPCGeometry> produce(const MuonGeometryRecord& record);
0037 
0038 private:
0039   //DDD
0040   edm::ESGetToken<DDCompactView, IdealGeometryRecord> idealGeomToken_;
0041   edm::ESGetToken<MuonGeometryConstants, IdealGeometryRecord> dddConstantsToken_;
0042   // dd4hep
0043   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> idealDD4hepGeomToken_;
0044   // Reco
0045   edm::ESGetToken<RecoIdealGeometry, RPCRecoGeometryRcd> recoIdealToken_;
0046 
0047   const bool fromDDD_;
0048   const bool fromDD4hep_;
0049 };
0050 
0051 RPCGeometryESModule::RPCGeometryESModule(const edm::ParameterSet& p)
0052     : fromDDD_{p.getUntrackedParameter<bool>("fromDDD", true)},
0053       fromDD4hep_{p.getUntrackedParameter<bool>("fromDD4hep", false)} {
0054   auto cc = setWhatProduced(this);
0055 
0056   if (fromDDD_) {
0057     idealGeomToken_ = cc.consumes();
0058     dddConstantsToken_ = cc.consumes();
0059   } else if (fromDD4hep_) {
0060     idealDD4hepGeomToken_ = cc.consumes();
0061     dddConstantsToken_ = cc.consumes();
0062   } else {
0063     recoIdealToken_ = cc.consumes();
0064   }
0065 }
0066 
0067 void RPCGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0068   edm::ParameterSetDescription desc;
0069   desc.addUntracked<bool>("fromDDD", true);
0070   desc.addUntracked<bool>("fromDD4hep", false);
0071   descriptions.add("RPCGeometryESModule", desc);
0072 }
0073 
0074 std::unique_ptr<RPCGeometry> RPCGeometryESModule::produce(const MuonGeometryRecord& record) {
0075   if (fromDDD_) {
0076     edm::LogVerbatim("RPCGeoemtryESModule") << "(0) RPCGeometryESModule  - DDD ";
0077     edm::ESTransientHandle<DDCompactView> cpv = record.getTransientHandle(idealGeomToken_);
0078     auto const& mdc = record.get(dddConstantsToken_);
0079     RPCGeometryBuilder builder;
0080     return std::unique_ptr<RPCGeometry>(builder.build(&(*cpv), mdc));
0081   } else if (fromDD4hep_) {
0082     edm::LogVerbatim("RPCGeoemtryESModule") << "(0) RPCGeometryESModule  - DD4hep ";
0083     edm::ESTransientHandle<cms::DDCompactView> cpv = record.getTransientHandle(idealDD4hepGeomToken_);
0084     auto const& mdc = record.get(dddConstantsToken_);
0085     RPCGeometryBuilder builder;
0086     return std::unique_ptr<RPCGeometry>(builder.build(&(*cpv), mdc));
0087   } else {
0088     edm::LogVerbatim("RPCGeoemtryESModule") << "(0) RPCGeometryESModule  - DB ";
0089     auto const& rigrpc = record.get(recoIdealToken_);
0090     RPCGeometryBuilderFromCondDB builder;
0091     return std::unique_ptr<RPCGeometry>(builder.build(rigrpc));
0092   }
0093 }
0094 
0095 DEFINE_FWK_EVENTSETUP_MODULE(RPCGeometryESModule);