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