ATLAS Offline Software
Loading...
Searching...
No Matches
PropSetterProxy.py
Go to the documentation of this file.
1# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2
3from AthenaCommon.Logging import logging
4from AthenaCommon.CFElements import isSequence
5from AthenaCommon.Configurable import ConfigurableAlgTool
6from GaudiKernel.GaudiHandles import PrivateToolHandle, PrivateToolHandleArray
7
8import fnmatch
9
10msg = logging.getLogger('PropSetterProxy')
11
12
14 __compPaths = {}
15 __scannedCA = None
16
17 def __init__(self, ca, path):
18 self.__path = path
19 self.__findComponents( ca )
20
21 def __setattr__(self, name, value):
22 if name.startswith("_PropSetterProxy"):
23 return super(PropSetterProxy, self).__setattr__(name, value)
24
25 if name != "OutputLevel":
26 msg.error("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" )
27
28 matches = 0
29 for component_path, component in PropSetterProxy.__compPaths.items():
30 if fnmatch.fnmatch( component_path, self.__path ):
31 matches += 1
32 if name in component._descriptors:
33 try:
34 setattr( component, name, value )
35 msg.info( "Set property %s to %s for component %s because it matched '%s'",
36 name, value, component_path, self.__path )
37 except Exception as ex:
38 msg.warning( "Failed to set property %s to value %s for component %s: %s",
39 name, value, component_path, ex )
40 else:
41 msg.warning( "Property %s does not exist for component %s",
42 name, component_path )
43
44 if not matches:
45 msg.warning("No components found matching '%s'", self.__path)
46
47
48 def __findComponents(self, ca):
49 if ca is not PropSetterProxy.__scannedCA:
50 PropSetterProxy.__scannedCA = ca
51 PropSetterProxy.__compPaths = {}
52 def __add(path, comp):
53 if comp.getName() == "":
54 return
55 PropSetterProxy.__compPaths[ path ] = comp
56
57
58 for svc in ca._services:
59 PropSetterProxy.__compPaths['SvcMgr/'+svc.getFullJobOptName()] = svc
60 for t in ca._publicTools:
61 PropSetterProxy.__compPaths['ToolSvc/'+t.getFullJobOptName()] = t
62 for t in ca._conditionsAlgs:
63 PropSetterProxy.__compPaths[t.getFullJobOptName()] = t
64 if ca._privateTools:
65 for t in ca._privateTools:
66 PropSetterProxy.__compPaths[t.getFullJobOptName()] = t
67
68 def __nestAlg(startpath, comp): # it actually dives inside the algorithms and (sub) tools
69 if comp.getName() == "":
70 return
71 for name, value in comp._descriptors.items():
72 if isinstance(value.cpp_type, (ConfigurableAlgTool, PrivateToolHandle)):
73 __add( startpath+"/"+name+"/"+value.getFullJobOptName(), value )
74 __nestAlg( startpath+"/"+name+"/"+value.getName(), value )
75 if isinstance( value.cpp_type, PrivateToolHandleArray):
76 for toolIndex,t in enumerate(value):
77 __add( startpath+"/"+name+"/"+t.getFullJobOptName(), t )
78 __nestAlg( startpath+"/"+name+"/"+t.getName(), value[toolIndex] )
79
80
81 def __nestSeq( startpath, seq ):
82 for c in seq.Members:
83 if isSequence(c):
84 __nestSeq( startpath+"/"+c.getName(), c )
85 else: # the algorithm or tool
86 __add( startpath+"/"+c.getFullJobOptName(), c )
87 __nestAlg( startpath+"/"+c.getFullJobOptName(), c )
88
89 __nestSeq("", ca._sequence)
90
91
92
93
94