ATLAS Offline Software
Control/AthenaCommon/python/AlgSequence.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 # File: AthenaCommon/python/AlgSequence.py
4 # Author: Wim Lavrijsen (WLavrijsen@lbl.gov)
5 # Author: Sebastien Binet (binet@cern.ch)
6 
7 __version__ = '$Revision: 1.21 $'
8 __author__ = """Wim Lavrijsen (WLavrijsen@lbl.gov)
9  Sebastien Binet <binet@cern.ch>
10  """
11 
12 __all__ = [ 'AlgSequence', 'AthSequencer',
13  'iter_algseq',
14  'dumpSequence',
15  'dumpMasterSequence']
16 
17 import GaudiSequencer.GaudiSequencerConf as GaudiSequencerConf
18 
19 
20 
21 
22 # create a new base class type to replace the old configurable
23 class AthSequencer( GaudiSequencerConf.AthSequencer ):
24  """Sequence of Gaudi algorithms"""
25 
26  def __init__( self, name = "AthSequencer", **kwargs ):
27  # call base class __init__ to pass new name
28  super( AthSequencer, self ).__init__( name, **kwargs )
29 
30  def getProperties( self ):
31 
32  props = super( AthSequencer, self ).getProperties()
33 
34 
35  if 'Members' in props:
36  props['Members'] = [ c.getFullName() for c in self.getChildren() ]
37  return props
38 
39  def insert( self, index, item ):
40  self.__iadd__( item, index = index )
41 
42  def setup( self ):
43 
44 
48  self._flags &= ~self._fIsLocked
49 
50  self.Members = [ c.getFullName() for c in self.getChildren() ]
51 
52  from AthenaCommon import Logging
53  msg = Logging.logging.getLogger( "AthSequencer" )
54  msg.debug( 'setup of sequence: %s', self.getName() )
55  if msg.isEnabledFor( Logging.logging.VERBOSE ):
56  # call of __repr__ is relatively expensive
57  msg.verbose( 'layout of sequence: %s\n%s', self.getName(), str(self) )
58 
59 
60  super( AthSequencer, self ).setup()
61 
62 # store the new AthSequencer into CfgMgr to make it available
63 from AthenaCommon import CfgMgr
64 CfgMgr.AthSequencer = AthSequencer
65 del CfgMgr
66 
67 
68 if hasattr(GaudiSequencerConf, 'AthRetrySequencer'):
69  # create a new base class type to replace the old configurable
70  class AthRetrySequencer( GaudiSequencerConf.AthRetrySequencer ):
71  """Sequence of Gaudi algorithms"""
72 
73  def __init__( self, name = "AthRetrySequencer", **kwargs ):
74  # call base class __init__ to pass new name
75  super( AthRetrySequencer, self ).__init__( name, **kwargs )
76 
77  def getProperties( self ):
78 
79  props = super( AthRetrySequencer, self ).getProperties()
80 
81 
82  if 'Members' in props:
83  props['Members'] = [ c.getFullName() for c in self.getChildren() ]
84  return props
85 
86  def insert( self, index, item ):
87  self.__iadd__( item, index = index )
88 
89  def setup( self ):
90 
91 
92  self.Members = [ c.getFullName() for c in self.getChildren() ]
93 
94  from AthenaCommon import Logging
95  msg = Logging.logging.getLogger( "AthRetrySequencer" )
96  msg.debug( 'setup of sequence: %s', self.getName() )
97  if msg.isEnabledFor( Logging.logging.VERBOSE ):
98  # call of __repr__ is relatively expensive
99  msg.verbose( 'layout of sequence: %s\n%s', self.getName(), str(self) )
100 
101 
102  super( AthRetrySequencer, self ).setup()
103  pass # AthRetrySequencer
104  # store the new AthRetrySequencer into CfgMgr to make it available
105  from AthenaCommon import CfgMgr
106  CfgMgr.AthRetrySequencer = AthRetrySequencer
107  del CfgMgr
108  pass # monkey-patching AthRetrySequencer
109 
110 
111 
112 def AlgSequence( name="AthAlgSeq", **kwargs ):
113  """Convenience method to get the default sequence for algorithms"""
114  return AthSequencer( name, **kwargs )
115 
116 
117 
118 def iter_algseq(seq):
119  """iterate over a (possibly nested) ``seq`` AlgSequence.
120 
121  if the sequence contains nested sub-sequences, everything will be flatten
122  out in-order.
123 
124  example:
125  >>> import AthenaCommon.AlgSequence as acas
126  >>> aaa = CfgMgr.AthSequencer('aaa')
127  >>> aaa += CfgMgr.AthSequencer('aaa1')
128  >>> aaa.aaa1 += CfgMgr.AthSequencer('aaa2')
129  >>> aaa.aaa1.aaa2 += CfgMgr.AthSequencer('aaa3')
130  >>> aaa.aaa1.aaa2.aaa3 += CfgMgr.AthSequencer('aaa4')
131  >>> aaa.aaa1.aaa2.aaa3.aaa4 += CfgMgr.AthSequencer('aaa5')
132  >>> aaa += CfgMgr.AthSequencer('aaa11')
133  >>> aaa.aaa11 += CfgMgr.AthSequencer('aaa21')
134  >>> print ([c.getName() for c in acas.iter_algseq(aaa)])
135  ['aaa', 'aaa1', 'aaa2', 'aaa3', 'aaa4', 'aaa5', 'aaa11', 'aaa21']
136  """
137  def _iter_algseq(seq):
138  yield seq
139  for c in seq.getChildren():
140  for sub in _iter_algseq(c):
141  yield sub
142  return _iter_algseq(seq)
143 
144 def dumpSequence (seq, indent=0):
145  def _dump (seq, indent):
146  o = list()
147  for c in seq.getChildren():
148  o.append( (c.getFullName(), indent) )
149  o.extend( _dump (c, indent+1) )
150  return o
151  out = [(seq.getFullName(),indent)]
152  out.extend( _dump( seq, indent=indent+1 ) )
153  for n,i in out:
154  print (" "*i,"+--",n)
155 
157  """
158  Helper function to display on screen the current master sequencer layout
159  """
160  # if the application manager has already been setup()'d we just have to
161  # dump the AthMasterSeq as all the work has been done for us
162  from AthenaCommon.AppMgr import theApp, AthAppMgr
163  app_state = theApp.state()
164  if app_state != AthAppMgr.State.OFFLINE:
165  return dumpSequence( AthSequencer ("AthMasterSeq") )
166 
167  # otherwise, manually do it...
168  dumpSequence( AthSequencer ("AthMasterSeq"), indent=0 )
169  dumpSequence( AthSequencer ("athAlgEvtSeq"), indent=1 )
170  dumpSequence( AthSequencer ("athBeginSeq"), indent=2 )
171  dumpSequence( AthSequencer ("athAllAlgSeq"), indent=2 )
172  dumpSequence( AthSequencer ("athCondSeq"), indent=3 )
173  dumpSequence( AthSequencer ("athAlgSeq"), indent=3 )
174  dumpSequence( AthSequencer ("athEndSeq"), indent=2 )
175  dumpSequence( AthSequencer ("athOutSeq"), indent=1 )
176  dumpSequence( AthSequencer ("athRegSeq"), indent=1 )
python.AlgSequence.iter_algseq
def iter_algseq(seq)
helper functions -------------------------------------------------------—
Definition: Control/AthenaCommon/python/AlgSequence.py:118
python.AlgSequence.AlgSequence
AlgSequence
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py:7
python.AlgSequence.AthRetrySequencer
AthRetrySequencer -------------------------------------------------------—.
Definition: Control/AthenaCommon/python/AlgSequence.py:70
python.AlgSequence.AthSequencer.__iadd__
def __iadd__(self, algo)
Definition: Control/AthenaConfiguration/python/AlgSequence.py:14
python.AlgSequence.AthRetrySequencer.getProperties
def getProperties(self)
Definition: Control/AthenaCommon/python/AlgSequence.py:77
python.AlgSequence.AthRetrySequencer.setup
def setup(self)
Definition: Control/AthenaCommon/python/AlgSequence.py:89
python.AlgSequence.AthSequencer.__init__
def __init__(self, name="AthSequencer", **kwargs)
Definition: Control/AthenaCommon/python/AlgSequence.py:26
python.AlgSequence.dumpSequence
def dumpSequence(seq, indent=0)
Definition: Control/AthenaCommon/python/AlgSequence.py:144
python.AlgSequence.AthRetrySequencer.insert
def insert(self, index, item)
Definition: Control/AthenaCommon/python/AlgSequence.py:86
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.AlgSequence.dumpMasterSequence
def dumpMasterSequence()
Definition: Control/AthenaCommon/python/AlgSequence.py:156
python.AlgSequence.AthSequencer.Members
Members
remove the lock for the sake of the next line, which updates the names of all the sequence's members ...
Definition: Control/AthenaCommon/python/AlgSequence.py:50
python.AlgSequence.AthRetrySequencer.__init__
def __init__(self, name="AthRetrySequencer", **kwargs)
Definition: Control/AthenaCommon/python/AlgSequence.py:73
python.AlgSequence.AthSequencer.setup
def setup(self)
Definition: Control/AthenaCommon/python/AlgSequence.py:42
python.AlgSequence.AthRetrySequencer.Members
Members
synchronize the list of Members with our Configurable children
Definition: Control/AthenaCommon/python/AlgSequence.py:92
python.AlgSequence.AthSequencer.getProperties
def getProperties(self)
Definition: Control/AthenaCommon/python/AlgSequence.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
python.AlgSequence.AthSequencer.insert
def insert(self, index, item)
Definition: Control/AthenaCommon/python/AlgSequence.py:39
python.AlgSequence.AthSequencer
sequence of Gaudi algorithms, to replace the generated configurable
Definition: Control/AthenaCommon/python/AlgSequence.py:23