Can we read an object in a TDirectory on one step?

Hello fellow Rooters,

Is it possible to read an object inside a few levels of TDirectory’s on one go, such as it is done when we specify the absolute path of a filesystem file?

For example, if in a TFile* called “file” I have a TObject named “myobj”, which is in a TDirectory called “level3”, which in turn is inside a TDirectory called “level2” which is in TDirectory “level1”: is it possible to get myobj’s TKey* (or the TObject* itself) by doing something like

Of course, this I’ve tried it but it didn’t work. I’ve also tried with the methods FindKey() and FindObject().

So, I’m hoping there’s some other way.
The alternative is doing my own code to parse the full string (and making sure each “leveln” is indeed a TDirectory…).

Cheers,
jbatista

MyClass *obj; file->GetObject("/level1/level2/level3/myobj",obj);Should be returning what you are looking for.

Cheers,
Philippe

[quote=“pcanal”]MyClass *obj; file->GetObject("/level1/level2/level3/myobj",obj);Should be returning what you are looking for.

Cheers,
Philippe[/quote]

Yes, that’s great! Thank you, Philippe.