File indexing completed on 2023-07-01 02:52:57
0001 #ifndef GEOMETRY_CALOGEOMETRY_CALOGEOMETRYEP_H
0002 #define GEOMETRY_CALOGEOMETRY_CALOGEOMETRYEP_H
0003
0004 #include <memory>
0005 #include "FWCore/Framework/interface/ModuleFactory.h"
0006 #include "FWCore/Framework/interface/ESProducer.h"
0007 #include "FWCore/Utilities/interface/ESGetToken.h"
0008 #include "FWCore/Framework/interface/ESTransientHandle.h"
0009 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0010 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0011 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0012 #include "Geometry/CaloEventSetup/interface/CaloGeometryLoader.h"
0013 #include "CondFormats/Alignment/interface/Alignments.h"
0014
0015 template <class T, class D>
0016 class CaloGeometryEP : public edm::ESProducer {
0017 public:
0018 using LoaderType = CaloGeometryLoader<T>;
0019 using PtrType = typename LoaderType::PtrType;
0020
0021 CaloGeometryEP(const edm::ParameterSet& ps) : applyAlignment_(ps.getParameter<bool>("applyAlignment")) {
0022 auto cc = setWhatProduced(this, &CaloGeometryEP<T, D>::produceAligned, edm::es::Label(T::producerTag()));
0023
0024 if (applyAlignment_) {
0025 alignmentsToken_ = cc.template consumesFrom<Alignments, typename T::AlignmentRecord>(edm::ESInputTag{});
0026 globalsToken_ = cc.template consumesFrom<Alignments, GlobalPositionRcd>(edm::ESInputTag{});
0027 }
0028 cpvToken_ = cc.template consumesFrom<D, IdealGeometryRecord>(edm::ESInputTag{});
0029 }
0030
0031 ~CaloGeometryEP() override {}
0032 PtrType produceAligned(const typename T::AlignedRecord& iRecord) {
0033 const Alignments* alignPtr(nullptr);
0034 const Alignments* globalPtr(nullptr);
0035 if (applyAlignment_)
0036 {
0037 const auto& alignments = iRecord.get(alignmentsToken_);
0038
0039 assert(alignments.m_align.size() == T::numberOfAlignments());
0040 alignPtr = &alignments;
0041
0042 const auto& globals = iRecord.get(globalsToken_);
0043 globalPtr = &globals;
0044 }
0045 edm::ESTransientHandle<D> cpv = iRecord.getTransientHandle(cpvToken_);
0046
0047 LoaderType loader;
0048 return loader.load(cpv.product(), alignPtr, globalPtr);
0049 }
0050
0051 private:
0052 edm::ESGetToken<Alignments, typename T::AlignmentRecord> alignmentsToken_;
0053 edm::ESGetToken<Alignments, GlobalPositionRcd> globalsToken_;
0054 edm::ESGetToken<D, IdealGeometryRecord> cpvToken_;
0055 bool applyAlignment_;
0056 };
0057
0058 #endif