ATLAS Offline Software
Loading...
Searching...
No Matches
python.AccumulatorCache Namespace Reference

Classes

class  DataHandle
class  NotHashable
class  AccumulatorCachable
class  AccumulatorDecorator

Functions

 make_hashable (obj)
 AccumulatorCache (func=None, maxSize=128, verifyResult=AccumulatorDecorator.VERIFY_NOTHING, deepCopy=True)

Variables

 _msg = logging.getLogger('AccumulatorCache')

Function Documentation

◆ AccumulatorCache()

AccumulatorCache ( func = None,
maxSize = 128,
verifyResult = AccumulatorDecorator.VERIFY_NOTHING,
deepCopy = True )
Function decorator, implements memoization.

Keyword arguments:
    maxSize: maximum size for the cache associated with the function (default 128)
    verifyResult:   takes two possible values
                    
                    AccumulatorDecorator.VERIFY_NOTHING -   default, the cached function result is returned with no verification
                    AccumulatorDecorator.VERIFY_HASH -      before returning the cached function value, the hash of the
                                                            result is checked to verify if this object was not modified
                                                            between function calls
    deepCopy:   if True (default) a deep copy of the function result will be stored in the cache.

Returns:
    An instance of AccumulatorDecorator.

Definition at line 247 of file AccumulatorCache.py.

248 verifyResult = AccumulatorDecorator.VERIFY_NOTHING, deepCopy = True):
249 """Function decorator, implements memoization.
250
251 Keyword arguments:
252 maxSize: maximum size for the cache associated with the function (default 128)
253 verifyResult: takes two possible values
254
255 AccumulatorDecorator.VERIFY_NOTHING - default, the cached function result is returned with no verification
256 AccumulatorDecorator.VERIFY_HASH - before returning the cached function value, the hash of the
257 result is checked to verify if this object was not modified
258 between function calls
259 deepCopy: if True (default) a deep copy of the function result will be stored in the cache.
260
261 Returns:
262 An instance of AccumulatorDecorator.
263 """
264
265 def wrapper_accumulator(func):
266 return AccumulatorDecorator(func, maxSize, verifyResult, deepCopy)
267
268 return wrapper_accumulator(func) if func else wrapper_accumulator

◆ make_hashable()

make_hashable ( obj)
Make obj hashable by turning mutable lists into non-mutable tuples.
This is e.g. useful when kwargs is passed to a cached Cfg function and
contains non-hashable lists.
This transformation is usually safe because list-valued properties can
be set from a tuple or list.

Example:  myCfg(**make_hashable(kwargs))

Definition at line 22 of file AccumulatorCache.py.

22def make_hashable(obj):
23 """Make obj hashable by turning mutable lists into non-mutable tuples.
24 This is e.g. useful when kwargs is passed to a cached Cfg function and
25 contains non-hashable lists.
26 This transformation is usually safe because list-valued properties can
27 be set from a tuple or list.
28
29 Example: myCfg(**make_hashable(kwargs))
30 """
31 if isinstance(obj, list):
32 return tuple(make_hashable(item) for item in obj)
33 elif isinstance(obj, dict):
34 return {key: make_hashable(value) for key, value in obj.items()}
35 elif isinstance(obj, set):
36 return {make_hashable(item) for item in obj}
37 return obj
38
39

Variable Documentation

◆ _msg

python.AccumulatorCache._msg = logging.getLogger('AccumulatorCache')
protected

Definition at line 6 of file AccumulatorCache.py.