ATLAS Offline Software
Functions
python.flagTestLOD Namespace Reference

Functions

def _make_fdict (flags)
 
def _eval_deferred (expr, fdict, hookargs, **kw)
 
def flagTestLOD (expr, flags, hook=None)
 
def deferFlag (expr, flags, gdict={})
 

Function Documentation

◆ _eval_deferred()

def python.flagTestLOD._eval_deferred (   expr,
  fdict,
  hookargs,
**  kw 
)
private

Definition at line 29 of file flagTestLOD.py.

29 def _eval_deferred (expr, fdict, hookargs, **kw):
30  dd = fdict.copy()
31  dd.update (hookargs)
32  dd.update (kw)
33  return eval (expr, globals(), dd)
34 
35 
36 

◆ _make_fdict()

def python.flagTestLOD._make_fdict (   flags)
private

Definition at line 16 of file flagTestLOD.py.

16 def _make_fdict (flags):
17  if isinstance (flags, FlagAddress):
18  return flags.asdict()
19  fdict = {}
20  if not isinstance(flags, list):
21  flags = [flags]
22  for f in flags:
23  for k, v in f.__dict__.items():
24  if isinstance (v, JobProperty):
25  fdict[k] = v()
26  return fdict
27 
28 

◆ deferFlag()

def python.flagTestLOD.deferFlag (   expr,
  flags,
  gdict = {} 
)
Helper for making deferred arguments that evaluate flags.

Numerous parts of the D3PD configuration use arbitrary global flags
to control how tuples are configured.  This is bad because there
can be interference when multiple tuples are configured in the
same job.

Better is to pass the flags in as arguments to the D3PDObject and pass
them to blocks using the DeferArg mechanism.

This helper is to ease this conversion, while still allowing
backwards compatibility with flag-based configuration.

deferFlag will return a DeferArg object that evaluates
the provided expression string EXP.  This will be evaluated
in an environment that includes names for all flags in the flags
class(es) FLAGS, merged with the value of the hookargs.

So if you do something like

  myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
                                        allow_args = ['doExtra'])
  myobj.defineBlock (0, 'myblock', filler_tool,
                     DoExtra = deferFlag ('doExtra', myFlags))

then the DoExtra property will be set from the property myFlags.doExtra()
unless it's overridden by passing an argument to the D3PDObject:

  alg += myobj (level, doExtra = True)

Flags are evaluated at the point where deferFlag is called.

GDICT gives extra names to be made available when evaluating EXPR.


Examples:
>>> from AthenaCommon.JobProperties import JobPropertyContainer, JobProperty
>>> f3=JobPropertyContainer ('f3')
>>> class flag3(JobProperty):
...   statusOn = True
...   allowedTypes=['bool']
...   StoredValue = True
>>> f3.add_JobProperty(flag3)
>>> arg = deferFlag ('flag3', f3)
>>> arg()
True
>>> arg({'flag3':False})
False
>>> arg = deferFlag ('foo', f3, {'foo' : 2})
>>> arg()
2

Definition at line 128 of file flagTestLOD.py.

128 def deferFlag (expr, flags, gdict={}):
129  """Helper for making deferred arguments that evaluate flags.
130 
131  Numerous parts of the D3PD configuration use arbitrary global flags
132  to control how tuples are configured. This is bad because there
133  can be interference when multiple tuples are configured in the
134  same job.
135 
136  Better is to pass the flags in as arguments to the D3PDObject and pass
137  them to blocks using the DeferArg mechanism.
138 
139  This helper is to ease this conversion, while still allowing
140  backwards compatibility with flag-based configuration.
141 
142  deferFlag will return a DeferArg object that evaluates
143  the provided expression string EXP. This will be evaluated
144  in an environment that includes names for all flags in the flags
145  class(es) FLAGS, merged with the value of the hookargs.
146 
147  So if you do something like
148 
149  myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
150  allow_args = ['doExtra'])
151  myobj.defineBlock (0, 'myblock', filler_tool,
152  DoExtra = deferFlag ('doExtra', myFlags))
153 
154  then the DoExtra property will be set from the property myFlags.doExtra()
155  unless it's overridden by passing an argument to the D3PDObject:
156 
157  alg += myobj (level, doExtra = True)
158 
159  Flags are evaluated at the point where deferFlag is called.
160 
161  GDICT gives extra names to be made available when evaluating EXPR.
162 
163 
164  Examples:
165  >>> from AthenaCommon.JobProperties import JobPropertyContainer, JobProperty
166  >>> f3=JobPropertyContainer ('f3')
167  >>> class flag3(JobProperty):
168  ... statusOn = True
169  ... allowedTypes=['bool']
170  ... StoredValue = True
171  >>> f3.add_JobProperty(flag3)
172  >>> arg = deferFlag ('flag3', f3)
173  >>> arg()
174  True
175  >>> arg({'flag3':False})
176  False
177  >>> arg = deferFlag ('foo', f3, {'foo' : 2})
178  >>> arg()
179  2
180 """
181  fdict = _make_fdict (flags)
182  return DeferArg ('_eval_deferred(expr, fdict, locals(), **_gdict)',
183  expr = expr,
184  fdict = fdict,
185  _gdict = gdict,
186  _eval_deferred = _eval_deferred)

◆ flagTestLOD()

def python.flagTestLOD.flagTestLOD (   expr,
  flags,
  hook = None 
)
Helper for making LOD functions to evaluate flags.

Numerous parts of the D3PD configuration use arbitrary global flags
to control which blocks are included.  This is bad because there
can be interference when multiple tuples are configured in the
same job.

Better is to use the level-of-detail mechanism to do this,
passing in flags as extra arguments to the D3PDObject.

This helper is to ease this conversion, while still allowing
backwards compatibility with flag-based configuration.

flagTestLOD will return a level-of-detail function that evaluates
the provided expression string EXP.  This will be evaluated
in an environment that includes names for all flags in the flags
class(es) FLAGS, merged with the value of the hookargs.
The requested level of detail is also available as `reqlev'.
Thus, if you have something like:

    myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
                                          allow_args = ['myLevel'])
    myobj.defineBlock (flagTestLOD('myLevel>2', myFlags),
                       'myblock', filler_tool)

then myblock will be included in the tuple if the property
myFlags.myLevel() is greater than two.  However, this can be overridden
by passing an argument to the D3PDObject:

    alg += myobj (level, myLevel=4)

Explicit inclusion / exclusion also overrides this determination.

Flags are evaluated at the point where flagTestLOD is called.

If HOOK is supplied, then it is called if the LOD test passes.
It is passed as arguments two dictionaries: the block filler tool
arguments and the hook arguments.

Examples:
>>> from AthenaCommon.JobProperties import JobPropertyContainer, JobProperty
>>> f1=JobPropertyContainer ('f1')
>>> f2=JobPropertyContainer ('f2')
>>> class flag1(JobProperty):
...   statusOn = True
...   allowedTypes=['bool']
...   StoredValue = True
>>> class flag2(JobProperty):
...   statusOn = True
...   allowedTypes=['bool']
...   StoredValue = False
>>> f1.add_JobProperty(flag1)
>>> f2.add_JobProperty(flag2)
>>> lod = flagTestLOD ('flag1', f1)
>>> lod(2, {}, {})
True
>>> lod(2, {}, {'flag1': False})
False
>>> lod(-999, {}, {})
False
>>> lod(999, {}, {'flag1': False})
True
>>> lod = flagTestLOD ('flag2 or reqlev>4', [f1,f2])
>>> lod(2, {}, {})
False
>>> lod(10, {}, {})
True
>>> def hook(*args):
...    print(args)
>>> lod = flagTestLOD ('flag2 or reqlev>4', [f1,f2], hook)
>>> lod(2, {}, {})
False
>>> lod(10, {'a':1}, {'b':2})
({'a': 1}, {'b': 2})
True

Definition at line 37 of file flagTestLOD.py.

37 def flagTestLOD (expr, flags, hook = None):
38  """Helper for making LOD functions to evaluate flags.
39 
40  Numerous parts of the D3PD configuration use arbitrary global flags
41  to control which blocks are included. This is bad because there
42  can be interference when multiple tuples are configured in the
43  same job.
44 
45  Better is to use the level-of-detail mechanism to do this,
46  passing in flags as extra arguments to the D3PDObject.
47 
48  This helper is to ease this conversion, while still allowing
49  backwards compatibility with flag-based configuration.
50 
51  flagTestLOD will return a level-of-detail function that evaluates
52  the provided expression string EXP. This will be evaluated
53  in an environment that includes names for all flags in the flags
54  class(es) FLAGS, merged with the value of the hookargs.
55  The requested level of detail is also available as `reqlev'.
56  Thus, if you have something like:
57 
58  myobj = make_SGDataVector_D3PDObject ('mycont', 'mykey', 'my_', 'myob',
59  allow_args = ['myLevel'])
60  myobj.defineBlock (flagTestLOD('myLevel>2', myFlags),
61  'myblock', filler_tool)
62 
63  then myblock will be included in the tuple if the property
64  myFlags.myLevel() is greater than two. However, this can be overridden
65  by passing an argument to the D3PDObject:
66 
67  alg += myobj (level, myLevel=4)
68 
69  Explicit inclusion / exclusion also overrides this determination.
70 
71  Flags are evaluated at the point where flagTestLOD is called.
72 
73  If HOOK is supplied, then it is called if the LOD test passes.
74  It is passed as arguments two dictionaries: the block filler tool
75  arguments and the hook arguments.
76 
77  Examples:
78  >>> from AthenaCommon.JobProperties import JobPropertyContainer, JobProperty
79  >>> f1=JobPropertyContainer ('f1')
80  >>> f2=JobPropertyContainer ('f2')
81  >>> class flag1(JobProperty):
82  ... statusOn = True
83  ... allowedTypes=['bool']
84  ... StoredValue = True
85  >>> class flag2(JobProperty):
86  ... statusOn = True
87  ... allowedTypes=['bool']
88  ... StoredValue = False
89  >>> f1.add_JobProperty(flag1)
90  >>> f2.add_JobProperty(flag2)
91  >>> lod = flagTestLOD ('flag1', f1)
92  >>> lod(2, {}, {})
93  True
94  >>> lod(2, {}, {'flag1': False})
95  False
96  >>> lod(-999, {}, {})
97  False
98  >>> lod(999, {}, {'flag1': False})
99  True
100  >>> lod = flagTestLOD ('flag2 or reqlev>4', [f1,f2])
101  >>> lod(2, {}, {})
102  False
103  >>> lod(10, {}, {})
104  True
105  >>> def hook(*args):
106  ... print(args)
107  >>> lod = flagTestLOD ('flag2 or reqlev>4', [f1,f2], hook)
108  >>> lod(2, {}, {})
109  False
110  >>> lod(10, {'a':1}, {'b':2})
111  ({'a': 1}, {'b': 2})
112  True
113 """
114 
115  fdict = _make_fdict (flags)
116  def flagTestLODFunc (reqlev, args, hookargs):
117  if reqlev < 0: return False # explicit exclusion
118  if reqlev > 900:
119  ret = True # explicit inclusion
120  else:
121  ret = _eval_deferred (expr, fdict, hookargs, reqlev=reqlev)
122  if ret and hook:
123  hook (args, hookargs)
124  return ret
125  return flagTestLODFunc
126 
127 
python.flagTestLOD._eval_deferred
def _eval_deferred(expr, fdict, hookargs, **kw)
Definition: flagTestLOD.py:29
python.flagTestLOD._make_fdict
def _make_fdict(flags)
Definition: flagTestLOD.py:16
python.flagTestLOD.deferFlag
def deferFlag(expr, flags, gdict={})
Definition: flagTestLOD.py:128
python.flagTestLOD.flagTestLOD
def flagTestLOD(expr, flags, hook=None)
Definition: flagTestLOD.py:37
python.PyAthena.v
v
Definition: PyAthena.py:157