CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
python.Events Class Reference

## Events

More...

Public Member Functions

def __del__ (self)
 
def __init__ (self, inputFiles='', kwargs)
 
def __iter__ (self)
 
def eventAuxiliary (self)
 
def fileIndex (self)
 
def fileIndicies (self)
 
def getByLabel (self, args)
 
def object (self)
 
def secondaryFileIndex (self)
 
def size (self)
 
def to (self, entryIndex)
 
def toBegin (self)
 

Private Member Functions

def _createFWLiteEvent (self)
 
def _next (self)
 
def _parseOptions (self, options)
 Private Member Functions ##. More...
 
def _toBeginCode (self)
 

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 456 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

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 459 of file __init__.py.

459  def __init__(self, inputFiles = '', **kwargs):
460  """inputFiles => Either a single filename or a list of filenames
461  Optional arguments:
462  forceEvent => Use fwlite::Event IF there is only one file
463  maxEvents => Maximum number of events to process
464  """
465  self._veryFirstTime = True
466  self._event = 0
467  self._eventCounts = 0
468  self._maxEvents = 0
469  self._forceEvent = False
470  self._mode = None
471  self._secondaryFilenames = None
472  if isinstance (inputFiles, list):
473  # it's a list
474  self._filenames = inputFiles[:]
475  elif isinstance (inputFiles, VarParsing):
476  # it's a VarParsing object
477  options = inputFiles
478  self._maxEvents = options.maxEvents
479  self._filenames = options.inputFiles
480  self._secondaryFilenames = options.secondaryInputFiles
481  else:
482  # it's probably a single string
483  self._filenames = [inputFiles]
484 
487  if 'maxEvents' in kwargs:
488  self._maxEvents = kwargs['maxEvents']
489  del kwargs['maxEvents']
490  if 'forceEvent' in kwargs:
491  self._forceEvent = kwargs['forceEvent']
492  del kwargs['forceEvent']
493  if 'options' in kwargs:
494  options = kwargs ['options']
495  self._maxEvents = options.maxEvents
496  self._filenames = options.inputFiles
497  self._secondaryFilenames = options.secondaryInputFiles
498  del kwargs['options']
499  # Since we deleted the options as we used them, that means
500  # that kwargs should be empty. If it's not, that means that
501  # somebody passed in an argument that we're not using and we
502  # should complain.
503  if len (kwargs):
504  raise RuntimeError("Unknown arguments %s" % kwargs)
505  if not self._filenames:
506  raise RuntimeError("No input files given")
507 
508 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

◆ __del__()

def python.Events.__del__ (   self)
(Internal) Destructor

Definition at line 623 of file __init__.py.

References python.Events._event.

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

Member Function Documentation

◆ __iter__()

def python.Events.__iter__ (   self)

Definition at line 585 of file __init__.py.

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

585  def __iter__ (self):
586  return self._next()
587 
588 

◆ _createFWLiteEvent()

def python.Events._createFWLiteEvent (   self)
private
(Internal) Creates an FWLite Event

Definition at line 630 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().

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

◆ _next()

def python.Events._next (   self)
private
(Internal) Iterator internals

Definition at line 659 of file __init__.py.

References python.Events._createFWLiteEvent(), python.Events._event, 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__().

659  def _next (self):
660  """(Internal) Iterator internals"""
661  if self._veryFirstTime:
662  self._createFWLiteEvent()
663  if self._toBegin:
664  self._toBeginCode()
665  while not self._event.atEnd() :
666  yield self
667  self._eventCounts += 1
668  if self._maxEvents > 0 and self._eventCounts >= self._maxEvents:
669  break
670  # Have we been asked to go to the first event?
671  if self._toBegin:
672  self._toBeginCode()
673  else:
674  # if not, lets go to the next event
675  self._event.__preinc__()
676 
677 
678 

◆ _parseOptions()

def python.Events._parseOptions (   self,
  options 
)
private

Private Member Functions ##.

(Internal) Parse options

Definition at line 612 of file __init__.py.

612  def _parseOptions (self, options):
613  """(Internal) Parse options"""
614 
615 

◆ _toBeginCode()

def python.Events._toBeginCode (   self)
private
(Internal) Does actual work of toBegin() call

Definition at line 616 of file __init__.py.

Referenced by python.Events._next().

616  def _toBeginCode (self):
617  """(Internal) Does actual work of toBegin() call"""
618  self._toBegin = False
619  self._event.toBegin()
620  self._eventCounts = 0
621 
622 

◆ eventAuxiliary()

def python.Events.eventAuxiliary (   self)
Returns eventAuxiliary object

Definition at line 528 of file __init__.py.

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

528  def eventAuxiliary (self):
529  """Returns eventAuxiliary object"""
530  if self._veryFirstTime:
531  raise RuntimeError("eventAuxiliary() called before "\
532  "toBegin() or to()")
533  return self._event.eventAuxiliary()
534 
535 

◆ fileIndex()

def python.Events.fileIndex (   self)

Definition at line 589 of file __init__.py.

References python.Events._event.

Referenced by python.Events.fileIndicies().

589  def fileIndex (self):
590  if self._event:
591  return self._event.fileIndex()
592  else:
593  # default non-existant value is -1. Return something else
594  return -2
595 
596 

◆ fileIndicies()

def python.Events.fileIndicies (   self)

◆ getByLabel()

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 541 of file __init__.py.

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

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

◆ object()

def python.Events.object (   self)
Returns event object

Definition at line 536 of file __init__.py.

References python.Events._event.

536  def object (self):
537  """Returns event object"""
538  return self._event
539 
540 

◆ secondaryFileIndex()

def python.Events.secondaryFileIndex (   self)

Definition at line 597 of file __init__.py.

References python.Events._event.

Referenced by python.Events.fileIndicies().

597  def secondaryFileIndex (self):
598  if self._event:
599  return self._event.secondaryFileIndex()
600  else:
601  # default non-existant value is -1. Return something else
602  return -2
603 
604 

◆ size()

def python.Events.size (   self)
Returns number of events

Definition at line 521 of file __init__.py.

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

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

521  def size (self):
522  """Returns number of events"""
523  if self._veryFirstTime:
524  self._createFWLiteEvent()
525  return self._event.size()
526 
527 

◆ to()

def python.Events.to (   self,
  entryIndex 
)
Jumps to event entryIndex

Definition at line 509 of file __init__.py.

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

509  def to (self, entryIndex):
510  """Jumps to event entryIndex"""
511  if self._veryFirstTime:
512  self._createFWLiteEvent()
513  return self._event.to ( int(entryIndex) )
514 
515 

◆ toBegin()

def python.Events.toBegin (   self)
Called to reset event loop to first event.

Definition at line 516 of file __init__.py.

516  def toBegin (self):
517  """Called to reset event loop to first event."""
518  self._toBegin = True
519 
520 

Member Data Documentation

◆ _event

python.Events._event
private

◆ _eventCounts

python.Events._eventCounts
private

Definition at line 467 of file __init__.py.

Referenced by python.Events._next().

◆ _filenames

python.Events._filenames
private

Definition at line 474 of file __init__.py.

Referenced by python.Events._createFWLiteEvent().

◆ _forceEvent

python.Events._forceEvent
private

Definition at line 469 of file __init__.py.

Referenced by python.Events._createFWLiteEvent().

◆ _maxEvents

python.Events._maxEvents
private

Parse optional arguments ##.

Definition at line 468 of file __init__.py.

Referenced by python.Events._next().

◆ _mode

python.Events._mode
private

Definition at line 470 of file __init__.py.

Referenced by python.Events._createFWLiteEvent().

◆ _secondaryFilenames

python.Events._secondaryFilenames
private

Definition at line 471 of file __init__.py.

◆ _tfile

python.Events._tfile
private

Definition at line 639 of file __init__.py.

◆ _toBegin

python.Events._toBegin
private

Definition at line 518 of file __init__.py.

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

◆ _veryFirstTime

python.Events._veryFirstTime
private