CMS 3D CMS Logo

Session.h
Go to the documentation of this file.
1 #ifndef CondCore_CondDB_Session_h
2 #define CondCore_CondDB_Session_h
3 //
4 // Package: CondDB
5 // Class : Session
6 //
10 //
11 // Author: Giacomo Govi
12 // Created: Apr 2013
13 //
14 
25 //
26 //#include <vector>
27 //#include <tuple>
28 // temporarely
29 
30 // TO BE REMOVED AFTER THE TRANSITION
31 namespace coral {
32  class ISessionProxy;
33  class ISchema;
34 } // namespace coral
35 // END TO BE REMOVED
36 
37 namespace cond {
38 
39  namespace persistency {
40 
41  class SessionConfiguration;
42 
43  // transaction class
44  class Transaction {
45  public:
46  explicit Transaction(SessionImpl& session);
47  Transaction(const Transaction& rhs);
48  Transaction& operator=(const Transaction& rhs);
49 
50  void start(bool readOnly = true);
51 
52  void commit();
53 
54  void rollback();
55 
56  bool isActive();
57 
58  private:
60  };
61 
62  // with full value semantics. destruction will close the DB connection.
63  class Session {
64  public:
65  // default constructor
66  Session();
67 
68  // constructor
69  explicit Session(const std::shared_ptr<SessionImpl>& sessionImpl);
70 
71  //
72  Session(const Session& rhs);
73 
74  //
75  virtual ~Session();
76 
77  //
78  Session& operator=(const Session& rhs);
79 
80  //
81  void close();
82 
83  //
85 
86  //
87  bool existsDatabase();
88 
89  //
90  void createDatabase();
91 
92  // read access to the iov sequence.
94 
95  // read access to the iov sequence.
96  IOVProxy readIov(const std::string& tag, const boost::posix_time::ptime& snapshottime);
97 
98  //
99  bool existsIov(const std::string& tag);
100 
101  // create a non-existing iov sequence with the specified tag.
102  // the type is required for consistency with the referenced payloads.
103  // fixme: add creation time - required for the migration
104  template <typename T>
106  cond::TimeType timeType,
107  cond::SynchronizationType synchronizationType = cond::SYNCH_ANY);
109  const std::string& tag,
110  cond::TimeType timeType,
111  cond::SynchronizationType synchronizationType = cond::SYNCH_ANY);
112 
114  const std::string& tag,
115  cond::TimeType timeType,
116  cond::SynchronizationType synchronizationType,
117  const boost::posix_time::ptime& creationTime);
118 
119  IOVEditor createIovForPayload(const Hash& payloadHash,
120  const std::string& tag,
121  cond::TimeType timeType,
122  cond::SynchronizationType synchronizationType = cond::SYNCH_ANY);
123 
124  void clearIov(const std::string& tag);
125 
126  // update an existing iov sequence with the specified tag.
127  // timeType and payloadType can't be modified.
129 
130  // functions to store a payload in the database. return the identifier of the item in the db.
131  template <typename T>
133  const T& payload,
134  const boost::posix_time::ptime& creationTime = boost::posix_time::microsec_clock::universal_time());
135 
136  template <typename T>
137  std::unique_ptr<T> fetchPayload(const cond::Hash& payloadHash);
138 
139  cond::Hash storePayloadData(const std::string& payloadObjectType,
140  const std::pair<Binary, Binary>& payloadAndStreamerInfoData,
141  const boost::posix_time::ptime& creationTime);
142 
143  bool fetchPayloadData(const cond::Hash& payloadHash,
145  cond::Binary& payloadData,
146  cond::Binary& streamerInfoData);
147 
148  bool existsGlobalTag(const std::string& name);
149 
152 
154  // essentially for the bridge. useless where ORA disappears.
155  GTProxy readGlobalTag(const std::string& name, const std::string& preFix, const std::string& postFix);
156 
157  // runinfo read only access
159 
160  // get the ongoing run
162 
163  // runinfo write access
165 
166  public:
168 
169  coral::ISessionProxy& coralSession();
170  // TO BE REMOVED in the long term. The new code will use coralSession().
171  coral::ISchema& nominalSchema();
172 
173  private:
174  std::shared_ptr<SessionImpl> m_session;
176  };
177 
178  template <typename T>
180  cond::TimeType timeType,
181  cond::SynchronizationType synchronizationType) {
182  return createIov(cond::demangledName(typeid(T)), tag, timeType, synchronizationType);
183  }
184 
185  template <typename T>
186  inline cond::Hash Session::storePayload(const T& payload, const boost::posix_time::ptime& creationTime) {
187  std::string payloadObjectType = cond::demangledName(typeid(payload));
188  cond::Hash ret;
189  try {
190  ret = storePayloadData(payloadObjectType, serialize(payload), creationTime);
191  } catch (const cond::persistency::Exception& e) {
192  std::string em(e.what());
193  throwException("Payload of type " + payloadObjectType + " could not be stored. " + em, "Session::storePayload");
194  }
195  return ret;
196  }
197 
198  template <>
199  inline cond::Hash Session::storePayload<std::string>(const std::string& payload,
200  const boost::posix_time::ptime& creationTime) {
201  std::string payloadObjectType("std::string");
202  cond::Hash ret;
203  try {
204  ret = storePayloadData(payloadObjectType, serialize(payload), creationTime);
205  } catch (const cond::persistency::Exception& e) {
206  std::string em(e.what());
207  throwException("Payload of type " + payloadObjectType + " could not be stored. " + em, "Session::storePayload");
208  }
209  return ret;
210  }
211 
212  template <typename T>
213  inline std::unique_ptr<T> Session::fetchPayload(const cond::Hash& payloadHash) {
214  cond::Binary payloadData;
215  cond::Binary streamerInfoData;
217  if (!fetchPayloadData(payloadHash, payloadType, payloadData, streamerInfoData))
218  throwException("Payload with id " + payloadHash + " has not been found in the database.",
219  "Session::fetchPayload");
220  std::unique_ptr<T> ret;
221  try {
222  ret = deserialize<T>(payloadType, payloadData, streamerInfoData);
223  } catch (const cond::persistency::Exception& e) {
224  std::string em(e.what());
225  throwException("Payload of type " + payloadType + " with id " + payloadHash + " could not be loaded. " + em,
226  "Session::fetchPayload");
227  }
228  return ret;
229  }
230 
232  public:
233  explicit TransactionScope(Transaction& transaction);
234 
236 
237  void start(bool readOnly = true);
238 
239  void commit();
240 
241  void close();
242 
243  private:
245  bool m_status;
246  };
247 
248  } // namespace persistency
249 } // namespace cond
250 #endif
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
cond::persistency::TransactionScope
Definition: Session.h:231
GTEditor.h
start
Definition: start.py:1
cond::TimeType
TimeType
Definition: Time.h:19
cond::Hash
std::string Hash
Definition: Types.h:43
cond::persistency::Session::existsIov
bool existsIov(const std::string &tag)
Definition: Session.cc:77
cond::persistency::GTProxy
Definition: GTProxy.h:32
cond::persistency::Transaction
Definition: Session.h:44
cond::Binary
Definition: Binary.h:15
RunInfoProxy.h
cond::persistency::RunInfoProxy
Definition: RunInfoProxy.h:26
cond::persistency::Session::clearIov
void clearIov(const std::string &tag)
Definition: Session.cc:137
cond::persistency::TransactionScope::m_status
bool m_status
Definition: Session.h:245
cond::persistency::IOVEditor
Definition: IOVEditor.h:28
IOVEditor.h
cond::persistency::TransactionScope::start
void start(bool readOnly=true)
Definition: Session.cc:236
cond::persistency::Session::readGlobalTag
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:163
cond::persistency::Session::close
void close()
Definition: Session.cc:50
cond::persistency::TransactionScope::close
void close()
Definition: Session.cc:246
cond::persistency::Session::createDatabase
void createDatabase()
Definition: Session.cc:61
cond::persistency::Session::fetchPayload
std::unique_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:213
cond::persistency::SessionImpl
Definition: SessionImpl.h:40
cond::persistency::Session::getLastRun
cond::RunInfo_t getLastRun()
Definition: Session.cc:201
cond::SynchronizationType
SynchronizationType
Definition: Types.h:27
IOVProxy.h
coral
Definition: Binary.h:9
Utils.h
cond::persistency::Session::m_transaction
Transaction m_transaction
Definition: Session.h:175
mps_fire.end
end
Definition: mps_fire.py:242
cond::persistency::TransactionScope::m_transaction
Transaction & m_transaction
Definition: Session.h:244
cond::persistency::Session::getRunInfo
RunInfoProxy getRunInfo(cond::Time_t start, cond::Time_t end)
Definition: Session.cc:193
jets_cff.payload
payload
Definition: jets_cff.py:32
cond::persistency::Session::readIov
IOVProxy readIov(const std::string &tag)
Definition: Session.cc:63
cond::persistency::IOVProxy
Definition: IOVProxy.h:92
cond
Definition: plugin.cc:23
cond::persistency::Session::storePayloadData
cond::Hash storePayloadData(const std::string &payloadObjectType, const std::pair< Binary, Binary > &payloadAndStreamerInfoData, const boost::posix_time::ptime &creationTime)
Definition: Session.cc:177
cond::persistency::Session::editIov
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:130
cond::persistency::GTEditor
Definition: GTEditor.h:28
cond::persistency::TransactionScope::commit
void commit()
Definition: Session.cc:241
cond::persistency::Transaction::Transaction
Transaction(SessionImpl &session)
Definition: Session.cc:9
Serialization.h
cond::SYNCH_ANY
Definition: Types.h:28
makeGlobalPositionRcd_cfg.tag
tag
Definition: makeGlobalPositionRcd_cfg.py:6
cond::persistency::Session::nominalSchema
coral::ISchema & nominalSchema()
Definition: Session.cc:224
cond::persistency::Session
Definition: Session.h:63
cond::Time_t
unsigned long long Time_t
Definition: Time.h:14
cond::persistency::Session::connectionString
std::string connectionString()
Definition: Session.cc:216
cond::persistency::Session::editGlobalTag
GTEditor editGlobalTag(const std::string &name)
Definition: Session.cc:156
cond::persistency::Transaction::commit
void commit()
Definition: Session.cc:23
cond::persistency::Session::coralSession
coral::ISessionProxy & coralSession()
Definition: Session.cc:218
cond::persistency::Exception
Base exception class for the object to relational access.
Definition: Exception.h:11
cond::persistency::Session::fetchPayloadData
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
Definition: Session.cc:185
BeamSpotPI::creationTime
Definition: BeamSpotPayloadInspectorHelper.h:44
cond::persistency::RunInfoEditor
Definition: RunInfoEditor.h:28
cond::persistency::Session::createIovForPayload
IOVEditor createIovForPayload(const Hash &payloadHash, const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.cc:114
cond::persistency::Transaction::isActive
bool isActive()
Definition: Session.cc:33
cond::RunInfo_t
Definition: Types.h:139
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
RunInfoEditor.h
cond::persistency::Session::storePayload
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:186
cond::persistency::Session::transaction
Transaction & transaction()
Definition: Session.cc:52
cond::persistency::Transaction::start
void start(bool readOnly=true)
Definition: Session.cc:18
HLT_FULL_cff.payloadType
payloadType
Definition: HLT_FULL_cff.py:9457
T
long double T
Definition: Basic3DVectorLD.h:48
cond::persistency::Session::m_session
std::shared_ptr< SessionImpl > m_session
Definition: Session.h:174
cond::persistency::Transaction::rollback
void rollback()
Definition: Session.cc:28
cond::persistency::Session::existsDatabase
bool existsDatabase()
Definition: Session.cc:55
cond::serialize
std::pair< Binary, Binary > serialize(const T &payload)
Definition: Serialization.h:66
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
cond::persistency::Session::createIov
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:179
Binary.h
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
cond::persistency::TransactionScope::~TransactionScope
~TransactionScope()
Definition: Session.cc:230
cond::persistency::Transaction::m_session
SessionImpl * m_session
Definition: Session.h:59
cond::persistency::Session::existsGlobalTag
bool existsGlobalTag(const std::string &name)
Definition: Session.cc:142
cond::persistency::Session::createGlobalTag
GTEditor createGlobalTag(const std::string &name)
Definition: Session.cc:147
cond::persistency::Transaction::operator=
Transaction & operator=(const Transaction &rhs)
Definition: Session.cc:13
Types.h
GTProxy.h
cond::persistency::Session::editRunInfo
RunInfoEditor editRunInfo()
Definition: Session.cc:210
cond::persistency::TransactionScope::TransactionScope
TransactionScope(Transaction &transaction)
Definition: Session.cc:226
cond::persistency::Session::operator=
Session & operator=(const Session &rhs)
Definition: Session.cc:44
cond::persistency::Session::~Session
virtual ~Session()
Definition: Session.cc:42
cond::persistency::Session::Session
Session()
Definition: Session.cc:35
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37