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

python.CFElements.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()

python.CFElements.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 123 of file CFElements.py.

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

◆ findAlgorithmByPredicate()

python.CFElements.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 104 of file CFElements.py.

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

◆ findAllAlgorithms()

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

Definition at line 131 of file CFElements.py.

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

◆ findAllAlgorithmsByName()

python.CFElements.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 145 of file CFElements.py.

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

◆ findOwningSequence()

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

Definition at line 92 of file CFElements.py.

92def findOwningSequence( start, nameToLookFor ):
93 """ find sequence that owns the sequence nameTooLookFor"""
94 for c in getSequenceChildren(start):
95 if c.getName() == nameToLookFor:
96 return start
97 if isSequence( c ):
98 found = findOwningSequence( c, nameToLookFor )
99 if found:
100 return found
101 return None
102
103

◆ findSubSequence()

python.CFElements.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 if start.getName() == nameToLookFor:
81 return start
82 for c in getSequenceChildren(start):
83 if isSequence( c ):
84 if c.getName() == nameToLookFor:
85 return c
86 found = findSubSequence( c, nameToLookFor )
87 if found:
88 return found
89 return None
90
91

◆ flatAlgorithmSequences()

python.CFElements.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 168 of file CFElements.py.

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

◆ getSequenceChildren()

python.CFElements.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()

python.CFElements.isSequence ( obj)

Definition at line 74 of file CFElements.py.

74def isSequence( obj ):
75 return isinstance(obj, AthSequencer)
76
77

◆ iterSequences()

python.CFElements.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 184 of file CFElements.py.

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

◆ parAND()

python.CFElements.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()

python.CFElements.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()

python.CFElements.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()

python.CFElements.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.