Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:48:54

0001 #include "Geometry/MTDNumberingBuilder/plugins/DDCmsMTDConstruction.h"
0002 #include "Geometry/MTDNumberingBuilder/plugins/CondDBCmsMTDConstruction.h"
0003 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0004 #include "DetectorDescription/Core/interface/DDCompactView.h"
0005 #include "DetectorDescription/Core/interface/DDutils.h"
0006 #include "DetectorDescription/DDCMS/interface/DDDetector.h"
0007 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0008 #include "FWCore/Framework/interface/ESProducer.h"
0009 #include "FWCore/Framework/interface/EventSetup.h"
0010 #include "FWCore/Framework/interface/ESHandle.h"
0011 #include "FWCore/Framework/interface/ESTransientHandle.h"
0012 #include "FWCore/Framework/interface/ModuleFactory.h"
0013 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0014 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0015 
0016 #include <memory>
0017 
0018 class MTDGeometricTimingDetESModule : public edm::ESProducer {
0019 public:
0020   MTDGeometricTimingDetESModule(const edm::ParameterSet& p);
0021   ~MTDGeometricTimingDetESModule() override;
0022 
0023   std::unique_ptr<GeometricTimingDet> produce(const IdealGeometryRecord&);
0024 
0025   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0026 
0027 private:
0028   const bool fromDDD_;
0029   const bool fromDD4hep_;
0030 
0031   edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddCompactToken_;
0032   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
0033   edm::ESGetToken<PGeometricTimingDet, IdealGeometryRecord> pGTDetToken_;
0034 };
0035 
0036 using namespace edm;
0037 
0038 MTDGeometricTimingDetESModule::MTDGeometricTimingDetESModule(const edm::ParameterSet& p)
0039     : fromDDD_(p.getParameter<bool>("fromDDD")), fromDD4hep_(p.getParameter<bool>("fromDD4hep")) {
0040   auto cc = setWhatProduced(this);
0041   if (fromDDD_) {
0042     ddCompactToken_ = cc.consumes<DDCompactView>(edm::ESInputTag());
0043   } else if (fromDD4hep_) {
0044     dd4hepToken_ = cc.consumes<cms::DDCompactView>(edm::ESInputTag());
0045   } else {
0046     pGTDetToken_ = cc.consumes<PGeometricTimingDet>(edm::ESInputTag());
0047   }
0048 }
0049 
0050 MTDGeometricTimingDetESModule::~MTDGeometricTimingDetESModule() {}
0051 
0052 void MTDGeometricTimingDetESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0053   edm::ParameterSetDescription descDB;
0054   descDB.add<bool>("fromDDD", false);
0055   descDB.add<bool>("fromDD4hep", false);
0056   descriptions.add("mtdNumberingGeometryDB", descDB);
0057 
0058   edm::ParameterSetDescription desc;
0059   desc.add<bool>("fromDDD", true);
0060   desc.add<bool>("fromDD4hep", false);
0061   descriptions.add("mtdNumberingGeometry", desc);
0062 }
0063 
0064 std::unique_ptr<GeometricTimingDet> MTDGeometricTimingDetESModule::produce(const IdealGeometryRecord& iRecord) {
0065   if (fromDDD_) {
0066     edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(ddCompactToken_);
0067     return DDCmsMTDConstruction::construct((*cpv));
0068   } else if (fromDD4hep_) {
0069     edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(dd4hepToken_);
0070     return DDCmsMTDConstruction::construct((*cpv));
0071   } else {
0072     PGeometricTimingDet const& pgd = iRecord.get(pGTDetToken_);
0073     return CondDBCmsMTDConstruction::construct(pgd);
0074   }
0075 }
0076 
0077 DEFINE_FWK_EVENTSETUP_MODULE(MTDGeometricTimingDetESModule);