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
cond::persistency::BasePayloadProxy::initializeForNewIOV
void initializeForNewIOV()
Definition: PayloadProxy.cc:18
cond::persistency::PayloadProxy::m_currentPayloadId
Hash m_currentPayloadId
Definition: PayloadProxy.h:103
cond::persistency::PayloadProxy
Definition: PayloadProxy.h:61
Exception.h
cond::Hash
std::string Hash
Definition: Types.h:43
cond::persistency::BasePayloadProxy::~BasePayloadProxy
virtual ~BasePayloadProxy()
Definition: PayloadProxy.cc:14
cond::persistency::BasePayloadProxy::loadMore
virtual void loadMore(CondGetter const &)
Definition: PayloadProxy.h:40
cond::persistency::CondGetter::~CondGetter
virtual ~CondGetter()
Definition: PayloadProxy.h:22
cond::persistency::BasePayloadProxy::m_session
Session m_session
Definition: PayloadProxy.h:49
cond::persistency::BasePayloadProxy::loadPayload
virtual void loadPayload()=0
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
cond::persistency::BasePayloadProxy::m_iovAtInitialization
Iov_t m_iovAtInitialization
Definition: PayloadProxy.h:48
cond::persistency::PayloadProxy::~PayloadProxy
~PayloadProxy() override
Definition: PayloadProxy.h:69
cond::persistency::PayloadProxy::loadPayload
void loadPayload() override
Definition: PayloadProxy.h:92
IOVProxy.h
cond::persistency::BasePayloadProxy::m_mostRecentSession
Session const * m_mostRecentSession
Definition: PayloadProxy.h:53
source
static const std::string source
Definition: EdmProvDump.cc:47
cond::persistency::CondGetter
Definition: PayloadProxy.h:20
cond::persistency::BasePayloadProxy::m_mostRecentCurrentIov
Iov_t const * m_mostRecentCurrentIov
Definition: PayloadProxy.h:52
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cond
Definition: plugin.cc:23
cond::persistency::CondGetter::get
virtual IOVProxy get(std::string name) const =0
cond::persistency::BasePayloadProxy::make
virtual void make()=0
cond::Iov_t::payloadId
Hash payloadId
Definition: Types.h:55
cond::persistency::Session
Definition: Session.h:63
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
cond::persistency::BasePayloadProxy::m_requests
std::shared_ptr< std::vector< Iov_t > > m_requests
Definition: PayloadProxy.h:50
cond::persistency::BasePayloadProxy
Definition: PayloadProxy.h:27
cond::persistency::PayloadProxy::initKeyList
void initKeyList(PayloadProxy const &)
Definition: PayloadProxy.h:71
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
cond::persistency::PayloadProxy::m_data
std::unique_ptr< DataT > m_data
Definition: PayloadProxy.h:102
cond::persistency::BasePayloadProxy::m_mostRecentRequests
std::shared_ptr< std::vector< Iov_t > > const * m_mostRecentRequests
Definition: PayloadProxy.h:54
cond::persistency::PayloadProxy::operator()
const DataT & operator()() const
Definition: PayloadProxy.h:74
cond::persistency::PayloadProxy::PayloadProxy
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
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::Iov_t
Definition: Types.h:47
Types.h
Session.h
cond::persistency::BasePayloadProxy::isValid
bool isValid() const
Definition: PayloadProxy.cc:16
cond::persistency::PayloadProxy::make
void make() override
Definition: PayloadProxy.h:81
cond::persistency::BasePayloadProxy::BasePayloadProxy
BasePayloadProxy(Iov_t const *mostRecentCurrentIov, Session const *mostRecentSession, std::shared_ptr< std::vector< Iov_t >> const *mostRecentRequests)
Definition: PayloadProxy.cc:7