CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/FWCore/Framework/src/DataProxy.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Framework
00004 // Class  :     DataProxy
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Author:      Chris Jones
00010 // Created:     Thu Mar 31 12:49:19 EST 2005
00011 //
00012 
00013 // system include files
00014 
00015 // user include files
00016 #include "FWCore/Framework/interface/DataProxy.h"
00017 #include "FWCore/Framework/interface/ComponentDescription.h"
00018 #include "FWCore/Framework/interface/MakeDataException.h"
00019 #include "FWCore/Framework/interface/EventSetupRecord.h"
00020 
00021 
00022 //
00023 // constants, enums and typedefs
00024 //
00025 namespace edm {
00026    namespace eventsetup {
00027 //
00028 // static data member definitions
00029 //
00030 static
00031 const ComponentDescription*
00032 dummyDescription()
00033 {
00034    static ComponentDescription s_desc;
00035    return &s_desc;
00036 }     
00037 //
00038 // constructors and destructor
00039 //
00040 DataProxy::DataProxy() :
00041    cache_(0),
00042    cacheIsValid_(false),
00043    nonTransientAccessRequested_(false),
00044    description_(dummyDescription())
00045 {
00046 }
00047 
00048 // DataProxy::DataProxy(const DataProxy& rhs)
00049 // {
00050 //    // do actual copying here;
00051 // }
00052 
00053 DataProxy::~DataProxy()
00054 {
00055 }
00056 
00057 //
00058 // assignment operators
00059 //
00060 // const DataProxy& DataProxy::operator=(const DataProxy& rhs)
00061 // {
00062 //   //An exception safe implementation is
00063 //   DataProxy temp(rhs);
00064 //   swap(rhs);
00065 //
00066 //   return *this;
00067 // }
00068 
00069 //
00070 // member functions
00071 //
00072 void 
00073 DataProxy::setCacheIsValidAndAccessType(bool iTransientAccessOnly) const { 
00074    cacheIsValid_ = true;
00075    if(!iTransientAccessOnly) {
00076       nonTransientAccessRequested_ = true;
00077    }
00078 }
00079       
00080 void DataProxy::clearCacheIsValid() { 
00081    cacheIsValid_ = false;
00082    nonTransientAccessRequested_ = false;
00083    cache_ = 0;
00084 }
00085       
00086 void 
00087 DataProxy::resetIfTransient() {
00088    if (!nonTransientAccessRequested_) {
00089       clearCacheIsValid();
00090       invalidateTransientCache();
00091    }
00092 }
00093 
00094 void 
00095 DataProxy::invalidateTransientCache() {
00096    invalidateCache();
00097 }
00098 //
00099 // const member functions
00100 //
00101 namespace  {
00102    void throwMakeException(const EventSetupRecord& iRecord,
00103                            const DataKey& iKey)  {
00104       throw MakeDataException(iRecord.key(),iKey);
00105    }
00106 }
00107       
00108       
00109 const void* 
00110 DataProxy::get(const EventSetupRecord& iRecord, const DataKey& iKey, bool iTransiently) const
00111 {
00112    if(!cacheIsValid()) {
00113       cache_ = const_cast<DataProxy*>(this)->getImpl(iRecord, iKey);
00114    }
00115    //It is safe to always set cache to valid.
00116    //We need to set the AccessType for each request so this can't be called in the if block above.
00117    //This also must be before the cache_ check since we want to setCacheIsValid before a possible
00118    // exception throw. If we don't, 'getImpl' will be called again on a second request for the data.
00119    setCacheIsValidAndAccessType(iTransiently);
00120    if(0 == cache_) {
00121       throwMakeException(iRecord, iKey);
00122    }
00123    return cache_;
00124 }
00125 
00126 void DataProxy::doGet(const EventSetupRecord& iRecord, const DataKey& iKey, bool iTransiently) const {
00127    get(iRecord, iKey, iTransiently);
00128 }
00129       
00130       
00131 //
00132 // static member functions
00133 //
00134    }
00135 }