ATLAS Offline Software
Loading...
Searching...
No Matches
python.utils.AtlRunQueryCache.Cache Class Reference
Inheritance diagram for python.utils.AtlRunQueryCache.Cache:
Collaboration diagram for python.utils.AtlRunQueryCache.Cache:

Public Types

typedef HLT::TypeInformation::for_each_type_c< typenameEDMLIST::map, my_functor, my_result<>, my_arg< HLT::TypeInformation::get_cont, CONTAINER > >::type result

Public Member Functions

 __init__ (self, cachedir, form)
 __call__ (self, f, *args, **kwds)

Public Attributes

 cachedir = cachedir.rstrip('/') if os.path.exists(cachedir) else None
 form = form

Protected Attributes

dict _cache = {}

Private Member Functions

 __name_pickle_cache (self, key)
 __write_to_cache (self, key, value)
 __is_cached (self, key)

Detailed Description

Definition at line 11 of file AtlRunQueryCache.py.

Member Typedef Documentation

◆ result

Definition at line 90 of file EDM_MasterSearch.h.

Constructor & Destructor Documentation

◆ __init__()

python.utils.AtlRunQueryCache.Cache.__init__ ( self,
cachedir,
form )

Definition at line 12 of file AtlRunQueryCache.py.

12 def __init__(self,cachedir,form):
13 self._cache = {}
14 self.cachedir = cachedir.rstrip('/') if os.path.exists(cachedir) else None
15 self.form = form
16 if self.cachedir:
17 print ("Initializing the cache at",cachedir.rstrip('/'))
18
19

Member Function Documentation

◆ __call__()

python.utils.AtlRunQueryCache.Cache.__call__ ( self,
f,
* args,
** kwds )

Definition at line 20 of file AtlRunQueryCache.py.

20 def __call__(self, f, *args, **kwds):
21 if not self.cachedir:
22 return f # caching is automatically disabled if no cache directory exists
23
24 print ("Providing cache functionality for function '%s()'" % f.func_name)
25 def newf(*args, **kwds):
26 key = kwds['cachekey']
27 if not self.__is_cached(key):
28 self.__write_to_cache(key,f(*args, **kwds))
29 else:
30 if DEBUG:
31 print ("DEBUG: returning cached value for '%s'" % (self.form % key))
32 pass
33 return self._cache[key]
34 return newf
35

◆ __is_cached()

python.utils.AtlRunQueryCache.Cache.__is_cached ( self,
key )
private

Definition at line 55 of file AtlRunQueryCache.py.

55 def __is_cached(self,key):
56 # check transient cache
57 if key in self._cache:
58 return True
59
60 # check for pickled version
61 pfname = self.__name_pickle_cache(key)
62 try:
63 pf = open( pfname, 'r' )
64 except OSError:
65 if DEBUG:
66 print ('DEBUG: could not read from cache: ' + pfname)
67 return False
68 try:
69 self._cache[key] = pickle.load(pf)
70 except pickle.UnpicklingError as err:
71 print ("ERROR: could not unpickle %s (%s)" % (pfname, err))
72 sys.exit(1)
73 pf.close()
74 return True
75
76
77
78
79

◆ __name_pickle_cache()

python.utils.AtlRunQueryCache.Cache.__name_pickle_cache ( self,
key )
private

Definition at line 36 of file AtlRunQueryCache.py.

36 def __name_pickle_cache(self,key):
37 filename = self.form % key
38 return '%s/%s.pickle' % (self.cachedir, filename)
39
40

◆ __write_to_cache()

python.utils.AtlRunQueryCache.Cache.__write_to_cache ( self,
key,
value )
private

Definition at line 41 of file AtlRunQueryCache.py.

41 def __write_to_cache(self,key, value):
42 # put into transient cache
43 self._cache[key] = value
44
45 # store pickled version
46 pfname = self.__name_pickle_cache(key)
47 pf = open( pfname, 'w' )
48 try:
49 pickle.dump(value, pf)
50 except pickle.PicklingError as err:
51 print ('ERROR: could not write to cache: %s (%s)' % (pfname, err))
52 sys.exit(1)
53 pf.close()
54

Member Data Documentation

◆ _cache

dict python.utils.AtlRunQueryCache.Cache._cache = {}
protected

Definition at line 13 of file AtlRunQueryCache.py.

◆ cachedir

python.utils.AtlRunQueryCache.Cache.cachedir = cachedir.rstrip('/') if os.path.exists(cachedir) else None

Definition at line 14 of file AtlRunQueryCache.py.

◆ form

python.utils.AtlRunQueryCache.Cache.form = form

Definition at line 15 of file AtlRunQueryCache.py.


The documentation for this class was generated from the following file: