CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_8_patch3/src/DataFormats/Common/interface/RefItemGet.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_RefItemGet_h
00002 #define DataFormats_Common_RefItemGet_h
00003 
00004 /*----------------------------------------------------------------------
00005   
00006 RefItemGet: Free function to get pointer to a referenced item.
00007 
00008 $Id: RefItemGet.h,v 1.5 2011/06/29 21:32:30 chrjones Exp $
00009 
00010 ----------------------------------------------------------------------*/
00011 #include "DataFormats/Common/interface/RefCore.h"
00012 #include "DataFormats/Common/interface/RefCoreGet.h"
00013 
00014 namespace edm {
00015   
00016   namespace refitem {
00017     template< typename C, typename T, typename F, typename KEY>
00018     struct GetPtrImpl {
00019       static T const* getPtr_(RefCore const& product, KEY const& key) {
00020         C const* prod = edm::template getProduct<C>(product);
00021         /*
00022         typename C::const_iterator it = prod->begin();
00023          std::advance(it, item.key());
00024          T const* p = it.operator->();
00025         */
00026         F func;
00027         T const* p = func(*prod, key);
00028         return p;
00029       }
00030     };
00031   }
00032 
00033   template <typename C, typename T, typename F, typename KEY>
00034   inline
00035   T const* getPtr_(RefCore const& product, KEY const& key) {
00036     return refitem::GetPtrImpl<C, T, F, KEY>::getPtr_(product, key);
00037   }
00038 
00039   template <typename C, typename T, typename F, typename KEY>
00040   inline
00041   T const* getPtr(RefCore const& product, KEY const& iKey) {
00042     T const* p=refitem::GetPtrImpl<C, T, F, KEY>::getPtr_(product, iKey);
00043     return p;
00044   }
00045 
00046 }
00047 
00048 #endif