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 11 of file AtlRunQueryCache.py.

Constructor & Destructor Documentation

◆ __init__()

def 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__()

def 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()

def 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()

def 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()

def 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

python.utils.AtlRunQueryCache.Cache._cache
private

Definition at line 13 of file AtlRunQueryCache.py.

◆ cachedir

python.utils.AtlRunQueryCache.Cache.cachedir

Definition at line 14 of file AtlRunQueryCache.py.

◆ form

python.utils.AtlRunQueryCache.Cache.form

Definition at line 15 of file AtlRunQueryCache.py.


The documentation for this class was generated from the following file:
hist_file_dump.f
f
Definition: hist_file_dump.py:140
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