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

Public Member Functions

def __init__ (self, file, proto=0)
 
def dump (self, o, key=None)
 
def clear_memo (self)
 

Private Member Functions

def _persistent_id (self, o)
 

Private Attributes

 __file
 
 __keys
 
 __io
 
 __pickle
 
 __pmap
 

Detailed Description

Definition at line 242 of file root_pickle.py.

Constructor & Destructor Documentation

◆ __init__()

def python.root_pickle.Pickler.__init__ (   self,
  file,
  proto = 0 
)
Create a root pickler.
FILE should be a Root TFile.  PROTO is the python pickle protocol
version to use.  The python part will be pickled to a Root
TObjString called _pickle; it will contain references to the
Root objects.

Definition at line 243 of file root_pickle.py.

243  def __init__ (self, file, proto=0):
244  """Create a root pickler.
245 FILE should be a Root TFile. PROTO is the python pickle protocol
246 version to use. The python part will be pickled to a Root
247 TObjString called _pickle; it will contain references to the
248 Root objects.
249 """
250  self.__file = file
251  self.__keys = file.GetListOfKeys()
252  self.__io = Write_Wrapper()
253  self.__pickle = pickle.Pickler (self.__io, proto)
254  self.__pickle.persistent_id = self._persistent_id
255  self.__pmap = {}
256  return
257 
258 

Member Function Documentation

◆ _persistent_id()

def python.root_pickle.Pickler._persistent_id (   self,
  o 
)
private

Definition at line 284 of file root_pickle.py.

284  def _persistent_id (self, o):
285  if hasattr (o, '_Root_Proxy__obj'):
286  o = o._Root_Proxy__obj()
287  if (isinstance (o, ROOT.TObject)):
288  # Write the object, and return the resulting NAME;CYCLE.
289  # We used to to this like this:
290  #o.Write()
291  #k = self.__file.GetKey (o.GetName())
292  #pid = "%s;%d" % (k.GetName(), k.GetCycle())
293  # It turns out, though, that destroying the python objects
294  # referencing the TKeys is quite expensive (O(logN) where
295  # N is the total number of pyroot objects?). Although
296  # we want to allow for the case of saving multiple objects
297  # with the same name, the most common case is that the name
298  # has not already been written to the file. So we optimize
299  # for that case, doing the key lookup before we write the
300  # object, not after. (Note further: GetKey() is very slow
301  # if the key does not actually exist, as it does a linear
302  # search of the key list. We use FindObject instead for the
303  # initial lookup, which is a hashed lookup, but it is not
304  # guaranteed to find the highest cycle. So if we do
305  # find an existing key, we need to look up again using GetKey.
306  nm = o.GetName()
307  k = self.__keys.FindObject(nm)
308  o.Write()
309  if k:
310  k = self.__file.GetKey (nm)
311  pid = "%s;%d" % (nm, k.GetCycle())
312  else:
313  pid = nm + ";1"
314  return pid
315  return
316 
317 
318 

◆ clear_memo()

def python.root_pickle.Pickler.clear_memo (   self)
Clears the pickler's internal memo.

Definition at line 277 of file root_pickle.py.

277  def clear_memo (self):
278  """Clears the pickler's internal memo."""
279  self.__pickle.memo.clear()
280  return
281 
282 
283 

◆ dump()

def python.root_pickle.Pickler.dump (   self,
  o,
  key = None 
)
Write a pickled representation of o to the open TFile.

Definition at line 259 of file root_pickle.py.

259  def dump (self, o, key=None):
260  """Write a pickled representation of o to the open TFile."""
261  if key is None:
262  key = '_pickle'
263  directory = _getdir()
264  try:
265  self.__file.cd()
266  self.__pickle.dump (o)
267  s = self.__io.getvalue()
268  self.__io.reopen()
269  s.Write (key)
270  self.__file.Flush()
271  self.__pmap.clear()
272  finally:
273  _setdir (directory)
274  return
275 
276 

Member Data Documentation

◆ __file

python.root_pickle.Pickler.__file
private

Definition at line 250 of file root_pickle.py.

◆ __io

python.root_pickle.Pickler.__io
private

Definition at line 252 of file root_pickle.py.

◆ __keys

python.root_pickle.Pickler.__keys
private

Definition at line 251 of file root_pickle.py.

◆ __pickle

python.root_pickle.Pickler.__pickle
private

Definition at line 253 of file root_pickle.py.

◆ __pmap

python.root_pickle.Pickler.__pmap
private

Definition at line 255 of file root_pickle.py.


The documentation for this class was generated from the following file:
python.root_pickle.dump
def dump(o, f, proto=0, key=None)
Definition: root_pickle.py:472
python.processes.powheg.ZZ.ZZ.__init__
def __init__(self, base_directory, **kwargs)
Constructor: all process options are set here.
Definition: ZZ.py:18
VKalVrtAthena::varHolder_detail::clear
void clear(T &var)
Definition: NtupleVars.h:48
calibdata.cd
cd
Definition: calibdata.py:51
python.root_pickle._getdir
def _getdir()
Definition: root_pickle.py:78