CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PayloadProxy.h
Go to the documentation of this file.
1 #ifndef CondCore_IOVService_PayloadProxy_h
2 #define CondCore_IOVService_PayloadProxy_h
3 
6 
7 namespace cond {
8 
9  /* get iov by name (key, tag, ...)
10 
11  */
12  class CondGetter {
13  public:
14  virtual ~CondGetter(){}
15  virtual IOVProxy get(std::string name) const=0;
16 
17  };
18 
19  /* implementation detail:
20  implements the not templated part...
21 
22  */
24  public:
25 
26  struct ObjId {
28  unsigned int oid1;
29  unsigned int oid2;
30  };
31  typedef std::vector<ObjId> ObjIds;
32  struct Stats {
33  int nProxy;
34  int nRefresh;
35  int nArefresh;
38  int nMake;
39  int nLoad;
41  };
42 
43  // global stat
44  static Stats gstats;
45  // local stat
47 
48  // errorPolicy=true will throw on load, false will set interval and token to invalid
50  bool errorPolicy);
51 
52  // errorPolicy=true will throw on load, false will set interval and token to invalid
54  const std::string & token,
55  bool errorPolicy);
56 
57  void loadIov( const std::string iovToken );
58  void loadTag( const std::string tag );
59 
60  virtual ~BasePayloadProxy();
61 
62  virtual void invalidateCache()=0;
63 
64  // current cached object token
65  std::string const & token() const { return m_token;}
66 
67  // load Element valid at time
69 
70  // load nth Element (to be used in simple iterators...)
72 
73  // find ad return interval (does not load)
75 
76  // load element if interval is valid
77  void make();
78 
79  bool isValid() const;
80 
81  TimeType timetype() const { return m_iov.timetype();}
82 
83  IOVProxy const & iov() const { return m_iov;}
84 
85  virtual void loadMore(CondGetter const &){}
86 
87  // reload the iov return true if size has changed
88  bool refresh();
89  bool refresh( cond::DbSession& newSession );
90 
91 
92  private:
93  virtual bool load(cond::DbSession& session, std::string const & token) =0;
94 
95 
96  protected:
97  bool m_doThrow;
101 
102  protected:
103  // current loaded payload
105 
106  };
107 
108 
109  /* proxy to the payload valid at a given time...
110 
111  */
112  template<typename DataT>
114  public:
115 
117  bool errorPolicy,
118  const char * source=0) :
119  BasePayloadProxy(session, errorPolicy) {}
120 
122  const std::string & token,
123  bool errorPolicy,
124  const char * source=0) :
125  BasePayloadProxy(session, token, errorPolicy) {}
126 
127  virtual ~PayloadProxy(){}
128 
129  // dereference (does not load)
130  const DataT & operator()() const {
131  return (*m_data);
132  }
133 
134  virtual void invalidateCache() {
135  m_data.clear();
136  m_token.clear(); // in base....
137  }
138 
139 
140  protected:
141  virtual bool load(cond::DbSession& session, std::string const & itoken) {
142  return m_data.load(session,itoken);
143  }
144 
145  private:
147  };
148 
149 }
150 #endif // CondCore_IOVService_PayloadProxy_h
IOVElementProxy m_element
Definition: PayloadProxy.h:99
TimeType timetype() const
Definition: PayloadProxy.h:81
void loadIov(const std::string iovToken)
Definition: PayloadProxy.cc:48
TimeType timetype() const
Definition: IOVProxy.cc:280
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
virtual ~PayloadProxy()
Definition: PayloadProxy.h:127
cond::ValidityInterval loadFor(cond::Time_t time)
Definition: PayloadProxy.cc:64
TimeType
Definition: Time.h:21
unsigned long long Time_t
Definition: Time.h:16
PayloadProxy(cond::DbSession &session, bool errorPolicy, const char *source=0)
Definition: PayloadProxy.h:116
cond::PayloadRef< DataT > m_data
Definition: PayloadProxy.h:146
virtual void loadMore(CondGetter const &)
Definition: PayloadProxy.h:85
virtual bool load(cond::DbSession &session, std::string const &itoken)
Definition: PayloadProxy.h:141
cond::ValidityInterval setIntervalFor(cond::Time_t time)
virtual void invalidateCache()=0
std::vector< ObjId > ObjIds
Definition: PayloadProxy.h:31
virtual bool load(cond::DbSession &session, std::string const &token)=0
void loadTag(const std::string tag)
Definition: PayloadProxy.cc:55
const DataT & operator()() const
Definition: PayloadProxy.h:130
virtual ~CondGetter()
Definition: PayloadProxy.h:14
BasePayloadProxy(cond::DbSession &session, bool errorPolicy)
Definition: PayloadProxy.cc:25
IOVProxy const & iov() const
Definition: PayloadProxy.h:83
PayloadProxy(cond::DbSession &session, const std::string &token, bool errorPolicy, const char *source=0)
Definition: PayloadProxy.h:121
virtual void invalidateCache()
Definition: PayloadProxy.h:134
std::string const & token() const
Definition: PayloadProxy.h:65