CMS 3D CMS Logo

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__ (self, url)
 
def get_dbtype (self, theType)
 
def init (self, drop=False)
 
def is_frontier (self)
 
def is_official (self)
 
def is_oracle (self)
 
def is_read_only (self)
 
def is_sqlite (self)
 
def is_valid (self)
 
def metadata (self)
 
def session (self)
 

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 332 of file conddblib.py.

Constructor & Destructor Documentation

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 334 of file conddblib.py.

334  def __init__(self, url):
335  # Workaround to avoid creating files if not present.
336  # Python's sqlite3 module does not use sqlite3_open_v2(),
337  # and therefore we cannot disable SQLITE_OPEN_CREATE.
338  # Only in the case of creating a new database we skip the check.
339  if url.drivername == 'sqlite':
340 
341  self.engine = sqlalchemy.create_engine(url)
342 
343  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
344  supports_foreign_keys = enabled_foreign_keys is not None
345  if not supports_foreign_keys:
346  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
347  elif not enabled_foreign_keys:
348  self.engine.execute('pragma foreign_keys = on')
349 
350  else:
351  self.engine = sqlalchemy.create_engine(url)
352 
353  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
354 
355  self._is_frontier = url.drivername == 'oracle+frontier'
356  self._is_oracle = url.drivername == 'oracle'
357  self._is_sqlite = url.drivername == 'sqlite'
358 
359  self._is_read_only = self._is_frontier or url.host in {
360  'cms_orcon_adg',
361  'cmsarc_lb',
362  }
363 
364  self._is_official = self._is_frontier or url.host in {
365  'cms_orcon_adg',
366  'cmsarc_lb',
367  'cms_orcoff_int',
368  'cms_orcoff_prep',
369  'cms_orcon_prod',
370  'cmsintr_lb',
371  }
372  self._url = url
373  self._backendName = ('sqlite' if self._is_sqlite else 'oracle' )
374  self._schemaName = ( None if self._is_sqlite else schema_name )
375  logging.debug(' ... using db "%s", schema "%s"' % (url, self._schemaName) )
376  logging.debug('Loading db types...')
377  self.get_dbtype(Tag).__name__
378  self.get_dbtype(Payload)
379  self.get_dbtype(IOV)
380  self.get_dbtype(TagLog)
381  self.get_dbtype(GlobalTag)
382  self.get_dbtype(GlobalTagMap)
383  self.get_dbtype(RunInfo)
384  if not self._is_sqlite:
385  self.get_dbtype(TagMetadata)
386  self.get_dbtype(BoostRunMap)
387  self._is_valid = self.is_valid()
388 
def is_valid(self)
Definition: conddblib.py:428
def __init__(self, url)
Definition: conddblib.py:334
def get_dbtype(self, theType)
Definition: conddblib.py:389
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 389 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().

389  def get_dbtype(self,theType):
390  basename = theType.__name__
391  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
392  return make_dbtype( self._backendName, self._schemaName, theType )
393  else:
394  return db_models[self._backendName][basename]
395 
def make_dbtype(backendName, schemaName, baseType)
Definition: conddblib.py:215
def get_dbtype(self, theType)
Definition: conddblib.py:389
def conddblib.Connection.init (   self,
  drop = False 
)
Initializes a database.

Definition at line 440 of file conddblib.py.

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

440  def init(self, drop=False):
441  '''Initializes a database.
442  '''
443  logging.info('Initializing database...')
444  if drop:
445  logging.debug('Dropping tables...')
446  self.metadata.drop_all(self.engine)
447  self._is_valid = False
448  else:
449  if not self._is_valid:
450  logging.debug('Creating tables...')
451  self.get_dbtype(Tag).__table__.create(bind = self.engine)
452  self.get_dbtype(Payload).__table__.create(bind = self.engine)
453  self.get_dbtype(IOV).__table__.create(bind = self.engine)
454  self.get_dbtype(TagLog).__table__.create(bind = self.engine)
455  self.get_dbtype(GlobalTag).__table__.create(bind = self.engine)
456  self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine)
457  self._is_valid = True
458 
def init(self, drop=False)
Definition: conddblib.py:440
def get_dbtype(self, theType)
Definition: conddblib.py:389
def conddblib.Connection.is_frontier (   self)

Definition at line 409 of file conddblib.py.

References conddblib.Connection._is_frontier.

409  def is_frontier(self):
410  return self._is_frontier
411 
def is_frontier(self)
Definition: conddblib.py:409
def conddblib.Connection.is_official (   self)

Definition at line 425 of file conddblib.py.

References conddblib.Connection._is_official.

425  def is_official(self):
426  return self._is_official
427 
def is_official(self)
Definition: conddblib.py:425
def conddblib.Connection.is_oracle (   self)

Definition at line 413 of file conddblib.py.

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

413  def is_oracle(self):
414  return self._is_oracle
415 
def is_oracle(self)
Definition: conddblib.py:413
def conddblib.Connection.is_read_only (   self)

Definition at line 421 of file conddblib.py.

References conddblib.Connection._is_read_only.

421  def is_read_only(self):
422  return self._is_read_only
423 
def is_read_only(self)
Definition: conddblib.py:421
def conddblib.Connection.is_sqlite (   self)

Definition at line 417 of file conddblib.py.

References conddblib.Connection._is_sqlite.

417  def is_sqlite(self):
418  return self._is_sqlite
419 
def is_sqlite(self)
Definition: conddblib.py:417
def conddblib.Connection.is_valid (   self)
Tests whether the current DB looks like a valid CMS Conditions one.

Definition at line 428 of file conddblib.py.

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

428  def is_valid(self):
429  '''Tests whether the current DB looks like a valid CMS Conditions one.
430  '''
431  engine_connection = self.engine.connect()
432  # temporarely avoid the check on the GT tables - there are releases in use where C++ does not create these tables.
433  _Tag = self.get_dbtype(Tag)
434  _IOV = self.get_dbtype(IOV)
435  _Payload = self.get_dbtype(Payload)
436  ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__,getSchema(table)) for table in [_Tag, _IOV, _Payload]])
437  engine_connection.close()
438  return ret
439 
def is_valid(self)
Definition: conddblib.py:428
def getSchema(tp)
Definition: conddblib.py:249
def get_dbtype(self, theType)
Definition: conddblib.py:389
def conddblib.Connection.metadata (   self)

Definition at line 405 of file conddblib.py.

405  def metadata(self):
406  return _Base.metadata
407 
def metadata(self)
Definition: conddblib.py:405
def conddblib.Connection.session (   self)

Definition at line 396 of file conddblib.py.

References conddblib.Connection._is_sqlite, conddblib.Connection._session, url_query.url_query._url, conddblib.Connection._url, conddblib.Connection.get_dbtype(), and conddblib.Connection.is_oracle().

396  def session(self):
397  s = self._session()
398  s.get_dbtype = self.get_dbtype
399  s._is_sqlite = self._is_sqlite
400  s.is_oracle = self.is_oracle
401  s._url = self._url
402  return s
403 
def is_oracle(self)
Definition: conddblib.py:413
def get_dbtype(self, theType)
Definition: conddblib.py:389

Member Data Documentation

conddblib.Connection._backendName
private

Definition at line 373 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._is_frontier
private

Definition at line 355 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 364 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 356 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 359 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 357 of file conddblib.py.

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

conddblib.Connection._is_valid
private

Definition at line 387 of file conddblib.py.

Referenced by conddblib.Connection.init().

conddblib.Connection._schemaName
private

Definition at line 374 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._session
private

Definition at line 353 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection._url
private

Definition at line 372 of file conddblib.py.

Referenced by cmstc.TagCollector._open(), and conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 341 of file conddblib.py.

Referenced by o2o_db_manager.DbManager.connect(), and conddblib.Connection.init().