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

Constructor & Destructor Documentation

◆ __init__()

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 307 of file conddblib.py.

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

Member Function Documentation

◆ get_dbtype()

def conddblib.Connection.get_dbtype (   self,
  theType 
)

Definition at line 361 of file conddblib.py.

361  def get_dbtype(self,theType):
362  basename = theType.__name__
363  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
364  return make_dbtype( self._backendName, self._schemaName, theType )
365  else:
366  return db_models[self._backendName][basename]
367 

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

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

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

381  def is_frontier(self):
382  return self._is_frontier
383 

References conddblib.Connection._is_frontier.

◆ is_official()

def conddblib.Connection.is_official (   self)

Definition at line 397 of file conddblib.py.

397  def is_official(self):
398  return self._is_official
399 

References conddblib.Connection._is_official.

◆ is_oracle()

def conddblib.Connection.is_oracle (   self)

Definition at line 385 of file conddblib.py.

385  def is_oracle(self):
386  return self._is_oracle
387 

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

◆ is_read_only()

def conddblib.Connection.is_read_only (   self)

Definition at line 393 of file conddblib.py.

393  def is_read_only(self):
394  return self._is_read_only
395 

References conddblib.Connection._is_read_only.

◆ is_sqlite()

def conddblib.Connection.is_sqlite (   self)

Definition at line 389 of file conddblib.py.

389  def is_sqlite(self):
390  return self._is_sqlite
391 

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

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

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

377  def metadata(self):
378  return _Base.metadata
379 

Referenced by conddblib.Connection.init().

◆ session()

def conddblib.Connection.session (   self)

Definition at line 368 of file conddblib.py.

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

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

Referenced by conddblib.Connection.get_dbtype().

◆ _is_frontier

conddblib.Connection._is_frontier
private

Definition at line 328 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

◆ _is_official

conddblib.Connection._is_official
private

Definition at line 337 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

◆ _is_oracle

conddblib.Connection._is_oracle
private

Definition at line 329 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

◆ _is_read_only

conddblib.Connection._is_read_only
private

Definition at line 332 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

◆ _is_sqlite

conddblib.Connection._is_sqlite
private

Definition at line 330 of file conddblib.py.

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

◆ _is_valid

conddblib.Connection._is_valid
private

Definition at line 359 of file conddblib.py.

Referenced by conddblib.Connection.init().

◆ _schemaName

conddblib.Connection._schemaName
private

Definition at line 347 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

◆ _session

conddblib.Connection._session
private

Definition at line 326 of file conddblib.py.

Referenced by conddblib.Connection.session().

◆ _url

conddblib.Connection._url
private

Definition at line 345 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:188
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:222
conddblib.connect
def connect(url, authPath=None, verbose=0)
Definition: conddblib.py:516