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 196 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 197 of file root_pickle.py.

197  def __init__ (self, file, proto=0):
198  """Create a root pickler.
199 FILE should be a Root TFile. PROTO is the python pickle protocol
200 version to use. The python part will be pickled to a Root
201 TObjString called _pickle; it will contain references to the
202 Root objects.
203 """
204  self.__file = file
205  self.__keys = file.GetListOfKeys()
206  self.__io = Write_Wrapper()
207  self.__pickle = pickle.Pickler (self.__io, proto)
208  self.__pickle.persistent_id = self._persistent_id
209  self.__pmap = {}
210  return
211 
212 

Member Function Documentation

◆ _persistent_id()

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

Definition at line 238 of file root_pickle.py.

238  def _persistent_id (self, o):
239  if hasattr (o, '_Root_Proxy__obj'):
240  o = o._Root_Proxy__obj()
241  if (isinstance (o, ROOT.TObject)):
242  # Write the object, and return the resulting NAME;CYCLE.
243  # We used to to this like this:
244  #o.Write()
245  #k = self.__file.GetKey (o.GetName())
246  #pid = "%s;%d" % (k.GetName(), k.GetCycle())
247  # It turns out, though, that destroying the python objects
248  # referencing the TKeys is quite expensive (O(logN) where
249  # N is the total number of pyroot objects?). Although
250  # we want to allow for the case of saving multiple objects
251  # with the same name, the most common case is that the name
252  # has not already been written to the file. So we optimize
253  # for that case, doing the key lookup before we write the
254  # object, not after. (Note further: GetKey() is very slow
255  # if the key does not actually exist, as it does a linear
256  # search of the key list. We use FindObject instead for the
257  # initial lookup, which is a hashed lookup, but it is not
258  # guaranteed to find the highest cycle. So if we do
259  # find an existing key, we need to look up again using GetKey.
260  nm = o.GetName()
261  k = self.__keys.FindObject(nm)
262  o.Write()
263  if k:
264  k = self.__file.GetKey (nm)
265  pid = "%s;%d" % (nm, k.GetCycle())
266  else:
267  pid = nm + ";1"
268  return pid
269  return
270 
271 
272 

◆ clear_memo()

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

Definition at line 231 of file root_pickle.py.

231  def clear_memo (self):
232  """Clears the pickler's internal memo."""
233  self.__pickle.memo.clear()
234  return
235 
236 
237 

◆ dump()

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

Definition at line 213 of file root_pickle.py.

213  def dump (self, o, key=None):
214  """Write a pickled representation of o to the open TFile."""
215  if key is None:
216  key = '_pickle'
217  directory = _getdir()
218  try:
219  self.__file.cd()
220  self.__pickle.dump (o)
221  s = self.__io.getvalue()
222  self.__io.reopen()
223  s.Write (key)
224  self.__file.Flush()
225  self.__pmap.clear()
226  finally:
227  _setdir (directory)
228  return
229 
230 

Member Data Documentation

◆ __file

python.root_pickle.Pickler.__file
private

Definition at line 204 of file root_pickle.py.

◆ __io

python.root_pickle.Pickler.__io
private

Definition at line 206 of file root_pickle.py.

◆ __keys

python.root_pickle.Pickler.__keys
private

Definition at line 205 of file root_pickle.py.

◆ __pickle

python.root_pickle.Pickler.__pickle
private

Definition at line 207 of file root_pickle.py.

◆ __pmap

python.root_pickle.Pickler.__pmap
private

Definition at line 209 of file root_pickle.py.


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