Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14: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 "CondFormats/GeometryObjects/interface/HcalParameters.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/HcalParametersFromDD.h"
0012 
0013 #include <memory>
0014 
0015 //#define EDM_ML_DEBUG
0016 
0017 class HcalParametersESModule : public edm::ESProducer {
0018 public:
0019   HcalParametersESModule(const edm::ParameterSet&);
0020 
0021   using ReturnType = std::unique_ptr<HcalParameters>;
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 HcalParametersESModule::HcalParametersESModule(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") << "HcalParametersESModule::HcalParametersESModule called with dd4hep: " << fromDD4hep_;
0043 #endif
0044 }
0045 
0046 void HcalParametersESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0047   edm::ParameterSetDescription desc;
0048   desc.add<bool>("fromDD4hep", false);
0049   descriptions.add("hcalParameters", desc);
0050 }
0051 
0052 HcalParametersESModule::ReturnType HcalParametersESModule::produce(const HcalParametersRcd& iRecord) {
0053   edm::LogInfo("HCalGeom") << "HcalParametersESModule::produce(const HcalParametersRcd& iRecord)";
0054 
0055   auto ptp = std::make_unique<HcalParameters>();
0056   HcalParametersFromDD builder;
0057 
0058   if (fromDD4hep_) {
0059 #ifdef EDM_ML_DEBUG
0060     edm::LogVerbatim("HCalGeom") << "HcalParametersESModule::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("HCalGeom") << "HcalParametersESModule::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(HcalParametersESModule);