RE: How to register ROOT object read from python pickle

From: Fine, Valeri <fine_at_bnl.gov>
Date: Tue, 11 Jan 2011 20:22:17 -0500


ROOT objects are C++ objects. You should use the ROOT I/O (for example, TFile class) to read / write ROOT objects.

Best regards , Valeri Fine



Brookhaven National Laboratory
Upton, NY 11973

> -----Original Message-----
> From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch]
On Behalf Of
> Benjamin Bannier
> Sent: Tuesday, January 11, 2011 4:34 PM
> To: ROOT Talk
> Subject: [ROOT] How to register ROOT object read from python pickle
>
> Dear ROOT experts,
>
> I am trying to get a ROOT object loaded from a python pickle via name
from some global
> registry like gDirectory or gROOT, but somehow cannot make it work.
>
> If I write an object like
>
> ----(out.py)
> import ROOT as r
> import pickle
>
> h = r.TH1D('h_test','', 100, -10, 10)
>
> pickle.dump(h, file('h.pkl', 'w'))
> ----
>
> and try to get it from gDirectory or gROOT like
>
> ----(in.py)
> import ROOT as r
> import pickle
>
> h = pickle.load(file('h.pkl'))
>
> for t in (r.gDirectory, r.gROOT):
> print t.FindObjectAny('h_test')
> print t.Get('h_test')
> ----
>
> I get nothing:
>
> ----
> $ python in.py
> <ROOT.TObject object at 0x(nil)>
> <ROOT.TObject object at 0x(nil)>
> <ROOT.TObject object at 0x(nil)>
> <ROOT.TObject object at 0x(nil)>
> ----
>
> How would I make these objects known to the usual suspects or if they
are already know how
> do I get them?
>
>
> Thanks,
>
> Benjamin
Received on Wed Jan 12 2011 - 02:22:24 CET

This archive was generated by hypermail 2.2.0 : Wed Jan 12 2011 - 05:50:01 CET