Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:45

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