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. 42 return (repr(self) == repr(other))
46 Allow use of an expression as an algorihtm/sequence in a Gaudi job 49 Convert the expression in nested sequencers and return the full name of 52 if not hasattr(self,
'_fullname'):
60 Class used to identify a note without sub-nodes. 65 class ControlFlowBool(ControlFlowLeaf):
70 return rhs
if self.
value else self
73 return self
if self.
value else rhs
76 return CFFalse
if self.
value else CFTrue
79 return 'CFTrue' if self.
value else 'CFFalse' 89 Represent order of execution of nodes. 97 return "(%r >> %r)" % (self.
lhs, self.
rhs)
100 self.lhs.visitNode(visitor)
101 self.rhs.visitNode(visitor)
106 And operation between control flow nodes. 114 return "(%r & %r)" % (self.
lhs, self.
rhs)
117 self.lhs.visitNode(visitor)
118 self.rhs.visitNode(visitor)
123 Or operation between control flow nodes. 131 return "(%r | %r)" % (self.
lhs, self.
rhs)
134 self.lhs.visitNode(visitor)
135 self.rhs.visitNode(visitor)
140 Invert logic (negation) of a control flow node. 147 return "~%r" % self.
item 150 self.item.visitNode(visitor)
155 Treat a control flow node as always successful, equivalent to (a | ~ a). 162 return "ignore(%r)" % self.
item 165 self.item.visitNode(visitor)
173 return "par(%r)" % self.
item 176 self.item.visitNode(visitor)
184 return "seq(%r)" % self.
item 187 self.item.visitNode(visitor)
196 return "line(%r, %r)" % (self.
name, self.
item)
199 self.item.visitNode(visitor)
208 print "%sEntering %s" % (self.
depths *
" ",
type(visitee))
209 if isinstance(visitee, ControlFlowLeaf):
210 print "%s Algorithm name: %s" % (
" " * self.
depths, visitee)
213 print "%sLeaving %s" % (self.
depths *
" ",
type(visitee))
237 if visitee
not in self.
ids:
239 dot_id = self.
ids[visitee] =
'T%s' % self.
number 240 dot_id = self.
ids[visitee]
243 if isinstance(visitee, ControlFlowLeaf):
244 entry =
'%s [label="%s", shape=box]' % (dot_id, visitee.name())
245 elif isinstance(visitee, OrNode):
246 entry =
'%s [label="OR", shape=invhouse]' % dot_id
247 elif isinstance(visitee, AndNode):
248 entry =
'%s [label="AND", shape=invhouse]' % dot_id
249 elif isinstance(visitee, OrderedNode):
250 entry =
'%s [label=">>", shape=point]' % dot_id
251 elif isinstance(visitee, InvertNode):
252 entry =
'%s [label="NOT", shape=circle, color=red]' % dot_id
253 elif isinstance(visitee, par):
254 entry =
'%s [label="PAR", shape=circle]' % dot_id
255 elif isinstance(visitee, seq):
256 entry =
'%s [label="SEQ", shape=circle]' % dot_id
258 entry =
'%s [label="%s", shape=circle]' % (
259 dot_id,
type(visitee))
260 self.nodes.append(entry)
261 if len(self.
stack) != 0:
265 mother = self.
stack[-1][1]
266 edge =
"%s->%s" % (dot_id, mother)
267 self.edges.append(edge)
268 self.stack.append((visitee, dot_id))
275 If AND nodes are inside AND nodes, the graph could be simplified 276 to not contain those (same true for OR and ordered) 279 if len(self.
stack) != 0:
280 mother = self.
stack[-1][1]
281 for entry
in self.
stack[::-1]:
282 if type(entry[0]) != thetype:
290 Check whether this node is actually needed 292 if len(self.
stack) != 0:
293 return not isinstance(visitee,
type(self.
stack[-1][0]))
306 """ % (
"\n".join(self.
nodes),
"\n".join(self.
edges))
308 with open(filename,
"w")
as outfile:
309 outfile.write(output)
313 Algorithm = _TestAlgorithm
322 sequence =
seq(b >> a >> f)
323 expression = sequence | ~c &
par(d & e & g)
324 a = (expression == expression)
325 aLine =
line(
"MyTriggerPath", expression)
328 print "\nPrinting trigger line:" 330 print "\nPrinting expression:" 332 print "\nTraversing through expression:\n" 333 expression.visitNode(visitor)
334 expression.visitNode(visitor2)
335 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)