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 #include <boost/shared_ptr.hpp>
26 
27 // TO BE REMOVED AFTER THE TRANSITION
28 namespace coral {
29  class ISessionProxy;
30  class ISchema;
31 }
32 // END TO BE REMOVED
33 
34 namespace cond {
35 
36  namespace persistency {
37 
38  class SessionConfiguration;
39 
40  // transaction class
41  class Transaction {
42  public:
43  explicit Transaction( SessionImpl& session );
44  Transaction( const Transaction& rhs );
45  Transaction& operator=( const Transaction& rhs );
46 
47  void start( bool readOnly=true );
48 
49  void commit();
50 
51  void rollback();
52 
53  bool isActive();
54  private:
56  };
57 
58  // with full value semantics. destruction will close the DB connection.
59  class Session {
60  public:
61  // default constructor
62  Session();
63 
64  // constructor
65  explicit Session( const std::shared_ptr<SessionImpl>& sessionImpl );
66 
67  //
68  Session( const Session& rhs );
69 
70  //
71  virtual ~Session();
72 
73  //
74  Session& operator=( const Session& rhs );
75 
76  //
77  void close();
78 
79  //
81 
82  //
83  bool existsDatabase();
84 
85  //
86  void createDatabase();
87 
88  // read access to the iov sequence.
89  // by default ( full=false ) the iovs are lazy-loaded in groups when required, with repeatable queries ( for FronTier )
90  // full=true will load the entire sequence in memory. Mainly for test/debugging.
92  bool full=false );//,const boost::posix_time::ptime& snapshottime )
93 
94  //
95  bool existsIov( const std::string& tag );
96 
97  // create a non-existing iov sequence with the specified tag.
98  // the type is required for consistency with the referenced payloads.
99  // fixme: add creation time - required for the migration
100  template <typename T>
101  IOVEditor createIov( const std::string& tag,
102  cond::TimeType timeType,
103  cond::SynchronizationType synchronizationType=cond::OFFLINE );
105  const std::string& tag,
106  cond::TimeType timeType,
107  cond::SynchronizationType synchronizationType=cond::OFFLINE );
108 
109  IOVEditor createIov( const std::string& payloadType,
110  const std::string& tag,
111  cond::TimeType timeType,
112  cond::SynchronizationType synchronizationType,
113  const boost::posix_time::ptime& creationTime );
114 
115  IOVEditor createIovForPayload( const Hash& payloadHash,
116  const std::string& tag, cond::TimeType timeType,
117  cond::SynchronizationType synchronizationType=cond::OFFLINE );
118 
119  void clearIov( const std::string& tag );
120 
121  // update an existing iov sequence with the specified tag.
122  // timeType and payloadType can't be modified.
123  IOVEditor editIov( const std::string& tag );
124 
125  // functions to store a payload in the database. return the identifier of the item in the db.
126  template <typename T> cond::Hash storePayload( const T& payload,
127  const boost::posix_time::ptime& creationTime = boost::posix_time::microsec_clock::universal_time() );
128  template <typename T> boost::shared_ptr<T> fetchPayload( const cond::Hash& payloadHash );
129 
130  // low-level function to access the payload data as a blob. mainly used for the data migration and testing.
131  // the version for ROOT
132  bool fetchPayloadData( const cond::Hash& payloadHash,
133  std::string& payloadType,
134  cond::Binary& payloadData,
135  cond::Binary& streamerInfoData );
136 
137  // internal functions. creates proxies without loading a specific tag.
138  IOVProxy iovProxy();
139 
140  bool existsGlobalTag( const std::string& name );
141 
142  GTEditor createGlobalTag( const std::string& name );
143  GTEditor editGlobalTag( const std::string& name );
144 
145  GTProxy readGlobalTag( const std::string& name );
146  // essentially for the bridge. useless where ORA disappears.
147  GTProxy readGlobalTag( const std::string& name,
148  const std::string& preFix,
149  const std::string& postFix );
150  public:
151 
152  bool checkMigrationLog( const std::string& sourceAccount,
153  const std::string& sourceTag,
154  std::string& destinationTag,
156  void addToMigrationLog( const std::string& sourceAccount,
157  const std::string& sourceTag,
158  const std::string& destinationTag,
159  cond::MigrationStatus status);
160  void updateMigrationLog( const std::string& sourceAccount,
161  const std::string& sourceTag,
162  cond::MigrationStatus status);
163 
164  bool lookupMigratedPayload( const std::string& sourceAccount,
165  const std::string& sourceToken,
166  std::string& payloadId );
167  void addMigratedPayload( const std::string& sourceAccount,
168  const std::string& sourceToken,
169  const std::string& payloadId );
170  void updateMigratedPayload( const std::string& sourceAccount,
171  const std::string& sourceToken,
172  const std::string& payloadId );
173  std::string parsePoolToken( const std::string& poolToken );
174 
176 
177  coral::ISessionProxy& coralSession();
178  // TO BE REMOVED in the long term. The new code will use coralSession().
179  coral::ISchema& nominalSchema();
180 
181  bool isOraSession();
182 
183  private:
184  cond::Hash storePayloadData( const std::string& payloadObjectType,
185  const std::pair<Binary,Binary>& payloadAndStreamerInfoData,
186  const boost::posix_time::ptime& creationTime );
187 
188  private:
189 
190  std::shared_ptr<SessionImpl> m_session;
192  };
193 
194  template <typename T> inline IOVEditor Session::createIov( const std::string& tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType ){
195  return createIov( cond::demangledName( typeid(T) ), tag, timeType, synchronizationType );
196  }
197 
198  template <typename T> inline cond::Hash Session::storePayload( const T& payload, const boost::posix_time::ptime& creationTime ){
199 
200  std::string payloadObjectType = cond::demangledName(typeid(payload));
201  return storePayloadData( payloadObjectType, serialize( payload, isOraSession() ), creationTime );
202  }
203 
204  template <typename T> inline boost::shared_ptr<T> Session::fetchPayload( const cond::Hash& payloadHash ){
205  cond::Binary payloadData;
206  cond::Binary streamerInfoData;
208  if(! fetchPayloadData( payloadHash, payloadType, payloadData, streamerInfoData ) )
209  throwException( "Payload with id="+payloadHash+" has not been found in the database.",
210  "Session::fetchPayload" );
211  return deserialize<T>( payloadType, payloadData, streamerInfoData, isOraSession() );
212  }
213 
215  public:
217 
219 
220  void start( bool readOnly=true );
221 
222  void commit();
223 
224  void close();
225  private:
227  bool m_status;
228 
229  };
230 
231 
232  }
233 }
234 #endif
void addToMigrationLog(const std::string &sourceAccount, const std::string &sourceTag, const std::string &destinationTag, cond::MigrationStatus status)
Definition: Session.cc:208
GTEditor editGlobalTag(const std::string &name)
Definition: Session.cc:157
Transaction(SessionImpl &session)
Definition: Session.cc:9
bool existsGlobalTag(const std::string &name)
Definition: Session.cc:144
MigrationStatus
Definition: Types.h:26
void updateMigratedPayload(const std::string &sourceAccount, const std::string &sourceToken, const std::string &payloadId)
Definition: Session.cc:244
void addMigratedPayload(const std::string &sourceAccount, const std::string &sourceToken, const std::string &payloadId)
Definition: Session.cc:235
void clearIov(const std::string &tag)
Definition: Session.cc:139
boost::shared_ptr< T > fetchPayload(const cond::Hash &payloadHash)
Definition: Session.h:204
void start(bool readOnly=true)
Definition: Session.cc:22
TransactionScope(Transaction &transaction)
Definition: Session.cc:272
Transaction & transaction()
Definition: Session.cc:66
void updateMigrationLog(const std::string &sourceAccount, const std::string &sourceTag, cond::MigrationStatus status)
Definition: Session.cc:218
TimeType
Definition: Time.h:21
std::string demangledName(const std::type_info &typeInfo)
Definition: ClassUtils.cc:156
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:268
Definition: GenABIO.cc:180
void start(bool readOnly=true)
Definition: Session.cc:283
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:186
std::string connectionString()
Definition: Session.cc:259
cond::Hash storePayloadData(const std::string &payloadObjectType, const std::pair< Binary, Binary > &payloadAndStreamerInfoData, const boost::posix_time::ptime &creationTime)
Definition: Session.cc:178
IOVEditor editIov(const std::string &tag)
Definition: Session.cc:132
std::string parsePoolToken(const std::string &poolToken)
Definition: Session.cc:254
IOVEditor createIovForPayload(const Hash &payloadHash, const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::OFFLINE)
Definition: Session.cc:120
bool existsIov(const std::string &tag)
Definition: Session.cc:88
std::pair< Binary, Binary > serialize(const T &payload, bool packingOnly=false)
Definition: Serialization.h:92
cond::Hash storePayload(const T &payload, const boost::posix_time::ptime &creationTime=boost::posix_time::microsec_clock::universal_time())
Definition: Session.h:198
coral::ISessionProxy & coralSession()
Definition: Session.cc:263
IOVEditor createIov(const std::string &tag, cond::TimeType timeType, cond::SynchronizationType synchronizationType=cond::OFFLINE)
Definition: Session.h:194
bool lookupMigratedPayload(const std::string &sourceAccount, const std::string &sourceToken, std::string &payloadId)
Definition: Session.cc:227
SynchronizationType
Definition: Types.h:31
GTEditor createGlobalTag(const std::string &name)
Definition: Session.cc:149
tuple status
Definition: ntuplemaker.py:245
Session & operator=(const Session &rhs)
Definition: Session.cc:56
GTProxy readGlobalTag(const std::string &name)
Definition: Session.cc:164
long double T
Transaction m_transaction
Definition: Session.h:191
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:11
std::shared_ptr< SessionImpl > m_session
Definition: Session.h:190
bool checkMigrationLog(const std::string &sourceAccount, const std::string &sourceTag, std::string &destinationTag, cond::MigrationStatus &status)
Definition: Session.cc:198