RE: [ROOT] TDirectory::Get() with objects in memory

From: Philippe Canal (pcanal@fnal.gov)
Date: Wed Aug 13 2003 - 17:49:36 MEST


Hi,

Maybe this is just a typo in your email but instead of:
    ptr=(*THF1)gDirectory->Get(histo);
you should have
    ptr=(TH1F*)gDirectory->Get(histo);
i.e. the class name was not spelled corrected and the star '*' should come
in second position.

Cheers,
Philippe.

-----Original Message-----
From: owner-roottalk@pcroot.cern.ch
[mailto:owner-roottalk@pcroot.cern.ch]On Behalf Of Sara VECCHIO
Sent: Wednesday, August 13, 2003 8:59 AM
To: roottalk@pcroot.cern.ch
Subject: Re: [ROOT] TDirectory::Get() with objects in memory


Hi, I have some problem with Get() funcion, too. But maybe it's only a
sintax error.

In a file.root I have some histograms. Using a macro I just open the file
then I try to get a pointer to an histogram and I get a null pointer. When
I type single lines on root prompt I can use the histoname as a pointer.

For example:


{
char histo[20];
THF1* ptr;
TFile *f = TFile::Open("file.root","update");
for(i=0;i<5;i++) {
sprintf(histo,"h%d",i);
ptr=(*THF1)gDirectory->Get(histo);
ptr->Draw();
}
}

doesn't work

but

root[0] TFile f("file.root","update");
root[1] THF1 *ptr = h1;
//or THF1 *ptr=(*THF1)gDirectory->Get("h1");
root[2] ptr->Draw();

works fine.

What's wrong in the first case?

(using gFile or gROOT instead of gDirectory doesn't change my results)

using 3.03.09.


Sara Vecchio



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:14 MET