Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-06 04:13:45

0001 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0003 #include "FWCore/Framework/interface/ModuleFactory.h"
0004 #include "FWCore/Framework/interface/ESProducer.h"
0005 #include "FWCore/Framework/interface/ESTransientHandle.h"
0006 #include "DetectorDescription/Core/interface/DDCompactView.h"
0007 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0008 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0009 #include "Geometry/MuonNumbering/interface/MuonGeometryConstants.h"
0010 #include "Geometry/MuonNumbering/plugins/MuonGeometryConstantsBuild.h"
0011 
0012 #include <memory>
0013 
0014 //#define EDM_ML_DEBUG
0015 
0016 class MuonGeometryConstantsESModule : public edm::ESProducer {
0017 public:
0018   MuonGeometryConstantsESModule(const edm::ParameterSet&);
0019 
0020   using ReturnType = std::unique_ptr<MuonGeometryConstants>;
0021 
0022   static void fillDescriptions(edm::ConfigurationDescriptions&);
0023 
0024   ReturnType produce(const IdealGeometryRecord&);
0025 
0026 private:
0027   edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
0028   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4hep_;
0029   bool fromDD4hep_;
0030 };
0031 
0032 MuonGeometryConstantsESModule::MuonGeometryConstantsESModule(const edm::ParameterSet& ps) {
0033   fromDD4hep_ = ps.getParameter<bool>("fromDD4hep");
0034   auto cc = setWhatProduced(this);
0035   if (fromDD4hep_)
0036     cpvTokenDD4hep_ = cc.consumesFrom<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0037   else
0038     cpvTokenDDD_ = cc.consumesFrom<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0039 
0040 #ifdef EDM_ML_DEBUG
0041   edm::LogVerbatim("MuonGeom") << "MuonGeometryConstantsESModule::MuonGeometryConstantsESModule called with dd4hep: "
0042                                << fromDD4hep_;
0043 #endif
0044 }
0045 
0046 void MuonGeometryConstantsESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0047   edm::ParameterSetDescription desc;
0048   desc.add<bool>("fromDD4hep", false);
0049   descriptions.add("muonGeometryConstants", desc);
0050 }
0051 
0052 MuonGeometryConstantsESModule::ReturnType MuonGeometryConstantsESModule::produce(const IdealGeometryRecord& iRecord) {
0053   edm::LogInfo("MuonGeom") << "MuonGeometryConstantsESModule::produce(const IdealGeometryRecord& iRecord)";
0054 
0055   auto ptp = std::make_unique<MuonGeometryConstants>();
0056   MuonGeometryConstantsBuild builder;
0057 
0058   if (fromDD4hep_) {
0059 #ifdef EDM_ML_DEBUG
0060     edm::LogVerbatim("MuonGeom") << "MuonGeometryConstantsESModule::Try to access cms::DDCompactView";
0061 #endif
0062     edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDD4hep_);
0063     builder.build(&(*cpv), *ptp);
0064   } else {
0065 #ifdef EDM_ML_DEBUG
0066     edm::LogVerbatim("MuonGeom") << "MuonGeometryConstantsESModule::Try to access DDCompactView";
0067 #endif
0068     edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDDD_);
0069     builder.build(&(*cpv), *ptp);
0070   }
0071 
0072   return ptp;
0073 }
0074 
0075 DEFINE_FWK_EVENTSETUP_MODULE(MuonGeometryConstantsESModule);