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

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

Referenced by listObject().

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

Definition at line 339 of file conddblib.py.

References communicate().

Referenced by _getCMSFrontierSQLAlchemyConnectionString().

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

Definition at line 344 of file conddblib.py.

References _getCMSFrontierConnectionString().

Referenced by make_url().

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

Definition at line 349 of file conddblib.py.

Referenced by make_url().

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

Definition at line 425 of file conddblib.py.

Referenced by listObject().

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

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

Definition at line 477 of file conddblib.py.

References alcazmumu_cfi.filter.

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

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

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

References _getCMSFrontierSQLAlchemyConnectionString(), and _getCMSOracleSQLAlchemyConnectionString().

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

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 172 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.