2 Classes for the implementation of the Control Flow Structure Syntax. 4 @see: https://github.com/lhcb/scheduling-event-model/tree/master/controlflow_syntax 10 Basic entry in the control flow graph. 41 return (repr(self) == repr(other))
45 Allow use of an expression as an algorihtm/sequence in a Gaudi job 48 Convert the expression in nested sequencers and return the full name of 51 if not hasattr(self,
'_fullname'):
59 Class used to identify a note without sub-nodes. 64 class ControlFlowBool(ControlFlowLeaf):
68 return rhs
if self.
value else self
70 return self
if self.
value else rhs
72 return CFFalse
if self.
value else CFTrue
74 return 'CFTrue' if self.
value else 'CFFalse' 82 Represent order of execution of nodes. 89 return "(%r >> %r)" % (self.
lhs, self.
rhs)
92 self.lhs.visitNode(visitor)
93 self.rhs.visitNode(visitor)
98 And operation between control flow nodes. 105 return "(%r & %r)" % (self.
lhs, self.
rhs)
108 self.lhs.visitNode(visitor)
109 self.rhs.visitNode(visitor)
114 Or operation between control flow nodes. 121 return "(%r | %r)" % (self.
lhs, self.
rhs)
124 self.lhs.visitNode(visitor)
125 self.rhs.visitNode(visitor)
130 Invert logic (negation) of a control flow node. 136 return "~%r" % self.
item 139 self.item.visitNode(visitor)
144 Treat a control flow node as always successful, equivalent to (a | ~ a). 150 return "ignore(%r)" % self.
item 153 self.item.visitNode(visitor)
161 return "par(%r)" % self.
item 164 self.item.visitNode(visitor)
172 return "seq(%r)" % self.
item 175 self.item.visitNode(visitor)
184 return "line(%r, %r)" % (self.
name, self.
item)
187 self.item.visitNode(visitor)
196 print "%sEntering %s" % (self.
depths*
" ",
type(visitee))
197 if isinstance(visitee, ControlFlowLeaf):
198 print "%s Algorithm name: %s" % (
" "*self.
depths, visitee)
201 print "%sLeaving %s" % (self.
depths *
" ",
type(visitee))
225 if visitee
not in self.
ids:
227 dot_id = self.
ids[visitee] =
'T%s' % self.
number 228 dot_id = self.
ids[visitee]
231 if isinstance(visitee, ControlFlowLeaf):
232 entry =
'%s [label="%s", shape=box]' % (dot_id, visitee.name())
233 elif isinstance(visitee, OrNode):
234 entry =
'%s [label="OR", shape=invhouse]' % dot_id
235 elif isinstance(visitee, AndNode):
236 entry =
'%s [label="AND", shape=invhouse]' % dot_id
237 elif isinstance(visitee, OrderedNode):
238 entry =
'%s [label=">>", shape=point]' % dot_id
239 elif isinstance(visitee, InvertNode):
240 entry =
'%s [label="NOT", shape=circle, color=red]' % dot_id
241 elif isinstance(visitee, par):
242 entry =
'%s [label="PAR", shape=circle]' % dot_id
243 elif isinstance(visitee, seq):
244 entry =
'%s [label="SEQ", shape=circle]' % dot_id
246 entry =
'%s [label="%s", shape=circle]' % (dot_id,
type(visitee))
247 self.nodes.append(entry)
248 if len(self.
stack) != 0:
251 mother = self.
stack[-1][1]
252 edge =
"%s->%s" % (dot_id, mother)
253 self.edges.append(edge)
254 self.stack.append((visitee, dot_id))
261 If AND nodes are inside AND nodes, the graph could be simplified 262 to not contain those (same true for OR and ordered) 265 if len(self.
stack) != 0:
266 mother = self.
stack[-1][1]
267 for entry
in self.
stack[::-1]:
268 if type(entry[0]) != thetype:
276 Check whether this node is actually needed 278 if len(self.
stack) != 0:
279 return not isinstance(visitee,
type(self.
stack[-1][0]))
292 """ % (
"\n".join(self.
nodes),
"\n".join(self.
edges))
294 with open(filename,
"w")
as outfile:
295 outfile.write(output)
299 Algorithm = _TestAlgorithm
308 sequence =
seq(b >> a >> f)
309 expression = sequence | ~c &
par(d & e & g)
310 a = (expression == expression)
311 aLine =
line(
"MyTriggerPath", expression)
314 print "\nPrinting trigger line:" 316 print "\nPrinting expression:" 318 print "\nTraversing through expression:\n" 319 expression.visitNode(visitor)
320 expression.visitNode(visitor2)
321 visitor2.write(
"out.dot")
def _visitSubNodes(self, visitor)
def makeSequences(expression)
def __init__(self, value)
def __init__(self, name, item)
def collapse_identical_ancestors(self, thetype)
def _visitSubNodes(self, visitor)
def __rshift__(self, rhs)
def __init__(self, lhs, rhs)
def _visitSubNodes(self, visitor)
def write(self, filename)
def visitNode(self, visitor)
def _visitSubNodes(self, visitor)
def _visitSubNodes(self, visitor)
def __init__(self, lhs, rhs)
def _visitSubNodes(self, visitor)
def is_needed(self, visitee)
Base class from which all concrete algorithm classes should be derived.
def __init__(self, lhs, rhs)
def _visitSubNodes(self, visitor)
def _visitSubNodes(self, visitor)
def _visitSubNodes(self, visitor)