Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-11-07 23:58:12

0001 #include "FWCore/Framework/interface/ESProducer.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/ESTransientHandle.h"
0004 #include "FWCore/Framework/interface/ModuleFactory.h"
0005 #include "FWCore/MessageLogger/interface/MessageLogger.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/Core/interface/DDutils.h"
0010 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0011 #include "Geometry/TrackerNumberingBuilder/plugins/DDDCmsTrackerContruction.h"
0012 #include "Geometry/TrackerNumberingBuilder/plugins/CondDBCmsTrackerConstruction.h"
0013 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0014 #include "CondFormats/GeometryObjects/interface/PGeometricDet.h"
0015 
0016 #include <memory>
0017 
0018 class TrackerGeometricDetESModule : public edm::ESProducer {
0019 public:
0020   TrackerGeometricDetESModule(const edm::ParameterSet& p);
0021   ~TrackerGeometricDetESModule(void) override;
0022   std::unique_ptr<GeometricDet> produce(const IdealGeometryRecord&);
0023 
0024   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0025 
0026 private:
0027   edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddToken_;
0028   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
0029   edm::ESGetToken<PGeometricDet, IdealGeometryRecord> pgToken_;
0030   bool fromDDD_;
0031   bool fromDD4hep_;
0032 };
0033 
0034 using namespace edm;
0035 
0036 TrackerGeometricDetESModule::TrackerGeometricDetESModule(const edm::ParameterSet& p)
0037     : fromDDD_(p.getParameter<bool>("fromDDD")), fromDD4hep_(p.getParameter<bool>("fromDD4hep")) {
0038   edm::LogVerbatim("TrackerGeom") << "TrackerGeometricDetESModule::fromDDD " << fromDDD_ << "  fromDD4hep "
0039                                   << fromDD4hep_;
0040   auto cc = setWhatProduced(this);
0041   if (fromDDD_) {
0042     ddToken_ = cc.consumes<DDCompactView>(edm::ESInputTag());
0043   } else if (fromDD4hep_) {
0044     dd4hepToken_ = cc.consumes<cms::DDCompactView>(edm::ESInputTag());
0045   } else {
0046     pgToken_ = cc.consumes<PGeometricDet>(edm::ESInputTag());
0047   }
0048 }
0049 
0050 TrackerGeometricDetESModule::~TrackerGeometricDetESModule(void) {}
0051 
0052 void TrackerGeometricDetESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053   edm::ParameterSetDescription descDB;
0054   descDB.add<bool>("fromDDD", false);
0055   descDB.add<bool>("fromDD4hep", false);
0056   descriptions.add("trackerNumberingGeometryDB", descDB);
0057 
0058   edm::ParameterSetDescription desc;
0059   desc.add<bool>("fromDDD", true);
0060   desc.add<bool>("fromDD4hep", false);
0061   descriptions.add("trackerNumberingGeometry", desc);
0062 
0063   edm::ParameterSetDescription descDD4hep;
0064   descDD4hep.add<bool>("fromDDD", false);
0065   descDD4hep.add<bool>("fromDD4hep", true);
0066   descriptions.add("DD4hep_trackerNumberingGeometry", descDD4hep);
0067 }
0068 
0069 std::unique_ptr<GeometricDet> TrackerGeometricDetESModule::produce(const IdealGeometryRecord& iRecord) {
0070   if (fromDDD_) {
0071     edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(ddToken_);
0072 
0073     return DDDCmsTrackerContruction::construct(*cpv, dbl_to_int(cpv->vector("detIdShifts")));
0074   } else if (fromDD4hep_) {
0075     edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(dd4hepToken_);
0076 
0077     return DDDCmsTrackerContruction::construct(*cpv, cpv->getVector<int>("detIdShifts"));
0078   } else {
0079     auto const& pgd = iRecord.get(pgToken_);
0080 
0081     return CondDBCmsTrackerConstruction::construct(pgd);
0082   }
0083 }
0084 
0085 DEFINE_FWK_EVENTSETUP_MODULE(TrackerGeometricDetESModule);