CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
23 //
24 // temporarely
25 
26 // TO BE REMOVED AFTER THE TRANSITION
27 namespace coral {
28  class ISessionProxy;
29  class ISchema;
30 }
31 // END TO BE REMOVED
32 
33 namespace cond {
34 
35  namespace persistency {
36 
37  class SessionConfiguration;
38 
39  // transaction class
40  class Transaction {
41  public:
42  explicit Transaction( SessionImpl& session );
43  Transaction( const Transaction& rhs );
44  Transaction& operator=( const Transaction& rhs );
45 
46  void start( bool readOnly=true );
47 
48  void commit();
49 
50  void rollback();
51 
52  bool isActive();
53  private:
55  };
56 
57  // with full value semantics. destruction will close the DB connection.
58  class Session {
59  public:
60  // default constructor
61  Session();
62 
63  // constructor
64  explicit Session( const std::shared_ptr<SessionImpl>& sessionImpl );
65 
66  //
67  Session( const Session& rhs );
68 
69  //
70  virtual ~Session();
71 
72  //
73  Session& operator=( const Session& rhs );
74 
75  //
76  void close();
77 
78  //
80 
81  //
82  bool existsDatabase();
83 
84  //
85  void createDatabase();
86 
87  // read access to the iov sequence.
88  // the iovs are lazy-loaded in groups when required, with repeatable queries ( for FronTier )
89  IOVProxy readIov( const std::string& tag, bool full=false );
90 
91  // read access to the iov sequence.
92  // the iovs are lazy-loaded in groups when required, with repeatable queries ( for FronTier )
93  IOVProxy readIov( const std::string& tag,
94  const boost::posix_time::ptime& snapshottime,
95  bool full=false );
96 
97  //
98  bool existsIov( const std::string& tag );
99 
100  // create a non-existing iov sequence with the specified tag.
101  // the type is required for consistency with the referenced payloads.
102  // fixme: add creation time - required for the migration
103  template <typename T>
104  IOVEditor createIov( const std::string& tag,
105  cond::TimeType timeType,
106  cond::SynchronizationType synchronizationType=cond::SYNCH_ANY );
108  const std::string& tag,
109  cond::TimeType timeType,
110  cond::SynchronizationType synchronizationType=cond::SYNCH_ANY );
111 
112  IOVEditor createIov( const std::string& payloadType,
113  const std::string& tag,
114  cond::TimeType timeType,
115  cond::SynchronizationType synchronizationType,
116  const boost::posix_time::ptime& creationTime );
117 
118  IOVEditor createIovForPayload( const Hash& payloadHash,
119  const std::string& tag, cond::TimeType timeType,
120  cond::SynchronizationType synchronizationType=cond::SYNCH_ANY );
121 
122  void clearIov( const std::string& tag );
123 
124  // update an existing iov sequence with the specified tag.
125  // timeType and payloadType can't be modified.
126  IOVEditor editIov( const std::string& tag );
127 
128  // functions to store a payload in the database. return the identifier of the item in the db.
129  template <typename T> cond::Hash storePayload( const T& payload,
130  const boost::posix_time::ptime& creationTime = boost::posix_time::microsec_clock::universal_time() );
131 
132  template <typename T> std::shared_ptr<T> fetchPayload( const cond::Hash& payloadHash );
133 
134  cond::Hash storePayloadData( const std::string& payloadObjectType,
135  const std::pair<Binary,Binary>& payloadAndStreamerInfoData,
136  const boost::posix_time::ptime& creationTime );
137 
138  bool fetchPayloadData( const cond::Hash& payloadHash,
139  std::string& payloadType,
140  cond::Binary& payloadData,
141  cond::Binary& streamerInfoData );
142 
143  // internal functions. creates proxies without loading a specific tag.
144  IOVProxy iovProxy();
145 
146  bool existsGlobalTag( const std::string& name );
147 
148  GTEditor createGlobalTag( const std::string& name );
149  GTEditor editGlobalTag( const std::string& name );
150 
151  GTProxy readGlobalTag( const std::string& name );
152  // essentially for the bridge. useless where ORA disappears.
153  GTProxy readGlobalTag( const std::string& name,
154  const std::string& preFix,
155  const std::string& postFix );
156  public:
157 
159 
160  coral::ISessionProxy& coralSession();
161  // TO BE REMOVED in the long term. The new code will use coralSession().
162  coral::ISchema& nominalSchema();
163 
164  private:
165 
166  std::shared_ptr<SessionImpl> m_session;
168  };
169 
170  template <typename T> inline IOVEditor Session::createIov( const std::string& tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType ){
171  return createIov( cond::demangledName( typeid(T) ), tag, timeType, synchronizationType );
172  }
173 
174  template <typename T> inline cond::Hash Session::storePayload( const T& payload, const boost::posix_time::ptime& creationTime ){
175 
176  std::string payloadObjectType = cond::demangledName(typeid(payload));
177  cond::Hash ret;
178  try{
179  ret = storePayloadData( payloadObjectType, serialize( payload ), creationTime );
180  } catch ( const cond::persistency::Exception& e ){
181  std::string em(e.what());
182  throwException( "Payload of type "+payloadObjectType+" could not be stored. "+em,"Session::storePayload");
183  }
184  return ret;
185  }
186 
187  template <typename T> inline std::shared_ptr<T> Session::fetchPayload( const cond::Hash& payloadHash ){
188  cond::Binary payloadData;
189  cond::Binary streamerInfoData;
191  if(! fetchPayloadData( payloadHash, payloadType, payloadData, streamerInfoData ) )
192  throwException( "Payload with id "+payloadHash+" has not been found in the database.",
193  "Session::fetchPayload" );
194  std::shared_ptr<T> ret;
195  try{
196  ret = deserialize<T>( payloadType, payloadData, streamerInfoData );
197  } catch ( const cond::persistency::Exception& e ){
198  std::string em(e.what());
199  throwException( "Payload of type "+payloadType+" with id "+payloadHash+" could not be loaded. "+em,"Session::fetchPayload");
200  }
201  return ret;
202  }
203 
205  public:
207 
209 
210  void start( bool readOnly=true );
211 
212  void commit();
213 
214  void close();
215  private:
217  bool m_status;
218 
219  };
220 
221 
222  }
223 }
224 #endif
virtual char const * what() const
Definition: Exception.cc:141
GTEditor editGlobalTag(const std::string &name)
Definition: Session.cc:166
Transaction(SessionImpl &session)
Definition: Session.cc:9
bool existsGlobalTag(const std::string &name)
Definition: Session.cc:153
tuple ret
prodAgent to be discontinued
Base exception class for the object to relational access.
Definition: Exception.h:11
std::pair< Binary, Binary > serialize(const T &payload)
Definition: Serialization.h:54
void clearIov(const std::string &tag)
Definition: Session.cc:148
tuple session
Definition: dataDML.py:2333
void start(bool readOnly=true)
Definition: Session.cc:22
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.h:170
TransactionScope(Transaction &transaction)
Definition: Session.cc:216
Transaction & transaction()
Definition: Session.cc:66
TimeType
Definition: Time.h:21
IOVProxy readIov(const std::string &tag, bool full=false)
Definition: Session.cc:81
Transaction & operator=(const Transaction &rhs)
Definition: Session.cc:17
coral::ISchema & nominalSchema()
Definition: Session.cc:212
Definition: GenABIO.cc:180
void start(bool readOnly=true)
Definition: Session.cc:227
tuple transaction
Definition: idDealer.py:60
std::string Hash
Definition: Types.h:45
bool fetchPayloadData(const cond::Hash &payloadHash, std::string &payloadType, cond::Binary &payloadData, cond::Binary &streamerInfoData)
Definition: Session.cc:195
std::string connectionString()
Definition: Session.cc:203
cond::Hash storePayloadData(const std::string &payloadObjectType, const std::pair< Binary, Binary > &payloadAndStreamerInfoData, const boost::posix_time::ptime &creationTime)
Definition: Session.cc:187
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:141
bool existsIov(const std::string &tag)
Definition: Session.cc:97
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:174
coral::ISessionProxy & coralSession()
Definition: Session.cc:207
SynchronizationType
Definition: Types.h:29
IOVEditor createIovForPayload(const Hash &payloadHash, const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::SYNCH_ANY)
Definition: Session.cc:129
GTEditor createGlobalTag(const std::string &name)
Definition: Session.cc:158
Session & operator=(const Session &rhs)
Definition: Session.cc:56
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:173
long double T
Transaction m_transaction
Definition: Session.h:167
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:14
std::shared_ptr< SessionImpl > m_session
Definition: Session.h:166
std::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:187