ATLAS Offline Software
Control/AthenaConfiguration/python/Utils.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 from GaudiKernel.GaudiHandles import GaudiHandle
3 from AthenaConfiguration.ComponentFactory import CompFactory
4 from AthenaCommon.Logging import logging
5 import collections
6 def loadDefaultComps(allcomps):
7  """Attempts to load all default components (those that are not actually configured)"""
8  loadedSome = False
9  def __load(comp, prop):
10  descr = comp._descriptors[prop]
11  if descr.default.getType() == "":
12  return
13  try:
14  childComp = CompFactory.getComp(descr.default.getType())(descr.default.getName())
15  comp._properties[prop] = childComp
16  nonlocal loadedSome
17  loadedSome = True
18  except Exception:
19  msg=logging.getLogger('loadDefaultComps')
20  msg.warning("Default component %s can not be loaded", descr.default.typeAndName )
21  pass
22 
23  for comp in allcomps:
24  for propName,value in comp._descriptors.items():
25  if propName in comp._properties: continue
26  if isinstance(value.default, GaudiHandle):
27  __load(comp, propName )
28 
29  if loadedSome:
30  loadDefaultComps(allcomps)
31 
32 def exposeHandles(allcomps):
33  """Sets all handle keys explicitly"""
34  def __getDefault(d):
35  if isinstance(d, collections.abc.Sequence):
36  return [el for el in d]
37  else:
38  return d.Path
39 
40  for comp in allcomps:
41  for propName, value in comp._descriptors.items():
42  if propName in comp._properties: continue
43  if "HandleKey" in value.cpp_type:
44  comp._properties[propName] = __getDefault(value.default)
45 
46 def setupLoggingLevels(flags, ca):
47  """Read the Exec.*MessageComponents flags and modify output level of components
48 
49  The specification of components uses python fnmatch library and resembles UNIX paths.
50  For instance an event algorithm MyAlgo/MyInstance would have following path:
51  MasterSeq/AthAllAlgSeq/AthAlgSeq/MyAlgo/MyInstance
52  A private tool MyTool of name ToolInstance used by this algo:
53  MasterSeq/AthAllAlgSeq/AthAlgSeq/MyAlgo/MyInstance/MyTool/ToolInstance
54  A public tool would have path:
55  ToolSvc/MyTool/ToolInstance
56  and so on.
57  The path specification can look like thi:
58  */ToolInstance - all tools that have matching instance name
59  */MyTool/* - all instances of the tool
60  */MyAlgo/MyInstance - specific algorithm
61  */MyAlg0/* - all instance of specific algorithm
62  */AthAlgSeq/* - all algorithms (with deeper sequences structure e.g. in HLT sub-components of sequences can controlled this way)
63  ToolSvc/My*/* - all public tools that instance name starts with My
64 
65  The modifications to the OutputLevel are applied form ERROR to VERBOSE.
66  This is to support pattern when large group of components is set to less verbose logging mode
67  and with more specific selection more verbosity is enabled. E.g. all algorithms can be set to WARNING,
68  the all having calo in the name to INFO, and CaloCellMaker to DEBUG.
69 
70  Each setting can be either a string or a list of strings.
71 
72  If the component-path contains no '/' it is assumed to be a plain component-name. In this case,
73  the output-level is set using the property MessageSvc.setDebug (or equivalent). This works also
74  for converters that do not inherit PropertyHolder.
75  """
76 
77  msgSvc=ca.getService("MessageSvc") #by the time this snippet runs, the ComponentAccumulator should really contain the MessageSvc
78 
79 
80 
81  from AthenaCommon.Constants import ERROR,WARNING,INFO,DEBUG,VERBOSE
82  def __tolist(d):
83  return ([d] if d != '' else []) if isinstance(d, str) else d
84  for flag_val, level,setter in [(flags.Exec.ErrorMessageComponents, ERROR, msgSvc.setError),
85  (flags.Exec.WarningMessageComponents, WARNING, msgSvc.setWarning),
86  (flags.Exec.InfoMessageComponents, INFO, msgSvc.setInfo),
87  (flags.Exec.DebugMessageComponents, DEBUG, msgSvc.setDebug),
88  (flags.Exec.VerboseMessageComponents, VERBOSE, msgSvc.setVerbose) ]:
89  for c in __tolist(flag_val):
90  if "/" in c:
91  ca.foreach_component(c).OutputLevel=level
92  else: # a plain component name is given
93  setter.append(c)
python.Utils.setupLoggingLevels
def setupLoggingLevels(flags, ca)
Definition: Control/AthenaConfiguration/python/Utils.py:46
Constants
some useful constants -------------------------------------------------—
python.Utils.exposeHandles
def exposeHandles(allcomps)
Definition: Control/AthenaConfiguration/python/Utils.py:32
python.Utils.loadDefaultComps
def loadDefaultComps(allcomps)
Definition: Control/AthenaConfiguration/python/Utils.py:6