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

Constructor & Destructor Documentation

◆ __init__()

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 301 of file conddblib.py.

301  def __init__(self, url):
302  # Workaround to avoid creating files if not present.
303  # Python's sqlite3 module does not use sqlite3_open_v2(),
304  # and therefore we cannot disable SQLITE_OPEN_CREATE.
305  # Only in the case of creating a new database we skip the check.
306  if url.drivername == 'sqlite':
307 
308  self.engine = sqlalchemy.create_engine(url)
309 
310  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
311  supports_foreign_keys = enabled_foreign_keys is not None
312  if not supports_foreign_keys:
313  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
314  elif not enabled_foreign_keys:
315  self.engine.execute('pragma foreign_keys = on')
316 
317  else:
318  self.engine = sqlalchemy.create_engine(url)
319 
320  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
321 
322  self._is_frontier = url.drivername == 'oracle+frontier'
323  self._is_oracle = url.drivername == 'oracle'
324  self._is_sqlite = url.drivername == 'sqlite'
325 
326  self._is_read_only = self._is_frontier or url.host in {
327  'cms_orcon_adg',
328  'cmsarc_lb',
329  }
330 
331  self._is_official = self._is_frontier or url.host in {
332  'cms_orcon_adg',
333  'cmsarc_lb',
334  'cms_orcoff_int',
335  'cms_orcoff_prep',
336  'cms_orcon_prod',
337  'cmsintr_lb',
338  }
339  self._url = url
340  self._backendName = ('sqlite' if self._is_sqlite else 'oracle' )
341  self._schemaName = ( None if self._is_sqlite else schema_name )
342  logging.debug(' ... using db "%s", schema "%s"' % (url, self._schemaName) )
343  logging.debug('Loading db types...')
344  self.get_dbtype(Tag).__name__
345  self.get_dbtype(Payload)
346  self.get_dbtype(IOV)
347  self.get_dbtype(TagLog)
348  self.get_dbtype(GlobalTag)
349  self.get_dbtype(GlobalTagMap)
350  self.get_dbtype(RunInfo)
351  if not self._is_sqlite:
352  self.get_dbtype(TagMetadata)
353  self.get_dbtype(BoostRunMap)
354  self._is_valid = self.is_valid()
355 

Member Function Documentation

◆ get_dbtype()

def conddblib.Connection.get_dbtype (   self,
  theType 
)

Definition at line 356 of file conddblib.py.

356  def get_dbtype(self,theType):
357  basename = theType.__name__
358  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
359  return make_dbtype( self._backendName, self._schemaName, theType )
360  else:
361  return db_models[self._backendName][basename]
362 

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().

◆ init()

def conddblib.Connection.init (   self,
  drop = False 
)
Initializes a database.

Definition at line 407 of file conddblib.py.

407  def init(self, drop=False):
408  '''Initializes a database.
409  '''
410  logging.info('Initializing database...')
411  if drop:
412  logging.debug('Dropping tables...')
413  self.metadata.drop_all(self.engine)
414  self._is_valid = False
415  else:
416  if not self._is_valid:
417  logging.debug('Creating tables...')
418  self.get_dbtype(Tag).__table__.create(bind = self.engine)
419  self.get_dbtype(Payload).__table__.create(bind = self.engine)
420  self.get_dbtype(IOV).__table__.create(bind = self.engine)
421  self.get_dbtype(TagLog).__table__.create(bind = self.engine)
422  self.get_dbtype(GlobalTag).__table__.create(bind = self.engine)
423  self.get_dbtype(GlobalTagMap).__table__.create(bind = self.engine)
424  self._is_valid = True
425 

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

◆ is_frontier()

def conddblib.Connection.is_frontier (   self)

Definition at line 376 of file conddblib.py.

376  def is_frontier(self):
377  return self._is_frontier
378 

References conddblib.Connection._is_frontier.

◆ is_official()

def conddblib.Connection.is_official (   self)

Definition at line 392 of file conddblib.py.

392  def is_official(self):
393  return self._is_official
394 

References conddblib.Connection._is_official.

◆ is_oracle()

def conddblib.Connection.is_oracle (   self)

Definition at line 380 of file conddblib.py.

380  def is_oracle(self):
381  return self._is_oracle
382 

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

◆ is_read_only()

def conddblib.Connection.is_read_only (   self)

Definition at line 388 of file conddblib.py.

388  def is_read_only(self):
389  return self._is_read_only
390 

References conddblib.Connection._is_read_only.

◆ is_sqlite()

def conddblib.Connection.is_sqlite (   self)

Definition at line 384 of file conddblib.py.

384  def is_sqlite(self):
385  return self._is_sqlite
386 

References conddblib.Connection._is_sqlite.

◆ is_valid()

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.

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

References python.cmstools.all(), conddblib.connect(), querying.connection.engine, conddblib.Connection.engine, conddblib.Connection.get_dbtype(), and conddblib.getSchema().

◆ metadata()

def conddblib.Connection.metadata (   self)

Definition at line 372 of file conddblib.py.

372  def metadata(self):
373  return _Base.metadata
374 

Referenced by conddblib.Connection.init().

◆ session()

def conddblib.Connection.session (   self)

Definition at line 363 of file conddblib.py.

363  def session(self):
364  s = self._session()
365  s.get_dbtype = self.get_dbtype
366  s._is_sqlite = self._is_sqlite
367  s.is_oracle = self.is_oracle
368  s._url = self._url
369  return s
370 

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().

Member Data Documentation

◆ _backendName

conddblib.Connection._backendName
private

Definition at line 340 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

◆ _is_frontier

conddblib.Connection._is_frontier
private

Definition at line 322 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

◆ _is_official

conddblib.Connection._is_official
private

Definition at line 331 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

◆ _is_oracle

conddblib.Connection._is_oracle
private

Definition at line 323 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

◆ _is_read_only

conddblib.Connection._is_read_only
private

Definition at line 326 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

◆ _is_sqlite

conddblib.Connection._is_sqlite
private

Definition at line 324 of file conddblib.py.

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

◆ _is_valid

conddblib.Connection._is_valid
private

Definition at line 354 of file conddblib.py.

Referenced by conddblib.Connection.init().

◆ _schemaName

conddblib.Connection._schemaName
private

Definition at line 341 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

◆ _session

conddblib.Connection._session
private

Definition at line 320 of file conddblib.py.

Referenced by conddblib.Connection.session().

◆ _url

conddblib.Connection._url
private

Definition at line 339 of file conddblib.py.

Referenced by conddblib.Connection.session().

◆ engine

conddblib.Connection.engine
init
int init
Definition: HydjetWrapper.h:64
conddblib.make_dbtype
def make_dbtype(backendName, schemaName, baseType)
Definition: conddblib.py:182
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
python.cmstools.all
def all(container)
workaround iterator generators for ROOT classes
Definition: cmstools.py:26
hitfit::scalar
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:166
TrackingMonitor_cfi.metadata
metadata
Definition: TrackingMonitor_cfi.py:71
conddblib.getSchema
def getSchema(tp)
Definition: conddblib.py:216
conddblib.connect
def connect(url, authPath=None, verbose=0)
Definition: conddblib.py:511