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

Public Member Functions

 __init__ (self, file, use_proxy=True, use_hash=False)
 load (self, key=None)
 persistent_load (self, pid)
 find_class (self, module, name)

Private Attributes

 __use_proxy = use_proxy
 __file = file
 __io = Read_Wrapper()
int __n = 0

Detailed Description

Definition at line 310 of file root_pickle.py.

Constructor & Destructor Documentation

◆ __init__()

python.root_pickle.Unpickler.__init__ ( self,
file,
use_proxy = True,
use_hash = False )
Create a root unpickler.
FILE should be a Root TFile.

Definition at line 311 of file root_pickle.py.

311 def __init__ (self, file, use_proxy = True, use_hash = False):
312 """Create a root unpickler.
313FILE should be a Root TFile.
314"""
315 self.__use_proxy = use_proxy
316 self.__file = file
317 self.__io = Read_Wrapper()
318 pickle.Unpickler.__init__ (self, self.__io)
319
320 self.__n = 0
321 xsave.add (file)
322
323 if use_hash:
324 htab = {}
325 ctab = {}
326 for k in file.GetListOfKeys():
327 nm = k.GetName()
328 cy = k.GetCycle()
329 htab[(nm,cy)] = k
330 if cy > ctab.get(nm,0):
331 ctab[nm] = cy
332 htab[(nm,9999)] = k
333 file._htab = htab
334 oget = file.Get
335 def xget (nm0):
336 nm = nm0
337 ipos = nm.find (';')
338 if ipos >= 0:
339 cy = nm[ipos+1]
340 if cy == '*':
341 cy = 10000
342 else:
343 cy = int(cy)
344 nm = nm[:ipos-1]
345 else:
346 cy = 9999
347 ret = htab.get ((nm,cy), None)
348 if not ret:
349 print ("did't find", nm, cy, len(htab))
350 return oget (nm0)
351 #ctx = ROOT.TDirectory.TContext (file)
352 ret = ret.ReadObj()
353 #del ctx
354 return ret
355 file.Get = xget
356 return
357
358

Member Function Documentation

◆ find_class()

python.root_pickle.Unpickler.find_class ( self,
module,
name )

Definition at line 387 of file root_pickle.py.

387 def find_class (self, module, name):
388 if module == 'copy_reg':
389 module = 'copyreg'
390 elif module == '__builtin__':
391 module = 'builtins'
392 try:
393 try:
394 __import__(module)
395 mod = sys.modules[module]
396 except ImportError:
397 print ("Making dummy module %s" % (module))
398 class DummyModule:
399 pass
400 mod = DummyModule()
401 sys.modules[module] = mod
402 klass = getattr(mod, name)
403 return klass
404 except AttributeError:
405 print ("Making dummy class %s.%s" % (module, name))
406 mod = sys.modules[module]
407 class Dummy(object):
408 pass
409 setattr (mod, name, Dummy)
410 return Dummy
411 return
412
413
414

◆ load()

python.root_pickle.Unpickler.load ( self,
key = None )
Read a pickled object representation from the open file.

Definition at line 359 of file root_pickle.py.

359 def load (self, key=None):
360 """Read a pickled object representation from the open file."""
361 if key is None:
362 key = '_pickle'
363 o = None
364 if _compat_hooks:
365 save = _compat_hooks[0]()
366 try:
367 self.__n += 1
368 s = self.__file.Get (key + ';%d' % self.__n)
369 self.__io.setvalue (s)
370 o = pickle.Unpickler.load(self)
371 self.__io.reopen ()
372 finally:
373 if _compat_hooks:
374 save = _compat_hooks[1](save)
375 return o
376

◆ persistent_load()

python.root_pickle.Unpickler.persistent_load ( self,
pid )

Definition at line 377 of file root_pickle.py.

377 def persistent_load (self, pid):
378 if self.__use_proxy:
379 o = Root_Proxy (self.__file, pid)
380 else:
381 o = self.__file.Get (pid)
382 #print ('load ', pid, o)
383 xsave.add(o)
384 return o
385
386

Member Data Documentation

◆ __file

python.root_pickle.Unpickler.__file = file
private

Definition at line 316 of file root_pickle.py.

◆ __io

python.root_pickle.Unpickler.__io = Read_Wrapper()
private

Definition at line 317 of file root_pickle.py.

◆ __n

int python.root_pickle.Unpickler.__n = 0
private

Definition at line 320 of file root_pickle.py.

◆ __use_proxy

python.root_pickle.Unpickler.__use_proxy = use_proxy
private

Definition at line 315 of file root_pickle.py.


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