CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 321 of file conddblib.py.

Constructor & Destructor Documentation

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 323 of file conddblib.py.

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

Member Function Documentation

def conddblib.Connection.get_dbtype (   self,
  theType 
)

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

379  def get_dbtype(self,theType):
380  basename = theType.__name__
381  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
382  return make_dbtype( self._backendName, self._schemaName, theType )
383  else:
384  return db_models[self._backendName][basename]
def make_dbtype
Definition: conddblib.py:190
def conddblib.Connection.init (   self,
  drop = False 
)
Initializes a database.

Definition at line 429 of file conddblib.py.

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

430  def init(self, drop=False):
431  '''Initializes a database.
432  '''
433  logging.info('Initializing database...')
434  if drop:
435  logging.debug('Dropping tables...')
436  self.metadata.drop_all(self.engine)
437  self._is_valid = False
438  else:
439  if not self._is_valid:
440  logging.debug('Creating tables...')
441  self.get_dbtype(Tag).__table__.create(bind = self.engine)
442  self.get_dbtype(Payload).__table__.create(bind = self.engine)
443  self.get_dbtype(IOV).__table__.create(bind = self.engine)
444  self.get_dbtype(TagLog).__table__.create(bind = self.engine)
445  self.get_dbtype(GlobalTag).__table__.create(bind = self.engine)
446  self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine)
447  self._is_valid = True
def conddblib.Connection.is_frontier (   self)

Definition at line 398 of file conddblib.py.

References conddblib.Connection._is_frontier.

399  def is_frontier(self):
400  return self._is_frontier
def conddblib.Connection.is_official (   self)

Definition at line 414 of file conddblib.py.

References conddblib.Connection._is_official.

415  def is_official(self):
416  return self._is_official
def conddblib.Connection.is_oracle (   self)

Definition at line 402 of file conddblib.py.

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

403  def is_oracle(self):
404  return self._is_oracle
def conddblib.Connection.is_read_only (   self)

Definition at line 410 of file conddblib.py.

References conddblib.Connection._is_read_only.

411  def is_read_only(self):
412  return self._is_read_only
def conddblib.Connection.is_sqlite (   self)

Definition at line 406 of file conddblib.py.

References conddblib.Connection._is_sqlite.

407  def is_sqlite(self):
408  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 417 of file conddblib.py.

References python.cmstools.all(), conddblib.Connection.get_dbtype(), and conddblib.getSchema().

418  def is_valid(self):
419  '''Tests whether the current DB looks like a valid CMS Conditions one.
420  '''
421  engine_connection = self.engine.connect()
422  # temporarely avoid the check on the GT tables - there are releases in use where C++ does not create these tables.
423  _Tag = self.get_dbtype(Tag)
424  _IOV = self.get_dbtype(IOV)
425  _Payload = self.get_dbtype(Payload)
426  ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__,getSchema(table)) for table in [_Tag, _IOV, _Payload]])
427  engine_connection.close()
428  return ret
def getSchema
Definition: conddblib.py:230
def all
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
def conddblib.Connection.metadata (   self)

Definition at line 394 of file conddblib.py.

395  def metadata(self):
396  return _Base.metadata
def conddblib.Connection.session (   self)

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

386  def session(self):
387  s = self._session()
388  s.get_dbtype = self.get_dbtype
389  s._is_sqlite = self._is_sqlite
390  s.is_oracle = self.is_oracle
391  s._url = self._url
392  return s

Member Data Documentation

conddblib.Connection._backendName
private

Definition at line 362 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._is_frontier
private

Definition at line 344 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 353 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 345 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 348 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 346 of file conddblib.py.

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

conddblib.Connection._is_valid
private

Definition at line 376 of file conddblib.py.

Referenced by conddblib.Connection.init().

conddblib.Connection._schemaName
private

Definition at line 363 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

conddblib.Connection._session
private

Definition at line 342 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection._url
private

Definition at line 361 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 330 of file conddblib.py.

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