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 reload();
33 
34  virtual ~BasePayloadProxy();
35 
36  virtual void make()=0;
37 
38  virtual void invalidateCache()=0;
39 
40  // current cached object token
41  const Hash& payloadId() const { return m_currentIov.payloadId;}
42 
43  // this one had the loading in a separate function in the previous impl
45 
46  bool isValid() const;
47 
48  TimeType timeType() const { return m_iovProxy.timeType();}
49 
50  virtual void loadMore(CondGetter const &){
51  }
52 
53  IOVProxy iov();
54 
55  const std::vector<Iov_t>& requests() const {
56  return m_requests;
57  }
58 
59  private:
60  virtual void loadPayload() = 0;
61 
62 
63  protected:
67  std::vector<Iov_t> m_requests;
68 
69  };
70 
71 
72  /* proxy to the payload valid at a given time...
73 
74  */
75  template<typename DataT>
76  class PayloadProxy : public BasePayloadProxy {
77  public:
78 
79  explicit PayloadProxy( const char * source=0 ) :
80  BasePayloadProxy() {}
81 
82  virtual ~PayloadProxy(){}
83 
84  // dereference
85  const DataT & operator()() const {
86  if( !m_data ) {
87  throwException( "The Payload has not been loaded.","PayloadProxy::operator()");
88  }
89  return (*m_data);
90  }
91 
92  virtual void make(){
93  if( isValid() ){
95  m_session.transaction().start(true);
96  loadPayload();
98  }
99  }
100 
101  virtual void invalidateCache() {
102  m_data.reset();
103  m_currentPayloadId.clear();
105  m_requests.clear();
106  }
107 
108  protected:
109  virtual void loadPayload() {
110  if( m_currentIov.payloadId.empty() ){
111  throwException( "Can't load payload: no valid IOV found.","PayloadProxy::loadPayload" );
112  }
115  m_requests.push_back( m_currentIov );
116  }
117 
118  private:
119  boost::shared_ptr<DataT> m_data;
121  };
122 
123  }
124 }
125 #endif // CondCore_CondDB_PayloadProxy_h
virtual void clear()
Definition: Types.cc:10
const std::vector< Iov_t > & requests() const
Definition: PayloadProxy.h:55
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:188
void start(bool readOnly=true)
Definition: Session.cc:22
const DataT & operator()() const
Definition: PayloadProxy.h:85
Transaction & transaction()
Definition: Session.cc:66
TimeType
Definition: Time.h:21
std::vector< Iov_t > m_requests
Definition: PayloadProxy.h:67
cond::TimeType timeType() const
Definition: IOVProxy.cc:166
unsigned long long Time_t
Definition: Time.h:16
Hash payloadId
Definition: Types.h:53
std::string Hash
Definition: Types.h:43
ValidityInterval setIntervalFor(Time_t target, bool loadPayload=false)
Definition: PayloadProxy.cc:30
void loadTag(const std::string &tag)
Definition: PayloadProxy.cc:18
const Hash & payloadId() const
Definition: PayloadProxy.h:41
void setUp(Session dbSession)
Definition: PayloadProxy.cc:13
virtual void loadMore(CondGetter const &)
Definition: PayloadProxy.h:50
boost::shared_ptr< DataT > m_data
Definition: PayloadProxy.h:119
static std::string const source
Definition: EdmProvDump.cc:43
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
PayloadProxy(const char *source=0)
Definition: PayloadProxy.h:79