Hi there,
I’ve never had a need to look at the return values from TTree::SetBranchAddress before, but I recently added a branch to my standard TTree and I want to ensure compatibility with old data (which doesn’t have this branch). I was hoping I could check for these return values, but it appears they are always 0, despite what would be expected from this.
I’m hoping I’m just doing something wrong, or that there is a more straightforward way to checking if a branch exists.
I wrote this crude test to illustrate the problem. The idea was to try to SetBranchAddress to a missing branch, and see that the returned value was -5 (kMissingBranch). Instead, the returned value was 0.
void test() {
TFile *out_file = new TFile("test.root", "recreate");
TTree *out_tree = new TTree("test_tree", "Test tree");
Int_t i;
out_tree->Branch("value", &i, "value/I");
for( int i = 100; i > 0; i-- ) {
out_tree->Fill();
}
out_tree->Write();
out_file->Close();
delete out_tree;
delete out_file;
TFile *file = new TFile("test.root");
TTree *tree = (TTree*)file->Get("test_tree");
Int_t value, fake_value;
Int_t r;
r = tree->SetBranchAddress("value", &value);
printf("value: r = %d\n", r);
r = tree->SetBranchAddress("fake_value", &fake_value);
printf("fake_value: r = %d\n", r);
return;
}
Output:
root [0] .x test.cxx
value: r = 0
Error in <TTree::SetBranchAddress>: unknown branch -> fake_value
fake_value: r = 0
I am running version 5.32/01 on Windows 7.
Thank you for the help!