Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v36r16 (ea80daf8)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
SuperAlgDynamicGraph.py
Go to the documentation of this file.
1 
11 from __future__ import print_function
12 
13 from Configurables import EventLoopMgr, GaudiExamplesCommonConf, TimingAuditor
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 EventCounter, HelloWorld, Prescaler
55 
56  p = self._makeAlg(Prescaler, PercentPass=50.0)
57  h = self._makeAlg(HelloWorld, name="HW")
58  c = self._makeAlg(EventCounter, name="Counter")
59  # the actual graph depends on the UseHelloWorld flag
60  return (p & h & c) if self.UseHelloWorld else (p & c)
61 
62 
63 s1 = MySuperAlg("s1", OutputLevel=INFO)
64 s2 = MySuperAlg("s2", OutputLevel=WARNING)
65 top = s1 >> s2
66 
67 MySuperAlg("s2", PercentPass=75, OutputLevel=DEBUG, UseHelloWorld=False)
68 
69 print("# --- Configured Control Flow Expression:")
70 print("#", top)
71 print("# ---")
72 EventLoopMgr(PrintControlFlowExpression=True)
73 
74 # -----------------------------------------------------------------
76  TopAlg=[top],
77  EvtMax=10, # events to be processed (default is 10)
78  EvtSel="NONE", # do not use any event input
79  ExtSvc=["ToolSvc", "AuditorSvc"],
80  AuditAlgorithms=True,
81 )
82 
83 AuditorSvc().Auditors.append(TimingAuditor("TIMER"))
GaudiKernel.Configurable.SuperAlgorithm
Definition: Configurable.py:1854
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:1903
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