Re: Mixed events from a TChain

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Mon, 03 Jan 2005 11:59:31 +0100


Hi Christian,

Before cloning the tree/TChain, you must open an ouput file, eg

        TChain* tree = new TChain("T");
        tree->Add("*.root");
        TFile *fout = new TFile("merge.root","recreate");
        Tree*  clone = tree->CloneTree();

Rene Brun

Christian Holm Christensen wrote:
>
> Hi all,
>
> I think there's a problem with TChain::CloneTree or something like
> that.
>
> If I create a TTree, and read it back so that each time a read an entry,
> I also read the previous entry (if available), then it works fine using
> TTree::CloneTree:
>
> TTree* tree = static_cast<TTree*>(file->Get("T"));
> TTree* clone = tree->CloneTree();
> tree->SetBranchAddress("vector", &array);
> clone->SetBranchAddress("vector", &other);
> Int_t entry = 0;
> while (tree->GetEntry(entry) > 0) {
> cout << "Got " << array->GetEntries() << " vectors" << endl;
> if (entry > 0) {
> clone->GetEntry(entry - 1);
> cout << "Got " << other->GetEntries() << " vectors" << endl;
> }
> entry++;
> }
>
> However, If I do the same thing with a TChain, the `clone' tree never
> fills the `other' array:
>
> TChain* tree = new TChain("T");
> tree->Add("*.root");
> Tree* clone = tree->CloneTree();
> // Rest as above
>
> The weird thing is, that the `clone' tree reads the right number of
> bytes, but never fills the `other' array.
>
> I have attached a small script as well as the output of running that
> script. Note, that the script first creates 3 files with a TTree in
> each. Then it reads back (as explained above) one of the files using a
> TTree, which works fine. Finally, it reads back all three files using a
> TChain, which fails miserably.
>
> Am I doing something wrong, or does the CloneTree facility not work with
> a TChain?
>
> I'm using
>
> ROOT Version 4.01/05 (CVS head around 14 December 2004)
> Debian GNU/Linux unstable (sid)
> G++ (GCC) 3.3.5 (Debian 1:3.3.5-5)
>
> Yours,
>
> --
> ___ | Christian Holm Christensen
> |_| | -------------------------------------------------------------
> | | Address: Sankt Hansgade 23, 1. th. Phone: (+45) 35 35 96 91
> _| DK-2200 Copenhagen N Cell: (+45) 24 61 85 91
> _| Denmark Office: (+45) 353 25 404
> ____| Email: cholm_at_nbi.dk Web: www.nbi.dk/~cholm
> | |
>
> --------------------------------------------------------------------------------
> Name: Mixed.C
> Mixed.C Type: text/x-c++src
> Encoding: 7bit
>
> Name: Mixed.log
> Mixed.log Type: text/x-log
> Encoding: 7bit
Received on Mon Jan 03 2005 - 12:01:23 MET

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:04 MET