Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-07-01 02:52:57

0001 #ifndef GEOMETRY_CALOGEOMETRY_CALOGEOMETRYEP_H
0002 #define GEOMETRY_CALOGEOMETRY_CALOGEOMETRYEP_H 1
0003 
0004 // system include files
0005 #include <memory>
0006 
0007 // user include files
0008 #include "FWCore/Framework/interface/ModuleFactory.h"
0009 #include "FWCore/Framework/interface/ESProducer.h"
0010 
0011 #include "FWCore/Utilities/interface/ESGetToken.h"
0012 #include "FWCore/Framework/interface/ESTransientHandle.h"
0013 #include "Geometry/Records/interface/IdealGeometryRecord.h"
0014 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
0015 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0016 #include "Geometry/EcalTestBeam/test/ee/CaloGeometryLoaderTest.h"
0017 #include "DetectorDescription/Core/interface/DDCompactView.h"
0018 
0019 #include "CondFormats/Alignment/interface/Alignments.h"
0020 
0021 //Forward declaration
0022 
0023 //
0024 // class declaration
0025 //
0026 
0027 template <class T>
0028 class CaloGeometryEPtest : public edm::ESProducer {
0029 public:
0030   using LoaderType = CaloGeometryLoaderTest<T>;
0031   using PtrType = typename LoaderType::PtrType;
0032 
0033   CaloGeometryEPtest(const edm::ParameterSet& ps) : m_applyAlignment(ps.getParameter<bool>("applyAlignment")) {
0034     auto cc = setWhatProduced(this, &CaloGeometryEPtest<T>::produceAligned, edm::es::Label(T::producerTag()));
0035     if (m_applyAlignment) {
0036       m_alignmentsToken = cc.template consumesFrom<Alignments, typename T::AlignmentRecord>(edm::ESInputTag{});
0037       m_globalsToken = cc.template consumesFrom<Alignments, GlobalPositionRcd>(edm::ESInputTag{});
0038     }
0039     m_geometryToken = cc.template consumesFrom<DDCompactView, IdealGeometryRecord>(edm::ESInputTag{});
0040   }
0041 
0042   ~CaloGeometryEPtest() override {}
0043   PtrType produceAligned(const typename T::AlignedRecord& iRecord) {
0044     const Alignments* alignPtr(nullptr);
0045     const Alignments* globalPtr(nullptr);
0046     if (m_applyAlignment)  // get ptr if necessary
0047     {
0048       const auto& alignments = iRecord.get(m_alignmentsToken);
0049 
0050       // require expected size
0051       assert(alignments.m_align.size() == T::numberOfAlignments());
0052       alignPtr = &alignments;
0053 
0054       globalPtr = &(iRecord.get(m_globalsToken));
0055     }
0056     edm::ESTransientHandle<DDCompactView> cpv = iRecord.getTransientHandle(m_geometryToken);
0057 
0058     LoaderType loader;
0059     return loader.load(cpv.product(), alignPtr, globalPtr);
0060   }
0061 
0062 private:
0063   edm::ESGetToken<Alignments, typename T::AlignmentRecord> m_alignmentsToken;
0064   edm::ESGetToken<Alignments, GlobalPositionRcd> m_globalsToken;
0065   edm::ESGetToken<DDCompactView, IdealGeometryRecord> m_geometryToken;
0066 
0067   bool m_applyAlignment;
0068 };
0069 
0070 #endif