TTree Fill Error


Please read tips for efficient and successful posting and posting code


Hi,

I want to create a new branch on an existing tree using entries from two existing branches

void makeAvgBranch() {
    TFile* inFile = new TFile("somefile.root", "update");
    TTree* tree = static_cast<TTree*>(inFile->Get("someTree"));
    tree->Print();
    Double_t newBranch;
    TBranch* avgBranch = tree->Branch("avg", &newBranch);
    Double_t data_a, data_b;
    tree->SetBranchAddress("a", &data_a);
    tree->SetBranchAddress("b", &data_b);
    for (int i = 0; i < tree->GetEntries(); i++) {
        tree->GetEntry(i);
        newBranch = 0.5*(data_a + data_b);
        avgBranch->Fill();
    }
    tree->Print();
}

However, when I tried to fill the new branch, I get the following errors:

Error in <TBranch::WriteBasketImpl>: basket's WriteBuffer failed.
Error in <TBranch::TBranch::Fill>: Failed to write out basket.

The errors only occur periodically.

Here is the info on the branches:

*............................................................................*
*Br   25 :a : Double_t                                        *
*Entries :  5388854 : Total  Size=   43124605 bytes  File Size  =    2529536 *
*Baskets :      122 : Basket Size=    1506304 bytes  Compression=  17.05     *
*............................................................................*
*Br   26 :b : Double_t                                         *
*Entries :  5388854 : Total  Size=   43124479 bytes  File Size  =    2886215 *
*Baskets :      122 : Basket Size=    1506304 bytes  Compression=  14.94     *
*............................................................................*
*Br   48 :avg : avg/D                                    *
*Entries :  5388854 : Total  Size=   43116791 bytes  All baskets in memory   *
*Baskets :       1350 : Basket Size=    32000 bytes  Compression=   1.00     *
*............................................................................*

where a and b are the two existing branches and avg is the new branch that I created. Why am I getting these errors? And how are they affecting the new branch?

The inFile file is probably not “writable” for you (check permissions).

BTW. After the “for” loop, you need: tree->Write();

You are right! I can’t change the original file. I tried cloning the necessary branches into a new tree, but that also does not seem to work.

You could copy the original files onto a directory you have write access to.

If that is not possible, you should consider putting the new branches in a new TTree in a new file and when using/reading the TTree, open both the original and new files and make the new TTree a friend of the old TTree.

Cheers,
Philippe.

PS.
With newer version (v6.14 and newer) of ROOT we recommend replacing

        avgBranch->Fill();

with

        avgBranch->BackFill();

to allow for better alignment of the new branches with the “clusters” of the existing TTree.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.