CMS 3D CMS Logo

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