File indexing completed on 2024-04-06 12:14:35
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/EcalSimulationParameters.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/EcalCommonData/interface/EcalSimParametersFromDD.h"
0011
0012 #include <memory>
0013
0014
0015
0016 class EcalSimParametersESModule : public edm::ESProducer {
0017 public:
0018 EcalSimParametersESModule(const edm::ParameterSet&);
0019
0020 using ReturnType = std::unique_ptr<EcalSimulationParameters>;
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 const bool fromDD4hep_;
0030 const std::string name_;
0031 };
0032
0033 EcalSimParametersESModule::EcalSimParametersESModule(const edm::ParameterSet& ps)
0034 : fromDD4hep_(ps.getParameter<bool>("fromDD4hep")), name_(ps.getParameter<std::string>("name")) {
0035 auto cc = setWhatProduced(this, name_);
0036 if (fromDD4hep_) {
0037 cpvTokenDD4hep_ = cc.consumesFrom<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0038 } else {
0039 cpvTokenDDD_ = cc.consumesFrom<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0040 }
0041
0042 #ifdef EDM_ML_DEBUG
0043 edm::LogVerbatim("EcalGeom") << "EcalSimParametersESModule::EcalSimParametersESModule called with dd4hep: "
0044 << fromDD4hep_ << " for " << name_;
0045 #endif
0046 }
0047
0048 void EcalSimParametersESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0049 edm::ParameterSetDescription desc;
0050 desc.add<bool>("fromDD4hep", false);
0051 desc.add<std::string>("name", "EcalHitsEB");
0052 descriptions.add("ecalSimulationParametersEB", desc);
0053 }
0054
0055 EcalSimParametersESModule::ReturnType EcalSimParametersESModule::produce(const IdealGeometryRecord& iRecord) {
0056 #ifdef EDM_ML_DEBUG
0057 edm::LogVerbatim("EcalGeom") << "EcalSimParametersESModule::produce(const IdealGeometryRecord& iRecord)";
0058 #endif
0059
0060 auto ptp = std::make_unique<EcalSimulationParameters>();
0061 EcalSimParametersFromDD builder;
0062 if (fromDD4hep_) {
0063 #ifdef EDM_ML_DEBUG
0064 edm::LogVerbatim("EcalGeom") << "EcalSimParametersESModule::Try to access cms::DDCompactView";
0065 #endif
0066 edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDD4hep_);
0067 builder.build(&(*cpv), name_, *ptp);
0068 } else {
0069 #ifdef EDM_ML_DEBUG
0070 edm::LogVerbatim("EcalGeom") << "EcalSimParametersESModule::Try to access DDCompactView";
0071 #endif
0072 edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDDD_);
0073 builder.build(&(*cpv), name_, *ptp);
0074 }
0075 return ptp;
0076 }
0077
0078 DEFINE_FWK_EVENTSETUP_MODULE(EcalSimParametersESModule);