Get a TNamed from gDirectory

Hello

I was trying to get a TNamed object from gDirectory.
While looking for within the documentation I only found that the only requirement for an object to be retrievable is to inherit from TNamed:
root.cern.ch/root/roottalk/roottalk03/3547.html

But If I try something like

TNamed *nam = new TNamed(“myname”,“mytitle”);

gDirectory->ls()

  • returns nothing and -
    gDirectory->Get(“myname”)
    (class TObject*)0x0

For reference Im using root v5.26 for SLC5 x86_64

thanks, carlos

Hi,

[quote]While looking for within the documentation I only found that the only requirement for an object to be retrievable is to inherit from TNamed:[/quote]Well … the additional implicit requirement is that the object is ‘stored’ in the directory. In the example you show, you never ‘store’ the object in the directory (You would need to use gDirectory->Append for example or have gDirectory points to a TFile where you stored that object in a previous session).

Cheers,
Philippe.

PS. Please note that the TNamed this requirement is actually now obsolete and any object which has a dictionary can be stored and retrieved from a TDirectory.

thanks Philippe

I assumed that the object was appended to the default TDirectory, like some other classes that inherit from TNamed. Yes, the gDirectory->Append works well.

cheers, carlos