CMS 3D CMS Logo

CMSSW_4_4_3_patch1/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 nRefresh;
00035       int nArefresh;
00036       int nMake;
00037       int nLoad;
00038       ObjIds ids;
00039     };
00040 
00041     // global stat
00042     static Stats gstats;
00043     // local stat
00044     Stats stats;
00045 
00046     // errorPolicy=true will throw on load, false will set interval and token to invalid
00047     BasePayloadProxy(cond::DbSession& session,
00048                      bool errorPolicy);
00049 
00050     // errorPolicy=true will throw on load, false will set interval and token to invalid
00051     BasePayloadProxy(cond::DbSession& session,
00052                      const std::string & token,
00053                      bool errorPolicy);
00054 
00055     void loadIov( const std::string iovToken );
00056     void loadTag( const std::string tag );
00057     
00058     virtual ~BasePayloadProxy();
00059 
00060     virtual void invalidateCache()=0;
00061 
00062     // current cached object token
00063     std::string const & token() const { return m_token;}
00064     
00065     // load Element valid at time
00066     cond::ValidityInterval loadFor(cond::Time_t time);
00067     
00068     // load nth Element (to be used in simple iterators...)
00069     cond::ValidityInterval loadFor(size_t n);
00070 
00071     // find ad return interval (does not load)
00072     cond::ValidityInterval setIntervalFor(cond::Time_t time);
00073     
00074     // load element if interval is valid
00075     void make();
00076 
00077     bool isValid() const;
00078 
00079     TimeType timetype() const { return m_iov.timetype();}
00080 
00081     IOVProxy const & iov() const { return m_iov;}
00082 
00083     virtual void loadMore(CondGetter const &){}
00084 
00085     // reload the iov return true if size has changed
00086     bool refresh();
00087 
00088 
00089   private:
00090     virtual bool load(cond::DbSession& session, std::string const & token) =0;   
00091 
00092 
00093   protected:
00094     bool m_doThrow;
00095     IOVProxy m_iov;
00096     IOVElementProxy m_element;
00097     mutable DbSession m_session;
00098 
00099   protected:
00100     // current loaded payload
00101     std::string  m_token;
00102 
00103   };
00104 
00105 
00106   /* proxy to the payload valid at a given time...
00107 
00108    */
00109   template<typename DataT>
00110   class PayloadProxy : public BasePayloadProxy {
00111   public:
00112  
00113     PayloadProxy(cond::DbSession& session,
00114                  bool errorPolicy,
00115                  const char * source=0) :
00116       BasePayloadProxy(session, errorPolicy) {}
00117 
00118     PayloadProxy(cond::DbSession& session,
00119                  const std::string & token,
00120                  bool errorPolicy,
00121                  const char * source=0) :
00122       BasePayloadProxy(session, token, errorPolicy) {}
00123     
00124     virtual ~PayloadProxy(){}
00125 
00126     // dereference (does not load)
00127     const DataT & operator()() const {
00128       return (*m_data); 
00129     }
00130         
00131     virtual void invalidateCache() {
00132       m_data.clear();
00133       m_token.clear(); // in base....
00134     }
00135 
00136 
00137   protected:
00138     virtual bool load(cond::DbSession& session, std::string const & itoken) {
00139       return m_data.load(session,itoken);
00140     }
00141 
00142   private:
00143      cond::PayloadRef<DataT> m_data;
00144   };
00145 
00146 }
00147 #endif // CondCore_IOVService_PayloadProxy_h