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 
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
46  ValidityInterval setIntervalFor( Time_t target, bool loadPayload=false );
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=nullptr ) :
82  BasePayloadProxy() {}
83 
84  ~PayloadProxy() override{}
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  void make() override{
95  if( isValid() ){
96  if( m_currentIov.payloadId == m_currentPayloadId ) return;
97  m_session.transaction().start(true);
98  loadPayload();
99  m_session.transaction().commit();
100  }
101  }
102 
103  virtual void invalidateTransientCache() {
104  m_data.reset();
105  m_currentPayloadId.clear();
106  }
107 
108  void invalidateCache() override {
109  m_data.reset();
110  m_currentPayloadId.clear();
111  m_currentIov.clear();
112  m_requests.clear();
113  }
114 
115  protected:
116  void loadPayload() override {
117  if( m_currentIov.payloadId.empty() ){
118  throwException( "Can't load payload: no valid IOV found.","PayloadProxy::loadPayload" );
119  }
120  m_data = m_session.fetchPayload<DataT>( m_currentIov.payloadId );
121  m_currentPayloadId = m_currentIov.payloadId;
122  m_requests.push_back( m_currentIov );
123  }
124 
125  private:
126  std::shared_ptr<DataT> m_data;
128  };
129 
130  }
131 }
132 #endif // CondCore_CondDB_PayloadProxy_h
std::shared_ptr< DataT > m_data
Definition: PayloadProxy.h:126
const std::vector< Iov_t > & requests() const
Definition: PayloadProxy.h:57
S make(const edm::ParameterSet &cfg)
const DataT & operator()() const
Definition: PayloadProxy.h:87
TimeType
Definition: Time.h:21
std::vector< Iov_t > m_requests
Definition: PayloadProxy.h:69
unsigned long long Time_t
Definition: Time.h:16
virtual void invalidateTransientCache()
Definition: PayloadProxy.h:103
std::string Hash
Definition: Types.h:45
const Hash & payloadId() const
Definition: PayloadProxy.h:43
Definition: plugin.cc:24
virtual void loadMore(CondGetter const &)
Definition: PayloadProxy.h:52
static std::string const source
Definition: EdmProvDump.cc:47
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14
PayloadProxy(const char *source=0)
Definition: PayloadProxy.h:81