[ROOT] TChain::SetBranchStatus nor working properly

From: Thomas Bretz (Thomas_Bretz@ph.tum.de)
Date: Sat Nov 08 2003 - 19:37:21 MET


Dear all,

I'm using root 3.05/05 (In our application I have also observed the same
behaviour with root 3.05/07)

There seems to be a problem with TChain::SetBranchStatus. In some cases it
does exactly the opposite of what I would expect...

The attached macro immidiatly shows what I mean.

Best regards,
Thomas.


void test()
{
    //
    // Write a simple file file simple objects...
    //
    TFile f("test.root", "recreate");
    TTree *t = new TTree("Events", "Test");
    TNamed *named = new TNamed;
    TNamed *named2 = new TNamed;
    t->Branch("TNamed.", "TNamed", &named);
    t->Branch("TNamed2.", "TNamed", &named2);

    for (int i=0; i<20000; i++)
    {
        named->SetName(Form("Name #%d", i));
        t->Fill();
    }
    f.Write();
    f.Close();

    TStopwatch w;

    //
    // This is much much too slow. It should be as fast as MChain2
    // below, but because GetEntry() is not called before setting
    // the branch status it's slow like a snake!
    //
    // For our own class (a copy of TArrayD but derived from TNamed)
    // this also results in a big memory leak!
    //
    MChain chain("Events");
    chain.Add("test.root");
    chain.SetBranchAddress("TNamed.", &named);
    chain.SetBranchStatus("*", 0);
    chain.SetBranchStatus("TNamed.", 1);
    w.Start();
    for (int i=0; i<chain.GetEntries(); i++)
        chain.GetEntry(i);
    w.Stop();
    w.Print();

    //
    // Reading the first entry before setting the branch status
    // results in only reading "TNamed."
    //
    MChain chain2("Events");
    chain2.Add("test.root");
    chain2.SetBranchAddress("TNamed.", &named);
    chain2.GetEntry(0);
    chain2.SetBranchStatus("*", 0);
    chain2.SetBranchStatus("TNamed.", 1);
    w.Start();
    for (int i=0; i<chain2.GetEntries(); i++)
        chain2.GetEntry(i);
    w.Stop();
    w.Print();

    //
    // For comparison: Not setting the branch status is about
    // two times slower, becuase "TNamed." and "TNamed2." are read
    //
    MChain chain3("Events");
    chain3.Add("test.root");
    chain3.SetBranchAddress("TNamed.", &named);
    w.Start();
    for (int i=0; i<chain3.GetEntries(); i++)
        chain3.GetEntry(i);
    w.Stop();
    w.Print();
}



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:16 MET