Re: Extracting histogram TFile

From: Arthur E. Snyder <snyder_at_slac.stanford.edu>
Date: Wed, 30 Nov 2005 11:26:49 -0800 (PST)

You may have notice that TH1F rather than TH1 was used in fetchFileHist. The historgram in the file is in fact a TH1F and this makes no difference to the behavior.

I have found the if I load fetchFile hist as a macro (.L fetchFileHist.C) or compile interactively (.L fetchFileHist.C+) it works. Only when I compile and load it to my library with my Makefile does it fail ...

-Art S.

A.E. Snyder, Group EC                        \!c*p?/
SLAC Mail Stop #95                          ((.   .))
Box 4349                                        |
Stanford, Ca, USA, 94309                      '\|/`
e-mail:snyder_at_slac.stanford.edu                 o
phone:650-926-2701                              _
http://www.slac.stanford.edu/~snyder          BaBar
FAX:650-926-2657                          Collaboration



On Wed, 30 Nov 2005, Arthur E. Snyder wrote:

> I'm trying to get histograms from a TFile for use in compiled code.
>
> Interactively I find that
>
> t=new TFile("myfile")
> TH1* h=0
> t->GetObject("histname",h)
> works. I get a point to the histogram and can draw it.
>
> However, when I try what I think is the samething in compiled code it
> fails, namely:
> TH1* fetchFileHist(TString file,TString name) {
> TFile* temp=new TFile(file);
> if(temp==0) {
> cout << "no file named '" << file << "' found" << endl;
> }
> TH1F* h=0;
> temp->GetObject(name,h);
> if(h==0) {
> cout << "no histogram named '" << name << "' in file '" << file << "'"
> << endl;
> return 0;
> }
> return (TH1*)h->Clone();
>
> }
>
> An example:
>
> root [0] t1=new TFile("pressureProf/mc/LER-brem-zone1.root")
> (class TFile*)0x9f25bf8
> root [1] .ls
> TFile** pressureProf/mc/LER-brem-zone1.root
> TFile* pressureProf/mc/LER-brem-zone1.root
> KEY: TH1F occupancy;1
> root [2] root [3] t1->GetObject("occupancy",h)
> root [4] h
> (class TH1*)0xa0fb2a8
>
> but
>
> root [5]
> hp=fetchFileHist("pressureProf/mc/LER-brem-zone1.root","occupancy")
> no histogram named 'occupancy' in file
> 'pressureProf/mc/LER-brem-zone1.root'
> (class TH1*)0x0
>
> fails to find the file
>
> --seems pretty odd. What going on? My usual stupidity?
>
> -Art S.
>
> A.E. Snyder, Group EC \!c*p?/
> SLAC Mail Stop #95 ((. .))
> Box 4349 |
> Stanford, Ca, USA, 94309 '\|/`
> e-mail:snyder_at_slac.stanford.edu o
> phone:650-926-2701 _
> http://www.slac.stanford.edu/~snyder BaBar
> FAX:650-926-2657 Collaboration
>
>
>
>
Received on Wed Nov 30 2005 - 20:27:01 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:13 MET