00001 #ifndef GEOMETRY_CALOGEOMETRY_CALOGEOMETRYEP_H 00002 #define GEOMETRY_CALOGEOMETRY_CALOGEOMETRYEP_H 1 00003 00004 // system include files 00005 #include <memory> 00006 #include "boost/shared_ptr.hpp" 00007 00008 // user include files 00009 #include "FWCore/Framework/interface/ModuleFactory.h" 00010 #include "FWCore/Framework/interface/ESProducer.h" 00011 00012 #include "FWCore/Framework/interface/ESHandle.h" 00013 #include "Geometry/Records/interface/IdealGeometryRecord.h" 00014 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h" 00015 #include "Geometry/CaloEventSetup/interface/CaloGeometryLoader.h" 00016 #include "DetectorDescription/Core/interface/DDCompactView.h" 00017 00018 #include "CondFormats/Alignment/interface/Alignments.h" 00019 00020 //Forward declaration 00021 00022 // 00023 // class declaration 00024 // 00025 00026 template <class T> 00027 class CaloGeometryEP : public edm::ESProducer 00028 { 00029 public: 00030 00031 typedef CaloGeometryLoader<T> LoaderType ; 00032 typedef typename LoaderType::PtrType PtrType ; 00033 00034 CaloGeometryEP<T>( const edm::ParameterSet& ps ) : 00035 m_cpv ( 0 ) , 00036 m_applyAlignment ( ps.getUntrackedParameter<bool>("applyAlignment", false) ) 00037 { 00038 setWhatProduced( this, 00039 &CaloGeometryEP<T>::produceAligned, 00040 dependsOn( &CaloGeometryEP<T>::idealRecordCallBack ), 00041 edm::es::Label( T::producerName() ) ) ; 00042 00043 // disable 00044 // setWhatProduced( this, 00045 // &CaloGeometryEP<T>::produceIdeal, 00046 // edm::es::Label( T::producerName() ) ) ; 00047 } 00048 00049 virtual ~CaloGeometryEP<T>() {} 00050 PtrType produceAligned( const typename T::AlignedRecord& iRecord ) 00051 { 00052 assert( 0 != m_cpv ) ; // should have been filled by call to callback method below 00053 00054 const Alignments* alignPtr ( 0 ) ; 00055 if( m_applyAlignment ) // get ptr if necessary 00056 { 00057 edm::ESHandle< Alignments > alignments ; 00058 iRecord.template getRecord< typename T::AlignmentRecord >().get( alignments ) ; 00059 00060 assert( alignments.isValid() && // require valid alignments and expected size 00061 ( alignments->m_align.size() == T::numberOfAlignments() ) ) ; 00062 alignPtr = alignments.product() ; 00063 } 00064 LoaderType loader ; 00065 PtrType ptr ( loader.load( m_cpv, alignPtr ) ) ; // no temporaries for shared+ptr!! 00066 return ptr ; 00067 } 00068 00069 PtrType produceIdeal( const typename T::IdealRecord& iRecord ) 00070 { 00071 assert( !m_applyAlignment ) ; 00072 idealRecordCallBack( iRecord ) ; // must call manually because is same record 00073 assert( 0 != m_cpv ) ; 00074 LoaderType loader ; 00075 PtrType ptr ( loader.load( m_cpv ) ) ; // no temporaries for shared+ptr!! 00076 return ptr ; 00077 } 00078 00079 void idealRecordCallBack( const typename T::IdealRecord& iRecord ) 00080 { 00081 edm::ESHandle< DDCompactView > cpv ; 00082 iRecord.get( cpv ) ; 00083 00084 m_cpv = &( *cpv ) ; 00085 } 00086 00087 private: 00088 00089 const DDCompactView* m_cpv ; 00090 00091 bool m_applyAlignment ; 00092 }; 00093 00094 #endif