ATLAS Offline Software
Loading...
Searching...
No Matches
python.AlgSequence.AlgSequenceIterator Class Reference
Inheritance diagram for python.AlgSequence.AlgSequenceIterator:
Collaboration diagram for python.AlgSequence.AlgSequenceIterator:

Public Types

typedef HLT::TypeInformation::for_each_type_c< typenameEDMLIST::map, my_functor, my_result<>, my_arg< HLT::TypeInformation::get_cont, CONTAINER > >::type result

Public Member Functions

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

Protected Attributes

 _sequence = sequence
int _index = 0
 _iterator = None

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.

Member Typedef Documentation

◆ result

Definition at line 90 of file EDM_MasterSearch.h.

Constructor & Destructor Documentation

◆ __init__()

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__()

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__()

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

int python.AlgSequence.AlgSequenceIterator._index = 0
protected

◆ _iterator

python.AlgSequence.AlgSequenceIterator._iterator = None
protected

◆ _sequence

python.AlgSequence.AlgSequenceIterator._sequence = sequence
protected

The documentation for this class was generated from the following file: