test
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
 
 _schemaName
 
 _session
 

Detailed Description

Definition at line 307 of file conddblib.py.

Constructor & Destructor Documentation

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

Definition at line 309 of file conddblib.py.

310  def __init__(self, url, init=False):
311  # Workaround to avoid creating files if not present.
312  # Python's sqlite3 module does not use sqlite3_open_v2(),
313  # and therefore we cannot disable SQLITE_OPEN_CREATE.
314  # Only in the case of creating a new database we skip the check.
315  if url.drivername == 'sqlite':
316 
317  #if not init and url.database is not None and not os.path.isfile(url.database):
318  # # url.database is None if opening a in-memory DB, e.g. 'sqlite://'
319  # raise Exception('SQLite database %s not found.' % url.database)
321  self.engine = sqlalchemy.create_engine(url)
322 
323  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
324  supports_foreign_keys = enabled_foreign_keys is not None
325  if not supports_foreign_keys:
326  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
327  elif not enabled_foreign_keys:
328  self.engine.execute('pragma foreign_keys = on')
329 
330  else:
331  self.engine = sqlalchemy.create_engine(url)
333  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
335  self._is_frontier = url.drivername == 'oracle+frontier'
336  self._is_oracle = url.drivername == 'oracle'
337  self._is_sqlite = url.drivername == 'sqlite'
339  self._is_read_only = self._is_frontier or url.host in {
340  'cms_orcon_adg',
341  'cmsarc_lb',
342  }
344  self._is_official = self._is_frontier or url.host in {
345  'cms_orcon_adg',
346  'cmsarc_lb',
347  'cms_orcoff_int',
348  'cms_orcoff_prep',
349  'cms_orcon_prod',
350  'cmsintr_lb',
351  }
352  self._backendName = ('sqlite' if self._is_sqlite else 'oracle' )
353  self._schemaName = ( None if self._is_sqlite else schema_name )
354  logging.debug(' ... using db "%s", schema "%s"' % (url, self._schemaName) )
355  logging.debug('Loading db types...')
356  self.get_dbtype(Tag).__name__
357  self.get_dbtype(Payload)
358  self.get_dbtype(IOV)
359  self.get_dbtype(TagLog)
360  self.get_dbtype(GlobalTag)
361  self.get_dbtype(GlobalTagMap)
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 362 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().

363  def get_dbtype(self,theType):
364  basename = theType.__name__
365  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
366  return make_dbtype( self._backendName, self._schemaName, theType )
367  else:
368  return db_models[self._backendName][basename]
def make_dbtype
Definition: conddblib.py:203
def conddblib.Connection.init (   self,
  drop = False 
)
Initializes a database.

Definition at line 412 of file conddblib.py.

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

413  def init(self, drop=False):
414  '''Initializes a database.
415  '''
416  logging.info('Initializing database...')
417  if drop:
418  logging.debug('Dropping tables...')
419  self.metadata.drop_all(self.engine)
420  else:
421  if self.is_valid():
422  raise Exception('Looks like the database is already a valid CMS Conditions one.')
423 
424  logging.debug('Creating tables...')
425  self.get_dbtype(Tag).__table__.create(bind = self.engine)
426  self.get_dbtype(Payload).__table__.create(bind = self.engine)
427  self.get_dbtype(IOV).__table__.create(bind = self.engine)
428  self.get_dbtype(TagLog).__table__.create(bind = self.engine)
429  self.get_dbtype(GlobalTag).__table__.create(bind = self.engine)
430  self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine)
431  #self.metadata.create_all(self.engine)
432 
433  # TODO: Create indexes
434  #logger.debug('Creating indexes...')
435 
436 
# Connection helpers
def conddblib.Connection.is_frontier (   self)

Definition at line 379 of file conddblib.py.

References conddblib.Connection._is_frontier.

380  def is_frontier(self):
381  return self._is_frontier
def conddblib.Connection.is_official (   self)

Definition at line 395 of file conddblib.py.

References conddblib.Connection._is_official.

396  def is_official(self):
397  return self._is_official
def conddblib.Connection.is_oracle (   self)

Definition at line 383 of file conddblib.py.

References conddblib.Connection._is_oracle.

384  def is_oracle(self):
385  return self._is_oracle
def conddblib.Connection.is_read_only (   self)

Definition at line 391 of file conddblib.py.

References conddblib.Connection._is_read_only.

392  def is_read_only(self):
393  return self._is_read_only
def conddblib.Connection.is_sqlite (   self)

Definition at line 387 of file conddblib.py.

References conddblib.Connection._is_sqlite.

388  def is_sqlite(self):
389  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 398 of file conddblib.py.

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

Referenced by conddblib.Connection.init().

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

Definition at line 375 of file conddblib.py.

376  def metadata(self):
377  return _Base.metadata
def conddblib.Connection.session (   self)

Definition at line 369 of file conddblib.py.

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

370  def session(self):
371  s = self._session()
372  s.get_dbtype = self.get_dbtype
373  return s

Member Data Documentation

conddblib.Connection._backendName
private

Definition at line 351 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._is_frontier
private

Definition at line 334 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 343 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 335 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 338 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 336 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite().

conddblib.Connection._schemaName
private

Definition at line 352 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._session
private

Definition at line 332 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 320 of file conddblib.py.

Referenced by conddblib.Connection.init().