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

Constructor & Destructor Documentation

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

Definition at line 236 of file conddblib.py.

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

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

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

Definition at line 287 of file conddblib.py.

References conddblib.Connection._is_frontier.

288  def is_frontier(self):
289  return self._is_frontier
def conddblib.Connection.is_official (   self)

Definition at line 303 of file conddblib.py.

References conddblib.Connection._is_official.

304  def is_official(self):
305  return self._is_official
def conddblib.Connection.is_oracle (   self)

Definition at line 291 of file conddblib.py.

References conddblib.Connection._is_oracle.

292  def is_oracle(self):
293  return self._is_oracle
def conddblib.Connection.is_read_only (   self)

Definition at line 299 of file conddblib.py.

References conddblib.Connection._is_read_only.

300  def is_read_only(self):
301  return self._is_read_only
def conddblib.Connection.is_sqlite (   self)

Definition at line 295 of file conddblib.py.

References conddblib.Connection._is_sqlite.

296  def is_sqlite(self):
297  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 306 of file conddblib.py.

References cond::ecalcond.all.

Referenced by conddblib.Connection.init().

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

Definition at line 283 of file conddblib.py.

284  def metadata(self):
285  return _Base.metadata
def conddblib.Connection.session (   self)

Definition at line 279 of file conddblib.py.

References conddblib.Connection._session.

280  def session(self):
281  return self._session()

Member Data Documentation

conddblib.Connection._is_frontier
private

Definition at line 261 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 270 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 262 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 265 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 263 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite().

conddblib.Connection._session
private

Definition at line 259 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 247 of file conddblib.py.

Referenced by conddblib.Connection.init().