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_CondDB_PayloadProxy_h
2 #define CondCore_CondDB_PayloadProxy_h
3 
6 
7 namespace cond {
8 
9  namespace persistency {
10 
11  // still needed??
12  /* get iov by name (key, tag, ...)
13  */
14  class CondGetter {
15  public:
16  virtual ~CondGetter(){}
17  virtual IOVProxy get(std::string name) const=0;
18 
19  };
20 
21  // implements the not templated part...
23  public:
24 
25  //
27 
28  void setUp( Session dbSession );
29 
30  void loadTag( const std::string& tag );
31 
32  void loadTag( const std::string& tag, const boost::posix_time::ptime& snapshotTime );
33 
34  void reload();
35 
36  virtual ~BasePayloadProxy();
37 
38  virtual void make()=0;
39 
40  virtual void invalidateCache()=0;
41 
42  // current cached object token
43  const Hash& payloadId() const { return m_currentIov.payloadId;}
44 
45  // this one had the loading in a separate function in the previous impl
47 
48  bool isValid() const;
49 
50  TimeType timeType() const { return m_iovProxy.timeType();}
51 
52  virtual void loadMore(CondGetter const &){
53  }
54 
55  IOVProxy iov();
56 
57  const std::vector<Iov_t>& requests() const {
58  return m_requests;
59  }
60 
61  private:
62  virtual void loadPayload() = 0;
63 
64 
65  protected:
69  std::vector<Iov_t> m_requests;
70 
71  };
72 
73 
74  /* proxy to the payload valid at a given time...
75 
76  */
77  template<typename DataT>
78  class PayloadProxy : public BasePayloadProxy {
79  public:
80 
81  explicit PayloadProxy( const char * source=0 ) :
82  BasePayloadProxy() {}
83 
84  virtual ~PayloadProxy(){}
85 
86  // dereference
87  const DataT & operator()() const {
88  if( !m_data ) {
89  throwException( "The Payload has not been loaded.","PayloadProxy::operator()");
90  }
91  return (*m_data);
92  }
93 
94  virtual void make(){
95  if( isValid() ){
97  m_session.transaction().start(true);
98  loadPayload();
100  }
101  }
102 
103  virtual void invalidateTransientCache() {
104  m_data.reset();
105  m_currentPayloadId.clear();
106  }
107 
108  virtual void invalidateCache() {
109  m_data.reset();
110  m_currentPayloadId.clear();
112  m_requests.clear();
113  }
114 
115  protected:
116  virtual void loadPayload() {
117  if( m_currentIov.payloadId.empty() ){
118  throwException( "Can't load payload: no valid IOV found.","PayloadProxy::loadPayload" );
119  }
122  m_requests.push_back( m_currentIov );
123  }
124 
125  private:
126  boost::shared_ptr<DataT> m_data;
128  };
129 
130  }
131 }
132 #endif // CondCore_CondDB_PayloadProxy_h
virtual void clear()
Definition: Types.cc:10
const std::vector< Iov_t > & requests() const
Definition: PayloadProxy.h:57
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:215
void start(bool readOnly=true)
Definition: Session.cc:22
const DataT & operator()() const
Definition: PayloadProxy.h:87
Transaction & transaction()
Definition: Session.cc:66
TimeType
Definition: Time.h:21
std::vector< Iov_t > m_requests
Definition: PayloadProxy.h:69
cond::TimeType timeType() const
Definition: IOVProxy.cc:191
unsigned long long Time_t
Definition: Time.h:16
virtual void invalidateTransientCache()
Definition: PayloadProxy.h:103
Hash payloadId
Definition: Types.h:53
std::string Hash
Definition: Types.h:43
ValidityInterval setIntervalFor(Time_t target, bool loadPayload=false)
Definition: PayloadProxy.cc:37
void loadTag(const std::string &tag)
Definition: PayloadProxy.cc:18
const Hash & payloadId() const
Definition: PayloadProxy.h:43
void setUp(Session dbSession)
Definition: PayloadProxy.cc:13
virtual void loadMore(CondGetter const &)
Definition: PayloadProxy.h:52
boost::shared_ptr< DataT > m_data
Definition: PayloadProxy.h:126
static std::string const source
Definition: EdmProvDump.cc:42
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
PayloadProxy(const char *source=0)
Definition: PayloadProxy.h:81