Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:14:38

0001 /****************************************************************************
0002 *
0003 * This is a part of TOTEM offline software.
0004 * Author:
0005 *   Laurent Forthomme
0006 *
0007 ****************************************************************************/
0008 
0009 #include <memory>
0010 
0011 #include "FWCore/Framework/interface/ModuleFactory.h"
0012 #include "FWCore/Framework/interface/ESProducer.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 
0015 #include "DetectorDescription/Core/interface/DDCompactView.h"   // DDL
0016 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"  // DD4hep
0017 
0018 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0019 #include "Geometry/Records/interface/TotemGeometryRcd.h"
0020 #include "Geometry/ForwardGeometry/interface/TotemGeometry.h"
0021 #include "Geometry/VeryForwardGeometryBuilder/interface/DetGeomDescBuilder.h"
0022 
0023 class TotemGeometryESModule : public edm::ESProducer {
0024 public:
0025   TotemGeometryESModule(const edm::ParameterSet&);
0026 
0027   std::unique_ptr<TotemGeometry> produce(const TotemGeometryRcd&);
0028 
0029   static void fillDescriptions(edm::ConfigurationDescriptions&);
0030 
0031 private:
0032   edm::ESGetToken<DDCompactView, IdealGeometryRecord> ddlToken_;
0033   edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> dd4hepToken_;
0034 
0035   const bool useDDL_;
0036   const bool useDD4hep_;
0037 };
0038 
0039 TotemGeometryESModule::TotemGeometryESModule(const edm::ParameterSet& iConfig)
0040     : useDDL_(iConfig.getParameter<bool>("useDDL")), useDD4hep_(iConfig.getParameter<bool>("useDD4hep")) {
0041   auto cc = setWhatProduced(this);
0042   if (useDDL_)
0043     ddlToken_ = cc.consumes();
0044   else if (useDD4hep_)
0045     dd4hepToken_ = cc.consumes();
0046   else
0047     throw cms::Exception("TotemGeometryESModule") << "Geometry must either be retrieved from a DDL or DD4hep payload!";
0048 }
0049 
0050 std::unique_ptr<TotemGeometry> TotemGeometryESModule::produce(const TotemGeometryRcd& iRecord) {
0051   if (useDDL_) {
0052     edm::ESTransientHandle<DDCompactView> hnd = iRecord.getTransientHandle(ddlToken_);
0053     return std::make_unique<TotemGeometry>(detgeomdescbuilder::buildDetGeomDescFromCompactView(*hnd, false).get());
0054   } else {
0055     edm::ESTransientHandle<cms::DDCompactView> hnd = iRecord.getTransientHandle(dd4hepToken_);
0056     return std::make_unique<TotemGeometry>(detgeomdescbuilder::buildDetGeomDescFromCompactView(*hnd, false).get());
0057   }
0058 }
0059 
0060 void TotemGeometryESModule::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0061   edm::ParameterSetDescription desc;
0062   desc.add<bool>("useDDL", true);
0063   desc.add<bool>("useDD4hep", false);
0064   descriptions.addWithDefaultLabel(desc);
0065 }
0066 
0067 //define this as a plug-in
0068 DEFINE_FWK_EVENTSETUP_MODULE(TotemGeometryESModule);