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
267 ret = ret.ReadObj()
268
269 return ret
270 root_file.Get = xget
271