CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/FWCore/Framework/interface/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 // 
00017 //
00018 // Author:      Chris Jones
00019 // Created:     Fri Apr  8 11:50:21 CDT 2005
00020 //
00021 
00022 // system include files
00023 #include "boost/shared_ptr.hpp"
00024 #include <cassert>
00025 
00026 // user include files
00027 #include "FWCore/Framework/interface/DataProxy.h"
00028 #include "FWCore/Framework/interface/EventSetupRecord.h"
00029 
00030 #include "FWCore/Framework/interface/produce_helpers.h"
00031 
00032 // forward declarations
00033 namespace edm {
00034    namespace eventsetup {
00035 
00036       template<class CallbackT, class RecordT, class DataT>
00037       class CallbackProxy : public DataProxy {
00038          
00039       public:
00040          typedef  typename produce::smart_pointer_traits<DataT>::type value_type;
00041          typedef  RecordT record_type;
00042          
00043          CallbackProxy(boost::shared_ptr<CallbackT>& iCallback) :
00044          data_(),
00045          callback_(iCallback) { 
00046             //The callback fills the data directly.  This is done so that the callback does not have to
00047             //  hold onto a temporary copy of the result of the callback since the callback is allowed
00048             //  to return multiple items where only one item is needed by this Proxy
00049             iCallback->holdOntoPointer(&data_) ; }
00050          virtual ~CallbackProxy() {
00051             DataT* dummy(0);
00052             callback_->holdOntoPointer(dummy) ;
00053          }
00054          // ---------- const member functions ---------------------
00055          
00056          // ---------- static member functions --------------------
00057          
00058          // ---------- member functions ---------------------------
00059          const void* getImpl(const EventSetupRecord& iRecord, const DataKey&) {
00060             assert(iRecord.key() == RecordT::keyForClass());
00061             (*callback_)(static_cast<const record_type&>(iRecord));
00062             return &(*data_);
00063          }
00064          
00065          void invalidateCache() {
00066             data_ = DataT();
00067             callback_->newRecordComing();
00068          }
00069       private:
00070          CallbackProxy(const CallbackProxy&); // stop default
00071          
00072          const CallbackProxy& operator=(const CallbackProxy&); // stop default
00073          
00074          // ---------- member data --------------------------------
00075          DataT data_;
00076          boost::shared_ptr<CallbackT> callback_;
00077       };
00078       
00079    }
00080 }
00081 
00082 #endif