CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 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

 _is_frontier
 
 _is_official
 
 _is_oracle
 
 _is_read_only
 
 _is_sqlite
 
 _session
 

Detailed Description

Definition at line 232 of file conddblib.py.

Constructor & Destructor Documentation

def conddblib.Connection.__init__ (   self,
  url,
  init = False 
)

Definition at line 234 of file conddblib.py.

235  def __init__(self, url, init=False):
236  # Workaround to avoid creating files if not present.
237  # Python's sqlite3 module does not use sqlite3_open_v2(),
238  # and therefore we cannot disable SQLITE_OPEN_CREATE.
239  # Only in the case of creating a new database we skip the check.
240  if url.drivername == 'sqlite':
241 
242  if not init and url.database is not None and not os.path.isfile(url.database):
243  # url.database is None if opening a in-memory DB, e.g. 'sqlite://'
244  raise Exception('SQLite database %s not found.' % url.database)
246  self.engine = sqlalchemy.create_engine(url)
247 
248  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
249  supports_foreign_keys = enabled_foreign_keys is not None
250  if not supports_foreign_keys:
251  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
252  elif not enabled_foreign_keys:
253  self.engine.execute('pragma foreign_keys = on')
254 
255  else:
256  self.engine = sqlalchemy.create_engine(url)
258  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
260  self._is_frontier = url.drivername == 'oracle+frontier'
261  self._is_oracle = url.drivername == 'oracle'
262  self._is_sqlite = url.drivername == 'sqlite'
264  self._is_read_only = self._is_frontier or url.host in {
265  'cms_orcon_adg',
266  'cmsarc_lb',
267  }
269  self._is_official = self._is_frontier or url.host in {
270  'cms_orcon_adg',
271  'cmsarc_lb',
272  'cms_orcoff_int',
273  'cms_orcoff_prep',
274  'cms_orcon_prod',
275  'cmsintr_lb',
276  }
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:183

Member Function Documentation

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

Definition at line 313 of file conddblib.py.

References conddblib.Connection.engine, and conddblib.Connection.is_valid().

314  def init(self, drop=False):
315  '''Initializes a database.
316  '''
317 
318  if drop:
319  logger.debug('Dropping tables...')
320  self.metadata.drop_all(self.engine)
321  else:
322  if self.is_valid():
323  raise Exception('Looks like the database is already a valid CMS Conditions one. Please use drop=True if you really want to scratch it.')
324 
325  logger.debug('Creating tables...')
326  self.metadata.create_all(self.engine)
327 
328  # TODO: Create indexes
329  #logger.debug('Creating indexes...')
330 
331 
# Connection helpers
def conddblib.Connection.is_frontier (   self)

Definition at line 285 of file conddblib.py.

References conddblib.Connection._is_frontier.

286  def is_frontier(self):
287  return self._is_frontier
def conddblib.Connection.is_official (   self)

Definition at line 301 of file conddblib.py.

References conddblib.Connection._is_official.

302  def is_official(self):
303  return self._is_official
def conddblib.Connection.is_oracle (   self)

Definition at line 289 of file conddblib.py.

References conddblib.Connection._is_oracle.

290  def is_oracle(self):
291  return self._is_oracle
def conddblib.Connection.is_read_only (   self)

Definition at line 297 of file conddblib.py.

References conddblib.Connection._is_read_only.

298  def is_read_only(self):
299  return self._is_read_only
def conddblib.Connection.is_sqlite (   self)

Definition at line 293 of file conddblib.py.

References conddblib.Connection._is_sqlite.

294  def is_sqlite(self):
295  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 304 of file conddblib.py.

References cond::ecalcond.all.

Referenced by conddblib.Connection.init().

305  def is_valid(self):
306  '''Tests whether the current DB looks like a valid CMS Conditions one.
307  '''
308 
309  engine_connection = self.engine.connect()
310  ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__) for table in [Tag, IOV, Payload, GlobalTag, GlobalTagMap]])
311  engine_connection.close()
312  return ret
def conddblib.Connection.metadata (   self)

Definition at line 281 of file conddblib.py.

282  def metadata(self):
283  return _Base.metadata
def conddblib.Connection.session (   self)

Definition at line 277 of file conddblib.py.

References conddblib.Connection._session.

278  def session(self):
279  return self._session()

Member Data Documentation

conddblib.Connection._is_frontier
private

Definition at line 259 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 268 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 260 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 263 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 261 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite().

conddblib.Connection._session
private

Definition at line 257 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 245 of file conddblib.py.

Referenced by conddblib.Connection.init().