CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
python.Events Class Reference

## Events

More...

Public Member Functions

def __del__
 
def __init__
 
def __iter__
 
def eventAuxiliary
 
def fileIndex
 
def fileIndicies
 
def getByLabel
 
def object
 
def secondaryFileIndex
 
def size
 
def to
 
def toBegin
 

Private Member Functions

def _createFWLiteEvent
 
def _next
 
def _parseOptions
 Private Member Functions ##. More...
 
def _toBeginCode
 

Private Attributes

 _event
 
 _eventCounts
 
 _filenames
 
 _forceEvent
 
 _maxEvents
 Parse optional arguments ##. More...
 
 _mode
 
 _secondaryFilenames
 
 _tfile
 
 _toBegin
 
 _veryFirstTime
 

Detailed Description

## Events

Python interface to FWLite ChainEvent class

Definition at line 458 of file __init__.py.

Constructor & Destructor Documentation

def python.Events.__init__ (   self,
  inputFiles = '',
  kwargs 
)
inputFiles    => Either a single filename or a list of filenames
Optional arguments:
forceEvent  => Use fwlite::Event IF there is only one file
maxEvents   => Maximum number of events to process

Definition at line 461 of file __init__.py.

462  def __init__(self, inputFiles = '', **kwargs):
463  """inputFiles => Either a single filename or a list of filenames
464  Optional arguments:
465  forceEvent => Use fwlite::Event IF there is only one file
466  maxEvents => Maximum number of events to process
467  """
468  self._veryFirstTime = True
469  self._event = 0
470  self._eventCounts = 0
471  self._maxEvents = 0
472  self._forceEvent = False
473  self._mode = None
474  self._secondaryFilenames = None
475  if isinstance (inputFiles, list):
476  # it's a list
477  self._filenames = inputFiles[:]
478  elif isinstance (inputFiles, VarParsing):
479  # it's a VarParsing object
480  options = inputFiles
481  self._maxEvents = options.maxEvents
482  self._filenames = options.inputFiles
483  self._secondaryFilenames = options.secondaryInputFiles
484  else:
485  # it's probably a single string
486  self._filenames = [inputFiles]
487  ##############################
488  ## Parse optional arguments ##
489  ##############################
490  if 'maxEvents' in kwargs:
491  self._maxEvents = kwargs['maxEvents']
492  del kwargs['maxEvents']
493  if 'forceEvent' in kwargs:
494  self._forceEvent = kwargs['forceEvent']
495  del kwargs['forceEvent']
496  if 'options' in kwargs:
497  options = kwargs ['options']
498  self._maxEvents = options.maxEvents
499  self._filenames = options.inputFiles
500  self._secondaryFilenames = options.secondaryInputFiles
501  del kwargs['options']
502  # Since we deleted the options as we used them, that means
503  # that kwargs should be empty. If it's not, that means that
504  # somebody passed in an argument that we're not using and we
505  # should complain.
506  if len (kwargs):
507  raise RuntimeError("Unknown arguments %s" % kwargs)
508  if not self._filenames:
509  raise RuntimeError("No input files given")
510 
_maxEvents
Parse optional arguments ##.
Definition: __init__.py:470
def python.Events.__del__ (   self)
(Internal) Destructor

Definition at line 625 of file __init__.py.

References python.Events._event.

626  def __del__ (self):
627  """(Internal) Destructor"""
628  # print "Goodbye cruel world, I'm leaving you today."
629  del self._event
630  # print "Goodbye, goodbye, goodbye."
631 

Member Function Documentation

def python.Events.__iter__ (   self)

Definition at line 587 of file __init__.py.

References python.Lumis._next(), python.Runs._next(), and python.Events._next().

588  def __iter__ (self):
589  return self._next()
590 
def python.Events._createFWLiteEvent (   self)
private
(Internal) Creates an FWLite Event

Definition at line 632 of file __init__.py.

References python.Events._event, python.Lumis._filenames, python.Runs._filenames, python.Events._filenames, python.Events._forceEvent, python.Events._mode, python.Events._toBegin, python.Lumis._veryFirstTime, python.Runs._veryFirstTime, and python.Events._veryFirstTime.

Referenced by python.Events._next(), python.Events.getByLabel(), python.Events.size(), and python.Events.to().

633  def _createFWLiteEvent (self):
634  """(Internal) Creates an FWLite Event"""
635  self._veryFirstTime = False
636  self._toBegin = True
637  if isinstance (self._filenames[0], ROOT.TFile):
638  self._event = ROOT.fwlite.Event (self._filenames[0])
639  self._mode = 'single'
640  return self._mode
641  if len (self._filenames) == 1 and self._forceEvent:
642  self._tfile = ROOT.TFile.Open (self._filenames[0])
643  self._event = ROOT.fwlite.Event (self._tfile)
644  self._mode = 'single'
645  return self._mode
646  filenamesSVec = ROOT.vector("string") ()
647  for name in self._filenames:
648  filenamesSVec.push_back (name)
649  if self._secondaryFilenames:
650  secondarySVec = ROOT.vector("string") ()
651  for name in self._secondaryFilenames:
652  secondarySVec.push_back (name)
653  self._event = ROOT.fwlite.MultiChainEvent (filenamesSVec,
654  secondarySVec)
655  self._mode = 'multi'
656  else:
657  self._event = ROOT.fwlite.ChainEvent (filenamesSVec)
658  self._mode = 'chain'
659  return self._mode
660 
def _createFWLiteEvent
Definition: __init__.py:632
def python.Events._next (   self)
private
(Internal) Iterator internals

Definition at line 661 of file __init__.py.

References python.Events._createFWLiteEvent(), python.Events._eventCounts, python.Events._maxEvents, python.Events._toBegin, python.Events._toBeginCode(), python.Lumis._veryFirstTime, python.Runs._veryFirstTime, and python.Events._veryFirstTime.

Referenced by python.Events.__iter__().

662  def _next (self):
663  """(Internal) Iterator internals"""
664  if self._veryFirstTime:
665  self._createFWLiteEvent()
666  if self._toBegin:
667  self._toBeginCode()
668  while not self._event.atEnd() :
669  yield self
670  self._eventCounts += 1
671  if self._maxEvents > 0 and self._eventCounts >= self._maxEvents:
672  break
673  # Have we been asked to go to the first event?
674  if self._toBegin:
675  self._toBeginCode()
676  else:
677  # if not, lets go to the next event
678  self._event.__preinc__()
679 
680 
def _createFWLiteEvent
Definition: __init__.py:632
def _toBeginCode
Definition: __init__.py:618
_maxEvents
Parse optional arguments ##.
Definition: __init__.py:470
def python.Events._parseOptions (   self,
  options 
)
private

Private Member Functions ##.

(Internal) Parse options

Definition at line 614 of file __init__.py.

615  def _parseOptions (self, options):
616  """(Internal) Parse options"""
617 
def _parseOptions
Private Member Functions ##.
Definition: __init__.py:614
def python.Events._toBeginCode (   self)
private
(Internal) Does actual work of toBegin() call

Definition at line 618 of file __init__.py.

Referenced by python.Events._next().

619  def _toBeginCode (self):
620  """(Internal) Does actual work of toBegin() call"""
621  self._toBegin = False
622  self._event.toBegin()
623  self._eventCounts = 0
624 
def _toBeginCode
Definition: __init__.py:618
def python.Events.eventAuxiliary (   self)
Returns eventAuxiliary object

Definition at line 530 of file __init__.py.

References python.Lumis._veryFirstTime, python.Runs._veryFirstTime, and python.Events._veryFirstTime.

531  def eventAuxiliary (self):
532  """Returns eventAuxiliary object"""
533  if self._veryFirstTime:
534  raise RuntimeError("eventAuxiliary() called before "\
535  "toBegin() or to()")
536  return self._event.eventAuxiliary()
537 
def eventAuxiliary
Definition: __init__.py:530
def python.Events.fileIndex (   self)

Definition at line 591 of file __init__.py.

References python.Events._event.

Referenced by python.Events.fileIndicies().

592  def fileIndex (self):
593  if self._event:
594  return self._event.fileIndex()
595  else:
596  # default non-existant value is -1. Return something else
597  return -2
598 
def python.Events.fileIndicies (   self)

Definition at line 607 of file __init__.py.

References fwlite::LuminosityBlockBase.fileIndex(), fwlite::RunBase.fileIndex(), fwlite::EventBase.fileIndex(), fwlite::ChainEvent.fileIndex(), fwlite::MultiChainEvent.fileIndex(), python.Events.fileIndex(), fwlite::LuminosityBlockBase.secondaryFileIndex(), fwlite::RunBase.secondaryFileIndex(), fwlite::EventBase.secondaryFileIndex(), fwlite::MultiChainEvent.secondaryFileIndex(), and python.Events.secondaryFileIndex().

608  def fileIndicies (self):
609  return (self.fileIndex(), self.secondaryFileIndex())
610 
def fileIndicies
Definition: __init__.py:607
def secondaryFileIndex
Definition: __init__.py:599
def python.Events.getByLabel (   self,
  args 
)
Calls FWLite's getByLabel.  Called:
getByLabel (moduleLabel, handle)
getByLabel (moduleLabel, productInstanceLabel, handle),
getByLabel (moduleLabel, productInstanceLabel, processLabel, handle),
or
getByLabel ( (mL, pIL,pL), handle)

Definition at line 543 of file __init__.py.

References python.Events._createFWLiteEvent(), python.Lumis._veryFirstTime, python.Runs._veryFirstTime, python.Events._veryFirstTime, submitPVResolutionJobs.count, if(), join(), and submitPVValidationJobs.split().

544  def getByLabel (self, *args):
545  """Calls FWLite's getByLabel. Called:
546  getByLabel (moduleLabel, handle)
547  getByLabel (moduleLabel, productInstanceLabel, handle),
548  getByLabel (moduleLabel, productInstanceLabel, processLabel, handle),
549  or
550  getByLabel ( (mL, pIL,pL), handle)
551  """
552  if self._veryFirstTime:
553  self._createFWLiteEvent()
554  length = len (args)
555  if length < 2 or length > 4:
556  # not called correctly
557  raise RuntimeError("Incorrect number of arguments")
558  # handle is always the last argument
559  argsList = list (args)
560  handle = argsList.pop()
561  if len(argsList)==1 :
562  if( isinstance (argsList[0], tuple) or
563  isinstance (argsList[0], list) ) :
564  if len (argsList[0]) > 3:
565  raise RuntimeError("getByLabel Error: label tuple has too " \
566  "many arguments '%s'" % argsList[0])
567  argsList = list(argsList[0])
568  if( isinstance(argsList[0], str) and ":" in argsList[0] ):
569  if argsList[0].count(":") > 3:
570  raise RuntimeError("getByLabel Error: label tuple has too " \
571  "many arguments '%s'" % argsList[0].split(":"))
572  argsList = argsList[0].split(":")
573  while len(argsList) < 3:
574  argsList.append ('')
575  (moduleLabel, productInstanceLabel, processLabel) = argsList
576  labelString = "'" + "', '".join(argsList) + "'"
577  if not handle._wrapper :
578  handle._resetWrapper()
579  handle._setStatus ( self._event.getByLabel( handle._typeInfoGetter(),
580  moduleLabel,
581  productInstanceLabel,
582  processLabel,
583  handle._addressOf() ),
584  labelString )
585  return handle.isValid()
586 
def _createFWLiteEvent
Definition: __init__.py:632
def getByLabel
Definition: __init__.py:543
if(conf_.getParameter< bool >("UseStripCablingDB"))
static std::string join(char **cmd)
Definition: RemoteFile.cc:19
def python.Events.object (   self)
Returns event object

Definition at line 538 of file __init__.py.

References python.Events._event.

539  def object (self):
540  """Returns event object"""
541  return self._event
542 
def python.Events.secondaryFileIndex (   self)

Definition at line 599 of file __init__.py.

References python.Events._event.

Referenced by python.Events.fileIndicies().

600  def secondaryFileIndex (self):
601  if self._event:
602  return self._event.secondaryFileIndex()
603  else:
604  # default non-existant value is -1. Return something else
605  return -2
606 
def secondaryFileIndex
Definition: __init__.py:599
def python.Events.size (   self)
Returns number of events

Definition at line 523 of file __init__.py.

References python.Events._createFWLiteEvent(), python.Lumis._veryFirstTime, python.Runs._veryFirstTime, and python.Events._veryFirstTime.

Referenced by ntupleDataFormat._Collection.__iter__(), and ntupleDataFormat._Collection.__len__().

524  def size (self):
525  """Returns number of events"""
526  if self._veryFirstTime:
527  self._createFWLiteEvent()
528  return self._event.size()
529 
def _createFWLiteEvent
Definition: __init__.py:632
def python.Events.to (   self,
  entryIndex 
)
Jumps to event entryIndex

Definition at line 511 of file __init__.py.

References python.Events._createFWLiteEvent(), python.Lumis._veryFirstTime, python.Runs._veryFirstTime, and python.Events._veryFirstTime.

512  def to (self, entryIndex):
513  """Jumps to event entryIndex"""
514  if self._veryFirstTime:
515  self._createFWLiteEvent()
516  return self._event.to ( int(entryIndex) )
517 
def _createFWLiteEvent
Definition: __init__.py:632
def python.Events.toBegin (   self)
Called to reset event loop to first event.

Definition at line 518 of file __init__.py.

519  def toBegin (self):
520  """Called to reset event loop to first event."""
521  self._toBegin = True
522 

Member Data Documentation

python.Events._event
private

Definition at line 468 of file __init__.py.

Referenced by python.Events.__del__(), python.Events._createFWLiteEvent(), python.Events.fileIndex(), python.Events.object(), and python.Events.secondaryFileIndex().

python.Events._eventCounts
private

Definition at line 469 of file __init__.py.

Referenced by python.Events._next(), and python.Events._toBeginCode().

python.Events._filenames
private

Definition at line 476 of file __init__.py.

Referenced by python.Events._createFWLiteEvent().

python.Events._forceEvent
private

Definition at line 471 of file __init__.py.

Referenced by python.Events._createFWLiteEvent().

python.Events._maxEvents
private

Parse optional arguments ##.

Definition at line 470 of file __init__.py.

Referenced by python.Events._next().

python.Events._mode
private

Definition at line 472 of file __init__.py.

Referenced by python.Events._createFWLiteEvent().

python.Events._secondaryFilenames
private

Definition at line 473 of file __init__.py.

python.Events._tfile
private

Definition at line 641 of file __init__.py.

python.Events._toBegin
private

Definition at line 520 of file __init__.py.

Referenced by python.Events._createFWLiteEvent(), python.Events._next(), and python.Events._toBeginCode().

python.Events._veryFirstTime
private

Definition at line 467 of file __init__.py.

Referenced by python.Events._createFWLiteEvent(), python.Events._next(), python.Events.eventAuxiliary(), python.Events.getByLabel(), python.Events.size(), and python.Events.to().