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

References prof2calltree.count, and alcazmumu_cfi.filter.

Referenced by listObject().

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

Definition at line 336 of file conddblib.py.

References communicate().

Referenced by _getCMSFrontierSQLAlchemyConnectionString().

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

Definition at line 341 of file conddblib.py.

References _getCMSFrontierConnectionString().

Referenced by make_url().

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

Definition at line 346 of file conddblib.py.

Referenced by make_url().

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

Definition at line 422 of file conddblib.py.

Referenced by listObject().

423 def _inserted_before(timestamp):
424  '''To be used inside filter().
425  '''
426 
427  if timestamp is None:
428  # XXX: Returning None does not get optimized (skipped) by SQLAlchemy,
429  # and returning True does not work in Oracle (generates "and 1"
430  # which breaks Oracle but not SQLite). For the moment just use
431  # this dummy condition.
432  return sqlalchemy.literal(True) == sqlalchemy.literal(True)
433 
434  return conddb.IOV.insertion_time <= _parse_timestamp(timestamp)
def _inserted_before
Definition: conddblib.py:422
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 386 of file conddblib.py.

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

Definition at line 474 of file conddblib.py.

References alcazmumu_cfi.filter.

475 def getPayload(session, hash):
476  # get payload from DB:
477  data, payloadType = session.query(Payload.data, Payload.object_type).filter(Payload.hash == hash).one()
478  return data
def getPayload
Definition: conddblib.py:474
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 435 of file conddblib.py.

References _exists(), _inserted_before(), cond::ecalcond.all, alcazmumu_cfi.filter, reco.get(), join(), and hitfit.scalar().

436 def listObject(session, name, snapshot=None):
437 
438  is_tag = _exists(session, Tag.name, name)
439  result = {}
440  if is_tag:
441  result['type'] = 'Tag'
442  result['name'] = session.query(Tag).get(name).name
443  result['timeType'] = session.query(Tag.time_type).\
444  filter(Tag.name == name).\
445  scalar()
446 
447  result['iovs'] = session.query(IOV.since, IOV.insertion_time, IOV.payload_hash, Payload.object_type).\
448  join(IOV.payload).\
449  filter(
450  IOV.tag_name == name,
451  _inserted_before(snapshot),
452  ).\
453  order_by(IOV.since.desc(), IOV.insertion_time.desc()).\
454  from_self().\
455  order_by(IOV.since, IOV.insertion_time).\
456  all()
457 
458  try:
459  is_global_tag = _exists(session, GlobalTag.name, name)
460  if is_global_tag:
461  result['type'] = 'GlobalTag'
462  result['name'] = session.query(GlobalTag).get(name)
463  result['tags'] = session.query(GlobalTagMap.record, GlobalTagMap.label, GlobalTagMap.tag_name).\
464  filter(GlobalTagMap.global_tag_name == name).\
465  order_by(GlobalTagMap.record, GlobalTagMap.label).\
466  all()
467  except sqlalchemy.exc.OperationalError:
468  sys.stderr.write("No table for GlobalTags found in DB.\n\n")
469 
470  if not is_tag and not is_global_tag:
471  raise Exception('There is no tag or global tag named %s in the database.' % name)
472 
473  return result
def _exists
Definition: conddblib.py:411
def _inserted_before
Definition: conddblib.py:422
def listObject
Definition: conddblib.py:435
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 352 of file conddblib.py.

References _getCMSFrontierSQLAlchemyConnectionString(), and _getCMSOracleSQLAlchemyConnectionString().

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

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.