CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Functions | Variables
conddblib Namespace Reference

Classes

class  Connection
 
class  Enum
 
class  EnumMetaclass
 
class  GlobalTag
 
class  GlobalTagMap
 
class  IOV
 
class  Payload
 
class  Synchronization
 
class  Tag
 
class  TimeType
 

Functions

def _exists
 
def _getCMSFrontierConnectionString
 
def _getCMSFrontierSQLAlchemyConnectionString
 
def _getCMSOracleSQLAlchemyConnectionString
 
def _inserted_before
 
def connect
 
def getPayload
 
def hash
 
def listObject
 
def make_url
 

Variables

string __author__ = 'Miguel Ojeda'
 
string __copyright__ = 'Copyright 2013, CERN'
 
list __credits__ = ['Giacomo Govi', 'Miguel Ojeda', 'Andreas Pfeiffer']
 
string __email__ = 'mojedasa@cern.ch'
 
string __license__ = 'Unknown'
 
string __maintainer__ = 'Miguel Ojeda'
 
tuple _Base = sqlalchemy.ext.declarative.declarative_base()
 
string contact_help = 'If you need assistance, please write an email to %s and %s. If you need immediate/urgent assistance, you can call the Offline DB expert on call (%s).'
 
string database_help
 
int description_length = 4000
 
string empty_label = '-'
 
tuple hash_length = len(hash(''))
 
tuple logger = logging.getLogger(__name__)
 
int name_length = 100
 
string offline_db_experts_email = 'cms-offlinedb-exp@cern.ch'
 
string offline_db_experts_phone = '+41 22 76 70817, or 70817 from CERN; check https://twiki.cern.ch/twiki/bin/viewauth/CMS/DBShifterHelpPage if it does not work; availability depends on the state of the LHC'
 
string web_experts_email = 'cms-cond-dev@cern.ch'
 

Detailed Description

CMS Conditions DB Python library.

Function Documentation

def conddblib._exists (   session,
  primary_key,
  value 
)
private

Definition at line 413 of file conddblib.py.

References KineDebug3.count(), and alcazmumu_cfi.filter.

Referenced by listObject().

414 def _exists(session, primary_key, value):
415  ret = None
416  try:
417  ret = session.query(primary_key).\
418  filter(primary_key == value).\
419  count() != 0
420  except sqlalchemy.exc.OperationalError:
421  pass
422 
423  return ret
def _exists
Definition: conddblib.py:413
def conddblib._getCMSFrontierConnectionString (   database)
private

Definition at line 338 of file conddblib.py.

References communicate().

Referenced by _getCMSFrontierSQLAlchemyConnectionString().

339 def _getCMSFrontierConnectionString(database):
340  import subprocess
341  return subprocess.Popen(['cmsGetFnConnect', 'frontier://%s' % database], stdout = subprocess.PIPE).communicate()[0].strip()
342 
static void * communicate(void *obj)
Definition: DQMNet.cc:1246
def _getCMSFrontierConnectionString
Definition: conddblib.py:338
def conddblib._getCMSFrontierSQLAlchemyConnectionString (   database,
  schema = 'cms_conditions' 
)
private

Definition at line 343 of file conddblib.py.

References _getCMSFrontierConnectionString().

Referenced by make_url().

344 def _getCMSFrontierSQLAlchemyConnectionString(database, schema = 'cms_conditions'):
345  import urllib
346  return 'oracle+frontier://@%s/%s' % (urllib.quote_plus(_getCMSFrontierConnectionString(database)), schema)
347 
def _getCMSFrontierConnectionString
Definition: conddblib.py:338
def _getCMSFrontierSQLAlchemyConnectionString
Definition: conddblib.py:343
def conddblib._getCMSOracleSQLAlchemyConnectionString (   database,
  schema = 'cms_conditions' 
)
private

Definition at line 348 of file conddblib.py.

Referenced by make_url().

349 def _getCMSOracleSQLAlchemyConnectionString(database, schema = 'cms_conditions'):
350  return 'oracle://%s@%s' % (schema, database)
351 
352 
353 # Entry point
def _getCMSOracleSQLAlchemyConnectionString
Definition: conddblib.py:348
def conddblib._inserted_before (   timestamp)
private
To be used inside filter().

Definition at line 424 of file conddblib.py.

Referenced by listObject().

425 def _inserted_before(timestamp):
426  '''To be used inside filter().
427  '''
428 
429  if timestamp is None:
430  # XXX: Returning None does not get optimized (skipped) by SQLAlchemy,
431  # and returning True does not work in Oracle (generates "and 1"
432  # which breaks Oracle but not SQLite). For the moment just use
433  # this dummy condition.
434  return sqlalchemy.literal(True) == sqlalchemy.literal(True)
435 
436  return conddb.IOV.insertion_time <= _parse_timestamp(timestamp)
def _inserted_before
Definition: conddblib.py:424
def conddblib.connect (   url,
  init = False,
  verbose = 0 
)
Returns a Connection instance to the CMS Condition DB.

See database_help for the description of the database parameter.

The verbosity level is as follows:

    0 = No output (default).
    1 = SQL statements issued, including their parameters.
    2 = In addition, results of the queries (all rows and the column headers).

Definition at line 388 of file conddblib.py.

389 def connect(url, init=False, verbose=0):
390  '''Returns a Connection instance to the CMS Condition DB.
391 
392  See database_help for the description of the database parameter.
393 
394  The verbosity level is as follows:
395 
396  0 = No output (default).
397  1 = SQL statements issued, including their parameters.
398  2 = In addition, results of the queries (all rows and the column headers).
399  '''
400 
401  if url.drivername == 'oracle' and url.password is None:
402  import getpass
403  url.password = getpass.getpass('Password for %s: ' % str(url))
404 
405  if verbose >= 1:
406  logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
407 
408  if verbose >= 2:
409  logging.getLogger('sqlalchemy.engine').setLevel(logging.DEBUG)
410 
411  return Connection(url, init=init)
412 
def connect
Definition: conddblib.py:388
def conddblib.getPayload (   session,
  hash 
)

Definition at line 476 of file conddblib.py.

References alcazmumu_cfi.filter.

477 def getPayload(session, hash):
478  # get payload from DB:
479  data, payloadType = session.query(Payload.data, Payload.object_type).filter(Payload.hash == hash).one()
480  return data
def getPayload
Definition: conddblib.py:476
def conddblib.hash (   data)

Definition at line 63 of file conddblib.py.

63 
64 def hash(data):
65  return hashlib.sha1(data).hexdigest()
66 
67 
# Constants
def hash
Definition: conddblib.py:63
def conddblib.listObject (   session,
  name,
  snapshot = None 
)

Definition at line 437 of file conddblib.py.

References _exists(), _inserted_before(), Vispa.Plugins.EdmBrowser.EdmDataAccessor.all(), alcazmumu_cfi.filter, reco.get(), join(), and hitfit.scalar().

438 def listObject(session, name, snapshot=None):
439 
440  is_tag = _exists(session, Tag.name, name)
441  result = {}
442  if is_tag:
443  result['type'] = 'Tag'
444  result['name'] = session.query(Tag).get(name).name
445  result['timeType'] = session.query(Tag.time_type).\
446  filter(Tag.name == name).\
447  scalar()
448 
449  result['iovs'] = session.query(IOV.since, IOV.insertion_time, IOV.payload_hash, Payload.object_type).\
450  join(IOV.payload).\
451  filter(
452  IOV.tag_name == name,
453  _inserted_before(snapshot),
454  ).\
455  order_by(IOV.since.desc(), IOV.insertion_time.desc()).\
456  from_self().\
457  order_by(IOV.since, IOV.insertion_time).\
458  all()
459 
460  try:
461  is_global_tag = _exists(session, GlobalTag.name, name)
462  if is_global_tag:
463  result['type'] = 'GlobalTag'
464  result['name'] = session.query(GlobalTag).get(name)
465  result['tags'] = session.query(GlobalTagMap.record, GlobalTagMap.label, GlobalTagMap.tag_name).\
466  filter(GlobalTagMap.global_tag_name == name).\
467  order_by(GlobalTagMap.record, GlobalTagMap.label).\
468  all()
469  except sqlalchemy.exc.OperationalError:
470  sys.stderr.write("No table for GlobalTags found in DB.\n\n")
471 
472  if not is_tag and not is_global_tag:
473  raise Exception('There is no tag or global tag named %s in the database.' % name)
474 
475  return result
def _exists
Definition: conddblib.py:413
def _inserted_before
Definition: conddblib.py:424
def listObject
Definition: conddblib.py:437
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
T get(const Candidate &c)
Definition: component.h:55
double scalar(const CLHEP::HepGenMatrix &m)
Return the matrix as a scalar. Raise an assertion if the matris is not .
Definition: matutil.cc:183
def conddblib.make_url (   database = 'pro')

Definition at line 354 of file conddblib.py.

References _getCMSFrontierSQLAlchemyConnectionString(), and _getCMSOracleSQLAlchemyConnectionString().

355 def make_url(database='pro'):
356 
357  schema = 'cms_conditions' # set the default
358  if ':' in database and '://' not in database: # check if we really got a shortcut like "pro:<schema>" (and not a url like proto://...), if so, disentangle
359  database, schema = database.split(':')
360  logging.debug(' ... using db "%s", schema "%s"' % (database, schema) )
361 
362  # Lazy in order to avoid calls to cmsGetFnConnect
363  mapping = {
364  'pro': lambda: _getCMSFrontierSQLAlchemyConnectionString('PromptProd', schema),
365  'arc': lambda: _getCMSFrontierSQLAlchemyConnectionString('FrontierArc', schema),
366  'int': lambda: _getCMSFrontierSQLAlchemyConnectionString('FrontierInt', schema),
367  'dev': lambda: _getCMSFrontierSQLAlchemyConnectionString('FrontierPrep', schema),
368 
369  'orapro': lambda: _getCMSOracleSQLAlchemyConnectionString('cms_orcon_adg', schema),
370  'oraarc': lambda: _getCMSOracleSQLAlchemyConnectionString('cmsarc_lb', schema),
371  'oraint': lambda: _getCMSOracleSQLAlchemyConnectionString('cms_orcoff_int', schema),
372  'oradev': lambda: _getCMSOracleSQLAlchemyConnectionString('cms_orcoff_prep', schema),
373 
374  'onlineorapro': lambda: _getCMSOracleSQLAlchemyConnectionString('cms_orcon_prod', schema),
375  'onlineoraint': lambda: _getCMSOracleSQLAlchemyConnectionString('cmsintr_lb', schema),
376  }
377 
378  if database in mapping:
379  database = mapping[database]()
380 
381  logging.debug('connection string set to "%s"' % database)
382 
383  try:
384  url = sqlalchemy.engine.url.make_url(database)
385  except sqlalchemy.exc.ArgumentError:
386  url = sqlalchemy.engine.url.make_url('sqlite:///%s' % database)
387  return url
def make_url
Definition: conddblib.py:354
def _getCMSOracleSQLAlchemyConnectionString
Definition: conddblib.py:348
def _getCMSFrontierSQLAlchemyConnectionString
Definition: conddblib.py:343

Variable Documentation

string conddblib.__author__ = 'Miguel Ojeda'

Definition at line 4 of file conddblib.py.

string conddblib.__copyright__ = 'Copyright 2013, CERN'

Definition at line 5 of file conddblib.py.

list conddblib.__credits__ = ['Giacomo Govi', 'Miguel Ojeda', 'Andreas Pfeiffer']

Definition at line 6 of file conddblib.py.

string conddblib.__email__ = 'mojedasa@cern.ch'

Definition at line 9 of file conddblib.py.

string conddblib.__license__ = 'Unknown'

Definition at line 7 of file conddblib.py.

string conddblib.__maintainer__ = 'Miguel Ojeda'

Definition at line 8 of file conddblib.py.

tuple conddblib._Base = sqlalchemy.ext.declarative.declarative_base()

Definition at line 171 of file conddblib.py.

string conddblib.contact_help = 'If you need assistance, please write an email to %s and %s. If you need immediate/urgent assistance, you can call the Offline DB expert on call (%s).'

Definition at line 78 of file conddblib.py.

string conddblib.database_help

Definition at line 79 of file conddblib.py.

int conddblib.description_length = 4000

Definition at line 71 of file conddblib.py.

string conddblib.empty_label = '-'

Definition at line 68 of file conddblib.py.

tuple conddblib.hash_length = len(hash(''))

Definition at line 72 of file conddblib.py.

tuple conddblib.logger = logging.getLogger(__name__)

Definition at line 20 of file conddblib.py.

Referenced by cscdqm::Configuration.printStats().

int conddblib.name_length = 100

Definition at line 70 of file conddblib.py.

string conddblib.offline_db_experts_email = 'cms-offlinedb-exp@cern.ch'

Definition at line 75 of file conddblib.py.

string conddblib.offline_db_experts_phone = '+41 22 76 70817, or 70817 from CERN; check https://twiki.cern.ch/twiki/bin/viewauth/CMS/DBShifterHelpPage if it does not work; availability depends on the state of the LHC'

Definition at line 76 of file conddblib.py.

string conddblib.web_experts_email = 'cms-cond-dev@cern.ch'

Definition at line 74 of file conddblib.py.