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 
22  BasePayloadProxy::Stats BasePayloadProxy::gstats = {0,0,0,0,0,0,0};
23 
24 
26  bool errorPolicy) :
27  m_doThrow(errorPolicy), m_iov(session),m_session(session) {
28  ++gstats.nProxy;
29  BasePayloadProxy::Stats s = {0,0,0,0,0,0,0,ObjIds()};
30  stats = s;
31  }
32 
34  const std::string & iovToken,
35  bool errorPolicy) :
36  m_doThrow(errorPolicy), m_iov(session),m_session(session) {
37  m_session.transaction().start(true);
38  m_iov.load( iovToken );
40  ++gstats.nProxy;
41  BasePayloadProxy::Stats s = {0,0,0,0,0,0,0,ObjIds()};
42  stats = s;
43  }
44 
45 
47 
48  void BasePayloadProxy::loadIov( const std::string iovToken ){
49  m_session.transaction().start(true);
50  m_iov.load( iovToken );
53  }
54 
55  void BasePayloadProxy::loadTag( const std::string tag ){
56  m_session.transaction().start(true);
57  cond::MetaData metadata(m_session);
58  std::string iovToken = metadata.getToken(tag);
59  m_iov.load( iovToken );
62  }
63 
65  m_element = *m_iov.find(time);
66  make();
68  }
69 
71  m_element.set(m_iov.iov(),n);
72  make();
74  }
75 
76 
78  ++gstats.nMake;
79  ++stats.nMake;
80  bool ok = false;
81  if ( isValid()) {
82  // check if (afterall) the payload is still the same...
83  if (m_element.token()==token()) return;
84  try {
85  m_session.transaction().start(true);
86  ok = load( m_session ,m_element.token());
88  if (ok) m_token = m_element.token();
89  } catch( const ora::Exception& e) {
90  if (m_doThrow) throw cond::Exception(std::string("Condition Payload loader: ")+ e.what());
91  ok = false;
92  }
93  }
94 
95  if (!ok) {
97  m_token.clear();
98  if (m_doThrow){
99  throw cond::Exception("Condition Payload loader: invalid data");
100  }
101  }
102  if (ok) {
103  ++gstats.nLoad; ++stats.nLoad;
104  stats.ids.push_back(ObjId());
105  fillIt(stats.ids.back(),m_token, m_element.since());
106  }
107  }
108 
109 
111  //FIXME: shall handle truncation...
112  if ( (!(time<m_element.till())) || time<m_element.since() ){
113  m_element = *m_iov.find(time);
114  }
116  }
117 
120  && !m_element.token().empty();
121  }
122 
123 
126  m_session.transaction().start(true);
127  bool anew = m_iov.refresh();
129  if (anew) {
132  }
133  return anew;
134  }
135 
138  m_session = newSession;
139  m_session.transaction().start(true);
140  bool anew = m_iov.refresh( m_session );
142  if (anew) {
145  }
146  return anew;
147  }
148 
149 }
IOVElementProxy m_element
Definition: PayloadProxy.h:99
virtual char const * what() const
Definition: Exception.cc:141
void loadIov(const std::string iovToken)
Definition: PayloadProxy.cc:48
DbTransaction & transaction()
Definition: DbSession.cc:189
int commit()
commit transaction.
Definition: OId.h:8
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
const std::string getToken(const std::string &tagname) const
Definition: MetaData.cc:53
cond::Time_t till() const
Definition: IOVProxy.h:71
cond::ValidityInterval loadFor(cond::Time_t time)
Definition: PayloadProxy.cc:64
Base exception class for the object to relational access.
Definition: Exception.h:10
int start(bool readOnly=false)
start transaction
const_iterator find(cond::Time_t time) const
Definition: IOVProxy.cc:264
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)
IOVSequence const & iov() const
Definition: IOVProxy.cc:276
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:202
cond::Time_t since() const
Definition: IOVProxy.h:67
void loadTag(const std::string tag)
Definition: PayloadProxy.cc:55
BasePayloadProxy(cond::DbSession &session, bool errorPolicy)
Definition: PayloadProxy.cc:25
bool fromString(const std::string &s)
Definition: OId.cc:64
int itemId() const
Definition: OId.cc:54
void load(const std::string &token)
Definition: IOVProxy.cc:197
std::string const & token() const
Definition: PayloadProxy.h:65