Re: [ROOT] Problems with TTree

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Jun 08 2001 - 11:32:57 MEST


Hi Daniel,

I do not have enough information to understand your problem.
Note that, currently, TBranch::SetFile is not setting the file name
for the descendant of the branch. This could be the problem.

Anyhow, I think that there is a much better solution to your problem.
Instead of splitting branches of the same tree into different files,
it is simpler, more secure, faster to use the Tree friendship feature
that has been introduced in version 3.01.
Create a Tree (say TA) for your top branch A and another Tree (say TB)
for the branch B. Each Tree in a separate file A.root and B.root.
To analyze the two trees, you can do:
  TFile fa("TA.root");
  TTree *TA = (TTree*)fa.Get("TA");
  TA->AddFriend("TB","B.root");
Now suppose that your branch A contains attributes x,y,z
and branch B contains attributes z,u,v,w
You can make queries like:
  TA->Draw("x");
  TA->Draw("x:u")
  TA->Draw("B.z:z',sqrt(y)<v");
etc

Rene Brun


Flath, Daniel wrote:
> 
> Dear Rooters,
> 
> I'm having trouble using some of the functionality of the TTree class.  Specifically, I'd like to store the branches of a TTree in files separate from that containing the TTree itself.  I am able to do this successfully if I create the branches (which store TObject descendants) with split mode turned off.  It is very desirable to me to keep split mode on since the class members in sub branches are often large and slow down analysis significantly.  With split mode those sub branches not being analyzed can be turned off and the analysis is much quicker.  If I turn split mode on, however, one large root file is generated containing tree and branches.
> 
> Unfortunately, the code is complex, so I will include here a small piece of code detailing what I do.  Any input on why this occurs would be greatly appreciated.
> 
> My thanks in advance,
> 
> Dan.
> 
> /////////////////////////////// BEGIN CODE ////////////////////////////////////
> class A: public TObject {/*A's guts*/};
> class B: public TObject {/*B's guts*/};
> 
> int     buffsize = 3200,
>         compress = 1,
>         split = 1;
> 
> A *a = new A();
> a->Create();
> B *b = new B();
> b->Create();
> TFile *f = new TFile("tree_file.root", "RECREATE", "tree file", compress);
> TTree *tree = new TTree("T", "root tree");
> tree->Branch("branch_a", "A", &a, buffsize, split);
> tree->Branch("branch_b", "B", &b, buffsize, split);
> tree->GetBranch("branch_a")->SetFile("a_file.root");
> tree->GetBranch("branch_b")->SetFile("b_file.root");
> 
> for (int i=0; i<100; i++) {
>         a->Clean();  a->Create();
>         b->Clean();  b->Create();
> 
>         // set members of a & b
> 
>         tree->Fill();
> }
> f->Write();
> f->Close();
> //////////////////////////////// END CODE /////////////////////////////////////
> 
> Daniel Flath
> <dflath@slac.stanford.edu>
> (650).926.8794



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:49 MET