Hi All,
First of all let me state that this a newbie question regarding usage of ROOT Trees.
I have a class called Neuron that I want to store in a ROOT tree. For the time being I am not concerned with the spilting details and leave it to the ROOT scheme.
So I want to make one tree called “NeuronTree” and store the Neuron objects as independent BRANCHES in this tree. I am using following code to acheive this;
[code]
{
TFile f = new TFile (“neuron.root”,“CREATE”);
TTree t(“NeuronTree”, " A Tree with Neurons");
// create 100 branches
for (Int_t i=0;i<100;i++){
TString name=“Neuron”;
Neuron neuron = new Neuron();
neuron->SetCellName(name+i);
neuron->SetLayer(i%5);
neuron->SetGeneticType(“ABS”);
t.Branch(name+i,“Neuron”,&neuron,32000,99);
t.Fill();
}
f->Write();
f->Close();
}[/code]
This results in stroring these objects into the tree in independent branches.
So the tree root is “NeuronTree” and it has 100 branches named Neuron0-99 which contain the data for a Neuron.
Now I have to read these objects and display their contents. However I dont want to provide name of these individual branches, rather loop over them based on the branch index . So after trying few examples here and there I could come up with following code;
Neuron *n = new Neuron();
TBranch *br = tree->Branch("Test","Neuron",&n,32000,99);
Int_t count =tree->GetNbranches();
for (Int_t i=0;i<count;i++){
tree->GetEntry(i);
n->Print()
}
I used statement
TBranch *br = tree->Branch(“Test”,“Neuron”,&n,32000,99);
only when I was not able to find out a way to refer to tree branches with index numbers and in my application I will not know the name of these individual branches in advance.
I will appreciate if someone can indicate me a possibly better way to read objects stored in tree branches.
Regards,
Asif