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

Functions

 _container (spec)
 _new_accumulator (dataType, containers)
 run (cuts, *, dataType=DataType.FullSim, containers=None, selectionName="SR", **options)
 run_merger (region_names, *, dataType=DataType.FullSim, noFilter=False)
 selectors (algs)
 named (algs, substr)
 prop (alg, name, default=_UNSET)

Variables

 _UNSET = object()
list _DUMMY_WPS

Detailed Description

Shared harness for the EventSelectionConfig unit tests.

Each *_unitTest.py script builds a real ConfigSequence containing a single
EventSelectionConfig block, configures it through a real ConfigAccumulator,
and inspects the resulting algorithm sequence. No mocking: the accumulator
instantiates the real CP algorithms, so a Python/C++ property-name mismatch
is caught here rather than at runtime.

In a full job the object-config blocks register the input containers and their
selection working points upstream. In isolation we register them here:
  * input containers      -> config.setSourceName(container, container)
  * object selection WPs  -> config.addSelection(container, wp, decoration)

Function Documentation

◆ _container()

python.EventSelectionConfigTestSupport._container ( spec)
protected
Strip a trailing '.selection' to get the bare container name.

Definition at line 32 of file EventSelectionConfigTestSupport.py.

32def _container(spec):
33 """Strip a trailing '.selection' to get the bare container name."""
34 return spec.split(".")[0]
35
36

◆ _new_accumulator()

python.EventSelectionConfigTestSupport._new_accumulator ( dataType,
containers )
protected

Definition at line 37 of file EventSelectionConfigTestSupport.py.

37def _new_accumulator(dataType, containers):
38 algSeq = AlgSequence()
39 config = ConfigAccumulator(dataType=dataType, algSeq=algSeq)
40 for cont in {_container(c) for c in containers}:
41 config.setSourceName(cont, cont)
42 for wp in _DUMMY_WPS:
43 # decoration string deliberately embeds the WP name so the
44 # extra-selection tests can assert on it via substring.
45 config.addSelection(cont, wp, f"{wp}_%SYS%")
46 return algSeq, config
47
48

◆ named()

python.EventSelectionConfigTestSupport.named ( algs,
substr )

Definition at line 102 of file EventSelectionConfigTestSupport.py.

102def named(algs, substr):
103 return [a for a in algs if substr in a.getName()]
104
105

◆ prop()

python.EventSelectionConfigTestSupport.prop ( alg,
name,
default = _UNSET )
Read a property set on the algorithm; return `default` if unset.

Definition at line 106 of file EventSelectionConfigTestSupport.py.

106def prop(alg, name, default=_UNSET):
107 """Read a property set on the algorithm; return `default` if unset."""
108 val = getattr(alg, name, _UNSET)
109 if val is _UNSET:
110 if default is _UNSET:
111 raise AttributeError(f"{alg.getName()} has no property {name!r}")
112 return default
113 return val

◆ run()

python.EventSelectionConfigTestSupport.run ( cuts,
* ,
dataType = DataType.FullSim,
containers = None,
selectionName = "SR",
** options )
Configure one EventSelectionConfig block and return its algorithms.

`containers` maps EventSelectionConfig option names to container specs,
e.g. {'electrons': 'AnaElectrons'} or {'jets': 'AnaJets.baseline'}.

Definition at line 49 of file EventSelectionConfigTestSupport.py.

50 selectionName="SR", **options):
51 """Configure one EventSelectionConfig block and return its algorithms.
52
53 `containers` maps EventSelectionConfig option names to container specs,
54 e.g. {'electrons': 'AnaElectrons'} or {'jets': 'AnaJets.baseline'}.
55 """
56 containers = containers or {}
57 algSeq, config = _new_accumulator(dataType, containers.values())
58 seq = ConfigSequence()
59 block = EventSelectionConfig()
60 block.setOptionValue("selectionName", selectionName)
61 block.setOptionValue("selectionCuts", cuts)
62 for opt, cname in containers.items():
63 block.setOptionValue(opt, cname)
64 for opt, val in options.items():
65 block.setOptionValue(opt, val)
66 seq.append(block)
67 seq.fullConfigure(config)
68 if isAthena:
69 return config.CA.getEventAlgos()
70 return list(algSeq)
71
72

◆ run_merger()

python.EventSelectionConfigTestSupport.run_merger ( region_names,
* ,
dataType = DataType.FullSim,
noFilter = False )
Build real regions then the merger, and return the algorithm sequence.

Each region is a trivial EventSelectionConfig (RUN_NUMBER + SAVE) so that
the merger's `EventSelection` dependency is satisfied and `eventSelectionNames`
is populated through the normal SAVE path (no manual metadata).

Definition at line 73 of file EventSelectionConfigTestSupport.py.

73def run_merger(region_names, *, dataType=DataType.FullSim, noFilter=False):
74 """Build real regions then the merger, and return the algorithm sequence.
75
76 Each region is a trivial EventSelectionConfig (RUN_NUMBER + SAVE) so that
77 the merger's `EventSelection` dependency is satisfied and `eventSelectionNames`
78 is populated through the normal SAVE path (no manual metadata).
79 """
80 algSeq, config = _new_accumulator(dataType, [])
81 seq = ConfigSequence()
82 for name in region_names:
83 block = EventSelectionConfig()
84 block.setOptionValue("selectionName", name)
85 block.setOptionValue("selectionCuts", "RUN_NUMBER >= 0\nSAVE")
86 seq.append(block)
87 merger = EventSelectionMergerConfig()
88 merger._instance_number = 1 # defensive: ensure the guard runs
89 merger.setOptionValue("noFilter", noFilter)
90 seq.append(merger)
91 seq.fullConfigure(config)
92 if isAthena:
93 return config.CA.getEventAlgos()
94 return list(algSeq)
95
96

◆ selectors()

python.EventSelectionConfigTestSupport.selectors ( algs)
Selector algorithms only (exclude the SAVE filter).

Definition at line 97 of file EventSelectionConfigTestSupport.py.

97def selectors(algs):
98 """Selector algorithms only (exclude the SAVE filter)."""
99 return [a for a in algs if a.getType() != "CP::SaveFilterAlg"]
100
101

Variable Documentation

◆ _DUMMY_WPS

list python.EventSelectionConfigTestSupport._DUMMY_WPS
protected
Initial value:
1= ["baseline", "mysel", "goodjet", "centraljet", "topjet",
2 "elsel", "musel", "esel", "msel", "tsel"]

Definition at line 28 of file EventSelectionConfigTestSupport.py.

◆ _UNSET

python.EventSelectionConfigTestSupport._UNSET = object()
protected

Definition at line 24 of file EventSelectionConfigTestSupport.py.