CMS 3D CMS Logo

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.3 2007/08/20 13:50:16 chrjones Exp $
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         typename C::const_iterator it = prod->begin();
00024          std::advance(it, item.key());
00025          T const* p = it.operator->();
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

Generated on Tue Jun 9 17:29:56 2009 for CMSSW by  doxygen 1.5.4