ATLAS Offline Software
Loading...
Searching...
No Matches
python.CFElements Namespace Reference

Classes

class  TestCF
class  TestNest

Functions

 parAND (name, subs=[], invert=False)
 parOR (name, subs=[], invert=False)
 seqAND (name, subs=[], invert=False)
 seqOR (name, subs=[], invert=False)
 getSequenceChildren (comp)
 checkSequenceConsistency (seq)
 isSequence (obj)
 findSubSequence (start, nameToLookFor)
 findOwningSequence (start, nameToLookFor)
 findAlgorithmByPredicate (startSequence, predicate, depth=1000000)
 findAlgorithm (startSequence, nameToLookFor, depth=1000000)
 findAllAlgorithms (sequence, nameToLookFor=None)
 findAllAlgorithmsByName (sequence, namesToLookFor=None)
 flatAlgorithmSequences (start)
 iterSequences (start)

Variables

 AthSequencer = CompFactory.AthSequencer

Function Documentation

◆ checkSequenceConsistency()

checkSequenceConsistency ( seq)
Enforce rules for sequence graph - identical items can not be added to itself (even indirectly) 

Definition at line 56 of file CFElements.py.

56def checkSequenceConsistency( seq ):
57 """ Enforce rules for sequence graph - identical items can not be added to itself (even indirectly) """
58
59 def __noSubSequenceOfName( s, n, seen = set() ):
60 seen = seen.copy()
61 seen.add (s)
62 for c in getSequenceChildren( s ):
63 if c in seen:
64 raise RuntimeError(f"Sequence {c.getName()} contains itself")
65 if isSequence( c ):
66 if c.getName() == n:
67 raise RuntimeError(f"Sequence {n} contains sub-sequence of the same name")
68 __noSubSequenceOfName( c, c.getName(), seen ) # check each sequence for repetition as well
69 __noSubSequenceOfName( c, n, seen )
70
71 __noSubSequenceOfName( seq, seq.getName() )
72
73

◆ findAlgorithm()

findAlgorithm ( startSequence,
nameToLookFor,
depth = 1000000 )
 Traverse sequences tree to find the algorithm of given name. The first encountered is returned.

The name() method is used to obtain the algorithm name, that one has to match to the request.

Definition at line 128 of file CFElements.py.

128def findAlgorithm( startSequence, nameToLookFor, depth = 1000000 ):
129 """ Traverse sequences tree to find the algorithm of given name. The first encountered is returned.
130
131 The name() method is used to obtain the algorithm name, that one has to match to the request.
132 """
133 return findAlgorithmByPredicate( startSequence, lambda alg: alg.getName() == nameToLookFor, depth )
134
135

◆ findAlgorithmByPredicate()

findAlgorithmByPredicate ( startSequence,
predicate,
depth = 1000000 )
 Traverse sequences tree to find the first algorithm satisfying given predicate. The first encountered is returned.

Depth of the search can be controlled by the depth parameter.
Typical use is to limit search to the startSequence with depth parameter set to 1

Definition at line 109 of file CFElements.py.

109def findAlgorithmByPredicate( startSequence, predicate, depth = 1000000 ):
110 """ Traverse sequences tree to find the first algorithm satisfying given predicate. The first encountered is returned.
111
112 Depth of the search can be controlled by the depth parameter.
113 Typical use is to limit search to the startSequence with depth parameter set to 1
114 """
115 for c in getSequenceChildren(startSequence):
116 if not isSequence(c):
117 if predicate(c):
118 return c
119 else:
120 if depth > 1:
121 found = findAlgorithmByPredicate( c, predicate, depth-1 )
122 if found:
123 return found
124
125 return None
126
127

◆ findAllAlgorithms()

findAllAlgorithms ( sequence,
nameToLookFor = None )
Returns flat listof of all algorithm instances in this, and in sub-sequences

Definition at line 136 of file CFElements.py.

136def findAllAlgorithms(sequence, nameToLookFor=None):
137 """
138 Returns flat listof of all algorithm instances in this, and in sub-sequences
139 """
140 algorithms = []
141 for child in getSequenceChildren(sequence):
142 if isSequence(child):
143 algorithms += findAllAlgorithms(child, nameToLookFor)
144 else:
145 if nameToLookFor is None or child.getName() == nameToLookFor:
146 algorithms.append(child)
147 return algorithms
148
149

◆ findAllAlgorithmsByName()

findAllAlgorithmsByName ( sequence,
namesToLookFor = None )
Finds all algorithms in sequence and groups them by name

Resulting dict has a following structure
{"Alg1Name":[(Alg1Instance, parentSequenceA, indexInSequenceA),(Alg1Instance, parentSequenceB, indexInSequenceB)],
 "Alg2Name":(Alg2Instance, parentSequence, indexInThisSequence),
 ....}

Definition at line 150 of file CFElements.py.

150def findAllAlgorithmsByName(sequence, namesToLookFor=None):
151 """
152 Finds all algorithms in sequence and groups them by name
153
154 Resulting dict has a following structure
155 {"Alg1Name":[(Alg1Instance, parentSequenceA, indexInSequenceA),(Alg1Instance, parentSequenceB, indexInSequenceB)],
156 "Alg2Name":(Alg2Instance, parentSequence, indexInThisSequence),
157 ....}
158 """
159 algorithms = collections.defaultdict(list)
160 for idx, child in enumerate(getSequenceChildren(sequence)):
161 if child.getName() == sequence.getName():
162 raise RuntimeError(f"Recursively-nested sequence: {child.getName()} contains itself")
163 if isSequence(child):
164 childAlgs = findAllAlgorithmsByName(child, namesToLookFor)
165 for algName in childAlgs:
166 algorithms[algName] += childAlgs[algName]
167 else:
168 if namesToLookFor is None or child.getName() in namesToLookFor:
169 algorithms[child.getName()].append( (child, sequence, idx) )
170 return algorithms
171
172

◆ findOwningSequence()

findOwningSequence ( start,
nameToLookFor )
find sequence that owns the sequence nameTooLookFor

Definition at line 97 of file CFElements.py.

97def findOwningSequence( start, nameToLookFor ):
98 """ find sequence that owns the sequence nameTooLookFor"""
99 for c in getSequenceChildren(start):
100 if c.getName() == nameToLookFor:
101 return start
102 if isSequence( c ):
103 found = findOwningSequence( c, nameToLookFor )
104 if found:
105 return found
106 return None
107
108

◆ findSubSequence()

findSubSequence ( start,
nameToLookFor )
Traverse sequences tree to find a sequence of a given name. The first one is returned. 

Definition at line 78 of file CFElements.py.

78def findSubSequence( start, nameToLookFor ):
79 """ Traverse sequences tree to find a sequence of a given name. The first one is returned. """
80 # Implemented as an iterative Depth-First search, which is faster than recursion in Python.
81
82 stack = [start]
83 while stack:
84 current = stack.pop()
85
86 if current.getName() == nameToLookFor:
87 return current
88
89 # Collect child sequences (plain loop is faster than generator expression)
90 for c in getSequenceChildren(current):
91 if isSequence(c):
92 stack.append(c)
93
94 return None
95
96

◆ flatAlgorithmSequences()

flatAlgorithmSequences ( start)
 Converts tree like structure of sequences into dictionary
keyed by top/start sequence name containing lists of of algorithms & sequences.

Definition at line 173 of file CFElements.py.

173def flatAlgorithmSequences( start ):
174 """ Converts tree like structure of sequences into dictionary
175 keyed by top/start sequence name containing lists of of algorithms & sequences."""
176
177 def __inner( seq, collector ):
178 for c in getSequenceChildren(seq):
179 collector[seq.getName()].append( c )
180 if isSequence( c ):
181 __inner( c, collector )
182
183 from collections import defaultdict,OrderedDict
184 c = defaultdict(list)
185 __inner(start, c)
186 return OrderedDict(c)
187
188

◆ getSequenceChildren()

getSequenceChildren ( comp)
Return sequence children (empty if comp is not a sequence)

Definition at line 48 of file CFElements.py.

48def getSequenceChildren(comp):
49 """Return sequence children (empty if comp is not a sequence)"""
50 try:
51 return comp.Members
52 except AttributeError:
53 return []
54
55

◆ isSequence()

isSequence ( obj)

Definition at line 74 of file CFElements.py.

74def isSequence( obj ):
75 return type(obj) is AthSequencer # faster than isinstance and we do not care about inheritance
76
77

◆ iterSequences()

iterSequences ( start)
Iterator of sequences and their algorithms from (and including) the `start`
sequence object. Do start from a sequence name use findSubSequence.

Definition at line 189 of file CFElements.py.

189def iterSequences( start ):
190 """Iterator of sequences and their algorithms from (and including) the `start`
191 sequence object. Do start from a sequence name use findSubSequence."""
192 def __inner( seq ):
193 for c in getSequenceChildren(seq):
194 yield c
195 if isSequence(c):
196 yield from __inner(c)
197 yield start
198 yield from __inner(start)
199
200
201
202# self test

◆ parAND()

parAND ( name,
subs = [],
invert = False )
parallel AND sequencer

Definition at line 7 of file CFElements.py.

7def parAND(name, subs=[], invert=False):
8 """parallel AND sequencer"""
9 return AthSequencer( name,
10 ModeOR = False,
11 Sequential = False,
12 StopOverride = True,
13 Invert = invert,
14 Members = subs.copy() )
15

◆ parOR()

parOR ( name,
subs = [],
invert = False )
parallel OR sequencer
This is the default sequencer and lets the DataFlow govern the execution entirely.

Definition at line 16 of file CFElements.py.

16def parOR(name, subs=[], invert=False):
17 """parallel OR sequencer
18 This is the default sequencer and lets the DataFlow govern the execution entirely.
19 """
20 return AthSequencer( name,
21 ModeOR = True,
22 Sequential = False,
23 StopOverride = True,
24 Invert = invert,
25 Members = subs.copy() )
26
ClassName: AthSequencer.

◆ seqAND()

seqAND ( name,
subs = [],
invert = False )
sequential AND sequencer

Definition at line 27 of file CFElements.py.

27def seqAND(name, subs=[], invert=False):
28 """sequential AND sequencer"""
29 return AthSequencer( name,
30 ModeOR = False,
31 Sequential = True,
32 StopOverride = False,
33 Invert = invert,
34 Members = subs.copy() )
35

◆ seqOR()

seqOR ( name,
subs = [],
invert = False )
sequential OR sequencer
Used when a barrier needs to be set by all subs reached irrespective of the decision

Definition at line 36 of file CFElements.py.

36def seqOR(name, subs=[], invert=False):
37 """sequential OR sequencer
38 Used when a barrier needs to be set by all subs reached irrespective of the decision
39 """
40 return AthSequencer( name,
41 ModeOR = True,
42 Sequential = True,
43 StopOverride = True,
44 Invert = invert,
45 Members = subs.copy() )
46
47

Variable Documentation

◆ AthSequencer

python.CFElements.AthSequencer = CompFactory.AthSequencer

Definition at line 5 of file CFElements.py.