Reading data from custom classes written in TTree

Dear experts,

I would like to read data from a TTree that contains objects of a custom class (inherited from TObject) without knowing the exact definition of that class. If possible, I would like to avoid reimplementing the class that was used for the tree creation since I do not have this part of the code under control.

Also without knowing the class, ROOT can obviously access the data – using a TBrowser, i see all the members I am interested in as branches.

However, the following example code does not work:

  TFile* inFile = new TFile("./myTree.root", "READ");
  TTree* inTree = inFile->Get("tree");

  Float_t vertexZ = 0;
  inTree->SetBranchAddress("VertexZ", &vertexZ);
  inTree->GetEntry(0);
  std::cout << vertexZ << std::endl;

VertexZ is the correct branch name, and there is no error message. But the value of vertexZ is just not reset when using GetEntry(0) (or other tree indices).

Am I missing something? Is “custom-class-agnostic” reading of trees possible at all?
NB: I am using ROOT5.

Thanks & best,
Rudiger

Thanks for the answer!

So from the linked topic I understand that I really need the class definition (extracted via MakeClass or directly). I cannot just access the branches, right?

So probably I cannot circumvent to implement a local copy/class skeleton in my code.

Best,
Rudiger

If you don’t know how to deal with your tree, see how various flavours of automatically generated “analysis skeletons” deal with it.

Moreover, you may be interested in: TFile::MakeProject

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