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

Constructor & Destructor Documentation

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 333 of file conddblib.py.

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

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

Definition at line 439 of file conddblib.py.

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

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

Definition at line 408 of file conddblib.py.

References conddblib.Connection._is_frontier.

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

Definition at line 424 of file conddblib.py.

References conddblib.Connection._is_official.

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

Definition at line 412 of file conddblib.py.

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

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

Definition at line 420 of file conddblib.py.

References conddblib.Connection._is_read_only.

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

Definition at line 416 of file conddblib.py.

References conddblib.Connection._is_sqlite.

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

Definition at line 427 of file conddblib.py.

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

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

Definition at line 404 of file conddblib.py.

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

Definition at line 395 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().

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

Member Data Documentation

conddblib.Connection._backendName
private

Definition at line 372 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._is_frontier
private

Definition at line 354 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 363 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 355 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 358 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 356 of file conddblib.py.

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

conddblib.Connection._is_valid
private

Definition at line 386 of file conddblib.py.

Referenced by conddblib.Connection.init().

conddblib.Connection._schemaName
private

Definition at line 373 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._session
private

Definition at line 352 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection._url
private

Definition at line 371 of file conddblib.py.

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

conddblib.Connection.engine

Definition at line 340 of file conddblib.py.

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