CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PayloadProxy.cc
Go to the documentation of this file.
2 
7 
8 namespace {
9 
10  void fillIt(cond::BasePayloadProxy::ObjId & obj, std::string const & token, cond::Time_t since) {
11  obj.since = since;
12  ora::OId oid;
13  oid.fromString( token );
14  obj.oid1 = oid.containerId();
15  obj.oid2 = oid.itemId();
16  }
17 
18 }
19 
20 namespace cond {
21 
23  bool errorPolicy) :
24  m_doThrow(errorPolicy), m_iov(session),m_session(session) {
25  BasePayloadProxy::Stats s = {0,0,0,0,0,0,0,ObjIds()};
26  stats = s;
27  }
28 
30  const std::string & iovToken,
31  bool errorPolicy) :
32  m_doThrow(errorPolicy), m_iov(session),m_session(session) {
33  m_session.transaction().start(true);
34  m_iov.load( iovToken );
36  BasePayloadProxy::Stats s = {0,0,0,0,0,0,0,ObjIds()};
37  stats = s;
38  }
39 
40 
42 
43  void BasePayloadProxy::loadIov( const std::string iovToken ){
44  m_session.transaction().start(true);
45  m_iov.load( iovToken );
48  }
49 
51  m_session.transaction().start(true);
52  cond::MetaData metadata(m_session);
53  std::string iovToken = metadata.getToken(tag);
54  m_iov.load( iovToken );
57  }
58 
60  m_element = *m_iov.find(time);
61  make();
63  }
64 
66  m_element.set(m_iov.iov(),n);
67  make();
69  }
70 
71 
73  ++stats.nMake;
74  bool ok = false;
75  if ( isValid()) {
76  // check if (afterall) the payload is still the same...
77  if (m_element.token()==token()) return;
78  try {
79  m_session.transaction().start(true);
80  ok = load( m_session ,m_element.token());
82  if (ok) m_token = m_element.token();
83  } catch( const ora::Exception& e) {
84  if (m_doThrow) throw cond::Exception(std::string("Condition Payload loader: ")+ e.what());
85  ok = false;
86  }
87  }
88 
89  if (!ok) {
91  m_token.clear();
92  if (m_doThrow){
93  throw cond::Exception("Condition Payload loader: invalid data");
94  }
95  }
96  if (ok) {
97  ++stats.nLoad;
98  stats.ids.push_back(ObjId());
99  fillIt(stats.ids.back(),m_token, m_element.since());
100  }
101  }
102 
103 
105  //FIXME: shall handle truncation...
106  if ( (!(time<m_element.till())) || time<m_element.since() ){
107  m_element = *m_iov.find(time);
108  }
110  }
111 
114  && !m_element.token().empty();
115  }
116 
117 
119  ++stats.nRefresh;
120  m_session.transaction().start(true);
121  bool anew = m_iov.refresh();
123  if (anew) {
125  ++stats.nArefresh;
126  }
127  return anew;
128  }
129 
131  ++stats.nReconnect;
132  m_session = newSession;
133  m_session.transaction().start(true);
134  bool anew = m_iov.refresh( m_session );
136  if (anew) {
138  ++stats.nAreconnect;
139  }
140  return anew;
141  }
142 
143 }
IOVElementProxy m_element
Definition: PayloadProxy.h:97
virtual char const * what() const
Definition: Exception.cc:141
IOVSequence const & iov() const
Definition: IOVProxy.cc:276
void loadIov(const std::string iovToken)
Definition: PayloadProxy.cc:43
DbTransaction & transaction()
Definition: DbSession.cc:208
int commit()
commit transaction.
Definition: OId.h:8
void load(const std::string &token)
Definition: IOVProxy.cc:200
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:52
cond::Time_t till() const
Definition: IOVProxy.h:71
cond::ValidityInterval loadFor(cond::Time_t time)
Definition: PayloadProxy.cc:59
Base exception class for the object to relational access.
Definition: Exception.h:10
int start(bool readOnly=false)
start transaction
unsigned long long Time_t
Definition: Time.h:16
void set(cond::Time_t is, cond::Time_t it, std::string const &itoken)
Definition: IOVProxy.h:59
std::string const & token() const
Definition: IOVProxy.h:75
int containerId() const
Definition: OId.cc:50
const Time_t invalidTime(0)
cond::ValidityInterval setIntervalFor(cond::Time_t time)
virtual void invalidateCache()=0
std::vector< ObjId > ObjIds
Definition: PayloadProxy.h:31
virtual bool load(cond::DbSession &session, std::string const &token)=0
bool refresh()
Definition: IOVProxy.cc:205
cond::Time_t since() const
Definition: IOVProxy.h:67
void loadTag(const std::string tag)
Definition: PayloadProxy.cc:50
BasePayloadProxy(cond::DbSession &session, bool errorPolicy)
Definition: PayloadProxy.cc:22
bool fromString(const std::string &s)
Definition: OId.cc:64
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:264
int itemId() const
Definition: OId.cc:54
std::string const & token() const
Definition: PayloadProxy.h:63