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

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

Member Function Documentation

◆ find_class()

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

Definition at line 391 of file root_pickle.py.

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

◆ load()

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

Definition at line 363 of file root_pickle.py.

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

◆ persistent_load()

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

Definition at line 381 of file root_pickle.py.

381 def persistent_load (self, pid):
382 if self.__use_proxy:
383 o = Root_Proxy (self.__file, pid)
384 else:
385 o = self.__file.Get (pid)
386 #print ('load ', pid, o)
387 xsave.add(o)
388 return o
389
390

Member Data Documentation

◆ __file

python.root_pickle.Unpickler.__file = file
private

Definition at line 320 of file root_pickle.py.

◆ __io

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

Definition at line 321 of file root_pickle.py.

◆ __n

int python.root_pickle.Unpickler.__n = 0
private

Definition at line 324 of file root_pickle.py.

◆ __use_proxy

python.root_pickle.Unpickler.__use_proxy = use_proxy
private

Definition at line 319 of file root_pickle.py.


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