The Gaudi Framework  master (37c0b60a)
SuperAlgDynamicGraph.py
Go to the documentation of this file.
1 
11 
12 from Configurables import AlgTimingAuditor, EventLoopMgr, GaudiTestSuiteCommonConf
13 from Gaudi.Configuration import *
14 from GaudiKernel.Configurable import SuperAlgorithm
15 
16 
19 
20 
21 GaudiTestSuiteCommonConf()
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 
64 s1 = MySuperAlg("s1", OutputLevel=INFO)
65 s2 = MySuperAlg("s2", OutputLevel=WARNING)
66 top = s1 >> s2
67 
68 MySuperAlg("s2", PercentPass=75, OutputLevel=DEBUG, UseHelloWorld=False)
69 
70 print("# --- Configured Control Flow Expression:")
71 print("#", top)
72 print("# ---")
73 EventLoopMgr(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 
84 AuditorSvc().Auditors.append(AlgTimingAuditor("TIMER"))
GaudiKernel.Configurable.SuperAlgorithm.graph
graph
Definition: Configurable.py:1879
GaudiKernel.Configurable.SuperAlgorithm
Definition: Configurable.py:1855
SuperAlgDynamicGraph.MySuperAlg.UseHelloWorld
def UseHelloWorld(self)
Definition: SuperAlgDynamicGraph.py:40
AuditorSvc
Definition: AuditorSvc.h:28
SuperAlgDynamicGraph.MySuperAlg
Job options file.
Definition: SuperAlgDynamicGraph.py:24
GaudiKernel.Configurable
Definition: Configurable.py:1
Gaudi.Configuration
Definition: Configuration.py:1
SuperAlgDynamicGraph.MySuperAlg.__init__
def __init__(self, *args, **kwargs)
Definition: SuperAlgDynamicGraph.py:33
GaudiKernel.Configurable.SuperAlgorithm._initGraph
def _initGraph(self)
Definition: Configurable.py:1912
GaudiKernel.Configurable.SuperAlgorithm._makeAlg
def _makeAlg(self, typ, **kwargs)
Definition: Configurable.py:1904
SuperAlgDynamicGraph.MySuperAlg._initGraph
def _initGraph(self)
Definition: SuperAlgDynamicGraph.py:49
SuperAlgDynamicGraph.MySuperAlg._hello_flag
_hello_flag
Definition: SuperAlgDynamicGraph.py:45
ApplicationMgr
Definition: ApplicationMgr.h:57