ATLAS Offline Software
MultiReaderAlg.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 
3 from D3PDMakerCoreComps.D3PDObject import D3PDObject
4 import D3PDMakerCoreComps
5 
6 from D3PDMakerConfig.D3PDMakerFlags import D3PDMakerFlags
7 from AthenaPython import PyAthena
8 
9 from D3PDMakerReader.D3PDMakerReaderConf import D3PD__MultiReaderAlg
10 
11 from AthenaCommon.Logging import logging
12 from AthenaCommon.AlgSequence import AlgSequence
13 topSequence = AlgSequence()
14 
15 
19 class MultiReaderAlg( D3PD__MultiReaderAlg ):
20 
21  def __init__( self,
22  name,
23  seq = topSequence,
24  tuplename = None,
25  preD3PDAlgSeqName = D3PDMakerFlags.PreD3PDAlgSeqName(), # noqa: B008 (constant string)
26  **kwargs ):
27 
28  self.__logger = logging.getLogger( "MultiReaderAlg" )
29 
30  # Work around initialization order issue.
31  seq.__iadd__( D3PDMakerCoreComps.DummyInitAlg( name + 'DummyInit' ),
32  index = 0 )
33 
34  # tuple name defaults to the algorithm name.
35  if tuplename is None:
36  tuplename = name
37 
38  # Create the algorithm Configurable.
39  D3PD__MultiReaderAlg.__init__ ( self, name,
40  TupleName = tuplename,
41  **kwargs )
42 
43  # Add to the supplied sequence.
44  if seq:
45  # But first, add a sequence for algorithms that should run
46  # before D3PD making, if it's not already there.
47  preseq = AlgSequence( preD3PDAlgSeqName )
48  if not hasattr( seq, preD3PDAlgSeqName ):
49  seq += [ preseq ]
50 
51  # We don't want to do filtering in the presequence.
52  preseq.StopOverride = True
53  # Now set up another sequence for filtering.
54  # Unlike the presequence, there should be a unique one of these
55  # per algorithm. We also need to break out an additional
56  # sequence to which users can add, and to wrap the whole
57  # thing in a sequence to prevent a failed filter
58  # decision from stopping other algorithms.
59  # Like this:
60  #
61  # ALG_FilterAlgorithmsWrap (StopOverride = True)
62  # ALG_FilterAlgorithmsHolder
63  # ALG_FilterAlgorithms
64  # ALG
65  # Dummy alg, to reset filter flag
66  suffix = D3PDMakerFlags.FilterAlgSeqSuffix()
67  wrap = AlgSequence( name + suffix + 'Wrap',
68  StopOverride = True )
69  holder = AlgSequence( name + suffix + 'Holder' )
70  self.filterSeq = AlgSequence( name + suffix )
71  holder += self.filterSeq
72  holder += self
73  wrap += holder
74  wrap += PyAthena.Alg( name + 'Dummy' )
75 
76  seq += wrap
77 
78  # Create a unique collection getter registry tool for this tree.
79  from AthenaCommon.AppMgr import ToolSvc
80  self._registry = \
81  D3PDMakerCoreComps.CollectionGetterRegistryTool (self.name() +
82  '_CollectionGetterRegistry')
83  ToolSvc += self._registry
84 
85  return
86 
87  def __iadd__( self, config ):
88  """Add a new IObjFillerTool to a tree."""
89 
90  nchild = len( self )
91  if not isinstance( config, list ):
92  # Check if this is a duplicate:
93  if hasattr( self, config.getName() ):
94  self.__logger.warning( "Duplicate D3PDObject with name \"%s\" ignored", config.ObjectName )
95  return self
96  # If not then add it to the algorithm:
97  self.__logger.info( "Adding D3PDObject with name \"%s\" and prefix \"%s\"",
98  config.ObjectName, config.Prefix )
99  self.Tools += [ config ]
100  self.Prefixes += [ config.Prefix ]
101  self.ClassNames += [ config.ObjectName ]
102  config = [ config ]
103  else:
104  for c in config:
105  self.__iadd__( c )
106  pass
107  return self
108 
109  super( MultiReaderAlg, self ).__iadd__( config )
110 
111  # Rescan all children to set the proper collection getter registry.
112  self._setRegistry( self )
113 
114  # Execute the hooks as well. They are needed after all...
115  for c in self.getChildren()[ nchild : ]:
116  D3PDObject.runHooks( c )
117  pass
118 
119  return self
120 
121  def _setRegistry( self, conf ):
122  """Scan CONF and all children to set the proper
123  collection getter registry for this tree.
124  """
125 
126  if 'CollectionGetterRegistry' in conf.properties():
127  conf.CollectionGetterRegistry = self._registry
128  for c in conf.getAllChildren():
129  self._setRegistry( c )
130 
131  return
grepfile.info
info
Definition: grepfile.py:38
python.MultiReaderAlg.MultiReaderAlg.__logger
__logger
Definition: MultiReaderAlg.py:23
python.MultiReaderAlg.MultiReaderAlg.__iadd__
def __iadd__(self, config)
Definition: MultiReaderAlg.py:87
python.AlgSequence.AlgSequence
AlgSequence
Definition: PhysicsAnalysis/D3PDTools/AnaAlgorithm/python/AlgSequence.py:7
python.MultiReaderAlg.MultiReaderAlg
A class very similar to D3PDMakerCoreComps.MakerAlg, but it creates a configured version of the D3PD:...
Definition: MultiReaderAlg.py:19
python.MultiReaderAlg.MultiReaderAlg.filterSeq
filterSeq
Definition: MultiReaderAlg.py:65
python.MultiReaderAlg.MultiReaderAlg.__init__
def __init__(self, name, seq=topSequence, tuplename=None, preD3PDAlgSeqName=D3PDMakerFlags.PreD3PDAlgSeqName(), **kwargs)
Definition: MultiReaderAlg.py:21
PyAthena::Alg
Definition: PyAthenaAlg.h:33
python.MultiReaderAlg.MultiReaderAlg._registry
_registry
Definition: MultiReaderAlg.py:75
python.MultiReaderAlg.MultiReaderAlg._setRegistry
def _setRegistry(self, conf)
Definition: MultiReaderAlg.py:121