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