ATLAS Offline Software
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 
11 from .D3PDObject import D3PDObject
12 from AthenaConfiguration.ComponentFactory import CompFactory
13 
14 D3PD = CompFactory.D3PD
15 
16 
17 def 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 
80 def IdentityAssociation (parent, **kw):
81  """A SimpleAssociation configured with an identity association.
82 
83 This can be useful to group blocks together in subblocks.
84 """
85  return SimpleAssociation (parent,
87  **kw)
D3PD::IdentityAssociationTool
A generic identity association; i.e., one that simply returns its input.
Definition: IdentityAssociationTool.h:34
python.SimpleAssociation.SimpleAssociation
def SimpleAssociation(parent, assoctool, prefix='', matched='', level=0, blockname=None, suffix='', **kw)
Definition: SimpleAssociation.py:17
D3PD::ContainedAssociationFillerTool
Represent a single association by containment.
Definition: ContainedAssociationFillerTool.h:54
python.SimpleAssociation.IdentityAssociation
def IdentityAssociation(parent, **kw)
Definition: SimpleAssociation.py:80