Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Framework/interface/ModuleFactory.h"
0003 #include "FWCore/Framework/interface/ESHandle.h"
0004 #include "FWCore/Framework/interface/ESTransientHandle.h"
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0007 #include "FWCore/ParameterSet/interface/ParameterSetDescription.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/PTrackerParametersRcd.h"
0012 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0013 #include "Geometry/TrackerGeometryBuilder/interface/TrackerParametersFromDD.h"
0014 #include "CondFormats/GeometryObjects/interface/PTrackerParameters.h"
0015 
0016 #include <memory>
0017 
0018 namespace edm {
0019   class ConfigurationDescriptions;
0020 }
0021 class PTrackerParameters;
0022 class PTrackerParametersRcd;
0023 
0024 class TrackerParametersESModule : public edm::ESProducer {
0025 public:
0026   TrackerParametersESModule(const edm::ParameterSet&);
0027 
0028   using ReturnType = std::unique_ptr<PTrackerParameters>;
0029 
0030   static void fillDescriptions(edm::ConfigurationDescriptions&);
0031 
0032   ReturnType produce(const PTrackerParametersRcd&);
0033 
0034 private:
0035   edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
0036   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4hep_;
0037   bool fromDD4hep_;
0038 };
0039 
0040 TrackerParametersESModule::TrackerParametersESModule(const edm::ParameterSet& ps) {
0041   fromDD4hep_ = ps.getParameter<bool>("fromDD4hep");
0042   auto cc = setWhatProduced(this);
0043   if (fromDD4hep_)
0044     cpvTokenDD4hep_ = cc.consumesFrom<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0045   else
0046     cpvTokenDDD_ = cc.consumesFrom<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0047 
0048 #ifdef EDM_ML_DEBUG
0049   edm::LogVerbatim("TrackerGeom") << "TrackerParametersESModule::TrackerParametersESModule called with dd4hep: "
0050                                   << fromDD4hep_;
0051 #endif
0052 }
0053 
0054 void TrackerParametersESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0055   edm::ParameterSetDescription desc;
0056   desc.add<bool>("fromDD4hep", false);
0057   descriptions.add("trackerParameters", desc);
0058 }
0059 
0060 TrackerParametersESModule::ReturnType TrackerParametersESModule::produce(const PTrackerParametersRcd& iRecord) {
0061   edm::LogInfo("TrackerGeom") << "TrackerParametersESModule::produce(const PTrackerParametersRcd& iRecord)";
0062 
0063   auto ptp = std::make_unique<PTrackerParameters>();
0064   TrackerParametersFromDD builder;
0065 
0066   if (fromDD4hep_) {
0067 #ifdef EDM_ML_DEBUG
0068     edm::LogVerbatim("TrackerGeom") << "TrackerParametersESModule::produce try to access cms::DDCompactView";
0069 #endif
0070     edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDD4hep_);
0071     builder.build(&(*cpv), *ptp);
0072   } else {
0073 #ifdef EDM_ML_DEBUG
0074     edm::LogVerbatim("TrackerGeom") << "TrackerParametersESModule::produce try to access DDCompactView";
0075 #endif
0076     edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDDD_);
0077     builder.build(&(*cpv), *ptp);
0078   }
0079 
0080   return ptp;
0081 }
0082 
0083 DEFINE_FWK_EVENTSETUP_MODULE(TrackerParametersESModule);