ATLAS Offline Software
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | List of all members
python.utils.AtlRunQueryCache.Cache Class Reference
Inheritance diagram for python.utils.AtlRunQueryCache.Cache:
Collaboration diagram for python.utils.AtlRunQueryCache.Cache:

Public Member Functions

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

Public Attributes

 cachedir
 
 form
 

Private Member Functions

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

Private Attributes

 _cache
 

Detailed Description

Definition at line 12 of file AtlRunQueryCache.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 13 of file AtlRunQueryCache.py.

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

Member Function Documentation

◆ __call__()

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

Definition at line 21 of file AtlRunQueryCache.py.

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

◆ __is_cached()

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

Definition at line 56 of file AtlRunQueryCache.py.

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

◆ __name_pickle_cache()

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

Definition at line 37 of file AtlRunQueryCache.py.

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

◆ __write_to_cache()

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

Definition at line 42 of file AtlRunQueryCache.py.

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

Member Data Documentation

◆ _cache

python.utils.AtlRunQueryCache.Cache._cache
private

Definition at line 14 of file AtlRunQueryCache.py.

◆ cachedir

python.utils.AtlRunQueryCache.Cache.cachedir

Definition at line 15 of file AtlRunQueryCache.py.

◆ form

python.utils.AtlRunQueryCache.Cache.form

Definition at line 16 of file AtlRunQueryCache.py.


The documentation for this class was generated from the following file:
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
Trk::open
@ open
Definition: BinningType.h:40