CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/DataFormats/Common/interface/ConvertHandle.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_ConvertHandle_h
00002 #define DataFormats_Common_ConvertHandle_h
00003 
00004 #include "DataFormats/Common/interface/BasicHandle.h"
00005 #include "DataFormats/Common/interface/Handle.h"
00006 #include "DataFormats/Common/interface/Wrapper.h"
00007 
00008 namespace edm {
00009 
00010   namespace handleimpl {
00011     void throwInvalidReference();
00012     void throwConvertTypeError(EDProduct const* product);
00013   }
00014 
00015   // Convert from handle-to-EDProduct to handle-to-T
00016   template <class T>
00017   void convert_handle(BasicHandle const& orig,
00018                       Handle<T>& result) {
00019     if(orig.failedToGet()) {
00020       Handle<T> h(orig.whyFailed());
00021       h.swap(result);
00022       return;
00023     }
00024     EDProduct const* originalWrap = orig.wrapper();
00025     if (originalWrap == 0) {
00026       handleimpl::throwInvalidReference();
00027     }
00028     Wrapper<T> const* wrap = dynamic_cast<Wrapper<T> const*>(originalWrap);
00029     if (wrap == 0) {
00030       handleimpl::throwConvertTypeError(originalWrap);
00031     }
00032 
00033     Handle<T> h(wrap->product(), orig.provenance());
00034     h.swap(result);
00035   }
00036 }
00037 
00038 #endif