CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/Geometry/CaloEventSetup/interface/CaloGeometryEP.h

Go to the documentation of this file.
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 "FWCore/Framework/interface/ESTransientHandle.h"
00014 #include "Geometry/Records/interface/IdealGeometryRecord.h"
00015 #include "CondFormats/AlignmentRecord/interface/GlobalPositionRcd.h"
00016 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00017 #include "Geometry/CaloEventSetup/interface/CaloGeometryLoader.h"
00018 #include "DetectorDescription/Core/interface/DDCompactView.h"
00019 
00020 #include "CondFormats/Alignment/interface/Alignments.h"
00021 
00022 //Forward declaration
00023 
00024 //
00025 // class declaration
00026 //
00027 
00028 template <class T>
00029 class CaloGeometryEP : public edm::ESProducer 
00030 {
00031    public:
00032 
00033       typedef CaloGeometryLoader<T>          LoaderType ;
00034       typedef typename LoaderType::PtrType   PtrType    ;
00035 
00036       CaloGeometryEP<T>( const edm::ParameterSet& ps ) :
00037          m_applyAlignment ( ps.getParameter<bool>("applyAlignment") )
00038       {
00039          setWhatProduced( this,
00040                           &CaloGeometryEP<T>::produceAligned,
00041 //                        dependsOn( &CaloGeometryEP<T>::idealRecordCallBack ),
00042                           edm::es::Label( T::producerTag() ) ) ;
00043       }
00044 
00045       virtual ~CaloGeometryEP<T>() {}
00046       PtrType produceAligned( const typename T::AlignedRecord& iRecord ) 
00047       {
00048          const Alignments* alignPtr  ( 0 ) ;
00049          const Alignments* globalPtr ( 0 ) ;
00050          if( m_applyAlignment ) // get ptr if necessary
00051          {
00052             edm::ESHandle< Alignments >                                      alignments ;
00053             iRecord.template getRecord< typename T::AlignmentRecord >().get( alignments ) ;
00054 
00055             assert( alignments.isValid() && // require valid alignments and expected size
00056                     ( alignments->m_align.size() == T::numberOfAlignments() ) ) ;
00057             alignPtr = alignments.product() ;
00058 
00059             edm::ESHandle< Alignments >                          globals   ;
00060             iRecord.template getRecord<GlobalPositionRcd>().get( globals ) ;
00061 
00062             assert( globals.isValid() ) ;
00063             globalPtr = globals.product() ;
00064          }
00065          edm::ESTransientHandle<DDCompactView> cpv ;
00066          iRecord.template getRecord<IdealGeometryRecord>().get( cpv ) ;
00067 
00068          LoaderType loader ;
00069          PtrType ptr ( loader.load( &(*cpv), alignPtr, globalPtr ) ) ; // no temporaries for shared+ptr!! 
00070 
00071          return ptr ; 
00072       }
00073 
00074    private:
00075 
00076 
00077       bool        m_applyAlignment ;
00078 };
00079 
00080 #endif