The Gaudi Framework  v36r1 (3e2fb5a8)
SuperAlgDynamicGraph.py
Go to the documentation of this file.
1 
11 from __future__ import print_function
12 
15 
16 from Gaudi.Configuration import *
17 from Configurables import TimingAuditor, EventLoopMgr
18 
19 from GaudiKernel.Configurable import SuperAlgorithm
20 
21 from Configurables import GaudiExamplesCommonConf
22 
23 GaudiExamplesCommonConf()
24 
25 
27  '''
28  Example implementation of a SuperAlgorithm specialization with behaviour
29  depending on a property.
30 
31  In this case the boolean option UseHelloWorld defines if the HelloWorld
32  instance has to be used or not.
33  '''
34 
35  def __init__(self, *args, **kwargs):
36  # preset the internal flag bypassing __setattr__
37  self.__dict__['_hello_flag'] = kwargs.pop('UseHelloWorld', True)
38  super(MySuperAlg, self).__init__(*args, **kwargs)
39 
40  # define setter and getter callbacks for UseHelloWorld
41  @property
42  def UseHelloWorld(self):
43  return self._hello_flag
44 
45  @UseHelloWorld.setter
46  def UseHelloWorld(self, value):
47  self._hello_flag = value
48  # re-generate the graph (which takes into account the flag)
49  self.graph = self._initGraph()
50 
51  def _initGraph(self):
52  '''
53  Prepare the graph represented by the SuperAlgorithm.
54  '''
55  from Configurables import Prescaler, HelloWorld, EventCounter
56  p = self._makeAlg(Prescaler, PercentPass=50.)
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 AuditorSvc().Auditors.append(TimingAuditor("TIMER"))
GaudiKernel.Configurable.SuperAlgorithm
Definition: Configurable.py:1777
SuperAlgDynamicGraph.MySuperAlg.graph
graph
Definition: SuperAlgDynamicGraph.py:49
SuperAlgDynamicGraph.MySuperAlg.UseHelloWorld
def UseHelloWorld(self)
Definition: SuperAlgDynamicGraph.py:42
AuditorSvc
Definition: AuditorSvc.h:28
SuperAlgDynamicGraph.MySuperAlg
Definition: SuperAlgDynamicGraph.py:26
GaudiKernel.Configurable
Definition: Configurable.py:1
Gaudi.Configuration
Definition: Configuration.py:1
SuperAlgDynamicGraph.MySuperAlg.__init__
def __init__(self, *args, **kwargs)
Definition: SuperAlgDynamicGraph.py:35
GaudiKernel.Configurable.SuperAlgorithm._makeAlg
def _makeAlg(self, typ, **kwargs)
Definition: Configurable.py:1827
SuperAlgDynamicGraph.MySuperAlg._initGraph
def _initGraph(self)
Definition: SuperAlgDynamicGraph.py:51
SuperAlgDynamicGraph.MySuperAlg._hello_flag
_hello_flag
Definition: SuperAlgDynamicGraph.py:47
ApplicationMgr
Definition: ApplicationMgr.h:57