CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Session.cc
Go to the documentation of this file.
2 #include "SessionImpl.h"
3 //
4 
5 namespace cond {
6 
7  namespace persistency {
8 
9  Transaction::Transaction(SessionImpl& session) : m_session(&session) {}
10 
11  Transaction::Transaction(const Transaction& rhs) : m_session(rhs.m_session) {}
12 
14  m_session = rhs.m_session;
15  return *this;
16  }
17 
18  void Transaction::start(bool readOnly) {
19  if (m_session)
20  m_session->startTransaction(readOnly);
21  }
22 
24  if (m_session)
26  }
27 
29  if (m_session)
31  }
32 
34 
35  Session::Session() : m_session(new SessionImpl), m_transaction(*m_session) {}
36 
37  Session::Session(const std::shared_ptr<SessionImpl>& sessionImpl)
38  : m_session(sessionImpl), m_transaction(*m_session) {}
39 
40  Session::Session(const Session& rhs) : m_session(rhs.m_session), m_transaction(rhs.m_transaction) {}
41 
43 
45  m_session = rhs.m_session;
47  return *this;
48  }
49 
50  void Session::close() { m_session->close(); }
51 
53 
54  //
57  return m_session->transaction->iovDbExists;
58  }
59 
60  //
61  void Session::createDatabase() { m_session->openDb(); }
62 
64  m_session->openIovDb();
66  proxy.load(tagName);
67  return proxy;
68  }
69 
70  IOVProxy Session::readIov(const std::string& tagName, const boost::posix_time::ptime& snapshottime) {
71  m_session->openIovDb();
73  proxy.load(tagName, snapshottime);
74  return proxy;
75  }
76 
78  m_session->openIovDb();
79  return m_session->iovSchema().tagTable().select(tag);
80  }
81 
82  //bool Session::getIovRange(const std::string& tag,
83  // cond::Time_t begin,
84  // cond::Time_t end,
85  // std::vector<std::tuple<cond::Time_t, cond::Hash> >& range) {
86  // m_session->openIovDb();
87  // boost::posix_time::ptime snapshotTime;
88  // return m_session->iovSchema().iovTable().getRange(tag, begin, end, snapshotTime, range);
89  //}
90 
92  const std::string& tag,
93  cond::TimeType timeType,
94  cond::SynchronizationType synchronizationType) {
95  m_session->openDb();
96  if (m_session->iovSchema().tagTable().select(tag))
97  throwException("The specified tag \"" + tag + "\" already exist in the database.", "Session::createIov");
98  IOVEditor editor(m_session, tag, timeType, payloadType, synchronizationType);
99  return editor;
100  }
101 
103  const std::string& tag,
104  cond::TimeType timeType,
105  cond::SynchronizationType synchronizationType,
106  const boost::posix_time::ptime& creationTime) {
107  m_session->openDb();
108  if (m_session->iovSchema().tagTable().select(tag))
109  throwException("The specified tag \"" + tag + "\" already exist in the database.", "Session::createIov");
110  IOVEditor editor(m_session, tag, timeType, payloadType, synchronizationType, creationTime);
111  return editor;
112  }
113 
115  const std::string& tag,
116  cond::TimeType timeType,
117  cond::SynchronizationType synchronizationType) {
118  m_session->openDb();
119  if (m_session->iovSchema().tagTable().select(tag))
120  throwException("The specified tag \"" + tag + "\" already exist in the database.",
121  "Session::createIovForPayload");
123  if (!m_session->iovSchema().payloadTable().getType(payloadHash, payloadType))
124  throwException("The specified payloadId \"" + payloadHash + "\" does not exist in the database.",
125  "Session::createIovForPayload");
126  IOVEditor editor(m_session, tag, timeType, payloadType, synchronizationType);
127  return editor;
128  }
129 
131  m_session->openIovDb();
132  IOVEditor editor(m_session);
133  editor.load(tag);
134  return editor;
135  }
136 
138  m_session->openIovDb();
139  m_session->iovSchema().iovTable().erase(tag);
140  }
141 
143  m_session->openGTDb();
144  return m_session->gtSchema().gtTable().select(name);
145  }
146 
148  m_session->openGTDb();
149  if (m_session->gtSchema().gtTable().select(name))
150  throwException("The specified Global Tag \"" + name + "\" already exist in the database.",
151  "Session::createGlobalTag");
152  GTEditor editor(m_session, name);
153  return editor;
154  }
155 
157  m_session->openGTDb();
158  GTEditor editor(m_session);
159  editor.load(name);
160  return editor;
161  }
162 
164  m_session->openGTDb();
166  proxy.load(name);
167  return proxy;
168  }
169 
170  GTProxy Session::readGlobalTag(const std::string& name, const std::string& preFix, const std::string& postFix) {
171  m_session->openGTDb();
173  proxy.load(name, preFix, postFix);
174  return proxy;
175  }
176 
178  const std::pair<Binary, Binary>& payloadAndStreamerInfoData,
179  const boost::posix_time::ptime& creationTime) {
180  m_session->openDb();
181  return m_session->iovSchema().payloadTable().insertIfNew(
182  payloadObjectType, payloadAndStreamerInfoData.first, payloadAndStreamerInfoData.second, creationTime);
183  }
184 
185  bool Session::fetchPayloadData(const cond::Hash& payloadHash,
187  cond::Binary& payloadData,
188  cond::Binary& streamerInfoData) {
189  m_session->openIovDb();
190  return m_session->iovSchema().payloadTable().select(payloadHash, payloadType, payloadData, streamerInfoData);
191  }
192 
194  if (!m_session->transaction.get())
195  throwException("The transaction is not active.", "Session::getRunInfo");
197  proxy.load(start, end);
198  return proxy;
199  }
200 
202  if (!m_session->transaction.get())
203  throwException("The transaction is not active.", "Session::getRunInfo");
204  m_session->openRunInfoDb();
206  ret.run = m_session->runInfoSchema().runInfoTable().getLastInserted(ret.start, ret.end);
207  return ret;
208  }
209 
211  RunInfoEditor editor(m_session);
212  editor.init();
213  return editor;
214  }
215 
216  std::string Session::connectionString() { return m_session->connectionString; }
217 
218  coral::ISessionProxy& Session::coralSession() {
219  if (!m_session->coralSession.get())
220  throwException("The session is not active.", "Session::coralSession");
221  return *m_session->coralSession;
222  }
223 
224  coral::ISchema& Session::nominalSchema() { return coralSession().nominalSchema(); }
225 
226  TransactionScope::TransactionScope(Transaction& transaction) : m_transaction(transaction), m_status(true) {
228  }
229 
231  if (!m_status && m_transaction.isActive()) {
233  }
234  }
235 
236  void TransactionScope::start(bool readOnly) {
237  m_transaction.start(readOnly);
238  m_status = false;
239  }
240 
243  m_status = true;
244  }
245 
247 
248  } // namespace persistency
249 } // namespace cond
GTEditor editGlobalTag(const std::string &name)
Definition: Session.cc:156
Transaction(SessionImpl &session)
Definition: Session.cc:9
bool existsGlobalTag(const std::string &name)
Definition: Session.cc:142
tuple ret
prodAgent to be discontinued
void clearIov(const std::string &tag)
Definition: Session.cc:137
boost::posix_time::ptime end
Definition: Types.h:151
void start(bool readOnly=true)
Definition: Session.cc:18
RunInfoEditor editRunInfo()
Definition: Session.cc:210
void load(Time_t low, Time_t up)
Definition: RunInfoProxy.cc:66
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:179
void load(const std::string &tag)
Definition: IOVEditor.cc:71
TransactionScope(Transaction &transaction)
Definition: Session.cc:226
Transaction & transaction()
Definition: Session.cc:52
TimeType
Definition: Time.h:19
unsigned long long Time_t
Definition: Time.h:14
Transaction & operator=(const Transaction &rhs)
Definition: Session.cc:13
void load(const std::string &gtName, const std::string &preFix="", const std::string &postFix="")
Definition: GTProxy.cc:107
coral::ISchema & nominalSchema()
Definition: Session.cc:224
void start(bool readOnly=true)
Definition: Session.cc:236
std::string Hash
Definition: Types.h:43
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
Definition: Session.cc:185
std::string connectionString()
Definition: Session.cc:216
boost::posix_time::ptime start
Definition: Types.h:150
cond::Hash storePayloadData(const std::string &payloadObjectType, const std::pair< Binary, Binary > &payloadAndStreamerInfoData, const boost::posix_time::ptime &creationTime)
Definition: Session.cc:177
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:130
void startTransaction(bool readOnly=true)
Definition: SessionImpl.cc:62
cond::RunInfo_t getLastRun()
Definition: Session.cc:201
bool existsIov(const std::string &tag)
Definition: Session.cc:77
void load(const std::string &tag)
Definition: IOVProxy.cc:139
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
string end
Definition: dataset.py:937
SynchronizationType
Definition: Types.h:27
Time_t run
Definition: Types.h:149
bool isTransactionActive(bool deep=true) const
Definition: SessionImpl.cc:105
IOVEditor createIovForPayload(const Hash &payloadHash, const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.cc:114
GTEditor createGlobalTag(const std::string &name)
Definition: Session.cc:147
Session & operator=(const Session &rhs)
Definition: Session.cc:44
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:163
void load(const std::string &gtName)
Definition: GTEditor.cc:43
Transaction m_transaction
Definition: Session.h:175
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
std::shared_ptr< SessionImpl > m_session
Definition: Session.h:174
RunInfoProxy getRunInfo(cond::Time_t start, cond::Time_t end)
Definition: Session.cc:193