00001 #ifndef DataFormats_Common_RefItemGet_h
00002 #define DataFormats_Common_RefItemGet_h
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "DataFormats/Common/interface/RefCore.h"
00012 #include "DataFormats/Common/interface/RefItem.h"
00013 #include "DataFormats/Common/interface/RefCoreGet.h"
00014
00015 namespace edm {
00016
00017 namespace refitem {
00018 template< typename C, typename T, typename F, typename KEY>
00019 struct GetPtrImpl {
00020 static T const* getPtr_(RefCore const& product, RefItem<KEY> const& item) {
00021 C const* prod = edm::template getProduct<C>(product);
00022
00023
00024
00025
00026
00027 F func;
00028 T const* p = func(*prod, item.key());
00029 return p;
00030 }
00031 };
00032 }
00033
00034 template <typename C, typename T, typename F, typename KEY>
00035 inline
00036 T const* getPtr_(RefCore const& product, RefItem<KEY> const& item) {
00037 return refitem::GetPtrImpl<C, T, F, KEY>::getPtr_(product, item);
00038 }
00039
00040 template <typename C, typename T, typename F, typename KEY>
00041 inline
00042 T const* getPtr(RefCore const& product, RefItem<KEY> const& item) {
00043 T const* p = static_cast<T const *>(item.ptr());
00044 if(0==p){
00045 p=getPtr_<C, T, F>(product,item);
00046 item.setPtr(p);
00047 }
00048 return p;
00049 }
00050 }
00051
00052 #endif