ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
python.AlgSequence.AlgSequenceIterator Class Reference
Inheritance diagram for python.AlgSequence.AlgSequenceIterator:
Collaboration diagram for python.AlgSequence.AlgSequenceIterator:

Public Member Functions

def __init__ (self, sequence)
 
def __iter__ (self)
 
def __next__ (self)
 

Private Attributes

 _sequence
 
 _index
 
 _iterator
 

Detailed Description

Iterator over a standalone algorithm sequence

This custom class is needed to implement a "recursive iteration", which
would loop over all algorithms in a sequence that itself may have
sub-sequences inside of it.

Definition at line 234 of file PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py.

Constructor & Destructor Documentation

◆ __init__()

def python.AlgSequence.AlgSequenceIterator.__init__ (   self,
  sequence 
)
Constructor for the algorithm sequence iterator

Keyword arguments:
  sequence -- The sequence to iterate over (recursively)

Definition at line 242 of file PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py.

242  def __init__( self, sequence ):
243  """Constructor for the algorithm sequence iterator
244 
245  Keyword arguments:
246  sequence -- The sequence to iterate over (recursively)
247  """
248 
249  # Set up the internal variables:
250  self._sequence = sequence
251  self._index = 0
252  self._iterator = None
253 
254  return
255 

Member Function Documentation

◆ __iter__()

def python.AlgSequence.AlgSequenceIterator.__iter__ (   self)
Function making this iterator iterable itself

Definition at line 256 of file PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py.

256  def __iter__( self ):
257  """Function making this iterator iterable itself
258  """
259  return self
260 

◆ __next__()

def python.AlgSequence.AlgSequenceIterator.__next__ (   self)
Function implementing the recursive iteration over an AlgSequence

This is where most of the logic is. The iterator loops over the
elements of the AlgSequence that was given to it, one by one. When
it finds an element in the AlgSequence that itself is also an
AlgSequence, then it creates a helper iterator object that would
process that sub-sequence, and continue the iteration using that
helper.

The end result is that the iteration should loop over every
algorithm in the sequence and its sub-sequences.

Definition at line 261 of file PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py.

261  def __next__( self ):
262  """Function implementing the recursive iteration over an AlgSequence
263 
264  This is where most of the logic is. The iterator loops over the
265  elements of the AlgSequence that was given to it, one by one. When
266  it finds an element in the AlgSequence that itself is also an
267  AlgSequence, then it creates a helper iterator object that would
268  process that sub-sequence, and continue the iteration using that
269  helper.
270 
271  The end result is that the iteration should loop over every
272  algorithm in the sequence and its sub-sequences.
273  """
274 
275  # First off, check whether we reached the end of the sequence.
276  if self._index >= len( self._sequence ):
277  raise StopIteration()
278 
279  # If not, check whether we are currently iterating over a
280  # sub-sequence.
281  if self._iterator:
282  try:
283  return self._iterator.__next__()
284  except StopIteration:
285  # If the sub-sequence is exhaused, then switch to the
286  # next element in our sequence, and call this function
287  # recursively.
288  self._index += 1
289  self._iterator = None
290  return self.__next__()
291  pass
292 
293  # If we are not iterating over a sub-sequence at the moment, let's
294  # just take the next element of our sequence.
295  element = self._sequence[ self._index ]
296 
297  # If this element is a sequence itself, then switch to "sub-sequence
298  # iterating mode", and call this function recursively in that mode.
299  if isinstance( element, AlgSequence ):
300  self._iterator = AlgSequenceIterator( element )
301  return self.__next__()
302 
303  # Apparently it's an algorithm we found. So update the internal
304  # index, and simply return the algorithm.
305  self._index += 1
306  return element
307 

Member Data Documentation

◆ _index

python.AlgSequence.AlgSequenceIterator._index
private

◆ _iterator

python.AlgSequence.AlgSequenceIterator._iterator
private

◆ _sequence

python.AlgSequence.AlgSequenceIterator._sequence
private

The documentation for this class was generated from the following file:
python.Bindings.__iter__
__iter__
Definition: Control/AthenaPython/python/Bindings.py:791
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18