File indexing completed on 2024-04-06 12:15:18
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include "FWCore/Framework/interface/ModuleFactory.h"
0020 #include "FWCore/Framework/interface/ESProducer.h"
0021 #include "FWCore/Framework/interface/ESTransientHandle.h"
0022 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
0023 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
0024 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0025 #include "CondFormats/GeometryObjects/interface/MuonOffsetMap.h"
0026 #include "DetectorDescription/Core/interface/DDCompactView.h"
0027 #include "DetectorDescription/DDCMS/interface/DDCompactView.h"
0028 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0029 #include "Geometry/MuonNumbering/interface/MuonOffsetFromDD.h"
0030
0031 #include <memory>
0032 #include <string>
0033 #include <vector>
0034
0035
0036
0037 class MuonOffsetESProducer : public edm::ESProducer {
0038 public:
0039 MuonOffsetESProducer(const edm::ParameterSet&);
0040
0041 using ReturnType = std::unique_ptr<MuonOffsetMap>;
0042
0043 static void fillDescriptions(edm::ConfigurationDescriptions&);
0044 ReturnType produce(const IdealGeometryRecord&);
0045
0046 private:
0047 const bool fromDD4hep_;
0048 const std::vector<std::string> names_;
0049 edm::ESGetToken<DDCompactView, IdealGeometryRecord> cpvTokenDDD_;
0050 edm::ESGetToken<cms::DDCompactView, IdealGeometryRecord> cpvTokenDD4hep_;
0051 };
0052
0053 MuonOffsetESProducer::MuonOffsetESProducer(const edm::ParameterSet& iConfig)
0054 : fromDD4hep_(iConfig.getParameter<bool>("fromDD4hep")),
0055 names_(iConfig.getParameter<std::vector<std::string>>("names")) {
0056 auto cc = setWhatProduced(this);
0057 if (fromDD4hep_) {
0058 cpvTokenDD4hep_ = cc.consumesFrom<cms::DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0059 } else {
0060 cpvTokenDDD_ = cc.consumesFrom<DDCompactView, IdealGeometryRecord>(edm::ESInputTag());
0061 }
0062 #ifdef EDM_ML_DEBUG
0063 edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::MuonOffsetESProducer called with dd4hep: " << fromDD4hep_;
0064 #endif
0065 }
0066
0067 void MuonOffsetESProducer::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
0068 edm::ParameterSetDescription desc;
0069 std::vector<std::string> names = {"MuonCommonNumbering",
0070 "MuonBarrel",
0071 "MuonEndcap",
0072 "MuonBarrelWheels",
0073 "MuonBarrelStation1",
0074 "MuonBarrelStation2",
0075 "MuonBarrelStation3",
0076 "MuonBarrelStation4",
0077 "MuonBarrelSuperLayer",
0078 "MuonBarrelLayer",
0079 "MuonBarrelWire",
0080 "MuonRpcPlane1I",
0081 "MuonRpcPlane1O",
0082 "MuonRpcPlane2I",
0083 "MuonRpcPlane2O",
0084 "MuonRpcPlane3S",
0085 "MuonRpcPlane4",
0086 "MuonRpcChamberLeft",
0087 "MuonRpcChamberMiddle",
0088 "MuonRpcChamberRight",
0089 "MuonRpcEndcap1",
0090 "MuonRpcEndcap2",
0091 "MuonRpcEndcap3",
0092 "MuonRpcEndcap4",
0093 "MuonRpcEndcapSector",
0094 "MuonRpcEndcapChamberB1",
0095 "MuonRpcEndcapChamberB2",
0096 "MuonRpcEndcapChamberB3",
0097 "MuonRpcEndcapChamberC1",
0098 "MuonRpcEndcapChamberC2",
0099 "MuonRpcEndcapChamberC3",
0100 "MuonRpcEndcapChamberE1",
0101 "MuonRpcEndcapChamberE2",
0102 "MuonRpcEndcapChamberE3",
0103 "MuonRpcEndcapChamberF1",
0104 "MuonRpcEndcapChamberF2",
0105 "MuonRpcEndcapChamberF3",
0106 "MuonEndcapStation1",
0107 "MuonEndcapStation2",
0108 "MuonEndcapStation3",
0109 "MuonEndcapStation4",
0110 "MuonEndcapSubrings",
0111 "MuonEndcapSectors",
0112 "MuonEndcapLayers",
0113 "MuonEndcapRing1",
0114 "MuonEndcapRing2",
0115 "MuonEndcapRing3",
0116 "MuonEndcapRingA",
0117 "MuonGEMEndcap",
0118 "MuonGEMSector",
0119 "MuonGEMChamber"};
0120 desc.add<bool>("fromDD4hep", false);
0121 desc.add<std::vector<std::string>>("names", names);
0122 descriptions.add("muonOffsetESProducer", desc);
0123 }
0124
0125 MuonOffsetESProducer::ReturnType MuonOffsetESProducer::produce(const IdealGeometryRecord& iRecord) {
0126 #ifdef EDM_ML_DEBUG
0127 edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::produce(const IdealGeometryRecord& iRecord)";
0128 #endif
0129
0130 auto ptp = std::make_unique<MuonOffsetMap>();
0131 MuonOffsetFromDD builder(names_);
0132
0133 if (fromDD4hep_) {
0134 #ifdef EDM_ML_DEBUG
0135 edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::Try to access cms::DDCompactView";
0136 #endif
0137 edm::ESTransientHandle<cms::DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDD4hep_);
0138 builder.build(&(*cpv), *ptp);
0139 } else {
0140 #ifdef EDM_ML_DEBUG
0141 edm::LogVerbatim("MuonGeom") << "MuonOffsetESProducer::Try to access DDCompactView";
0142 #endif
0143 edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(cpvTokenDDD_);
0144 builder.build(&(*cpv), *ptp);
0145 }
0146 return ptp;
0147 }
0148
0149 DEFINE_FWK_EVENTSETUP_MODULE(MuonOffsetESProducer);