ATLAS Offline Software
D3PDObject.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/D3PDObject.py
5 # @author scott snyder <snyder@bnl.gov>
6 # @date Aug, 2009
7 # @brief D3PD object creator class.
8 #
9 
10 
11 from .Block import Block
12 from AthenaCommon.Logging import logging
13 from .StackedDict import StackedDict
14 from AthenaConfiguration.ComponentFactory import CompFactory
15 
16 D3PD = CompFactory.D3PD
17 
18 
19 def _make_name (name, prefix, name_prefix, parent_prefix, default_prefix):
20  """Helper to form the name for object filler tools."""
21  if name is None:
22  pref = prefix + name_prefix
23  if len (pref) == 0: pref = default_prefix
24  if len (pref) == 0:
25  pref = 'Unnamed_'
26  name = parent_prefix + pref + 'Filler'
27  return name
28 
29 
30 def _testLOD (lod, reqlev, args, hookargs):
31  """Helper to perform LOD test.
32 
33  lod: The level-of-detail to test. Either an integer or a callable.
34  reqlev: Requested level of detail for this object. An integer.
35  args: Arguments to be passed to the block.
36  hookargs: Arguments passed to the D3PD object, to be passed
37  on to LOD functions.
38 """
39  # Decide whether to include this block.
40  # If the block's LOD is callable, call it.
41  # Otherwise, just compare.
42  if callable (lod):
43  # Allow for an optional third hookargs argument.
44  try:
45  doblock = lod (reqlev, args, hookargs)
46  except TypeError as exc:
47  if (len(exc.args) > 0 and
48  (exc.args[0].find ('takes exactly 2 arguments') >= 0 or
49  exc.args[0].find ('takes 2 positional') >= 0)):
50  doblock = lod (reqlev, args)
51  else:
52  raise
53  else:
54  doblock = (lod <= reqlev)
55 
56  return doblock
57 
58 
59 class DeferArg (object):
60  """Defer evaluating a block argument until the D3PDObject is instantiated.
61 
62  Sometimes you want to pass an argument to a block function that isn't
63  known at the time the D3PDObject is defined, for example the
64  StoreGate key to use. You could do this with a hook function
65  or a LOD function, but that's a bit cumbersome. Instead, you can
66  use DeferArg. DeferArg stores a string. If a block argument
67  has a value that's an instance of DeferArg, then this string
68  is evaluated at the time the D3PDObject is instantiated.
69  The arguments passed to the D3PDObject will be available
70  in the context in which the string is evaluated.
71  A global dictionary may be provided as an optional argument;
72  any additional keyword arguments will be merged into this
73  dictionary.
74 
75  Example:
76 
77  FooD3PDObject.defineBlock (1, 'SomeBlock', SomeTool,
78  Name = DeferArg ('"name_" + sgkey'))
79 
80  If FooD3PDObject is then instantiated with a StoreGate key of `Bar',
81  then the Name argument of this block will be set to `name_Bar'.
82 """
83  def __init__ (self, str, gdict = globals(), **kw): # noqa: B008 (globals is already a global ref.)
84  self.str = str
85  self.gdict = gdict
86  self.kw = kw
87  return
88 
89 
90  def __call__ (self, hookargs = {}, **kw):
91  gdict = self.gdict.copy()
92  gdict.update (self.kw)
93  hookargs = hookargs.copy()
94  hookargs.update (kw)
95  return eval (self.str, gdict, hookargs)
96 
97 
98 
99 class D3PDObject:
100  """D3PD object creator class.
101 
102  For each type of object written to the D3PD, create
103  an instance of this class. The arguments to the constructor
104  are a function to create the Configurable for the object filler
105  tool and a default value for the variable name prefix
106  for this block.
107 
108  After creating the instance, one calls defineBlock to define
109  the blocks of variables that can be written for this object.
110 
111  Finally, one calls the object in order to create the
112  configurable.
113 
114  So, a typical usage might look like this.
115 
116  def makeElectronD3PDObject (name, prefix,
117  getter = None,
118  sgkey = 'ElectronAODCollection')
119  if not getter:
120  getter = CompFactory.D3PD.SGDataVectorGetterTool \
121  (name + '_Getter',
122  TypeName = 'ElectronContainer',
123  SGKey = sgkey)
124 
125  return CompFactory.D3PD.VectorFillerTool (name,
126  Prefix = prefix,
127  Getter = getter)
128 
129  ElectronD3PDObject = D3PDObject (makeElectronD3PDObject, 'el_')
130 
131  ElectronD3PDObject.defineBlock (0, 'Kinematics',
132  EventCommonD3PDMaker.FourMomFillerTool)
133 
134  alg = ...
135  alg += ElectronD3PDObject (level)
136 """
137 
138  _hookArgsStore = {}
139 
140 
141  def __init__ (self, maker, default_prefix = '', default_object_name = '',
142  default_name = None, allow_args = [], **kw):
143  """Constructor.
144 
145  Arguments:
146  maker: A function to create the IObjFillerTool Configurable
147  for this object. It is called with two fixed arguments,
148  the tool name and the variable name prefix. Any other
149  arguments provided to the call will be passed through.
150  default_prefix: Default variable name prefix for objects
151  of this type.
152  default_object_name: Default D3PDObject name, something like
153  'EventInfoD3PDObject'
154  default_name: If specified, the default tool name to use
155  for these objects.
156  allow_args: Additional arguments that may be passed in when
157  instantiating the D3PDObject, but which are not
158  to be passed to the maker function. This can be
159  used to allow for additional arguments to hook
160  or level-of-detail functions.
161 
162  Any additional arguments are passed into any hook functions.
163 
164 """
165  self._maker = maker
166  self._default_object_name = default_object_name
167  self._blocks = []
168  self._hooks = []
169  self._all_blocknames = {}
170  self._default_prefix = default_prefix
171  self._default_name = default_name
172  self._hookArgs = kw
173  self._parent = None
174  self._allow_args = allow_args
175  return
176 
177 
178  def defineBlock (self, lod, name, func, prefix = None, **kw):
179  """Define a new block of variables for this object type.
180 
181  Arguments:
182  lod: Level of detail of this block. See below.
183  name: Name of this block.
184  func: Function to create the block Configurable.
185  prefix: Variable name prefix for this block.
186  kw: Arguments to pass to the creation function.
187 
188  The creation function will be called like this:
189 
190  b.func (name, BlockName = blockname, **b.kw)
191 
192  where name is the name for the tool.
193 
194  However, if b.func is a class deriving from D3PDObject, then the creation
195  function will instead be called like this:
196 
197  b.func (level, name, parent_prefix, **b.kw)
198 
199  LOD is used to control whether this block should be included.
200 
201  In the simple case, this is an integer, and the block is included
202  if the block's level of detail is less than or equal to the
203  requested level of detail (unless the block was explicitly
204  included or excluded).
205 
206  In the general case, LOD may be a function. The first two arguments
207  passed to the function will be the requested level of detail
208  and the block filler
209  arguments. The requested level of detail will be an integer;
210  it will be 999 if the block was explicitly included, and -999
211  if the block was explicitly excluded. The block filler arguments
212  is a dictionary of keyword arguments. The LOD function should
213  return a boolean value saying whether or not the block should
214  be included. It may also alter the dictionary of arguments
215  (this overrides all other argument settings).
216  The LOD function may optionally take a third argument; if present,
217  this is a dictionary of the arguments passed to the D3PDObject
218  (the same arguments that are passed to hook functions).
219 """
220  if prefix is not None:
221  kw = kw.copy()
222  kw['Prefix'] = prefix
223 
224  # Record this block name.
225  # Also recursively record any blocks that it contains.
226  # This will check that the names are unique.
227  self._add_blockname (name)
228  if isinstance (func, D3PDObject):
229  for n in func.allBlocknames():
230  self._add_blockname (n)
231  func._parent = self
232  func._allow_args = self._allow_args
233 
234  self._blocks.append (Block (name, lod, func, kw))
235  return self._blocks[-1]
236 
237 
238  def removeBlock (self, name, allowMissing = False):
239  """Remove the block NAME from this object."""
240  bb = None
241  for b in self._blocks:
242  if isinstance (b.func, D3PDObject):
243  if b.func.removeBlock (name, True):
244  return True
245  if b.name == name:
246  bb = b
247  break
248 
249  if not bb:
250  if allowMissing:
251  return False
252  raise ValueError ('Unknown block name: ', name)
253 
254  self._blocks.remove (bb)
255  self._remove_blockname (name)
256  if isinstance (bb.func, D3PDObject):
257  for n in bb.func.allBlocknames():
258  self._remove_blockname (n)
259 
260  return True
261 
262 
263  def defineHook (self, hook):
264  """Define a new hook function for this D3PD object.
265 
266  HOOK is a function that will be called for each instance
267  of this D3PD object after all block filler tools have been
268  added.
269 
270  The arguments to the hook function are the object filler tool,
271  followed by the arguments that were passed to __call__.
272 """
273  self._hooks.append (hook)
274 
275 
276  def _add_blockname (self, n, warnonly = False):
277  """Add a new block name N to the list of all names.
278  Raises an exception if a block name is duplicated.
279 """
280  if n in self._all_blocknames:
281  if warnonly:
282  log = logging.getLogger ('D3PDObject')
283  log.warn ('Duplicate block name: %s (%s %s %s)',
284  n,
285  self._default_prefix,
286  self._default_name,
288  else:
289  raise ValueError ('Duplicate block name: %s (%s %s %s)' %
290  (n,
291  self._default_prefix,
292  self._default_name,
293  self._default_object_name))
294  self._all_blocknames[n] = 1
295  if self._parent:
296  self._parent._add_blockname (n, True)
297  return
298 
299 
300  def _remove_blockname (self, n):
301  """Remove block name N."""
302  del self._all_blocknames[n]
303  if self._parent:
304  self._parent._remove_blockname (n)
305  return
306 
307 
308  def allBlocknames (self):
309  """Return a dictionary the keys of which are the names of all blocks
310  defined for this object. This list will include any blocks defined
311  recursively.
312 """
313  return self._all_blocknames
314 
315 
316  def __call__ (self,
317  level,
318  name = None,
319  prefix = None,
320  name_prefix = '',
321  parent_prefix = '',
322  object_name = None,
323  include = [],
324  exclude = [],
325  blockargs = {},
326  parent_hookargs = None,
327  *args, **kw):
328  """Create a Configurable to fill an object of this type.
329 
330  Arguments:
331  level: Requested level of detail for this object. An integer.
332  name: Tool name. If omitted, one will be constructed.
333  prefix: Variable name prefix for this object.
334  name_prefix: If name wasn't specified, this is a prefix
335  to add to the tool name.
336  parent_prefix: Variable name prefix for any parent tool.
337  object_name: Name of the D3PDObject, like 'EventInfoD3PDObject'
338  include: List of block names to include, regardless
339  of level of detail.
340  exclude: List of block names to exclude, regardless
341  of level of detail.
342  blockargs: Extra arguments to pass to block filler tools.
343  The keys are block names.
344  Values are dictionaries of keyword arguments.
345  These override anything specified in defineBlock.
346  parent_hookargs: [Not to be used by user code.]
347  Dictionary of hook args from the parent,
348  to be merged into our hook arg dictionary.
349  args, kw: Additional arguments to pass to the maker function.
350  However, any entries in KW that have the form
351  BLOCK_parm, where BLOCK is a known block name,
352  will instead be interpreted as arguments to pass
353  to a block filler tool. These override entries
354  in BLOCKARGS.
355 """
356 
357  # Prefix defaults to that given to the constructor.
358  if prefix is None:
359  prefix = self._default_prefix
360 
361  # Object name defaults to that given in the constructor
362  if object_name is None:
363  object_name = self._default_object_name
364 
365  # The tool name.
366  if name is None:
367  name = self._default_name
368  name = _make_name (name, prefix, name_prefix, parent_prefix,
369  self._default_prefix)
370 
371  # Copy blockargs and kw.
372  blockargs = dict ([(k, v.copy()) for (k, v) in blockargs.items()])
373  kw = kw.copy()
374 
375  # Move any block filler args from kw to blockargs.
376  for k in list (kw.keys()):
377  # It is possible for block names themselves to contain
378  # underscores. So in the case we have more than one underscore
379  # in the name, try all prefixes we can make, stopping at
380  # the first (shortest) match.
381  kk = k.split('_')
382  for i in range(1, len(kk)):
383  this_key = '_'.join (kk[:i])
384  if this_key in self._all_blocknames:
385  this_var = '_'.join (kk[i:])
386  blockargs.setdefault(this_key,{})[this_var] = kw[k]
387  del kw[k]
388  break
389 
390  # Don't pass extra args listed in allow_args to the maker function.
391  kw2 = kw.copy()
392  for k in self._allow_args:
393  if k in kw2: del kw2[k]
394 
395  # Call the maker function.
396  try:
397  c = self._maker (name=name, prefix=prefix, object_name=object_name,
398  *args, **kw2) # noqa: B026 (star-arg unpacking after keyword OK here
399  # because we are handling failures below)
400  except TypeError as exc:
401  if (len(exc.args) > 0 and
402  exc.args[0].find ("unexpected keyword argument 'object_name'") >= 0):
403  log = logging.getLogger ('D3PDObject')
404  log.warn ("Maker function missing `object_name' formal arg: %s", self._maker)
405  c = self._maker (name=name, prefix=prefix, *args, **kw2) # noqa: B026 (see above)
406  else:
407  raise
408 
409  # Construct arguments to pass to hooks.
410  # Use a StackedDict: that allows any additions that a LOD function
411  # makes to hookargs to be visible in the rest of the D3PDObject.
412  if parent_hookargs is None:
413  parent_hookargs = {}
414  local_hookargs = {}
415  hookargs = StackedDict (local_hookargs, kw,
416  self._hookArgs, parent_hookargs)
417  local_hookargs['level'] = level
418  local_hookargs['name'] = name
419  local_hookargs['prefix'] = prefix
420  local_hookargs['name_prefix'] = name_prefix
421  local_hookargs['parent_prefix'] = parent_prefix
422  local_hookargs['include'] = include
423  local_hookargs['exclude'] = exclude
424  local_hookargs['blockargs'] = blockargs
425  local_hookargs['d3pdo'] = self
426 
427  # Create block filler tools.
428  self._makeBlockFillers (c, level, parent_prefix + prefix,
429  include, exclude, blockargs, hookargs)
430 
431  # We used to run the hooks from here.
432  # But in that case, we don't have access to the containing
433  # algorithm --- too early for that.
434  # So we break out the running of the hooks to a separate method
435  # that gets called after the tool gets added to the algorithm.
436  # A catch, though, is that we have to remember the arguments
437  # that we pass to the hook functions. We can't attach it
438  # to the configurable, since it doesn't have a dictionary.
439  # Instead, we need to keep a dictionary here of the tools
440  # and the corresponding hook args.
441  D3PDObject._hookArgsStore[c.getName()] = (self._hooks, args, hookargs)
442  return c
443 
444 
445  @staticmethod
446  def runHooks (c, flags, acc):
447  """Run creation hooks for configurable C.
448 
449 Should be run by the D3PD maker algorithm; not for general use.
450 """
451  info = D3PDObject._hookArgsStore.get (c.getName())
452  if info:
453  (hooks, args, hookargs) = info
454  for h in hooks:
455  h (c,
456  flags,
457  acc,
458  *args,
459  **dict(hookargs)
460  )
461  return
462 
463 
464  def blockFillers (self,
465  level,
466  parent_name,
467  parent_prefix = '',
468  include = [],
469  exclude = [],
470  blockargs = {},
471  hookargs = {}):
472  """Return a list of block filler tool configurables.
473 
474  Arguments:
475  level: Requested level of detail for this object. An integer.
476  parent_name: Name of the parent component.
477  parent_prefix: Variable name prefix for any parent tool.
478  include: List of block names to include, regardless
479  of level of detail.
480  exclude: List of block names to exclude, regardless
481  of level of detail.
482  blockargs: Extra arguments to pass to block filler tools.
483  The keys are block names.
484  Values are dictionaries of keyword arguments.
485  These override anything specified in defineBlock.
486  hookargs: Arguments passed to the D3PD object, to be passed
487  on to LOD functions.
488  """
489  out = []
490  for b in self._blocks:
491  # Find the requested level.
492  if b.name in include:
493  # Always request inclusion.
494  reqlev = 999
495  elif b.name in exclude:
496  # Always request exclusion.
497  reqlev = -999
498  else:
499  # Request level passed in.
500  reqlev = level
501 
502  # Block filler arguments.
503  args = b.kw.copy()
504  args.update (blockargs.get (b.name, {}))
505 
506  # Need to copy lists in arguments; otherwise, += operations
507  # can modify the saved value.
508  # Also evaluate deferred arguments here: need to do it before
509  # calling the LOD function, as that should have the final
510  # say about any changes in the argument list.
511  for k, v in args.items():
512  if isinstance(v, list):
513  args[k] = v[:]
514  if isinstance(v, DeferArg):
515  args[k] = v(hookargs)
516 
517  if _testLOD (b.lod, reqlev, args, hookargs):
518  fillername = parent_name + '_' + b.name
519  if isinstance (b.func, D3PDObject): # ugly!
520  for k in self._allow_args:
521  if k in hookargs:
522  args[k] = hookargs[k]
523  bf = b.func (level, fillername,
524  parent_prefix = parent_prefix,
525  include = include,
526  exclude = exclude,
527  blockargs = blockargs,
528  parent_hookargs = hookargs,
529  **args)
530  else:
531  bf = b.func (fillername, **args)
532 
533  out += [bf]
534  if b._hooks:
535  D3PDObject._hookArgsStore[bf.getName()] = (b._hooks, args, hookargs)
536 
537  return out
538 
539 
540  def _makeBlockFillers (self,
541  c,
542  level,
543  parent_prefix,
544  include,
545  exclude,
546  blockargs,
547  hookargs):
548  """Create block filler tools for object C, for the specified
549  level of detail.
550 
551  Arguments:
552  c: Object for which to create the block fillers.
553  level: Requested level of detail for this object. An integer.
554  parent_prefix: Variable name prefix for any parent tool.
555  include: List of block names to include, regardless
556  of level of detail.
557  exclude: List of block names to exclude, regardless
558  of level of detail.
559  blockargs: Extra arguments to pass to block filler tools.
560  The keys are block names.
561  Values are dictionaries of keyword arguments.
562  These override anything specified in defineBlock.
563  hookargs: Arguments passed to the D3PD object, to be passed
564  on to LOD functions.
565 """
566  for bf in self.blockFillers (level, c.getName(), parent_prefix,
567  include, exclude, blockargs,
568  hookargs):
569  c.BlockFillers += [bf]
570  return
571 
572 
573 
574  def copy (self,
575  default_prefix = None,
576  default_object_name = None,
577  default_name = None,
578  **kw_in):
579  """Return a copy of this D3PD object, possibly changing parameters."""
580  if default_prefix is None:
581  default_prefix = self._default_prefix
582  if default_object_name is None:
583  default_object_name = self._default_object_name
584  if default_name is None:
585  default_name = self._default_name
586  kw = self._hookArgs.copy()
587  kw.update (kw_in)
588 
589  c = D3PDObject (self._maker,
590  default_prefix,
591  default_object_name,
592  default_name,
593  **kw)
594 
595  #def defineBlock (self, lod, name, func, prefix = None, **kw):
596  for b in self._blocks:
597  func = b.func
598  if isinstance (func, D3PDObject):
599  func = func.copy()
600  c.defineBlock (b.lod, b.name, func, **b.kw)
601 
602  for h in self._hooks:
603  c.defineHook (h)
604 
605  return c
606 
607 
608 def make_Void_D3PDObject (default_prefix = '',
609  default_object_name = '',
610  default_name = None,
611  allow_args = []):
612  """Helper to make a D3PDObject for the case where no explicit
613 input object is being used.
614 
615  Arguments:
616  default_prefix: The default prefix to put in front of variables.
617  default_object_name: The name of the D3PDObject which is created,
618  like 'EventInfoD3PDObject'
619  default_name: If specified, the default tool name to use
620  for these objects.
621  allow_args: Additional arguments that may be passed in when
622  instantiating the D3PDObject, but which are not
623  to be passed to the maker function. This can be
624  used to allow for additional arguments to hook
625  or level-of-detail functions.
626 
627  Typical usage would be something like this:
628 
629  METD3PDObject = \
630  make_Void_D3PDObject ('trig_', 'METD3PDObject')
631 
632 """
633  def make_obj (name, prefix, object_name):
634  from D3PDMakerConfig.D3PDMakerFlags import D3PDMakerFlags
635  return D3PD.VoidObjFillerTool (name,
636  Prefix = prefix,
637  ObjectName = object_name,
638  SaveMetadata = \
639  D3PDMakerFlags.SaveObjectMetadata)
640  return D3PDObject (make_obj, default_prefix, default_object_name,
641  default_name = default_name,
642  allow_args = allow_args)
643 
644 
645 
646 def make_SG_D3PDObject (default_typeName,
647  default_sgkey,
648  default_prefix,
649  default_object_name = None,
650  default_allowMissing = False,
651  default_getterClass = D3PD.SGObjGetterTool,
652  allow_args = []):
653  """Helper to make a D3PDObject for the common case where the default
654 input source is a single object from StoreGate.
655 
656  Arguments:
657  default_typeName: The default name of the type being
658  fetched from StoreGate.
659  default_sgkey: The default value for the StoreGate key.
660  default_prefix: The default prefix to put in front of variables.
661  default_object_name: The name of the D3PDObject which is created,
662  like 'EventInfoD3PDObject'
663  default_allowMissing: The default value for the AllowMissing
664  property (defaults to False).
665  default_getterClass: Default value to use for the getter class,
666  when we create the getter. Defaults to SGObjGetterTool.
667  allow_args: Additional arguments that may be passed in when
668  instantiating the D3PDObject, but which are not
669  to be passed to the maker function. This can be
670  used to allow for additional arguments to hook
671  or level-of-detail functions.
672 
673  Typical usage would be something like this:
674 
675  METD3PDObject = \
676  make_SG_D3PDObject ('MissingET',
677  D3PDMakerFlags.MissingETSGKey,
678  'met_', 'METD3PDObject')
679 
680 """
681  def make_obj (name, prefix, object_name,
682  getter = None,
683  sgkey = None,
684  allowMissing = default_allowMissing,
685  typeName = default_typeName,
686  getterClass = default_getterClass):
687  if sgkey is None: sgkey = default_sgkey
688  if not getter:
689  getter = getterClass (name + '_Getter',
690  TypeName = typeName,
691  SGKey = sgkey)
692  from D3PDMakerConfig.D3PDMakerFlags import D3PDMakerFlags
693  return D3PD.ObjFillerTool (name,
694  Prefix = prefix,
695  Getter = getter,
696  ObjectName = object_name,
697  AllowMissing=allowMissing,
698  SaveMetadata = \
699  D3PDMakerFlags.SaveObjectMetadata)
700 
701  if default_object_name is None:
702  default_object_name = default_typeName
703  default_object_name = default_object_name.split('::')[-1]
704 
705  return D3PDObject (make_obj, default_prefix, default_object_name,
706  sgkey = default_sgkey,
707  typeName = default_typeName,
708  allow_args = allow_args)
709 
710 
711 
712 def make_SGDataVector_D3PDObject (default_typeName,
713  default_sgkey,
714  default_prefix,
715  default_object_name = None,
716  default_allowMissing = False,
717  default_getterFilter = None,
718  default_label = None,
719  default_getterClass = \
720  D3PD.SGDataVectorGetterTool,
721  allow_args = [],
722  **other_defaults):
723  """Helper to make a D3PDObject for the common case where the default
724 input source is a DataVector container from StoreGate.
725 
726  Arguments:
727  default_typeName: The default name of the type being
728  fetched from StoreGate.
729  default_sgkey: The default value for the StoreGate key.
730  default_prefix: The default prefix to put in front of variables.
731  default_object_name: The name of the D3PDObject which is created,
732  like 'EventInfoD3PDObject'
733  default_allowMissing: The default value for the AllowMissing
734  property (defaults to False).
735  default_label: The default value to use for the collection label
736  (default to the prefix).
737  default_getterFilter: A collection getter filter to wrap
738  around the primary getter (defaults to no filter).
739  If this is a string, then it is interpreted as the
740  StoreGate key of a SelectedParticles object to use
741  to do the filtering.
742  default_getterClass: Default value to use for the getter class,
743  when we create the getter. Defaults to SGDataVectorGetterTool,
744  which is appropriate for iterating over a DataVector.
745  allow_args: Additional arguments that may be passed in when
746  instantiating the D3PDObject, but which are not
747  to be passed to the maker function. This can be
748  used to allow for additional arguments to hook
749  or level-of-detail functions.
750 
751  Typical usage would be something like this:
752 
753  JetD3PDObject = \
754  make_SGDataVector_D3PDObject ('JetCollection',
755  D3PDMakerFlags.JetSGKey,
756  'jet_', 'JetD3PDObject')
757 
758  In addition, each object has automatically defined a
759  ContainerFlagFillerTool block named `SelectionFlags'.
760  This means that you can pass in an argument like
761 
762  SelectionFlags_FlagNames [ 'selected@MyContainerType/mine:Objects in mine' ]
763 
764  This will create a flag variable `selected' which will be true if
765  the object contained in the SG container MyContainerType/mine.
766  The string after the colon is used for documentation.
767 """
768  def make_obj (name, prefix, object_name,
769  getter = None,
770  sgkey = None,
771  label = default_label,
772  allowMissing = default_allowMissing,
773  getterFilter = default_getterFilter,
774  typeName = default_typeName,
775  getterClass = default_getterClass,
776  **kw):
777  if sgkey is None: sgkey = default_sgkey
778  if label is None: label = prefix
779  if not getter:
780  getter = getterClass (name + '_Getter',
781  TypeName = typeName,
782  SGKey = sgkey,
783  Label = label)
784  if getterFilter:
785  if isinstance(getterFilter, str):
786  selgetter = D3PD.SGObjGetterTool \
787  (name + '_SelectionGetter',
788  TypeName = 'SelectedParticles',
789  SGKey = getterFilter)
791  (name + '_GetterFilter',
792  Getter = getter,
793  SelectionGetter = selgetter)
794  else:
795  getter = getterFilter (name + '_GetterFilter',
796  Getter = getter)
797  defs = other_defaults.copy()
798  defs.update (kw)
799  from D3PDMakerConfig.D3PDMakerFlags import D3PDMakerFlags
800  return D3PD.VectorFillerTool (name,
801  Prefix = prefix,
802  Getter = getter,
803  ObjectName = object_name,
804  AllowMissing=allowMissing,
805  SaveMetadata = \
806  D3PDMakerFlags.SaveObjectMetadata,
807  **defs)
808 
809  if default_object_name is None:
810  default_object_name = default_typeName
811  if default_object_name.endswith ('Collection'):
812  default_object_name = default_object_name[:-10]
813  if default_object_name.endswith ('Container'):
814  default_object_name = default_object_name[:-9]
815  default_object_name = default_object_name.split('::')[-1]
816 
817  ret = D3PDObject (make_obj, default_prefix, default_object_name,
818  sgkey = default_sgkey,
819  typeName = default_typeName,
820  allow_args = allow_args)
821 
822  # Automatically add SelectionFlags to each object.
823  # It won't actually create any variables unless the Flags property is set.
824  ret.defineBlock (0, 'SelectionFlags',
826 
827  return ret
828 
python.D3PDObject.make_SGDataVector_D3PDObject
def make_SGDataVector_D3PDObject(default_typeName, default_sgkey, default_prefix, default_object_name=None, default_allowMissing=False, default_getterFilter=None, default_label=None, default_getterClass=\ D3PD.SGDataVectorGetterTool, allow_args=[], **other_defaults)
Definition: D3PDObject.py:712
python.D3PDObject.D3PDObject.defineHook
def defineHook(self, hook)
Definition: D3PDObject.py:263
D3PD::SelectedParticlesFilterTool
A collection getter that filters the results of another based on the contents of a SelectedParticles ...
Definition: SelectedParticlesFilterTool.h:46
python.D3PDObject.D3PDObject
Definition: D3PDObject.py:99
python.D3PDObject.DeferArg
Definition: D3PDObject.py:59
python.D3PDObject._make_name
def _make_name(name, prefix, name_prefix, parent_prefix, default_prefix)
Definition: D3PDObject.py:19
python.D3PDObject.D3PDObject.removeBlock
def removeBlock(self, name, allowMissing=False)
Definition: D3PDObject.py:238
python.D3PDObject.D3PDObject._hookArgs
_hookArgs
Definition: D3PDObject.py:171
python.D3PDObject.D3PDObject.allBlocknames
def allBlocknames(self)
Definition: D3PDObject.py:308
D3PD::SGObjGetterTool
Getter tool to retrieve single objects from StoreGate.
Definition: SGObjGetterTool.h:48
python.D3PDObject.D3PDObject.runHooks
def runHooks(c, flags, acc)
Definition: D3PDObject.py:446
python.D3PDObject.D3PDObject._default_object_name
_default_object_name
Definition: D3PDObject.py:165
python.D3PDObject.make_SG_D3PDObject
def make_SG_D3PDObject(default_typeName, default_sgkey, default_prefix, default_object_name=None, default_allowMissing=False, default_getterClass=D3PD.SGObjGetterTool, allow_args=[])
Definition: D3PDObject.py:646
python.D3PDObject.DeferArg.str
str
Definition: D3PDObject.py:84
python.D3PDObject.DeferArg.__call__
def __call__(self, hookargs={}, **kw)
Definition: D3PDObject.py:90
D3PD::VoidObjFillerTool
Object filler tool for tools taking no input.
Definition: VoidObjFillerTool.h:48
python.D3PDObject.D3PDObject._add_blockname
def _add_blockname(self, n, warnonly=False)
Definition: D3PDObject.py:276
python.D3PDObject.make_Void_D3PDObject
def make_Void_D3PDObject(default_prefix='', default_object_name='', default_name=None, allow_args=[])
Definition: D3PDObject.py:608
python.D3PDObject.D3PDObject.defineBlock
def defineBlock(self, lod, name, func, prefix=None, **kw)
Definition: D3PDObject.py:178
python.D3PDObject.D3PDObject._remove_blockname
def _remove_blockname(self, n)
Definition: D3PDObject.py:300
python.D3PDObject._testLOD
def _testLOD(lod, reqlev, args, hookargs)
Definition: D3PDObject.py:30
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.D3PDObject.D3PDObject._maker
_maker
Definition: D3PDObject.py:164
python.D3PDObject.D3PDObject._blocks
_blocks
Definition: D3PDObject.py:166
D3PD::ObjFillerTool
Object filler tool for a single object.
Definition: ObjFillerTool.h:52
python.D3PDObject.DeferArg.__init__
def __init__(self, str, gdict=globals(), **kw)
Definition: D3PDObject.py:83
python.D3PDObject.D3PDObject._default_prefix
_default_prefix
Definition: D3PDObject.py:169
python.D3PDObject.D3PDObject.__call__
def __call__(self, level, name=None, prefix=None, name_prefix='', parent_prefix='', object_name=None, include=[], exclude=[], blockargs={}, parent_hookargs=None, *args, **kw)
Definition: D3PDObject.py:316
python.D3PDObject.D3PDObject.blockFillers
def blockFillers(self, level, parent_name, parent_prefix='', include=[], exclude=[], blockargs={}, hookargs={})
Definition: D3PDObject.py:464
python.PyAthena.v
v
Definition: PyAthena.py:154
python.D3PDObject.DeferArg.kw
kw
Definition: D3PDObject.py:86
python.D3PDObject.D3PDObject._parent
_parent
Definition: D3PDObject.py:172
python.D3PDObject.D3PDObject._default_name
_default_name
Definition: D3PDObject.py:170
python.D3PDObject.DeferArg.gdict
gdict
Definition: D3PDObject.py:85
pickleTool.object
object
Definition: pickleTool.py:30
python.D3PDObject.D3PDObject._allow_args
_allow_args
Definition: D3PDObject.py:173
calibdata.copy
bool copy
Definition: calibdata.py:27
python.D3PDObject.D3PDObject.__init__
def __init__(self, maker, default_prefix='', default_object_name='', default_name=None, allow_args=[], **kw)
Definition: D3PDObject.py:141
D3PD::ContainerFlagFillerTool
Flag objects that are present in other containers.
Definition: ContainerFlagFillerTool.h:42
python.D3PDObject.D3PDObject._all_blocknames
_all_blocknames
Definition: D3PDObject.py:168
python.D3PDObject.D3PDObject._makeBlockFillers
def _makeBlockFillers(self, c, level, parent_prefix, include, exclude, blockargs, hookargs)
Definition: D3PDObject.py:540
D3PD::VectorFillerTool
Object filler tool for a collection of objects, saved as vectors.
Definition: VectorFillerTool.h:70
python.D3PDObject.D3PDObject._hooks
_hooks
Definition: D3PDObject.py:167
python.D3PDObject.D3PDObject.copy
def copy(self, default_prefix=None, default_object_name=None, default_name=None, **kw_in)
Definition: D3PDObject.py:574