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 111 of file EventSelectionConfigTestSupport.py.

111def named(algs, substr):
112 return [a for a in algs if substr in a.getName()]
113
114

◆ prop()

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

Definition at line 115 of file EventSelectionConfigTestSupport.py.

115def prop(alg, name, default=_UNSET):
116 """Read a property set on the algorithm; return `default` if unset."""
117 val = getattr(alg, name, _UNSET)
118 if val is _UNSET:
119 if default is _UNSET:
120 raise AttributeError(f"{alg.getName()} has no property {name!r}")
121 return default
122 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
68 if isAthena:
69 try:
70 seq.fullConfigure(config)
71 return config.CA.getEventAlgos()
72 finally:
73 config.CA.wasMerged()
74
75 seq.fullConfigure(config)
76 return list(algSeq)
77
78

◆ 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 (a single RUN_NUMBER cut) so
that the merger's `EventSelection` dependency is satisfied and
`eventSelectionNames` is populated. The event filter is emitted implicitly
at the end of each block (no explicit SAVE needed).

Definition at line 79 of file EventSelectionConfigTestSupport.py.

79def run_merger(region_names, *, dataType=DataType.FullSim, noFilter=False):
80 """Build real regions then the merger, and return the algorithm sequence.
81
82 Each region is a trivial EventSelectionConfig (a single RUN_NUMBER cut) so
83 that the merger's `EventSelection` dependency is satisfied and
84 `eventSelectionNames` is populated. The event filter is emitted implicitly
85 at the end of each block (no explicit SAVE needed).
86 """
87 algSeq, config = _new_accumulator(dataType, [])
88 seq = ConfigSequence()
89 for name in region_names:
90 block = EventSelectionConfig()
91 block.setOptionValue("selectionName", name)
92 block.setOptionValue("selectionCuts", "RUN_NUMBER >= 0")
93 seq.append(block)
94 merger = EventSelectionMergerConfig()
95 merger._instance_number = 1 # defensive: ensure the guard runs
96 merger.setOptionValue("noFilter", noFilter)
97 seq.append(merger)
98 seq.fullConfigure(config)
99 if isAthena:
100 algs = config.CA.getEventAlgos()
101 config.CA.wasMerged()
102 return algs
103 return list(algSeq)
104
105

◆ selectors()

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

Definition at line 106 of file EventSelectionConfigTestSupport.py.

106def selectors(algs):
107 """Selector algorithms only (exclude the SAVE filter)."""
108 return [a for a in algs if a.getType() != "CP::SaveFilterAlg"]
109
110

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.