Re: How to register ROOT object read from python pickle

From: Tim Head <betatim_at_gmail.com>
Date: Tue, 11 Jan 2011 21:23:05 -0600


On 11 January 2011 15:33, Benjamin Bannier <bbannier_at_gmail.com> wrote:
>
> 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')
> ----
>

<snip>
>
> How would I make these objects known to the usual suspects or if they
> are already know how do I get them?
>

Try:

h.SetDirectory(r.gDirectory)

after doing that both gROOT.Get() and gDirectory.Get() return the histogram. But I am not sure if this is the "correct" way of doing this, if it has unpleasant side effects or is missing some side effects. It is very hard to know with ROOT ...

When the histogram is first unpickled its directory is set to nothing, check out h.GetDirectory() after unpickling it.

Out of curiosity, why do you bother with being able to retrieve things using the root gDirectory etc mechanism and don't store things in a dictionary?

Tim

-- 
http://tim.jottit.com/
Received on Wed Jan 12 2011 - 04:23:11 CET

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