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

Constructor & Destructor Documentation

◆ __init__()

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 309 of file conddblib.py.

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

Member Function Documentation

◆ get_dbtype()

def conddblib.Connection.get_dbtype (   self,
  theType 
)

Definition at line 363 of file conddblib.py.

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]
369 

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

414  def init(self, drop=False):
415  '''Initializes a database.
416  '''
417  logging.info('Initializing database...')
418  if drop:
419  logging.debug('Dropping tables...')
420  self.metadata.drop_all(self.engine)
421  self._is_valid = False
422  else:
423  if not self._is_valid:
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._is_valid = True
432 

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

383  def is_frontier(self):
384  return self._is_frontier
385 

References conddblib.Connection._is_frontier.

◆ is_official()

def conddblib.Connection.is_official (   self)

Definition at line 399 of file conddblib.py.

399  def is_official(self):
400  return self._is_official
401 

References conddblib.Connection._is_official.

◆ is_oracle()

def conddblib.Connection.is_oracle (   self)

Definition at line 387 of file conddblib.py.

387  def is_oracle(self):
388  return self._is_oracle
389 

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

◆ is_read_only()

def conddblib.Connection.is_read_only (   self)

Definition at line 395 of file conddblib.py.

395  def is_read_only(self):
396  return self._is_read_only
397 

References conddblib.Connection._is_read_only.

◆ is_sqlite()

def conddblib.Connection.is_sqlite (   self)

Definition at line 391 of file conddblib.py.

391  def is_sqlite(self):
392  return self._is_sqlite
393 

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

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

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

379  def metadata(self):
380  return _Base.metadata
381 

Referenced by conddblib.Connection.init().

◆ session()

def conddblib.Connection.session (   self)

Definition at line 370 of file conddblib.py.

370  def session(self):
371  s = self._session()
372  s.get_dbtype = self.get_dbtype
373  s._is_sqlite = self._is_sqlite
374  s.is_oracle = self.is_oracle
375  s._url = self._url
376  return s
377 

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

Referenced by conddblib.Connection.get_dbtype().

◆ _is_frontier

conddblib.Connection._is_frontier
private

Definition at line 330 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

◆ _is_official

conddblib.Connection._is_official
private

Definition at line 339 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

◆ _is_oracle

conddblib.Connection._is_oracle
private

Definition at line 331 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

◆ _is_read_only

conddblib.Connection._is_read_only
private

Definition at line 334 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

◆ _is_sqlite

conddblib.Connection._is_sqlite
private

Definition at line 332 of file conddblib.py.

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

◆ _is_valid

conddblib.Connection._is_valid
private

Definition at line 361 of file conddblib.py.

Referenced by conddblib.Connection.init().

◆ _schemaName

conddblib.Connection._schemaName
private

Definition at line 349 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

◆ _session

conddblib.Connection._session
private

Definition at line 328 of file conddblib.py.

Referenced by conddblib.Connection.session().

◆ _url

conddblib.Connection._url
private

Definition at line 347 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:190
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:224
conddblib.connect
def connect(url, authPath=None, verbose=0)
Definition: conddblib.py:518