How to reference an object in a TFile?

From: Tom Roberts <tjrob_at_fnal.gov>
Date: Sun, 07 Jan 2007 15:44:17 -0600


I am an experienced C++ developer new to root.

I am implementing a graphical user interface for my users, and I want them to be able to select any single TNtuple out of any open Root file.

So I loop over gROOT->GetListOfFiles() and descend each file's directory tree, putting the TNtuple pointers into a std::vector<TNtuple*> (and also their names into a TGListBox from which the user will select). Inside that loop I can call p->GetName() and p->GetEntries(), for p the current pointer to a TNtuple. But later, after all NTuples have been found and the loop over files is complete, I cannot call any TNtuple function using those pointers -- an interpreter segfault happens. I guess those objects no longer remain in memory (??).

Is there a better way to do this? I do not expect my users to understand TBrowser and then know enough to open the TreeViewer -- I am basically re-implementing HistoScope for Root files....

I tried keeping a std::vector<TString> with each entry the full name of the TNtuple (i.e. /path/file.root:/path/name ). How can I turn that name into a TNtuple pointer I can use? -- do I need to laboriously descend into the file as before? (a pain, as TDirectory::GetPath() does not return the actual root path when inside a TFile)

What is the difference between folders and directories? -- there seem to be parallel but different functions and objects...(??)

How does it decide which objects to remove from memory? -- after all, I had recently referenced each and every NTuple....

	[If it matters, my loop just uses pointers to TDirectory-s,
	 never opening any TFile nor calling any cd() function.]


Tom Roberts Received on Sun Jan 07 2007 - 22:44:29 CET

This archive was generated by hypermail 2.2.0 : Sun Jan 07 2007 - 23:50:00 CET