ATLAS Offline Software
PropSetterProxy.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
2 
3 from AthenaCommon.Logging import logging
4 from AthenaCommon.CFElements import isSequence
5 from AthenaCommon.Configurable import ConfigurableAlgTool
6 from GaudiKernel.GaudiHandles import PrivateToolHandle, PrivateToolHandleArray
7 
8 msg = logging.getLogger('PropSetterProxy')
9 
11  __compPaths = {}
12  __scannedCA = None
13 
14  def __init__(self, ca, path):
15  self.__path = path
16  self.__findComponents( ca )
17 
18  def __setattr__(self, name, value):
19  if name.startswith("_PropSetterProxy"):
20  return super(PropSetterProxy, self).__setattr__(name, value)
21 
22  if name != "OutputLevel":
23  msg.error("The foreach_component is a debugging feature and should not be used in production jobs, remove it before committing to the repository, proceeding to set the properties now" )
24 
25  import fnmatch
26  for component_path, component in PropSetterProxy.__compPaths.items():
27  if fnmatch.fnmatch( component_path, self.__path ):
28  if name in component._descriptors:
29  try:
30  setattr( component, name, value )
31  msg.info( "Set property: %s to value %s of component %s because it matched %s ",
32  name, str(value), component_path, self.__path )
33  except Exception as ex:
34  msg.warning( "Failed to set property: %s to value %s of component %s because it matched %s, reason: %s",
35  name, str(value), component_path, self.__path, str(ex) )
36  pass
37  else:
38  msg.warning( "No such property: %s in component %s, tried to set it because it matched %s",
39  name, component_path, self.__path )
40 
41 
42  def __findComponents(self, ca):
43  if ca is not PropSetterProxy.__scannedCA:
44  PropSetterProxy.__scannedCA = ca
45  PropSetterProxy.__compPaths = {}
46  def __add(path, comp):
47  if comp.getName() == "":
48  return
49  PropSetterProxy.__compPaths[ path ] = comp
50 
51 
52  for svc in ca._services:
53  PropSetterProxy.__compPaths['SvcMgr/'+svc.getFullJobOptName()] = svc
54  for t in ca._publicTools:
55  PropSetterProxy.__compPaths['ToolSvc/'+t.getFullJobOptName()] = t
56  for t in ca._conditionsAlgs:
57  PropSetterProxy.__compPaths[t.getFullJobOptName()] = t
58  if ca._privateTools:
59  for t in ca._privateTools:
60  PropSetterProxy.__compPaths[t.getFullJobOptName()] = t
61 
62  def __nestAlg(startpath, comp): # it actually dives inside the algorithms and (sub) tools
63  if comp.getName() == "":
64  return
65  for name, value in comp._descriptors.items():
66  if isinstance( value.cpp_type, ConfigurableAlgTool ) or isinstance( value.cpp_type, PrivateToolHandle ):
67  __add( startpath+"/"+name+"/"+value.getFullJobOptName(), value )
68  __nestAlg( startpath+"/"+name+"/"+value.getName(), value )
69  if isinstance( value.cpp_type, PrivateToolHandleArray):
70  for toolIndex,t in enumerate(value):
71  __add( startpath+"/"+name+"/"+t.getFullJobOptName(), t )
72  __nestAlg( startpath+"/"+name+"/"+t.getName(), value[toolIndex] )
73 
74 
75  def __nestSeq( startpath, seq ):
76  for c in seq.Members:
77  if isSequence(c):
78  __nestSeq( startpath+"/"+c.getName(), c )
79  else: # the algorithm or tool
80  __add( startpath+"/"+c.getFullJobOptName(), c )
81  __nestAlg( startpath+"/"+c.getFullJobOptName(), c )
82 
83  __nestSeq("", ca._sequence)
84 
85 
86 
87 
88 
python.PropSetterProxy.PropSetterProxy.__findComponents
def __findComponents(self, ca)
Definition: PropSetterProxy.py:42
python.PropSetterProxy.PropSetterProxy.__path
__path
Definition: PropSetterProxy.py:15
python.PropSetterProxy.PropSetterProxy.__init__
def __init__(self, ca, path)
Definition: PropSetterProxy.py:14
python.PropSetterProxy.PropSetterProxy
Definition: PropSetterProxy.py:10
Configurable
athena/gaudi ----------------------------------------------------------—
python.PropSetterProxy.PropSetterProxy.__setattr__
def __setattr__(self, name, value)
Definition: PropSetterProxy.py:18
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
python.CFElements.isSequence
def isSequence(obj)
Definition: CFElements.py:96