[ROOT] Re: size of the filtered tree

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Feb 15 2002 - 10:18:54 MET


Hi Dmitriy,

You cannot write files bigger than 2 GBytes.
In your example, you should have received plenty of error messages
generated by tree->Fill() or when closing the file.
When you read back the file, a statement like
   TTree *tree = (TTree*)file.Get('mytree");
will return the last saved tree header in the file (via AutoSave).
The default value for AutoSave is to save the Tree header every time
100 MBytes of data written to the file. This explains why you get only
55000 entries.

Rene Brun

Dmitriy Bandourine wrote:
> 
> Hi Rooters,
> 
> I select the events from the chain of several root-files
> to write them then to new-created tree.
> I found out an interesting feature, that the size
> of the file with new tree, small.root file, does not exceed 2 Gb,
> or, to be exact, in my case 1999999930 bytes.
> As a consequence, The events, that should also selected and written,
> are descarded.
> For example, the counter  "n_written" used below:
> [...]
>      if ( SelectionFunction() ) {
>        tree->Fill();
>        n_written++;
>      }
> [...]
> shows me 70 000. But when I analyze the small.root I see that real nember
> is only 55 000.
> 
> How to fix it?
> 
> PS. This email is continuation of my previous email's to roottalk with
> the subject "filter out the chain", that are also availabble below.
> 
> With best wishes,
> Dmitriy
> 
> ---------- Forwarded message ----------
> Date: Fri, 1 Feb 2002 11:39:10 -0600
> From: Dmitriy Bandourine <bandurin@fnal.gov>
> To: Rene Brun <Rene.Brun@cern.ch>
> Cc: roottalk@pcroot.cern.ch
> Subject: Re: filter out the chain
> 
> Thank you Rene again.
> The last variant works perfectly. I tried both
> clicking some leaves and rereading new tree from "small.root".
> The cut function really removed the unwanted events from initial chain and
> saved to new tree properly.
> 
>  - Dmitriy -
> 
> On Fri, 1 Feb 2002, Rene Brun wrote:
> 
> > Hi Dmitryi,
> >
> > Could you try the following variant?
> >  TChain *chain = new TChain("Global");
> >  chain->Add("file1.root");
> >  chain->Add("file2.root");
> >  chain->Add("file3.root");
> >  chain->GetEntry(0);  //<========new line
> >
> >    TFile *newFile = new TFile("small.root","recreate");
> >    TTree *tree = (TTree*)chain->GetTree()->CloneTree(0); //<===new line
> >
> >
> > Rene Brun
> >
> > //<=====Dmitriy Bandourine wrote:
> > >
> > > Thank you Rene!
> > >
> > > With your changes ew tree was created and written to the file "small.root"
> > > But when I tried to read this tree in new session, I got:
> > > *----
> > > Error in <TFile::ReadBuffer>: error reading all requested bytes from file  small.root, got 0 of 26444
> > > *---
> > >
> > > When I clicked on some leaf in one of braches of the tree in "small.root", I got
> > > *---
> > > root [2] <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
> > > Error in <TFile::ReadBuffer>: error reading all requested bytes from file small.root, got 0 of 26444
> > > C++ runtime abort: terminate() called by the exception handling mechanism.
> > > *---
> > >
> > > I expect that the size of the created "small.root" file  should be at
> > > least 5-6 times larger than it is.
> > >
> > >  - Dmitriy -
> > >
> > > On Fri, 1 Feb 2002, Rene Brun wrote:
> > >
> > > > Hi Dmitriy,
> > > >
> > > > TTree::CloneTree returns a clone of the original object. In case of a TChain,
> > > > CloneTree returns a TChain*. You cannot fill a TChain, only a TTree.
> > > > I suggest the following changes in your code:
> > > >
> > > >
> > > > void filter()
> > > > {
> > > > TChain *chain = new TChain("Global");
> > > > chain->Add("file1.root");
> > > > chain->Add("file2.root");
> > > > chain->Add("file3.root");
> > > >
> > > >   cout << " Creating new root-file ..."<< endl;
> > > >   TFile *newFile = new TFile("small.root","recreate");
> > > >   cout << " Creating new tree ..."<< endl;
> > > >   TChain *newchain = (TChain*)chain->CloneTree(0); //<====
> > > >   TTree *tree = newchain->GetTree(); //<=====
> > > >
> > > >   if (fChain == 0) return;
> > > >   Int_t nentries = Int_t(fChain->GetEntries());
> > > >
> > > >   Int_t nbytes = 0, nb = 0;
> > > >   for (Int_t jentry=0; jentry<nentries;jentry++) {
> > > >      Int_t ientry = LoadTree(jentry); //in case of a TChain,
> > > >      nb = fChain->GetEntry(jentry);   nbytes += nb;
> > > >
> > > >     if ( SelectionFunction() ) tree->Fill();
> > > >
> > > >   }// end loop over events
> > > >
> > > >   newFile->cd();
> > > >   tree->Write();
> > > > }
> > > >
> > > > Rene Brun
> > > >
> > > > Dmitriy Bandourine wrote:
> > > > >
> > > > > Hi rooters,
> > > > >
> > > > > I need to filter out the events containing in the chain
> > > > > of root-files using some function INSIDE the loop over events
> > > > > and then save them in new tree with analogous branch structure.
> > > > > The method with
> > > > > TTree *tree = chain.CloneTree(Tcut);
> > > > > does not suit me because, as mentioned above, I need to use a
> > > > > selection function, which return value depends on the event parameters.
> > > > >
> > > > > My script looks like this:
> > > > > #===========================================
> > > > > void filter()
> > > > > {
> > > > > TChain *chain = new TChain("Global");
> > > > > chain->Add("file1.root");
> > > > > chain->Add("file2.root");
> > > > > chain->Add("file3.root");
> > > > >
> > > > >   cout << " Creating new root-file ..."<< endl;
> > > > >   TFile *newFile = new TFile("small.root","recreate");
> > > > >   cout << " Creating new tree ..."<< endl;
> > > > >   TTree *tree = chain.CloneTree(0);
> > > > >
> > > > >   if (fChain == 0) return;
> > > > >   Int_t nentries = Int_t(fChain->GetEntries());
> > > > >
> > > > >   Int_t nbytes = 0, nb = 0;
> > > > >   for (Int_t jentry=0; jentry<nentries;jentry++) {
> > > > >      Int_t ientry = LoadTree(jentry); //in case of a TChain,
> > > > >      nb = fChain->GetEntry(jentry);   nbytes += nb;
> > > > >
> > > > >     if ( SelectionFunction() ) tree->Fill();
> > > > >
> > > > >   }// end loop over events
> > > > >
> > > > >   newFile->cd();
> > > > >   tree->Write();
> > > > > }
> > > > > #==============================================
> > > > >
> > > > > For 3.01.06 in this case I get:
> > > > > Warning in <TChain::Fill()>: may not use this method
> > > > > and nothing written to "tree".
> > > > > For 3.02.07 I get:
> > > > > *** Break *** segmentation violation
> > > > >
> > > > > How to initialize properly "tree"?
> > > > > Obviously, the string:
> > > > >  TTree *tree = chain.CloneTree(0);
> > > > > does not help
> > > > >
> > > > > Thanks in advance,
> > > > > Dmitri
> > > >
> >



This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:41 MET