CMS 3D CMS Logo

PayloadProxy.h
Go to the documentation of this file.
1 #ifndef CondCore_CondDB_PayloadProxy_h
2 #define CondCore_CondDB_PayloadProxy_h
3 
8 
9 #include <memory>
10 #include <string>
11 #include <vector>
12 
13 namespace cond {
14 
15  namespace persistency {
16 
17  // still needed??
18  /* get iov by name (key, tag, ...)
19  */
20  class CondGetter {
21  public:
22  virtual ~CondGetter() {}
23  virtual IOVProxy get(std::string name) const = 0;
24  };
25 
26  // implements the not templated part...
28  public:
29  //
30  BasePayloadProxy(Iov_t const* mostRecentCurrentIov,
31  Session const* mostRecentSession,
32  std::shared_ptr<std::vector<Iov_t>> const* mostRecentRequests);
33 
34  virtual ~BasePayloadProxy();
35 
36  virtual void make() = 0;
37 
38  bool isValid() const;
39 
40  virtual void loadMore(CondGetter const&) {}
41 
42  void initializeForNewIOV();
43 
44  private:
45  virtual void loadPayload() = 0;
46 
47  protected:
50  std::shared_ptr<std::vector<Iov_t>> m_requests;
51 
54  std::shared_ptr<std::vector<Iov_t>> const* m_mostRecentRequests;
55  };
56 
57  /* proxy to the payload valid at a given time...
58 
59  */
60  template <typename DataT>
61  class PayloadProxy : public BasePayloadProxy {
62  public:
63  explicit PayloadProxy(Iov_t const* mostRecentCurrentIov,
64  Session const* mostRecentSession,
65  std::shared_ptr<std::vector<Iov_t>> const* mostRecentRequests,
66  const char* source = nullptr)
67  : BasePayloadProxy(mostRecentCurrentIov, mostRecentSession, mostRecentRequests) {}
68 
69  ~PayloadProxy() override {}
70 
71  void initKeyList(PayloadProxy const&) {}
72 
73  // dereference
74  const DataT& operator()() const {
75  if (!m_data) {
76  throwException("The Payload has not been loaded.", "PayloadProxy::operator()");
77  }
78  return (*m_data);
79  }
80 
81  void make() override {
82  if (isValid()) {
84  return;
85  m_session.transaction().start(true);
86  loadPayload();
88  }
89  }
90 
91  protected:
92  void loadPayload() override {
93  if (m_iovAtInitialization.payloadId.empty()) {
94  throwException("Can't load payload: no valid IOV found.", "PayloadProxy::loadPayload");
95  }
99  }
100 
101  private:
102  std::unique_ptr<DataT> m_data;
104  };
105 
106  } // namespace persistency
107 } // namespace cond
108 #endif // CondCore_CondDB_PayloadProxy_h
std::shared_ptr< std::vector< Iov_t > > m_requests
Definition: PayloadProxy.h:50
const DataT & operator()() const
Definition: PayloadProxy.h:74
void start(bool readOnly=true)
Definition: Session.cc:18
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
Transaction & transaction()
Definition: Session.cc:52
Hash payloadId
Definition: Types.h:55
std::string Hash
Definition: Types.h:43
void initKeyList(PayloadProxy const &)
Definition: PayloadProxy.h:71
PayloadProxy(Iov_t const *mostRecentCurrentIov, Session const *mostRecentSession, std::shared_ptr< std::vector< Iov_t >> const *mostRecentRequests, const char *source=nullptr)
Definition: PayloadProxy.h:63
BasePayloadProxy(Iov_t const *mostRecentCurrentIov, Session const *mostRecentSession, std::shared_ptr< std::vector< Iov_t >> const *mostRecentRequests)
Definition: PayloadProxy.cc:7
std::shared_ptr< std::vector< Iov_t > > const * m_mostRecentRequests
Definition: PayloadProxy.h:54
std::unique_ptr< DataT > m_data
Definition: PayloadProxy.h:102
virtual void loadMore(CondGetter const &)
Definition: PayloadProxy.h:40
static std::string const source
Definition: EdmProvDump.cc:49
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12