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

Constructor & Destructor Documentation

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

Definition at line 240 of file conddblib.py.

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

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

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

Definition at line 291 of file conddblib.py.

References conddblib.Connection._is_frontier.

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

Definition at line 307 of file conddblib.py.

References conddblib.Connection._is_official.

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

Definition at line 295 of file conddblib.py.

References conddblib.Connection._is_oracle.

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

Definition at line 303 of file conddblib.py.

References conddblib.Connection._is_read_only.

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

Definition at line 299 of file conddblib.py.

References conddblib.Connection._is_sqlite.

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

References Vispa.Plugins.EdmBrowser.EdmDataAccessor.all().

Referenced by conddblib.Connection.init().

311  def is_valid(self):
312  '''Tests whether the current DB looks like a valid CMS Conditions one.
313  '''
314  engine_connection = self.engine.connect()
315  #ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__) for table in [Tag, IOV, Payload, GlobalTag, GlobalTagMap]])
316  # temporarely avoid the check on the GT tables - there are releases in use where C++ does not create these tables.
317  ret = all([self.engine.dialect.has_table(engine_connection, table.__tablename__) for table in [Tag, IOV, Payload]])
318  engine_connection.close()
319  return ret
def conddblib.Connection.metadata (   self)

Definition at line 287 of file conddblib.py.

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

Definition at line 283 of file conddblib.py.

References conddblib.Connection._session.

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

Member Data Documentation

conddblib.Connection._is_frontier
private

Definition at line 265 of file conddblib.py.

Referenced by conddblib.Connection.is_frontier().

conddblib.Connection._is_official
private

Definition at line 274 of file conddblib.py.

Referenced by conddblib.Connection.is_official().

conddblib.Connection._is_oracle
private

Definition at line 266 of file conddblib.py.

Referenced by conddblib.Connection.is_oracle().

conddblib.Connection._is_read_only
private

Definition at line 269 of file conddblib.py.

Referenced by conddblib.Connection.is_read_only().

conddblib.Connection._is_sqlite
private

Definition at line 267 of file conddblib.py.

Referenced by conddblib.Connection.is_sqlite().

conddblib.Connection._session
private

Definition at line 263 of file conddblib.py.

Referenced by conddblib.Connection.session().

conddblib.Connection.engine

Definition at line 251 of file conddblib.py.

Referenced by conddblib.Connection.init().