SND@LHC Software
Loading...
Searching...
No Matches
rootpyPickler.Unpickler Class Reference
Inheritance diagram for rootpyPickler.Unpickler:
Collaboration diagram for rootpyPickler.Unpickler:

Public Member Functions

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

Static Public Attributes

 find_global = find_class
 

Private Attributes

 __use_proxy
 
 __file
 
 __io
 
 __n
 
 __serial
 

Detailed Description

Definition at line 219 of file rootpyPickler.py.

Constructor & Destructor Documentation

◆ __init__()

rootpyPickler.Unpickler.__init__ (   self,
  root_file,
  use_proxy = True,
  use_hash = False 
)
Create a ROOT unpickler.
`file` should be a ROOT TFile.

Definition at line 220 of file rootpyPickler.py.

220 def __init__(self, root_file, use_proxy=True, use_hash=False):
221 """Create a ROOT unpickler.
222 `file` should be a ROOT TFile.
223 """
224 global xserial
225 xserial += 1
226 self.__use_proxy = use_proxy
227 self.__file = root_file
228 self.__io = IO_Wrapper()
229 self.__n = 0
230 self.__serial = '{0:d}-'.format(xserial).encode('utf-8')
231 xdict[self.__serial] = root_file
232 if sys.version_info[0] < 3:
233 pickle.Unpickler.__init__(self, self.__io)
234 else:
235 super(Unpickler, self).__init__(self.__io)
236
237 if use_hash:
238 htab = {}
239 ctab = {}
240 for k in root_file.GetListOfKeys():
241 nm = k.GetName()
242 cy = k.GetCycle()
243 htab[(nm, cy)] = k
244 if cy > ctab.get(nm, 0):
245 ctab[nm] = cy
246 htab[(nm, 9999)] = k
247 root_file._htab = htab
248 oget = root_file.Get
249
250 def xget(nm0):
251 nm = nm0
252 ipos = nm.find(';')
253 if ipos >= 0:
254 cy = nm[ipos+1]
255 if cy == '*':
256 cy = 10000
257 else:
258 cy = int(cy)
259 nm = nm[:ipos - 1]
260 else:
261 cy = 9999
262 ret = htab.get((nm, cy), None)
263 if not ret:
264 print(("warning didn't find {0} {1} {2}",nm, cy, len(htab) ))
265 return oget(nm0)
266 #ctx = ROOT.TDirectory.TContext(file)
267 ret = ret.ReadObj()
268 #del ctx
269 return ret
270 root_file.Get = xget
271

Member Function Documentation

◆ find_class()

rootpyPickler.Unpickler.find_class (   self,
  module,
  name 
)

Definition at line 304 of file rootpyPickler.py.

304 def find_class(self, module, name):
305 try:
306 try:
307
312 if sys.version_info[0] >2:
313 if module == 'copy_reg': module = 'copyreg'
314 if module == '__builtin__': module = 'builtins'
315 __import__(module)
316 mod = sys.modules[module]
317 except ImportError:
318 #log.info("Making dummy module {0}".format(module))
319
320 class DummyModule:
321 pass
322
323 mod = DummyModule()
324 sys.modules[module] = mod
325 klass = getattr(mod, name)
326 return klass
327 except AttributeError:
328 #log.info("Making dummy class {0}.{1}".format(module, name))
329 mod = sys.modules[module]
330
331 class Dummy(object):
332 pass
333
334 setattr(mod, name, Dummy)
335 return Dummy
336

◆ load()

rootpyPickler.Unpickler.load (   self,
  skey = None 
)
Read a pickled object representation from the open file.

Definition at line 272 of file rootpyPickler.py.

272 def load(self, skey=None):
273 """Read a pickled object representation from the open file."""
274 key = skey
275 if skey is None:
276 key = '_pickle'
277 elif skey.find(';')<0: key = skey+';'
278 obj = None
279 if _compat_hooks:
280 save = _compat_hooks[0]()
281 try:
282 self.__n += 1
283 s = self.__file.Get(key + ';{0:d}'.format(self.__n))
284 self.__io.setvalue(s.GetName())
285 if sys.version_info[0] < 3:
286 obj = pickle.Unpickler.load(self)
287 else:
288 obj = super(Unpickler, self).load()
289 self.__io.reopen()
290 finally:
291 if _compat_hooks:
292 save = _compat_hooks[1](save)
293 return obj
294

◆ persistent_load()

rootpyPickler.Unpickler.persistent_load (   self,
  pid 
)

Definition at line 295 of file rootpyPickler.py.

295 def persistent_load(self, pid):
296 if self.__use_proxy:
297 obj = ROOT_Proxy(self.__file, pid.decode('utf-8'))
298 else:
299 obj = self.__file.Get(pid)
300 #log.debug("load {0} {1}".format(pid, obj))
301 xdict[self.__serial + pid] = obj
302 return obj
303

Member Data Documentation

◆ __file

rootpyPickler.Unpickler.__file
private

Definition at line 227 of file rootpyPickler.py.

◆ __io

rootpyPickler.Unpickler.__io
private

Definition at line 228 of file rootpyPickler.py.

◆ __n

rootpyPickler.Unpickler.__n
private

Definition at line 229 of file rootpyPickler.py.

◆ __serial

rootpyPickler.Unpickler.__serial
private

Definition at line 230 of file rootpyPickler.py.

◆ __use_proxy

rootpyPickler.Unpickler.__use_proxy
private

Definition at line 226 of file rootpyPickler.py.

◆ find_global

rootpyPickler.Unpickler.find_global = find_class
static

Definition at line 338 of file rootpyPickler.py.


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