Extracting histogram TFile

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


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:16:19 MET

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