Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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