CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/CondCore/IOVService/interface/PayloadProxy.h

Go to the documentation of this file.
00001 #ifndef CondCore_IOVService_PayloadProxy_h
00002 #define CondCore_IOVService_PayloadProxy_h
00003 
00004 #include "CondCore/IOVService/interface/IOVProxy.h"
00005 #include "CondCore/DBCommon/interface/PayloadRef.h"
00006 
00007 namespace cond {
00008 
00009   /* get iov by name (key, tag, ...)
00010 
00011    */
00012   class CondGetter {
00013   public:
00014     virtual ~CondGetter(){}
00015     virtual IOVProxy get(std::string name) const=0;
00016 
00017   };
00018 
00019   /* implementation detail: 
00020     implements the not templated part...
00021 
00022    */
00023   class BasePayloadProxy {
00024   public:
00025 
00026     struct ObjId {
00027       cond::Time_t since;
00028       unsigned int oid1;
00029       unsigned int oid2;
00030     };
00031     typedef  std::vector<ObjId> ObjIds;
00032     struct Stats {
00033       int nProxy;
00034       int nMake;
00035       int nLoad;
00036       ObjIds ids;
00037     };
00038 
00039     // global stat
00040     static Stats gstats;
00041     // local stat
00042     Stats stats;
00043 
00044     // errorPolicy=true will throw on load, false will set interval and token to invalid
00045     BasePayloadProxy(cond::DbSession& session,
00046                      const std::string & token,
00047                      bool errorPolicy);
00048     
00049     virtual ~BasePayloadProxy();
00050 
00051     virtual void invalidateCache()=0;
00052 
00053     // current cached object token
00054     std::string const & token() const { return m_token;}
00055     
00056     // load Element valid at time
00057     cond::ValidityInterval loadFor(cond::Time_t time);
00058     
00059     // load nth Element (to be used in simple iterators...)
00060     cond::ValidityInterval loadFor(size_t n);
00061 
00062     // find ad return interval (does not load)
00063     cond::ValidityInterval setIntervalFor(cond::Time_t time);
00064     
00065     // load element if interval is valid
00066     void make();
00067 
00068     bool isValid() const;
00069 
00070     TimeType timetype() const { return m_iov.timetype();}
00071 
00072     IOVProxy const & iov() const { return m_iov;}
00073 
00074     virtual void loadMore(CondGetter const &){}
00075 
00076     // reload the iov return true if size has changed
00077     bool refresh();
00078 
00079 
00080   private:
00081     virtual bool load(cond::DbSession& session, std::string const & token) =0;   
00082 
00083 
00084   protected:
00085     bool m_doThrow;
00086     IOVProxy m_iov;
00087     IOVElementProxy m_element;
00088 
00089   protected:
00090     // current loaded payload
00091     std::string  m_token;
00092 
00093   };
00094 
00095 
00096   /* proxy to the payload valid at a given time...
00097 
00098    */
00099   template<typename DataT>
00100   class PayloadProxy : public BasePayloadProxy {
00101   public:
00102  
00103     PayloadProxy(cond::DbSession& session,
00104                  const std::string & token,
00105                  bool errorPolicy,
00106                  const char * source=0) :
00107       BasePayloadProxy(session, token, errorPolicy) {}
00108     
00109     virtual ~PayloadProxy(){}
00110 
00111     // dereference (does not load)
00112     const DataT & operator()() const {
00113       return (*m_data); 
00114     }
00115         
00116     virtual void invalidateCache() {
00117       m_data.clear();
00118       m_token.clear(); // in base....
00119     }
00120 
00121 
00122   protected:
00123     virtual bool load(cond::DbSession& session, std::string const & itoken) {
00124       return m_data.load(session,itoken);
00125     }
00126 
00127   private:
00128      cond::PayloadRef<DataT> m_data;
00129   };
00130 
00131 }
00132 #endif // CondCore_IOVService_PayloadProxy_h