Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:15

0001 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0002 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0003 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0004 #include "FWCore/Framework/interface/ESProducer.h"
0005 #include "FWCore/Framework/interface/ModuleFactory.h"
0006 #include "FWCore/Framework/interface/ESHandle.h"
0007 #include "FWCore/Framework/interface/ESTransientHandle.h"
0008 #include "DetectorDescription/Core/interface/DDCompactView.h"
0009 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0010 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0011 #include "Geometry/Records/interface/PMTDParametersRcd.h"
0012 #include "Geometry/MTDGeometryBuilder/interface/MTDParametersFromDD.h"
0013 #include "CondFormats/GeometryObjects/interface/PMTDParameters.h"
0014 
0015 #include <memory>
0016 
0017 class MTDParametersESModule : public edm::ESProducer {
0018 public:
0019   MTDParametersESModule(const edm::ParameterSet&);
0020 
0021   using ReturnType = std::unique_ptr<PMTDParameters>;
0022 
0023   static void fillDescriptions(edm::ConfigurationDescriptions&);
0024 
0025   ReturnType produce(const PMTDParametersRcd&);
0026 
0027 private:
0028   MTDParametersFromDD builder;
0029 
0030   const bool fromDD4hep_;
0031   edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddCompactToken_;
0032   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
0033 };
0034 
0035 MTDParametersESModule::MTDParametersESModule(const edm::ParameterSet& pset)
0036     : fromDD4hep_(pset.getParameter<bool>("fromDD4hep")) {
0037   auto cc = setWhatProduced(this);
0038   if (!fromDD4hep_) {
0039     ddCompactToken_ = cc.consumesFrom<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0040   } else {
0041     dd4hepToken_ = cc.consumesFrom<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0042   }
0043 }
0044 
0045 void MTDParametersESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0046   edm::ParameterSetDescription desc;
0047   desc.add<bool>("fromDD4hep", false);
0048   descriptions.add("mtdParameters", desc);
0049 }
0050 
0051 MTDParametersESModule::ReturnType MTDParametersESModule::produce(const PMTDParametersRcd& iRecord) {
0052   auto ptp = std::make_unique<PMTDParameters>();
0053   if (!fromDD4hep_) {
0054     auto cpv = iRecord.getTransientHandle(ddCompactToken_);
0055     builder.build(cpv.product(), *ptp);
0056   } else {
0057     auto cpv = iRecord.getTransientHandle(dd4hepToken_);
0058     builder.build(cpv.product(), *ptp);
0059   }
0060 
0061   return ptp;
0062 }
0063 
0064 DEFINE_FWK_EVENTSETUP_MODULE(MTDParametersESModule);