ATLAS Offline Software
Classes | Functions | Variables
python.CFElements Namespace Reference

Classes

class  TestCF
 
class  TestNest
 

Functions

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

Variables

 AthSequencer = CompFactory.AthSequencer
 

Function Documentation

◆ checkSequenceConsistency()

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

Definition at line 69 of file CFElements.py.

69 def checkSequenceConsistency( seq ):
70  """ Enforce rules for sequence graph - identical items can not be added to itself (even indirectly) """
71 
72  def __noSubSequenceOfName( s, n, seen = set() ):
73  seen = seen.copy()
74  seen.add (s)
75  for c in getSequenceChildren( s ):
76  if c in seen:
77  raise RuntimeError(f"Sequence {c.getName()} contains itself")
78  if isSequence( c ):
79  if c.getName() == n:
80  raise RuntimeError(f"Sequence {n} contains sub-sequence of the same name")
81  __noSubSequenceOfName( c, c.getName(), seen ) # check each sequence for repetition as well
82  __noSubSequenceOfName( c, n, seen )
83 
84  __noSubSequenceOfName( seq, seq.getName() )
85  for c in getSequenceChildren( seq ):
87 
88 

◆ findAlgorithm()

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

145 def findAlgorithm( startSequence, nameToLookFor, depth = 1000000 ):
146  """ Traverse sequences tree to find the algorithm of given name. The first encountered is returned.
147 
148  The name() method is used to obtain the algorithm name, that one has to match to the request.
149  """
150  return findAlgorithmByPredicate( startSequence, lambda alg: alg.getName() == nameToLookFor, depth )
151 
152 

◆ findAlgorithmByPredicate()

def 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 126 of file CFElements.py.

126 def findAlgorithmByPredicate( startSequence, predicate, depth = 1000000 ):
127  """ Traverse sequences tree to find the first algorithm satisfying given predicate. The first encountered is returned.
128 
129  Depth of the search can be controlled by the depth parameter.
130  Typical use is to limit search to the startSequence with depth parameter set to 1
131  """
132  for c in getSequenceChildren(startSequence):
133  if not isSequence(c):
134  if predicate(c):
135  return c
136  else:
137  if depth > 1:
138  found = findAlgorithmByPredicate( c, predicate, depth-1 )
139  if found:
140  return found
141 
142  return None
143 
144 

◆ findAllAlgorithms()

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

Definition at line 153 of file CFElements.py.

153 def findAllAlgorithms(sequence, nameToLookFor=None):
154  """
155  Returns flat listof of all algorithm instances in this, and in sub-sequences
156  """
157  algorithms = []
158  for child in getSequenceChildren(sequence):
159  if isSequence(child):
160  algorithms += findAllAlgorithms(child, nameToLookFor)
161  else:
162  if nameToLookFor is None or child.getName() == nameToLookFor:
163  algorithms.append(child)
164  return algorithms
165 
166 

◆ findAllAlgorithmsByName()

def 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 167 of file CFElements.py.

167 def findAllAlgorithmsByName(sequence, namesToLookFor=None):
168  """
169  Finds all algorithms in sequence and groups them by name
170 
171  Resulting dict has a following structure
172  {"Alg1Name":[(Alg1Instance, parentSequenceA, indexInSequenceA),(Alg1Instance, parentSequenceB, indexInSequenceB)],
173  "Alg2Name":(Alg2Instance, parentSequence, indexInThisSequence),
174  ....}
175  """
176  algorithms = collections.defaultdict(list)
177  for idx, child in enumerate(getSequenceChildren(sequence)):
178  if child.getName() == sequence.getName():
179  raise RuntimeError(f"Recursively-nested sequence: {child.getName()} contains itself")
180  if isSequence(child):
181  childAlgs = findAllAlgorithmsByName(child, namesToLookFor)
182  for algName in childAlgs:
183  algorithms[algName] += childAlgs[algName]
184  else:
185  if namesToLookFor is None or child.getName() in namesToLookFor:
186  algorithms[child.getName()].append( (child, sequence, idx) )
187  return algorithms
188 
189 

◆ findOwningSequence()

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

Definition at line 114 of file CFElements.py.

114 def findOwningSequence( start, nameToLookFor ):
115  """ find sequence that owns the sequence nameTooLookFor"""
116  for c in getSequenceChildren(start):
117  if c.getName() == nameToLookFor:
118  return start
119  if isSequence( c ):
120  found = findOwningSequence( c, nameToLookFor )
121  if found:
122  return found
123  return None
124 
125 

◆ findSubSequence()

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

Definition at line 100 of file CFElements.py.

100 def findSubSequence( start, nameToLookFor ):
101  """ Traverse sequences tree to find a sequence of a given name. The first one is returned. """
102  if start.getName() == nameToLookFor:
103  return start
104  for c in getSequenceChildren(start):
105  if isSequence( c ):
106  if c.getName() == nameToLookFor:
107  return c
108  found = findSubSequence( c, nameToLookFor )
109  if found:
110  return found
111  return None
112 
113 

◆ flatAlgorithmSequences()

def 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 190 of file CFElements.py.

190 def flatAlgorithmSequences( start ):
191  """ Converts tree like structure of sequences into dictionary
192  keyed by top/start sequence name containing lists of of algorithms & sequences."""
193 
194  def __inner( seq, collector ):
195  for c in getSequenceChildren(seq):
196  collector[seq.getName()].append( c )
197  if isSequence( c ):
198  __inner( c, collector )
199 
200  from collections import defaultdict,OrderedDict
201  c = defaultdict(list)
202  __inner(start, c)
203  return OrderedDict(c)
204 
205 

◆ getAllSequenceNames()

def python.CFElements.getAllSequenceNames (   seq,
  depth = 0 
)
Generate a list of sequence names and depths in the graph, e.g.
[('AthAlgSeq', 0), ('seq1', 1), ('seq2', 1), ('seq1', 2)]
represents
\\__ AthAlgSeq (seq: PAR AND)
    \\__ seq1 (seq: SEQ AND)
       \\__ seq2 (seq: SEQ AND)

Definition at line 52 of file CFElements.py.

52 def getAllSequenceNames(seq, depth=0):
53  """ Generate a list of sequence names and depths in the graph, e.g.
54  [('AthAlgSeq', 0), ('seq1', 1), ('seq2', 1), ('seq1', 2)]
55  represents
56  \\__ AthAlgSeq (seq: PAR AND)
57  \\__ seq1 (seq: SEQ AND)
58  \\__ seq2 (seq: SEQ AND)
59  """
60 
61  seqNameList = [(seq.getName(), depth)]
62  for c in getSequenceChildren(seq):
63  if isSequence(c):
64  seqNameList += getAllSequenceNames(c, depth+1)
65 
66  return seqNameList
67 
68 

◆ getSequenceChildren()

def python.CFElements.getSequenceChildren (   comp)
Return sequence children (empty if comp is not a sequence)

Definition at line 44 of file CFElements.py.

44 def getSequenceChildren(comp):
45  """Return sequence children (empty if comp is not a sequence)"""
46  try:
47  return comp.Members
48  except AttributeError:
49  return []
50 
51 

◆ isSequence()

def python.CFElements.isSequence (   obj)

Definition at line 96 of file CFElements.py.

96 def isSequence( obj ):
97  return isinstance(obj, AthSequencer)
98 
99 

◆ iterSequences()

def 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 206 of file CFElements.py.

206 def iterSequences( start ):
207  """Iterator of sequences and their algorithms from (and including) the `start`
208  sequence object. Do start from a sequence name use findSubSequence."""
209  def __inner( seq ):
210  for c in getSequenceChildren(seq):
211  yield c
212  if isSequence(c):
213  yield from __inner(c)
214  yield start
215  yield from __inner(start)
216 
217 
218 
219 # self test

◆ parAND()

def python.CFElements.parAND (   name,
  subs = [] 
)
parallel AND sequencer

Definition at line 7 of file CFElements.py.

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

◆ parOR()

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

Definition at line 15 of file CFElements.py.

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

◆ seqAND()

def python.CFElements.seqAND (   name,
  subs = [] 
)
sequential AND sequencer

Definition at line 25 of file CFElements.py.

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

◆ seqOR()

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

Definition at line 33 of file CFElements.py.

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

◆ stepSeq()

def python.CFElements.stepSeq (   name,
  filterAlg,
  rest 
)
elementary HLT step sequencer, filterAlg is gating, rest is anything that needs to happen within the step 

Definition at line 89 of file CFElements.py.

89 def stepSeq(name, filterAlg, rest):
90  """ elementary HLT step sequencer, filterAlg is gating, rest is anything that needs to happen within the step """
91  stepReco = parOR(name+"_reco", rest)
92  stepAnd = seqAND(name, [ filterAlg, stepReco ])
93  return stepAnd
94 
95 

Variable Documentation

◆ AthSequencer

python.CFElements.AthSequencer = CompFactory.AthSequencer

Definition at line 5 of file CFElements.py.

python.CFElements.flatAlgorithmSequences
def flatAlgorithmSequences(start)
Definition: CFElements.py:190
python.CFElements.findAllAlgorithms
def findAllAlgorithms(sequence, nameToLookFor=None)
Definition: CFElements.py:153
AthSequencer
ClassName: AthSequencer.
Definition: AthSequencer.h:40
python.CFElements.findOwningSequence
def findOwningSequence(start, nameToLookFor)
Definition: CFElements.py:114
python.CFElements.findAlgorithmByPredicate
def findAlgorithmByPredicate(startSequence, predicate, depth=1000000)
Definition: CFElements.py:126
python.CFElements.findAllAlgorithmsByName
def findAllAlgorithmsByName(sequence, namesToLookFor=None)
Definition: CFElements.py:167
python.CFElements.stepSeq
def stepSeq(name, filterAlg, rest)
Definition: CFElements.py:89
dumpHVPathFromNtuple.append
bool append
Definition: dumpHVPathFromNtuple.py:91
python.CFElements.seqAND
def seqAND(name, subs=[])
Definition: CFElements.py:25
python.CFElements.checkSequenceConsistency
def checkSequenceConsistency(seq)
Definition: CFElements.py:69
python.CFElements.seqOR
def seqOR(name, subs=[])
Definition: CFElements.py:33
python.CFElements.parOR
def parOR(name, subs=[])
Definition: CFElements.py:15
python.CFElements.getAllSequenceNames
def getAllSequenceNames(seq, depth=0)
Definition: CFElements.py:52
python.CFElements.isSequence
def isSequence(obj)
Definition: CFElements.py:96
python.CFElements.findSubSequence
def findSubSequence(start, nameToLookFor)
Definition: CFElements.py:100
python.CFElements.findAlgorithm
def findAlgorithm(startSequence, nameToLookFor, depth=1000000)
Definition: CFElements.py:145
python.CFElements.getSequenceChildren
def getSequenceChildren(comp)
Definition: CFElements.py:44
python.CFElements.iterSequences
def iterSequences(start)
Definition: CFElements.py:206
python.CFElements.parAND
def parAND(name, subs=[])
Definition: CFElements.py:7