The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
SuperAlgDynamicGraph.py
Go to the documentation of this file.
11
12from Configurables import AlgTimingAuditor, EventLoopMgr, GaudiTestSuiteCommonConf
13from Gaudi.Configuration import *
14from GaudiKernel.Configurable import SuperAlgorithm
15
16
19
20
21GaudiTestSuiteCommonConf()
22
23
25 """
26 Example implementation of a SuperAlgorithm specialization with behaviour
27 depending on a property.
28
29 In this case the boolean option UseHelloWorld defines if the HelloWorld
30 instance has to be used or not.
31 """
32
33 def __init__(self, *args, **kwargs):
34 # preset the internal flag bypassing __setattr__
35 self.__dict__["_hello_flag"] = kwargs.pop("UseHelloWorld", True)
36 super(MySuperAlg, self).__init__(*args, **kwargs)
37
38 # define setter and getter callbacks for UseHelloWorld
39 @property
40 def UseHelloWorld(self):
41 return self._hello_flag
42
43 @UseHelloWorld.setter
44 def UseHelloWorld(self, value):
45 self._hello_flag = value
46 # re-generate the graph (which takes into account the flag)
47 self.graph = self._initGraph()
48
49 def _initGraph(self):
50 """
51 Prepare the graph represented by the SuperAlgorithm.
52 """
53 from Configurables import Gaudi__TestSuite__EventCounter as EventCounter
54 from Configurables import Gaudi__TestSuite__Prescaler as Prescaler
55 from Configurables import HelloWorld
56
57 p = self._makeAlg(Prescaler, name="Prescaler", PercentPass=50.0)
58 h = self._makeAlg(HelloWorld, name="HW")
59 c = self._makeAlg(EventCounter, name="Counter")
60 # the actual graph depends on the UseHelloWorld flag
61 return (p & h & c) if self.UseHelloWorld else (p & c)
62
63
64s1 = MySuperAlg("s1", OutputLevel=INFO)
65s2 = MySuperAlg("s2", OutputLevel=WARNING)
66top = s1 >> s2
67
68MySuperAlg("s2", PercentPass=75, OutputLevel=DEBUG, UseHelloWorld=False)
69
70print("# --- Configured Control Flow Expression:")
71print("#", top)
72print("# ---")
73EventLoopMgr(PrintControlFlowExpression=True)
74
75# -----------------------------------------------------------------
77 TopAlg=[top],
78 EvtMax=10, # events to be processed (default is 10)
79 EvtSel="NONE", # do not use any event input
80 ExtSvc=["ToolSvc", "AuditorSvc", "Gaudi::Monitoring::MessageSvcSink"],
81 AuditAlgorithms=True,
82)
83
84AuditorSvc().Auditors.append(AlgTimingAuditor("TIMER"))
The Application Manager class.
This service manages Auditors.
Definition AuditorSvc.h:22
Class definition of EventLoopMgr.