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

Public Member Functions

 __init__ (self, name="AlgSequence")
 name (self)
 insert (self, index, algOrSeq)
 addSelfToJob (self, job)
 __getitem__ (self, index)
 __getattr__ (self, name)
 __delattr__ (self, name)
 __iter__ (self)
 __iadd__ (self, algOrSeq, index=None)
 __eq__ (self, other)
 __str__ (self)
 __len__ (self)

Protected Attributes

 _name = name
list _algsAndSequences = []

Detailed Description

Standalone algorithm sequence

This is a light-weight emulation of Athena's AthSequencer class,
implementing a simple algorithm sequence for EventLoop jobs.

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

Constructor & Destructor Documentation

◆ __init__()

python.AlgSequence.AlgSequence.__init__ ( self,
name = "AlgSequence" )
Algorithm sequence constructor

Keyword arguments:
  name -- The name of the algorithm sequence (for debugging)

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

26 def __init__( self, name = "AlgSequence" ):
27 """Algorithm sequence constructor
28
29 Keyword arguments:
30 name -- The name of the algorithm sequence (for debugging)
31 """
32
33 # Set up the member variables:
34 self._name = name
35 self._algsAndSequences = []
36
37 return
38

Member Function Documentation

◆ __delattr__()

python.AlgSequence.AlgSequence.__delattr__ ( self,
name )
Remove one algorithm/sequence from this sequence, by name

This is to allow removing algorithms (or even sequences) from this
sequence in case that would be needed.

Keyword arguments:
  name -- The name of the algorithm/sequence to delete from the
          sequence

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

110 def __delattr__( self, name ):
111 """Remove one algorithm/sequence from this sequence, by name
112
113 This is to allow removing algorithms (or even sequences) from this
114 sequence in case that would be needed.
115
116 Keyword arguments:
117 name -- The name of the algorithm/sequence to delete from the
118 sequence
119 """
120
121 # Look up the algorithm by name:
122 for algOrSeq in self._algsAndSequences:
123 if algOrSeq.name() == name:
124 # If we found it, remove it:
125 self._algsAndSequences.remove( algOrSeq )
126 return
127
128 # If no algorithm/sequence with this name was found, that's a
129 # problem:
130 raise AttributeError( f'Algorithm/sequence with name "{name}" was '
131 'not found' )
132

◆ __eq__()

python.AlgSequence.AlgSequence.__eq__ ( self,
other )
Check for equality with another object

The implementation of this is very simple. We only check that
the name of the sequences would match.

Keyword arguments:
  other -- The object to compare this one against

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

175 def __eq__( self, other ):
176 """Check for equality with another object
177
178 The implementation of this is very simple. We only check that
179 the name of the sequences would match.
180
181 Keyword arguments:
182 other -- The object to compare this one against
183 """
184
185 # First check that the other object is also an AlgSequence one:
186 if not isinstance( other, AlgSequence ):
187 return False
188
189 # Base the equality purely on the name of the sequence. This may
190 # need to be made smarter at one point.
191 return ( self.name() == other.name() )
192

◆ __getattr__()

python.AlgSequence.AlgSequence.__getattr__ ( self,
name )
Access one algorithm/sequence in this sequence, by name

This is to allow modifying the properties of algorithms in a
sequence that was set up centrally.

Keyword arguments:
  name -- The name of the algorithm/sequence to look up in the
          sequence

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

84 def __getattr__( self, name ):
85 """Access one algorithm/sequence in this sequence, by name
86
87 This is to allow modifying the properties of algorithms in a
88 sequence that was set up centrally.
89
90 Keyword arguments:
91 name -- The name of the algorithm/sequence to look up in the
92 sequence
93 """
94
95 # Short-circuit internal/dunder attribute lookups, which must never
96 # be answered from the sequence contents (and would otherwise
97 # recurse if '_algsAndSequences' itself is missing):
98 if name.startswith( '_' ):
99 raise AttributeError( name )
100
101 # Look up the algorithm by name:
102 for algOrSeq in self._algsAndSequences:
103 if algOrSeq.name() == name:
104 return algOrSeq
105
106 # If no algorithm with this name was found, that's a problem:
107 raise AttributeError( f'Algorithm/sequence with name "{name}" was '
108 'not found' )
109

◆ __getitem__()

python.AlgSequence.AlgSequence.__getitem__ ( self,
index )
Return one algorithm/sequence from the sequence by index

This is to allow getting the n'th element of an algorithm sequence
(which itself may either be an algorithm or a sequence),
including the n'th element from the back of it if needed.

Keyword arguments:
  index -- The index of the algorithm/sequence to get from the
           sequence

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

70 def __getitem__( self, index ):
71 """Return one algorithm/sequence from the sequence by index
72
73 This is to allow getting the n'th element of an algorithm sequence
74 (which itself may either be an algorithm or a sequence),
75 including the n'th element from the back of it if needed.
76
77 Keyword arguments:
78 index -- The index of the algorithm/sequence to get from the
79 sequence
80 """
81
82 return self._algsAndSequences[ index ]
83

◆ __iadd__()

python.AlgSequence.AlgSequence.__iadd__ ( self,
algOrSeq,
index = None )
Add one algorithm/sequence to the sequence

This function is used to add one algorithm (or algorithm sequence)
to the sequence object, using the '+=' operator.

Keyword arguments:
  algOrSeq -- The algorithm/sequence to add to the sequence

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

144 def __iadd__( self, algOrSeq, index = None ):
145 """Add one algorithm/sequence to the sequence
146
147 This function is used to add one algorithm (or algorithm sequence)
148 to the sequence object, using the '+=' operator.
149
150 Keyword arguments:
151 algOrSeq -- The algorithm/sequence to add to the sequence
152 """
153
154 # Check that the received object is of the right type:
155 if not isinstance( algOrSeq, ( AnaAlgorithmConfig, PythonConfig,
156 AlgSequence ) ):
157 raise TypeError( 'The received object is not of type '
158 'AnaAlgorithmConfig or PythonConfig or AlgSequence' )
159
160 # Now check if an equivalent algorithm/sequence is already in the
161 # list. As that's also an error.
162 if algOrSeq in self:
163 raise RuntimeError( f'Algorithm/sequence {algOrSeq.name()} is '
164 'already in this sequence' )
165
166 # Add the algorithm/sequence to the internal list:
167 if index is None:
168 self._algsAndSequences.append( algOrSeq )
169 else:
170 self._algsAndSequences.insert( index, algOrSeq )
171
172 # Return the modified object:
173 return self
174

◆ __iter__()

python.AlgSequence.AlgSequence.__iter__ ( self)
Create an iterator over all the algorithms of this sequence

This is to allow for a Python-like iteration over all algorithms
that are part of the sequence. This includes iterating over the
algorithms that may be in sub-sequences of this sequence.

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

133 def __iter__( self ):
134 """Create an iterator over all the algorithms of this sequence
135
136 This is to allow for a Python-like iteration over all algorithms
137 that are part of the sequence. This includes iterating over the
138 algorithms that may be in sub-sequences of this sequence.
139 """
140
141 # Create the iterator to process the internal list of algorithms:
142 return AlgSequenceIterator( self._algsAndSequences )
143

◆ __len__()

python.AlgSequence.AlgSequence.__len__ ( self)
Return the size/length of the algorithm sequence

Just returning the number of algorithms and sequences that are in
this sequence. So this is not a recursive count.

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

207 def __len__( self ):
208 """Return the size/length of the algorithm sequence
209
210 Just returning the number of algorithms and sequences that are in
211 this sequence. So this is not a recursive count.
212 """
213
214 return len( self._algsAndSequences )
215
216 class AlgSequenceIterator:

◆ __str__()

python.AlgSequence.AlgSequence.__str__ ( self)
Print the algorithm sequence in a user-friendly way

This function takes care of printing the full configuration of every
algorithm in the sequence.

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

193 def __str__( self ):
194 """Print the algorithm sequence in a user-friendly way
195
196 This function takes care of printing the full configuration of every
197 algorithm in the sequence.
198 """
199
200 result = AnaAlgorithmConfig._printHeader( f'AlgSequence/{self.name()}' )
201 result += '\n'
202 for algOrSeq in self._algsAndSequences:
203 result += f"| {indentBy( str( algOrSeq ), '| ' )}\n"
204 result += AnaAlgorithmConfig._printFooter( f'AlgSequence/{self.name()}' )
205 return result
206

◆ addSelfToJob()

python.AlgSequence.AlgSequence.addSelfToJob ( self,
job )
add a copy of this config to the EventLoop job object

Keyword arguments:
  job      -- The job object to add ourself to

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

61 def addSelfToJob( self, job ):
62 """add a copy of this config to the EventLoop job object
63
64 Keyword arguments:
65 job -- The job object to add ourself to
66 """
67 for alg in self:
68 alg.addSelfToJob (job)
69

◆ insert()

python.AlgSequence.AlgSequence.insert ( self,
index,
algOrSeq )
Insert one algorithm/sequence into this sequence

This allows us to extend existing sequences with a greater
flexibility.

Keyword arguments:
  index    -- The index to insert the algorithm/sequence under
  algOrSeq -- The object to insert

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

48 def insert( self, index, algOrSeq ):
49 """Insert one algorithm/sequence into this sequence
50
51 This allows us to extend existing sequences with a greater
52 flexibility.
53
54 Keyword arguments:
55 index -- The index to insert the algorithm/sequence under
56 algOrSeq -- The object to insert
57 """
58
59 return self.__iadd__( algOrSeq, index = index )
60

◆ name()

python.AlgSequence.AlgSequence.name ( self)
Return the name of this sequence

Mainly for debugging purposes, and for when we are embedding
one sequence into another one.

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

39 def name( self ):
40 """Return the name of this sequence
41
42 Mainly for debugging purposes, and for when we are embedding
43 one sequence into another one.
44 """
45
46 return self._name
47

Member Data Documentation

◆ _algsAndSequences

python.AlgSequence.AlgSequence._algsAndSequences = []
protected

◆ _name

python.AlgSequence.AlgSequence._name = name
protected

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