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

Constructor & Destructor Documentation

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

Definition at line 239 of file conddblib.py.

240  def __init__(self, url, init=False):
241  # Workaround to avoid creating files if not present.
242  # Python's sqlite3 module does not use sqlite3_open_v2(),
243  # and therefore we cannot disable SQLITE_OPEN_CREATE.
244  # Only in the case of creating a new database we skip the check.
245  if url.drivername == 'sqlite':
246 
247  if not init and url.database is not None and not os.path.isfile(url.database):
248  # url.database is None if opening a in-memory DB, e.g. 'sqlite://'
249  raise Exception('SQLite database %s not found.' % url.database)
251  self.engine = sqlalchemy.create_engine(url)
252 
253  enabled_foreign_keys = self.engine.execute('pragma foreign_keys').scalar()
254  supports_foreign_keys = enabled_foreign_keys is not None
255  if not supports_foreign_keys:
256  logger.warning('Your SQLite database does not support foreign keys, so constraints will not be checked. Please upgrade.')
257  elif not enabled_foreign_keys:
258  self.engine.execute('pragma foreign_keys = on')
259 
260  else:
261  self.engine = sqlalchemy.create_engine(url)
263  self._session = sqlalchemy.orm.scoped_session(sqlalchemy.orm.sessionmaker(bind=self.engine))
265  self._is_frontier = url.drivername == 'oracle+frontier'
266  self._is_oracle = url.drivername == 'oracle'
267  self._is_sqlite = url.drivername == 'sqlite'
269  self._is_read_only = self._is_frontier or url.host in {
270  'cms_orcon_adg',
271  'cmsarc_lb',
272  }
274  self._is_official = self._is_frontier or url.host in {
275  'cms_orcon_adg',
276  'cmsarc_lb',
277  'cms_orcoff_int',
278  'cms_orcoff_prep',
279  'cms_orcon_prod',
280  'cmsintr_lb',
281  }
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 317 of file conddblib.py.

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

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

Definition at line 290 of file conddblib.py.

References conddblib.Connection._is_frontier.

291  def is_frontier(self):
292  return self._is_frontier
def conddblib.Connection.is_official (   self)

Definition at line 306 of file conddblib.py.

References conddblib.Connection._is_official.

307  def is_official(self):
308  return self._is_official
def conddblib.Connection.is_oracle (   self)

Definition at line 294 of file conddblib.py.

References conddblib.Connection._is_oracle.

295  def is_oracle(self):
296  return self._is_oracle
def conddblib.Connection.is_read_only (   self)

Definition at line 302 of file conddblib.py.

References conddblib.Connection._is_read_only.

303  def is_read_only(self):
304  return self._is_read_only
def conddblib.Connection.is_sqlite (   self)

Definition at line 298 of file conddblib.py.

References conddblib.Connection._is_sqlite.

299  def is_sqlite(self):
300  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 309 of file conddblib.py.

References cond::ecalcond.all.

Referenced by conddblib.Connection.init().

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

Definition at line 286 of file conddblib.py.

287  def metadata(self):
288  return _Base.metadata
def conddblib.Connection.session (   self)

Definition at line 282 of file conddblib.py.

References conddblib.Connection._session.

283  def session(self):
284  return self._session()

Member Data Documentation

conddblib.Connection._is_frontier
private

Definition at line 264 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 273 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 265 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 268 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 266 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite().

conddblib.Connection._session
private

Definition at line 262 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 250 of file conddblib.py.

Referenced by conddblib.Connection.init().