CMS 3D CMS Logo

DataProxyTemplate.h

Go to the documentation of this file.
00001 #ifndef FWCore_Framework_DataProxyTemplate_h
00002 #define FWCore_Framework_DataProxyTemplate_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Framework
00006 // Class  :     DataProxyTemplate
00007 // 
00016 //
00017 // Author:      Chris Jones
00018 // Created:     Thu Mar 31 12:45:32 EST 2005
00019 // $Id: DataProxyTemplate.h,v 1.10 2007/10/26 23:27:55 elmer Exp $
00020 //
00021 
00022 // system include files
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/DataProxy.h"
00026 #include "FWCore/Framework/interface/MakeDataException.h"
00027 #include "FWCore/Framework/interface/EventSetupRecord.h"
00028 #include <cassert>
00029 
00030 // forward declarations
00031 
00032 namespace edm {
00033    namespace eventsetup {
00034 template<class RecordT, class DataT>
00035 class DataProxyTemplate : public DataProxy
00036 {
00037 
00038    public:
00039       typedef DataT value_type;
00040       typedef RecordT record_type;
00041    
00042       DataProxyTemplate() : cache_(0) {}
00043       //virtual ~DataProxyTemplate();
00044 
00045       // ---------- const member functions ---------------------
00046 
00047       // ---------- static member functions --------------------
00048 
00049       // ---------- member functions ---------------------------
00050       virtual const DataT* get(const RecordT& iRecord,
00051                                 const DataKey& iKey) const {
00052          if(!cacheIsValid()) {
00053             cache_ = const_cast<DataProxyTemplate<RecordT, DataT>*>(this)->make(iRecord, iKey);
00054             const_cast<DataProxyTemplate<RecordT, DataT>*>(this)->setCacheIsValid();
00055          }
00056          if(0 == cache_) {
00057             throwMakeException(iRecord, iKey);
00058          }
00059          return cache_;
00060       }
00061       
00062       void doGet(const EventSetupRecord& iRecord, const DataKey& iKey) const {
00063          assert(iRecord.key() == RecordT::keyForClass());
00064          get(static_cast<const RecordT&>(iRecord), iKey);
00065       }
00066    protected:
00067       virtual const DataT* make(const RecordT&, const DataKey&) = 0;
00068       
00069       virtual void throwMakeException(const RecordT& /*iRecord*/,
00070                                        const DataKey& iKey) const {
00071          throw MakeDataException<record_type, value_type>(iKey);
00072       }
00073 
00074    private:
00075       DataProxyTemplate(const DataProxyTemplate&); // stop default
00076 
00077       const DataProxyTemplate& operator=(const DataProxyTemplate&); // stop default
00078 
00079       // ---------- member data --------------------------------
00080       mutable const DataT* cache_;
00081 };
00082 
00083    }
00084 }
00085 #endif

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