ATLAS Offline Software
Loading...
Searching...
No Matches
python.root_pickle.Pickler Class Reference
Inheritance diagram for python.root_pickle.Pickler:
Collaboration diagram for python.root_pickle.Pickler:

Public Member Functions

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

Protected Member Functions

 _persistent_id (self, o)

Private Attributes

 __file = file
 __keys = file.GetListOfKeys()
 __io = Write_Wrapper()
 __pickle = pickle.Pickler (self.__io, proto)
dict __pmap = {}

Detailed Description

Definition at line 200 of file root_pickle.py.

Constructor & Destructor Documentation

◆ __init__()

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

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

Member Function Documentation

◆ _persistent_id()

python.root_pickle.Pickler._persistent_id ( self,
o )
protected

Definition at line 242 of file root_pickle.py.

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

◆ clear_memo()

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

Definition at line 235 of file root_pickle.py.

235 def clear_memo (self):
236 """Clears the pickler's internal memo."""
237 self.__pickle.memo.clear()
238 return
239
240
241

◆ dump()

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

Definition at line 217 of file root_pickle.py.

217 def dump (self, o, key=None):
218 """Write a pickled representation of o to the open TFile."""
219 if key is None:
220 key = '_pickle'
221 directory = _getdir()
222 try:
223 self.__file.cd()
224 self.__pickle.dump (o)
225 s = self.__io.getvalue()
226 self.__io.reopen()
227 s.Write (key)
228 self.__file.Flush()
229 self.__pmap.clear()
230 finally:
231 _setdir (directory)
232 return
233
234
void clear()
Empty the pool.
-event-from-file

Member Data Documentation

◆ __file

python.root_pickle.Pickler.__file = file
private

Definition at line 208 of file root_pickle.py.

◆ __io

python.root_pickle.Pickler.__io = Write_Wrapper()
private

Definition at line 210 of file root_pickle.py.

◆ __keys

python.root_pickle.Pickler.__keys = file.GetListOfKeys()
private

Definition at line 209 of file root_pickle.py.

◆ __pickle

python.root_pickle.Pickler.__pickle = pickle.Pickler (self.__io, proto)
private

Definition at line 211 of file root_pickle.py.

◆ __pmap

dict python.root_pickle.Pickler.__pmap = {}
private

Definition at line 213 of file root_pickle.py.


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