ATLAS Offline Software
Trigger/TrigTools/TrigInDetConfig/python/utils.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 #
3 # Helper methods for configuration
4 
5 from AthenaConfiguration.AthConfigFlags import AthConfigFlags
6 import logging
7 
8 
10  flags: AthConfigFlags, config_name: str, log: logging.Logger) -> AthConfigFlags:
11 
12  """Get the flags for the named config, ensure that they are set to be active
13 
14  Parameters
15  ----------
16  flags : AthConfigFlags
17  The instance of the flags to check
18  config_name : str
19  The name of the desired tracking config
20  log : logging.Logger
21  Logger to print related messages
22 
23  Returns
24  -------
25  Either the current flags instance if all the ActiveConfig is correct or a new
26  version with cloned flags
27 
28  the flags correspond to InDet/ITk format
29  """
30 
31  if flags.hasFlag("Tracking.ActiveConfig.input_name"):
32  if flags.Tracking.ActiveConfig.input_name == config_name:
33  log.debug(
34  "flags.Tracking.ActiveConfig is for %s",
35  flags.Tracking.ActiveConfig.input_name,
36  )
37  return flags
38  else:
39  log.info(
40  "flags.Tracking.ActiveConfig is not for %s but %s",
41  config_name,
42  flags.Tracking.ActiveConfig.input_name,
43  )
44  else:
45 
46  log.info(
47  "Menu code invoked ID config without flags.Tracking.ActiveConfig for %s",
48  config_name,
49  )
50 
51  return _cloneFlagsToActiveConfig(flags, config_name)
52 
53 
55  flags: AthConfigFlags, config_name: str, log: logging.Logger) -> AthConfigFlags:
56 
57  """
58  InDet/ITk specific clone and replace of ActiveConfig without checking flags vs config_name
59 
60  this function should be used only high up in the menu creation where a context of tracking flags
61  does not exist yet and is created for the first time in generateChainConfigs function
62  or there are multiple contexts for ActiveConfig like in LRT
63 
64  in other cases getFlagsForActiveConfig should be used instead
65 
66  """
67 
68  log.info(f"Cloning tracking config for {config_name} to flags.Tracking.ActiveConfig")
69  return _cloneFlagsToActiveConfig(flags, config_name)
70 
71 def _cloneFlagsToActiveConfig(flags: AthConfigFlags, config_name: str) -> AthConfigFlags:
72 
73  prefix = "Trigger.InDetTracking."
74  if flags.Detector.GeometryITk:
75  prefix = "Trigger.ITkTracking."
76  if flags.Trigger.useActsTracking:
77  prefix = "Trigger.ActsTracking."
78 
79  return flags.cloneAndReplace(
80  "Tracking.ActiveConfig",
81  prefix + config_name,
82  keepOriginal = True
83  )
python.utils.getFlagsForActiveConfig
AthConfigFlags getFlagsForActiveConfig(AthConfigFlags flags, str config_name, logging.Logger log)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:9
python.utils.cloneFlagsToActiveConfig
AthConfigFlags cloneFlagsToActiveConfig(AthConfigFlags flags, str config_name, logging.Logger log)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:54
python.utils._cloneFlagsToActiveConfig
AthConfigFlags _cloneFlagsToActiveConfig(AthConfigFlags flags, str config_name)
Definition: Trigger/TrigTools/TrigInDetConfig/python/utils.py:71