CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Attributes
conddblib.Connection Class Reference
Inheritance diagram for conddblib.Connection:

Public Member Functions

def __init__
 
def get_dbtype
 
def init
 
def is_frontier
 
def is_official
 
def is_oracle
 
def is_read_only
 
def is_sqlite
 
def is_valid
 
def metadata
 
def session
 

Public Attributes

 engine
 

Private Attributes

 _backendName
 
 _is_frontier
 
 _is_official
 
 _is_oracle
 
 _is_read_only
 
 _is_sqlite
 
 _is_valid
 
 _schemaName
 
 _session
 
 _url
 

Detailed Description

Definition at line 301 of file conddblib.py.

Constructor & Destructor Documentation

def conddblib.Connection.__init__ (   self,
  url,
  init = False 
)

Definition at line 303 of file conddblib.py.

304  def __init__(self, url, init=False):
305  # Workaround to avoid creating files if not present.
306  # Python's sqlite3 module does not use sqlite3_open_v2(),
307  # and therefore we cannot disable SQLITE_OPEN_CREATE.
308  # Only in the case of creating a new database we skip the check.
309  if url.drivername == 'sqlite':
310 
311  #if not init and url.database is not None and not os.path.isfile(url.database):
312  # # url.database is None if opening a in-memory DB, e.g. 'sqlite://'
313  # raise Exception('SQLite database %s not found.' % url.database)
315  self.engine = sqlalchemy.create_engine(url)
316 
317  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
318  supports_foreign_keys = enabled_foreign_keys is not None
319  if not supports_foreign_keys:
320  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
321  elif not enabled_foreign_keys:
322  self.engine.execute('pragma foreign_keys = on')
323 
324  else:
325  self.engine = sqlalchemy.create_engine(url)
327  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
329  self._is_frontier = url.drivername == 'oracle+frontier'
330  self._is_oracle = url.drivername == 'oracle'
331  self._is_sqlite = url.drivername == 'sqlite'
333  self._is_read_only = self._is_frontier or url.host in {
334  'cms_orcon_adg',
335  'cmsarc_lb',
336  }
338  self._is_official = self._is_frontier or url.host in {
339  'cms_orcon_adg',
340  'cmsarc_lb',
341  'cms_orcoff_int',
342  'cms_orcoff_prep',
343  'cms_orcon_prod',
344  'cmsintr_lb',
345  }
346  self._url = url
347  self._backendName = ('sqlite' if self._is_sqlite else 'oracle' )
348  self._schemaName = ( None if self._is_sqlite else schema_name )
349  logging.debug(' ... using db "%s", schema "%s"' % (url, self._schemaName) )
350  logging.debug('Loading db types...')
351  self.get_dbtype(Tag).__name__
352  self.get_dbtype(Payload)
353  self.get_dbtype(IOV)
354  self.get_dbtype(TagLog)
355  self.get_dbtype(GlobalTag)
356  self.get_dbtype(GlobalTagMap)
357  self._is_valid = self.is_valid()
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:183

Member Function Documentation

def conddblib.Connection.get_dbtype (   self,
  theType 
)

Definition at line 358 of file conddblib.py.

References conddblib.Connection._backendName, conddblib.Connection._schemaName, relativeConstraints.keys, and conddblib.make_dbtype().

Referenced by conddblib.Connection.init(), conddblib.Connection.is_valid(), and conddblib.Connection.session().

359  def get_dbtype(self,theType):
360  basename = theType.__name__
361  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
362  return make_dbtype( self._backendName, self._schemaName, theType )
363  else:
364  return db_models[self._backendName][basename]
def make_dbtype
Definition: conddblib.py:201
def conddblib.Connection.init (   self,
  drop = False 
)
Initializes a database.

Definition at line 407 of file conddblib.py.

References conddblib.Connection._is_valid, querying.connection.engine, conddblib.Connection.engine, conddblib.Connection.get_dbtype(), and conddblib.Connection.is_valid().

408  def init(self, drop=False):
409  '''Initializes a database.
410  '''
411  logging.info('Initializing database...')
412  if drop:
413  logging.debug('Dropping tables...')
414  self.metadata.drop_all(self.engine)
415  else:
416  if self._is_valid:
417  raise Exception('Looks like the database is already a valid CMS Conditions one.')
418 
419  logging.debug('Creating tables...')
420  self.get_dbtype(Tag).__table__.create(bind = self.engine)
421  self.get_dbtype(Payload).__table__.create(bind = self.engine)
422  self.get_dbtype(IOV).__table__.create(bind = self.engine)
423  self.get_dbtype(TagLog).__table__.create(bind = self.engine)
424  self.get_dbtype(GlobalTag).__table__.create(bind = self.engine)
425  self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine)
426  self._is_valid = self.is_valid()
427 
# Connection helpers
def conddblib.Connection.is_frontier (   self)

Definition at line 376 of file conddblib.py.

References conddblib.Connection._is_frontier.

377  def is_frontier(self):
378  return self._is_frontier
def conddblib.Connection.is_official (   self)

Definition at line 392 of file conddblib.py.

References conddblib.Connection._is_official.

393  def is_official(self):
394  return self._is_official
def conddblib.Connection.is_oracle (   self)

Definition at line 380 of file conddblib.py.

References conddblib.Connection._is_oracle.

381  def is_oracle(self):
382  return self._is_oracle
def conddblib.Connection.is_read_only (   self)

Definition at line 388 of file conddblib.py.

References conddblib.Connection._is_read_only.

389  def is_read_only(self):
390  return self._is_read_only
def conddblib.Connection.is_sqlite (   self)

Definition at line 384 of file conddblib.py.

References conddblib.Connection._is_sqlite.

385  def is_sqlite(self):
386  return self._is_sqlite
def conddblib.Connection.is_valid (   self)
Tests whether the current DB looks like a valid CMS Conditions one.

Definition at line 395 of file conddblib.py.

References Vispa.Plugins.EdmBrowser.EdmDataAccessor.all(), conddblib.Connection.get_dbtype(), and conddblib.getSchema().

Referenced by conddblib.Connection.init().

396  def is_valid(self):
397  '''Tests whether the current DB looks like a valid CMS Conditions one.
398  '''
399  engine_connection = self.engine.connect()
400  # temporarely avoid the check on the GT tables - there are releases in use where C++ does not create these tables.
401  _Tag = self.get_dbtype(Tag)
402  _IOV = self.get_dbtype(IOV)
403  _Payload = self.get_dbtype(Payload)
404  ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__,getSchema(table)) for table in [_Tag, _IOV, _Payload]])
405  engine_connection.close()
406  return ret
def getSchema
Definition: conddblib.py:235
def conddblib.Connection.metadata (   self)

Definition at line 372 of file conddblib.py.

373  def metadata(self):
374  return _Base.metadata
def conddblib.Connection.session (   self)

Definition at line 365 of file conddblib.py.

References conddblib.Connection._is_sqlite, conddblib.Connection._session, and conddblib.Connection.get_dbtype().

366  def session(self):
367  s = self._session()
368  s.get_dbtype = self.get_dbtype
369  s._is_sqlite = self._is_sqlite
370  return s

Member Data Documentation

conddblib.Connection._backendName
private

Definition at line 346 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._is_frontier
private

Definition at line 328 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 337 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 329 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 332 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 330 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite(), and conddblib.Connection.session().

conddblib.Connection._is_valid
private

Definition at line 356 of file conddblib.py.

Referenced by conddblib.Connection.init().

conddblib.Connection._schemaName
private

Definition at line 347 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._session
private

Definition at line 326 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection._url
private

Definition at line 345 of file conddblib.py.

Referenced by cmstc.TagCollector._open().

conddblib.Connection.engine

Definition at line 314 of file conddblib.py.

Referenced by conddblib.Connection.init().