ATLAS Offline Software
Loading...
Searching...
No Matches
python.atlascp Namespace Reference

Classes

class  Corrections

Functions

 _make_tool_class (tool_type_name)
 __getattr__ (name)
 configure (path, *, namespace="CP")

Variables

dict _class_cache = {}

Function Documentation

◆ __getattr__()

python.atlascp.__getattr__ ( name)
Return a constructor for the named CP tool type.

Called when code accesses ``atlascp.<ToolTypeName>``. Returns a callable
that creates and initializes a ``Tool`` subclass instance.

Parameters
----------
name:
    Tool type name without namespace, e.g. "MuonEfficiencyScaleFactors".

Returns
-------
callable
    A constructor with signature
    ``(instance_name=None, /, *, namespace="CP", properties=None, rename_containers=None)``.
    ``instance_name`` is positional-only and optional; all other arguments are keyword-only.
    When omitted, an auto-generated unique name is used.

Definition at line 45 of file atlascp.py.

45def __getattr__(name):
46 """Return a constructor for the named CP tool type.
47
48 Called when code accesses ``atlascp.<ToolTypeName>``. Returns a callable
49 that creates and initializes a ``Tool`` subclass instance.
50
51 Parameters
52 ----------
53 name:
54 Tool type name without namespace, e.g. "MuonEfficiencyScaleFactors".
55
56 Returns
57 -------
58 callable
59 A constructor with signature
60 ``(instance_name=None, /, *, namespace="CP", properties=None, rename_containers=None)``.
61 ``instance_name`` is positional-only and optional; all other arguments are keyword-only.
62 When omitted, an auto-generated unique name is used.
63 """
64 def constructor(instance_name=None, /, *, namespace="CP", properties=None, rename_containers=None):
65 if instance_name is None:
66 instance_name = f"unique{uuid.uuid4().hex[:12]}"
67 type_and_name = f"{namespace}::{name}/{instance_name}"
68 cls = _make_tool_class(name)
69 instance = cls.__new__(cls)
70 Tool.__init__(instance, type_and_name, properties=properties, rename_containers=rename_containers)
71 return instance
72 constructor.__name__ = name
73 constructor.__qualname__ = name
74 return constructor
75
76

◆ _make_tool_class()

python.atlascp._make_tool_class ( tool_type_name)
protected
Return a named Tool subclass for tool_type_name, creating it if needed.

Parameters
----------
tool_type_name:
    The C++ class name without namespace, e.g. "MuonEfficiencyScaleFactors".

Returns
-------
type
    A subclass of Tool whose ``__name__`` equals ``tool_type_name``.
    Repeated calls with the same name return the same class object.

Definition at line 26 of file atlascp.py.

26def _make_tool_class(tool_type_name):
27 """Return a named Tool subclass for tool_type_name, creating it if needed.
28
29 Parameters
30 ----------
31 tool_type_name:
32 The C++ class name without namespace, e.g. "MuonEfficiencyScaleFactors".
33
34 Returns
35 -------
36 type
37 A subclass of Tool whose ``__name__`` equals ``tool_type_name``.
38 Repeated calls with the same name return the same class object.
39 """
40 if tool_type_name not in _class_cache:
41 _class_cache[tool_type_name] = type(tool_type_name, (Tool,), {})
42 return _class_cache[tool_type_name]
43
44

◆ configure()

python.atlascp.configure ( path,
* ,
namespace = "CP" )
Load a TOML config file and return an initialized Corrections object.

The ``[global]`` section provides default ``rename_containers`` and
``properties``. Tool entries are defined as ``[[tool.TypeName]]`` blocks;
multiple blocks of the same type create multiple tool instances.

Parameters
----------
path:
    Path to a TOML configuration file (str or Path).
namespace:
    C++ namespace for all tools (default ``"CP"``).

Returns
-------
Corrections

Definition at line 128 of file atlascp.py.

128def configure(path, *, namespace="CP"):
129 """Load a TOML config file and return an initialized Corrections object.
130
131 The ``[global]`` section provides default ``rename_containers`` and
132 ``properties``. Tool entries are defined as ``[[tool.TypeName]]`` blocks;
133 multiple blocks of the same type create multiple tool instances.
134
135 Parameters
136 ----------
137 path:
138 Path to a TOML configuration file (str or Path).
139 namespace:
140 C++ namespace for all tools (default ``"CP"``).
141
142 Returns
143 -------
144 Corrections
145 """
146 cfg = load_config(path)
147 global_cfg = cfg.get("global", {})
148 tools = []
149 for type_name, entries in cfg.get("tool", {}).items():
150 for entry in entries:
151 merged = merge_tool_config(global_cfg, entry)
152 constructor = __getattr__(type_name)
153 tool = constructor(
154 namespace=namespace,
155 properties=merged["properties"] or None,
156 rename_containers=merged["rename_containers"] or None,
157 )
158 tools.append((type_name, tool))
159 return Corrections(tools)
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)

Variable Documentation

◆ _class_cache

dict python.atlascp._class_cache = {}
protected

Definition at line 23 of file atlascp.py.