ATLAS Offline Software
Loading...
Searching...
No Matches
SimpleAssociation.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3#
4# @file D3PDMakerCoreComps/python/SimpleAssociation.py
5# @author scott snyder <snyder@bnl.gov>
6# @date Aug, 2009
7# @brief Helper for setting up an association to a contained object.
8#
9
10
11from .D3PDObject import D3PDObject
12from AthenaConfiguration.ComponentFactory import CompFactory
13
14D3PD = CompFactory.D3PD
15
16
17def SimpleAssociation (parent,
18 assoctool,
19 prefix = '',
20 matched = '',
21 level = 0,
22 blockname = None,
23 suffix = '',
24 **kw):
25 """Helper for setting up an association to a contained object.
26
27 parent: The parent D3PDobject or block.
28 assoctool: The class for the (single) association tool.
29 prefix: Prefix to add to the contained variables, if any.
30 matched: If not null, a flag variable with this name will
31 be created, set to true when the association succeeds.
32 level: Level of detail for the block.
33 blockname: Name for the block.
34 suffix: Suffix to add to the contained variables, if any.
35
36 Extra arguments are passed to the association tool.
37
38 Here's an example. Suppose we have a generic tool that tuples
39 Perigee objects, producing variables z0, d0, etc. Suppose that
40 we also have an `electron' object that has a method to return
41 a Perigee. We want to use the Perigee filling tool to tuple
42 these variables as a new block.
43
44 We can do this by creating an associator tool that will go from
45 an electron object to its contained Perigee object. We then configure
46 things by creating a ContainedAssociationFillerTool using this
47 associator. We then add this as a block to the electron object,
48 and then add a Perigee block to the associator block. The helper
49 here reduces the amount of boilerplate configuration code
50 we need to do this.
51
52 Usage is something like this:
53
54 ElectronObject = ...
55 ElectronPerigee = SimpleAssocation (ElectronObject,
56 electronPerigeeAssociator)
57 ElectronPerigee.defineBlock (1, 'Perigee', PerigeeFillerTool)
58
59 If the electron prefix is `el_', this would create variables
60 `el_z0', etc. With `prefix="track"', the names would be
61 `el_trackz0', etc.
62
63 If we add `matched="hastrack"', then this will add a boolean
64 variable `el_hastrack', which is true if the association succeeded.
65"""
66 if blockname is None:
67 blockname = assoctool.__name__
68
69 def maker (name, prefix, object_name, **kw2):
70 assoc = assoctool (name + 'Assoc', **kw2)
72 (name, Prefix = prefix, Suffix = suffix,
73 Associator = assoc, Matched = matched)
74
75 obj = D3PDObject (maker, prefix)
76 parent.defineBlock (level, blockname, obj, **kw)
77 return obj
78
79
80def IdentityAssociation (parent, **kw):
81 """A SimpleAssociation configured with an identity association.
82
83This can be useful to group blocks together in subblocks.
84"""
85 return SimpleAssociation (parent,
87 **kw)
Represent a single association by containment.
A generic identity association; i.e., one that simply returns its input.