ROOT Version: 5
Platform: Scientific Linux 6.10
Compiler: g++ 4.4.7
Hi everyone! I am trying to create a ROOT file with TTrees that contain several TBranches, which contain a single entry each. Here is a working test code displaying the issue. In this code, I am trying to create a TTree with 10 TBranches. Each TBranch has two TLeaves, both ranging from 0 to 9. Instead, I get 10 TTrees with 10 TBranches of varying number of entries. The values get appended to TBranches that have already been created, instead of āfreezingā their values and making a new branch.
#include <iostream>
#include <string>
#include <sstream>
#include "TFile.h"
#include "TTree.h"
#include "TBranch.h"
#include "TString.h"
using namespace std;
struct Values{
int val1, val2;
};
int main(){
int i = 0;
int j = 0;
string name;
stringstream nameformat;
TString t_name;
TFile* data = TFile::Open("Test.root", "recreate");
for(i = 0; i < 10; i++){
name = "Test";
nameformat << i;
name += nameformat.str();
nameformat.str("");
t_name = name;
TTree* tree = new TTree(t_name, t_name); //Make 10 TTrees in the TFile, each TTree will contain 10 branches with two values from 0 to 9
for(j = 0; j < 10; j++){
name = "Test";
nameformat << j;
name += nameformat.str();
nameformat.str("");
t_name = name;
Values Val;
Val.val1 = i;
Val.val2 = j;
TBranch* b1 = tree->Branch(t_name, &Val, "Value1/I:Value2/I"); //Each branch should contain only one instance i and only one instance of j
}
tree->Fill();
tree->Write(); //The resulting tree will have branches with varying number of entries from 0 to 9
}
data->Close();
return 0;
}