SetBranchAddress and GetEntry not working as expected

I have a tree that was made with another root script, and I want to read certain values for my analysis. The docs say I should define my variables, call SetBranchAddress on my tree, call GetEntry on the tree, and after that I my variables should have the values appropriate to that entry of the tree. A colleague tried it this way on his tree, and it worked fine:

f = new TFile(“tree.root”);
float test;
T->SetBranchAddress(“integradius”, &test);
T->GetEntries();
for(int i = 0; i<50; i++){ T->GetEntry(i); cout << test << endl;}

I tried to do the identical thing with my tree, …

root [0] f = new TFile("…/data/20110419090551_DES2219-4147.root");
Warning in TClass::TClass: no dictionary for class Db::DBImage is available
Warning in TClass::TClass: no dictionary for class Db::DatabaseBase is available
Warning in TClass::TClass: no dictionary for class XYZTree is available
Warning in TClass::TClass: no dictionary for class Db::DBTruth is available
Warning in TClass::TClass: no dictionary for class Db::DBSCoaddObject is available
Warning in TClass::TClass: no dictionary for class Db::DBSObject is available
root [1] float test = 9.9;
root [2] tree->SetBranchAddress(“magerr_model_g”, &test);
root [3] tree->GetEntries();
root [4] for(int i = 0; i<50; i++){ tree->GetEntry(i); cout << test << endl;}
9.9
9.9
9.9

9.9
9.9
9.9

… and found that GetEntry never changes the value of my variable. (Those warnings always come, and I ignore them, apparently without ill effects.) A Scan …

root [5] tree->Scan(“magerr_model_g”);
Warning in TGMimeTypes::TGMimeTypes: error opening mime type file /etc/root/root.mimes


  • Row * magerr_mo *

  •    0 * 0.1407223 *
    
  •    1 * 0.2882340 *
    
  •    2 * 0.1940311 *
    

  •   22 * 0.0596469 *
    
  •   23 * 0.0983687 *
    
  •   24 * 0.1284388 *
    

Type to continue or q to quit ==> q


… verifies that the values in this branch of the tree are “interesting”. In addition, if there were no branch with this name, or if the values were of a different type, root would have complained (even without the Scan). It doesn’t make any difference whether test is declared as float of Float_t.

It seems to me I am not doing anything complicated or esoteric here. Calling SetBranchAddress and GetEntry in this way is “the default and recommended way” to read a TTree. (root.cern.ch/root/html528/TTree. … e:GetEntry) I have boiled the code down to a few lines, so typos and strange interactions are unlikely. I am totally puzzled by this behavior and would appreciate any help to get this script working properly. (I have browsed this forum and found a number of similar posts, but nothing close enough to get me moving again.)

Regards,
Art Carlson
University Observatory Munich

[quote]Warning in TClass::TClass: no dictionary for class Db::DBImage is available[/quote]Tells me that you TTree contains objects but root [1] float test = 9.9; root [2] tree->SetBranchAddress("magerr_model_g", &test);you are trying to access only one data member directly. This decomposition is not yet detected automatically and you need to set the TTree in a mode that support this access (but disable the access via objects) by calling tree->SetMakeClass(1);

Cheers,
Philippe.

Thanks, I figured out that my tree contained objects, and that that was the source of the problem. If I load the definitions of those objects, then I can get them back from the tree and query them for their members. That has some tricky bits on my installation, but fundamentally works.

The solution with SetMakeClass, one might think, could work even better, e.g. by avoiding the necessity of loading the object definitions. In fact, when I try it, I run into a segmentation violation. Do you have any idea how to get around that?

root [0] f = new TFile("…/data/20110419090551_DES2219-4147.root");
Warning in TClass::TClass: no dictionary for class Db::DBImage is available
Warning in TClass::TClass: no dictionary for class Db::DatabaseBase is available
Warning in TClass::TClass: no dictionary for class XYZTree is available
Warning in TClass::TClass: no dictionary for class Db::DBTruth is available
Warning in TClass::TClass: no dictionary for class Db::DBSCoaddObject is available
Warning in TClass::TClass: no dictionary for class Db::DBSObject is available
root [1] float test = 9.9;
root [2] tree->SetMakeClass(1);
root [3] tree->SetBranchAddress(“magerr_model_g”, &test);
root [4] tree->GetEntries()
(const Long64_t)35808
root [5] tree->GetEntry(20000)

*** Break *** segmentation violation

-art-

Hi,

Maybe you have collection of object and/or your data member is not a float.
See the result of running tree->MakeSelector(“sel”) on your tree.

Cheers,
Philippe.