Back to home page

Project CMSSW displayed by LXR

 
 

    


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

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