CMS 3D CMS Logo

CallbackProxy.h

Go to the documentation of this file.
00001 #ifndef Framework_CallbackProxy_h
00002 #define Framework_CallbackProxy_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     CallbackProxy
00007 // 
00016 //
00017 // Author:      Chris Jones
00018 // Created:     Fri Apr  8 11:50:21 CDT 2005
00019 // $Id: CallbackProxy.h,v 1.7 2006/08/26 18:38:32 chrjones Exp $
00020 //
00021 
00022 // system include files
00023 #include "boost/shared_ptr.hpp"
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/DataProxyTemplate.h"
00027 
00028 #include "FWCore/Framework/interface/produce_helpers.h"
00029 
00030 // forward declarations
00031 namespace edm {
00032    namespace eventsetup {
00033 
00034 template<class CallbackT, class RecordT, class DataT>
00035       class CallbackProxy : public DataProxyTemplate<RecordT, typename produce::smart_pointer_traits<DataT>::type >
00036 {
00037 
00038    public:
00039    typedef typename DataProxyTemplate<RecordT, typename produce::smart_pointer_traits<DataT>::type >::value_type value_type;
00040    typedef typename DataProxyTemplate<RecordT, typename produce::smart_pointer_traits<DataT>::type >::record_type record_type;
00041    
00042    CallbackProxy(boost::shared_ptr<CallbackT>& iCallback) :
00043    data_(),
00044    callback_(iCallback) { 
00045       //The callback fills the data directly.  This is done so that the callback does not have to
00046       //  hold onto a temporary copy of the result of the callback since the callback is allowed
00047       //  to return multiple items where only one item is needed by this Proxy
00048       iCallback->holdOntoPointer(&data_) ; }
00049       virtual ~CallbackProxy() {
00050          DataT* dummy(0);
00051          callback_->holdOntoPointer(dummy) ;
00052       }
00053       // ---------- const member functions ---------------------
00054    
00055       // ---------- static member functions --------------------
00056 
00057       // ---------- member functions ---------------------------
00058       const value_type* make(const record_type& iRecord, const DataKey&) {
00059          (*callback_)(iRecord);
00060          return &(*data_) ;
00061       }
00062       void invalidateCache() {
00063          data_ = DataT();
00064          callback_->newRecordComing();
00065       }
00066    private:
00067       CallbackProxy(const CallbackProxy&); // stop default
00068 
00069       const CallbackProxy& operator=(const CallbackProxy&); // stop default
00070 
00071       // ---------- member data --------------------------------
00072       DataT data_;
00073       boost::shared_ptr<CallbackT> callback_;
00074 };
00075 
00076    }
00077 }
00078 
00079 #endif

Generated on Tue Jun 9 17:35:20 2009 for CMSSW by  doxygen 1.5.4