Re: [ROOT] Diverting Branch to separate file

From: Rene Brun (Rene.Brun@cern.ch)
Date: Tue Mar 27 2001 - 14:06:48 MEST


Hi Dmitri,

If you run the small example sent in my previous mail, you will get this output
******************************************************************************
*Tree    :tree      : a test                                                 *
*Entries :     1000 : Total =          375172 bytes  File  Size =      46370 *
*        :          : Tree compression factor =   8.09                       *
******************************************************************************
*Br    0 :Clones_   : Clones_/I                                              *
*Entries :     1000 : Total  Size=          0 bytes  File Size  =          0 *
*Baskets :        0 : Basket Size=      32000 bytes  Compression=   1.00     *
*............................................................................*
*Br    1 :Clones.fUniqueID : fUniqueID[Clones_]/i                            *
*Entries :     1000 : Total  Size=     187598 bytes  File Size  =      42850 *
*Baskets :        6 : Basket Size=      32000 bytes  Compression=   4.38     *
*............................................................................*
*Br    2 :Clones.fBits : fBits[Clones_]/i                                    *
*Entries :     1000 : Total  Size=     187574 bytes  File Size  =       3520 *
*Baskets :        6 : Basket Size=      32000 bytes  Compression=  53.29     *
*............................................................................*

You can see that 3 branches are produced:
  Clones_  contains the TClonesArray counter. All the data in this branch 
           fit nicely in memory (no basket written to the file). The buffer
           will be Streamed with the tree header in tehe main file.
  Clones.fUniqueID:  has 6 baskets written to test.clones.root. Like for Clones_
           the remaining buffer in memory will be Streamed with the Tree header.
  Clones.fBits:  same as Clones.fUniqueID.

As a result, look at the result of the following few commands:
root [0] TFile f("test.root")
root [1] tree->GetBranch("Clones.fBits")->GetFileName()
(const char* 0x887e51c)"test.clones.root"
root [2] tree->GetBranch("Clones.fUniqueID")->GetFileName()
(const char* 0x88723ec)"test.clones.root"
root [3] tree->GetBranch("Clones_")->GetFileName()         
(const char* 0x403b458c)""
root [4] tree->GetBranch("Clones")->GetFileName() 
(const char* 0x403b458c)""

I will implement TBranchClones::SetFile to make the implicit loop on
all subbranches of the TClonesArray.

Rene Brun

Dimitri Peressounko wrote:
> 
>          Dear Rene,
> 
> I try your example with one more line:
> br->SetFile("test.clones.root");
> and obtained exacly the same result as before:
> 
> root [0]  TFile * f = new TFile("test.root")
> root [1] TTree * t = (TTree*) f->Get("tree")
> root [2] t->GetBranch("Clones")->GetFileName()
> (const char* 0x403ff98c)""
> 
> May be I am missing something? Why GetFileName is empty?
> 
>                       Dmitri.
> 
> On Tue, 27 Mar 2001, Rene Brun wrote:
> 
> > Hi Dimitri,
> >
> > TBranch::SetFile acts on one branch only, not on its sub branches.
> > In the case of a TClonesArray, one has to loop on all the subbranches as shown
> > in the example below.
> > Note that in case you have a few entries only, data are buffered in
> > the branch baskets. If all the buffers fit in memory, they are written
> > in one single block together with the tree header on the master file.
> > In this case, the associated files will be empty.
> >
> > Rene Brun
> >
> >
> > {
> >    TFile * f = new TFile("test.root","recreate");
> >    TClonesArray *d = new TClonesArray("TObject",10);
> >    TTree * t = new TTree("tree","a test");
> >    TBranch *br =  t->Branch("Clones",&d,32000);
> >    TIter next(br->GetListOfBranches());
> >    TBranch *brc;
> >    while((brc=(TBranch*)next())) {
> >       brc->SetFile("test.clones.root");
> >    }
> >    for (Int_t i=0;i<1000;i++) {
> >       for (Int_t j=0;j<(i%50);j++) {
> >          TObject *obj = new ((*d)[j]) TObject();
> >          obj->SetUniqueID(100*i+j);
> >       }
> >       t->Fill();
> >    }
> >    t->Print();
> >    t->Write();
> > }
> >
> >
> > Dimitri Peressounko wrote:
> > >
> > >    Hi, Rooters!
> > >
> > > I am trying to divert branch ot TClonesArray to separate file:
> > >
> > > root [0] TFile * f = new TFile("test.root","new")
> > > root [1] TClonesArray * d = new TClonesArray("TObject",10)
> > > root [2] TTree * t = new TTree("tree","a test")
> > > root [3] TBranch * br =  t->Branch("Clones",&d,32000);
> > > root [4] br->SetFile("test.clones.root")
> > > root [5] t->GetBranch("Clones")->GetFileName()
> > > (const char* 0x858a01c)"test.clones.root"
> > > root [6] t->Fill()
> > > (Int_t)4
> > > root [7] t->Write()
> > > (Int_t)761
> > > root [8] .q
> > >
> > > Now I am reading back this branch and find, that file = "".
> > >
> > > root [0] TFile * f = new TFile("test.root")
> > > root [1] TTree * t = (TTree *) f->Get("tree")
> > > root [2] t->GetBranch("Clones")->GetFileName()
> > > (const char* 0x403ff98c)""
> > >
> > > file test.clones.root is not created as well.
> > > What I am doing wrong?
> > >
> > >              Dmitri
> >



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