Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-09 23:31:56

0001 /*
0002 //\class ME0GeometryESModule
0003 
0004  Description: ME0 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:  29 Apr 2020 
0009 */
0010 
0011 #include "Geometry/GEMGeometryBuilder/src/ME0GeometryBuilder.h"
0012 #include "Geometry/GEMGeometryBuilder/src/ME0GeometryBuilderFromCondDB.h"
0013 #include "Geometry/GEMGeometry/interface/ME0Geometry.h"
0014 
0015 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0016 #include "Geometry/Records/interface/ME0RecoGeometryRcd.h"
0017 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0018 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0019 #include "DetectorDescription/Core/interface/DDCompactView.h"
0020 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0021 
0022 #include "CondFormats/GeometryObjects/interface/RecoIdealGeometry.h"
0023 
0024 #include "FWCore/Framework/interface/EventSetup.h"
0025 #include "FWCore/Framework/interface/ESTransientHandle.h"
0026 #include "FWCore/Framework/interface/ModuleFactory.h"
0027 #include "FWCore/Framework/interface/ESProducer.h"
0028 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0029 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0030 
0031 #include <memory>
0032 
0033 class ME0GeometryESModule : public edm::ESProducer {
0034 public:
0035   ME0GeometryESModule(const edm::ParameterSet& p);
0036 
0037   static void fillDescriptions(edm::ConfigurationDescriptions&);
0038 
0039   std::unique_ptr<ME0Geometry> produce(const MuonGeometryRecord& record);
0040 
0041 private:
0042   edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvToken_;
0043   edm::ESGetToken<MuonGeometryConstants, IdealGeometryRecord> mdcToken_;
0044   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepcpvToken_;
0045   edm::ESGetToken<RecoIdealGeometry, ME0RecoGeometryRcd> rigme0Token_;
0046   // use the DDD or DD4hep as Geometry source
0047   bool fromDDD_;
0048   bool fromDD4hep_;
0049 };
0050 
0051 ME0GeometryESModule::ME0GeometryESModule(const edm::ParameterSet& p) {
0052   fromDDD_ = p.getParameter<bool>("fromDDD");
0053   fromDD4hep_ = p.getParameter<bool>("fromDD4hep");
0054   auto cc = setWhatProduced(this);
0055   if (fromDDD_) {
0056     cpvToken_ = cc.consumes();
0057     mdcToken_ = cc.consumes();
0058   } else if (fromDD4hep_) {
0059     dd4hepcpvToken_ = cc.consumes();
0060     mdcToken_ = cc.consumes();
0061   } else {
0062     rigme0Token_ = cc.consumes();
0063   }
0064   edm::LogVerbatim("GEMGeometry") << "ME0GeometryESModule::initailized with flags " << fromDDD_ << ":" << fromDD4hep_;
0065 }
0066 
0067 void ME0GeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0068   edm::ParameterSetDescription desc;
0069   desc.add<bool>("fromDDD", true);
0070   desc.add<bool>("fromDD4hep", false);
0071   descriptions.add("me0Geometry", desc);
0072 }
0073 
0074 std::unique_ptr<ME0Geometry> ME0GeometryESModule::produce(const MuonGeometryRecord& record) {
0075   edm::LogVerbatim("GEMGeometry") << "ME0GeometryESModule::produce with fromDDD = " << fromDDD_ << " fromDD4hep "
0076                                   << fromDD4hep_;
0077   if (fromDDD_) {
0078     edm::LogVerbatim("ME0GeometryESModule") << "(0) ME0GeometryESModule - DDD ";
0079     edm::LogVerbatim("GEMGeometry") << "ME0GeometryESModule::produce :: ME0GeometryBuilder builder";
0080     auto cpv = record.getTransientHandle(cpvToken_);
0081     const auto& mdc = record.get(mdcToken_);
0082     ME0GeometryBuilder builder;
0083     return std::unique_ptr<ME0Geometry>(builder.build(cpv.product(), mdc));
0084   } else if (fromDD4hep_) {
0085     edm::LogVerbatim("ME0GeometryESModule") << "(0) ME0GeometryESModule - DD4hep ";
0086     edm::LogVerbatim("GEMGeometry") << "ME0GeometryESModule::produce :: ME0GeometryBuilder builder DD4hep";
0087     auto cpv = record.getTransientHandle(dd4hepcpvToken_);
0088     const auto& mdc = record.get(mdcToken_);
0089     ME0GeometryBuilder builder;
0090     return std::unique_ptr<ME0Geometry>(builder.build(cpv.product(), mdc));
0091   } else {
0092     edm::LogVerbatim("ME0GeometryESModule") << "(0) ME0GeometryESModule - DB ";
0093     edm::LogVerbatim("GEMGeometry") << "ME0GeometryESModule::produce :: ME0GeometryBuilderFromCondDB builder";
0094     const auto& rigme0 = record.get(rigme0Token_);
0095     ME0GeometryBuilderFromCondDB builder;
0096     return std::unique_ptr<ME0Geometry>(builder.build(rigme0));
0097   }
0098 }
0099 
0100 DEFINE_FWK_EVENTSETUP_MODULE(ME0GeometryESModule);