Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
69 def AlgSequence( name="AthAlgSeq", **kwargs ):
70  """Convenience method to get the default sequence for algorithms"""
71  return AthSequencer( name, **kwargs )
72 
73 
74 
75 def iter_algseq(seq):
76  """iterate over a (possibly nested) ``seq`` AlgSequence.
77 
78  if the sequence contains nested sub-sequences, everything will be flatten
79  out in-order.
80 
81  example:
82  >>> import AthenaCommon.AlgSequence as acas
83  >>> aaa = CfgMgr.AthSequencer('aaa')
84  >>> aaa += CfgMgr.AthSequencer('aaa1')
85  >>> aaa.aaa1 += CfgMgr.AthSequencer('aaa2')
86  >>> aaa.aaa1.aaa2 += CfgMgr.AthSequencer('aaa3')
87  >>> aaa.aaa1.aaa2.aaa3 += CfgMgr.AthSequencer('aaa4')
88  >>> aaa.aaa1.aaa2.aaa3.aaa4 += CfgMgr.AthSequencer('aaa5')
89  >>> aaa += CfgMgr.AthSequencer('aaa11')
90  >>> aaa.aaa11 += CfgMgr.AthSequencer('aaa21')
91  >>> print ([c.getName() for c in acas.iter_algseq(aaa)])
92  ['aaa', 'aaa1', 'aaa2', 'aaa3', 'aaa4', 'aaa5', 'aaa11', 'aaa21']
93  """
94  def _iter_algseq(seq):
95  yield seq
96  for c in seq.getChildren():
97  for sub in _iter_algseq(c):
98  yield sub
99  return _iter_algseq(seq)
100 
101 def dumpSequence (seq, indent=0):
102  def _dump (seq, indent):
103  o = list()
104  for c in seq.getChildren():
105  o.append( (c.getFullName(), indent) )
106  o.extend( _dump (c, indent+1) )
107  return o
108  out = [(seq.getFullName(),indent)]
109  out.extend( _dump( seq, indent=indent+1 ) )
110  for n,i in out:
111  print (" "*i,"+--",n)
112 
114  """
115  Helper function to display on screen the current master sequencer layout
116  """
117  # if the application manager has already been setup()'d we just have to
118  # dump the AthMasterSeq as all the work has been done for us
119  from AthenaCommon.AppMgr import theApp, AthAppMgr
120  app_state = theApp.state()
121  if app_state != AthAppMgr.State.OFFLINE:
122  return dumpSequence( AthSequencer ("AthMasterSeq") )
123 
124  # otherwise, manually do it...
125  dumpSequence( AthSequencer ("AthMasterSeq"), indent=0 )
126  dumpSequence( AthSequencer ("athAlgEvtSeq"), indent=1 )
127  dumpSequence( AthSequencer ("athBeginSeq"), indent=2 )
128  dumpSequence( AthSequencer ("athAllAlgSeq"), indent=2 )
129  dumpSequence( AthSequencer ("athCondSeq"), indent=3 )
130  dumpSequence( AthSequencer ("athAlgSeq"), indent=3 )
131  dumpSequence( AthSequencer ("athEndSeq"), indent=2 )
132  dumpSequence( AthSequencer ("athOutSeq"), indent=1 )
133  dumpSequence( AthSequencer ("athRegSeq"), indent=1 )
python.AlgSequence.iter_algseq
def iter_algseq(seq)
helper functions -------------------------------------------------------—
Definition: Control/AthenaCommon/python/AlgSequence.py:75
python.AlgSequence.AlgSequence
AlgSequence
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py:7
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:101
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.AlgSequence.dumpMasterSequence
def dumpMasterSequence()
Definition: Control/AthenaCommon/python/AlgSequence.py:113
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.AthSequencer.setup
def setup(self)
Definition: Control/AthenaCommon/python/AlgSequence.py:42
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