Re: What characters cause trouble in object names?

From: Philippe Canal <pcanal_at_fnal.gov>
Date: Wed, 29 Apr 2009 13:34:14 -0500


Hi Christian,

TDirectory::Get and GetObject will look inside nested directories if any. Hence the issue is with the '/'.

To retrieve an object with a slash in its name, use GetKey instead:

TKey *key = testFile->GetKey("This is a / complicated string, apparently") TH1F *h = (TH1F*)key->ReadObjectAny(TH1F::Class());

Cheers,
Philippe.

Christian Ohm wrote:
> Hi ROOTers,
>
> I have a script that produces "a million" histograms, and since it's a
> pain to give them separate names and titles, I have one single
> descriptive (and unique) TString per object that I use for both
> purposes. However, when I try to retrieve a histogram containing a
> slash ('/') in the name, e.g. "dE/dx vs. p (hadronic cells only)",
> ROOT won't find it:
>
> Writing a histogram:
> root [0] TString str = TString("This is a / complicated string,
> apparently");
> root [1] TH1F *testHizzie = new TH1F(str,str,10,0,1)
> root [2] TFile *myFile = new TFile("test.root","recreate")
> root [3] testHizzie->Write()
>
> Reading it back:
> root [0] TFile *testFile = new TFile("test.root");
> root [1] TH1F *h = (TH1F*) testFile->Get("This is a / complicated
> string, apparently")
> root [2] h
> (class TH1F*)0x0
>
> It shows up in the TBrowser though - no problem - but it doesn't show
> up when I do gDirectory-ls(). So unless I missed something, there seem
> to be characters that should be avoided in object names - is there a
> list of them somewhere? Or is there a way to 'escape' the slash if
> it's causing trouble when ROOT parses the string? I skimmed some
> relevant parts in the manual but couldn't find any info - if it's not
> there, maybe it could be added?
>
> Thanks,
> Christian
>
Received on Wed Apr 29 2009 - 20:36:09 CEST

This archive was generated by hypermail 2.2.0 : Fri May 01 2009 - 23:50:01 CEST