CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondCore/DBCommon/interface/PayloadRef.h

Go to the documentation of this file.
00001 #ifndef CondCore_DBCommon_PayloadRef_h
00002 #define CondCore_DBCommon_PayloadRef_h
00003 #include "CondCore/DBCommon/interface/DbTransaction.h"
00004 
00005 namespace cond {
00006 
00007   /* manages various types of wrappers...
00008    */
00009   template<typename DataT>
00010   class PayloadRef {
00011   public:
00012 
00013     PayloadRef() {}
00014     ~PayloadRef(){}
00015     
00016     // dereference (does not re-load)
00017     const DataT & operator*() const {
00018       return *m_Data; 
00019     }
00020     
00021     void clear() {
00022       m_Data.reset();
00023     }
00024     
00025     
00026     bool load( DbSession& dbSess, std::string const & itoken) {
00027       clear();
00028       bool ok = false;
00029       // is it ok to open a transaction here? or could be at higher level?
00030       boost::shared_ptr<DataT> tmp = dbSess.getTypedObject<DataT>( itoken );
00031       if (tmp.get()) {
00032         m_Data = tmp;
00033         ok =  true;
00034       }
00035       return ok;
00036     }
00037     
00038     
00039   private:
00040     boost::shared_ptr<DataT> m_Data;
00041   };
00042   
00043 }
00044 #endif // CondCore_PayloadProxy_h