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

Constructor & Destructor Documentation

◆ __init__()

def conddblib.Connection.__init__ (   self,
  url 
)

Definition at line 323 of file conddblib.py.

323  def __init__(self, url):
324  # Workaround to avoid creating files if not present.
325  # Python's sqlite3 module does not use sqlite3_open_v2(),
326  # and therefore we cannot disable SQLITE_OPEN_CREATE.
327  # Only in the case of creating a new database we skip the check.
328  if url.drivername == 'sqlite':
329 
330  self.engine = sqlalchemy.create_engine(url)
331 
332  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
333  supports_foreign_keys = enabled_foreign_keys is not None
334  if not supports_foreign_keys:
335  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
336  elif not enabled_foreign_keys:
337  self.engine.execute('pragma foreign_keys = on')
338 
339  else:
340  self.engine = sqlalchemy.create_engine(url, max_identifier_length=30)
341 
342  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
343 
344  self._is_frontier = url.drivername == 'oracle+frontier'
345  self._is_oracle = url.drivername == 'oracle'
346  self._is_sqlite = url.drivername == 'sqlite'
347 
348  self._is_read_only = self._is_frontier or url.host in {
349  'cms_orcon_adg',
350  'cmsarc_lb',
351  }
352 
353  self._is_official = self._is_frontier or url.host in {
354  'cms_orcon_adg',
355  'cmsarc_lb',
356  'cms_orcoff_int',
357  'cms_orcoff_prep',
358  'cms_orcon_prod',
359  'cmsintr_lb',
360  }
361  self._url = url
362  self._backendName = ('sqlite' if self._is_sqlite else 'oracle' )
363  self._schemaName = ( None if self._is_sqlite else schema_name )
364  logging.debug('Loading db types...')
365  self.get_dbtype(Tag).__name__
366  self.get_dbtype(Payload)
367  self.get_dbtype(IOV)
368  self.get_dbtype(TagLog)
369  self.get_dbtype(GlobalTag)
370  self.get_dbtype(GlobalTagMap)
371  self.get_dbtype(RunInfo)
372  if not self._is_sqlite:
373  self.get_dbtype(TagMetadata)
374  self.get_dbtype(TagAuthorization)
375  self.get_dbtype(BoostRunMap)
376  self._is_valid = self.is_valid()
377 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ get_dbtype()

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

378  def get_dbtype(self,theType):
379  basename = theType.__name__
380  if self._backendName not in db_models.keys() or basename not in db_models[self._backendName].keys():
381  return make_dbtype( self._backendName, self._schemaName, theType )
382  else:
383  return db_models[self._backendName][basename]
384 
def make_dbtype(backendName, schemaName, baseType)
Definition: conddblib.py:190

◆ init()

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, conddblib.Connection.get_dbtype(), and conddblib.Connection.metadata().

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

◆ is_frontier()

def conddblib.Connection.is_frontier (   self)

Definition at line 398 of file conddblib.py.

References conddblib.Connection._is_frontier.

398  def is_frontier(self):
399  return self._is_frontier
400 

◆ is_official()

def conddblib.Connection.is_official (   self)

Definition at line 414 of file conddblib.py.

References conddblib.Connection._is_official.

414  def is_official(self):
415  return self._is_official
416 

◆ is_oracle()

def conddblib.Connection.is_oracle (   self)

Definition at line 402 of file conddblib.py.

References conddblib.Connection._is_oracle.

Referenced by conddblib.Connection.session().

402  def is_oracle(self):
403  return self._is_oracle
404 

◆ is_read_only()

def conddblib.Connection.is_read_only (   self)

Definition at line 410 of file conddblib.py.

References conddblib.Connection._is_read_only.

410  def is_read_only(self):
411  return self._is_read_only
412 

◆ is_sqlite()

def conddblib.Connection.is_sqlite (   self)

Definition at line 406 of file conddblib.py.

References conddblib.Connection._is_sqlite.

406  def is_sqlite(self):
407  return self._is_sqlite
408 

◆ is_valid()

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.connect(), querying.connection.engine, conddblib.Connection.engine, conddblib.Connection.get_dbtype(), and conddblib.getSchema().

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

◆ metadata()

def conddblib.Connection.metadata (   self)

Definition at line 394 of file conddblib.py.

Referenced by conddblib.Connection.init().

394  def metadata(self):
395  return _Base.metadata
396 

◆ session()

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

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

Member Data Documentation

◆ _backendName

conddblib.Connection._backendName
private

Definition at line 362 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

◆ _is_frontier

conddblib.Connection._is_frontier
private

Definition at line 344 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

◆ _is_official

conddblib.Connection._is_official
private

Definition at line 353 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

◆ _is_oracle

conddblib.Connection._is_oracle
private

Definition at line 345 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

◆ _is_read_only

conddblib.Connection._is_read_only
private

Definition at line 348 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

◆ _is_sqlite

conddblib.Connection._is_sqlite
private

Definition at line 346 of file conddblib.py.

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

◆ _is_valid

conddblib.Connection._is_valid
private

Definition at line 376 of file conddblib.py.

Referenced by conddblib.Connection.init().

◆ _schemaName

conddblib.Connection._schemaName
private

Definition at line 363 of file conddblib.py.

Referenced by conddblib.Connection.get_dbtype().

◆ _session

conddblib.Connection._session
private

Definition at line 342 of file conddblib.py.

Referenced by conddblib.Connection.session().

◆ _url

conddblib.Connection._url
private

Definition at line 361 of file conddblib.py.

Referenced by conddblib.Connection.session().

◆ engine

conddblib.Connection.engine