Hi!
I’ve been having issues while trying to access data from a root file with the following structure:
There are 4 branches inside one tree inside an event folder, and there are 100 event folders.
I don’t exactly know how to do that, however I wrote the following code:
TFile *myFile = new TFile(fileName,"READ");
TBranch *myBranch;
TLeaf *myLeaf;
Float_t energy = 0;
TString event = "";
// loop through 100 events
for(Int_t i = 0; i < 100; i++){
cout << "Event" << i << endl;
TTree *myTree = (TTree*)myFile->Get(Form("Event%d/fTreeR",i));
cout << "flag0\n";
if(!myTree){
continue;
}
cout << "flag1\n";
//myTree->Print();
myTree->SetBranchAddress("AliFOCALClusterItr.fEnergy",&energy);
//myBranch = (TBranch*)myTree->Branch("AliFOCALClusterItr");
//myTree->SetBranchAddress("AliFOCALClusterItr.fEnergy",&energy);
cout << "flag2\n";
cout << "There were " << myTree->GetEntries() << " entries in the TTree.\n";
cout << "flag3\n";
for(int j = 0; j < myTree->GetEntries(); j++){
cout << "flag4\n";
myTree->GetEntry(j);
cout << "flag5\n";
cout << "energy = " << energy << endl;
}
cout << "i = " << i << endl;
delete myTree;
}
//myTree->SetBranchAddress("AliFOCALClusterItr.fEnergy",&energy);
//TBranch *branch = myTree->GetBranch("AliFOCALClusterItr.fEnergy");
//branch->SetAdress(&energy);
//TH1F *hist = new TH1F("Energy","AliFOCALClusterItr.fEnergy copy");
myFile->Close();
I put some flags to try to figure out what was happening, and the following is what I get in the terminal:
So there are 2 problems:
i - how do I access the content of a leaf inside a branch inside the tree? And do I need to loop through this leaf data or is there a way of accessing the objet inside the leaf (e.g. a TH1F histogram)
ii - the events are read until the 29th, when a break segmentation violation occurs. Is this event 29 empty, is there a memory leakage in my code or what is going on?
As you can see, I’m a bit lost here and I appreciate any help.
Thank you already!
_ROOT Version: 6.24/06
_Platform: Ubuntu 20.04