I have been trying to fill a single tree with branches as vectors and maps.
However, when I try to read the tree, it shows segmentation fault.
Any help will be appreciated.
Thanks!
Example code:
//-----------------------------------------------------------------------------
#include "TFile.h"
#include "TTree.h"
#include "vector"
void check1() {
//Write --------------------------------------------------------
std::vector<double> U1j;
map<string, double> ampl ;
//double mm;
TFile* fileout = new TFile("readcheck.root", "RECREATE");
TTree* tree = new TTree("Norm","");
tree->Branch("U1j", &U1j);
//tree->Branch("mm", &mm, "mm/D");
tree->Branch("ampl", &l);
for(Int_t i=0; i<5; i++)
{ ampl.clear();
U1j.clear();
ampl.insert(pair<string, double>("kstar892",1.0*i));
ampl.insert(pair<string, double>("rho770",2.0*i));
ampl.insert(pair<string, double>("omega782",3.0*i));
//mm = i*10.0;
for(int j=0; j<3; j++)
{ U1j.push_back(i*20.0);
}
tree->Fill();
}
fileout->Write();
fileout->Close();
//Read -----------------------------------------------------------
std::vector<double> *U1j = 0 ;
map<string, double> *Ampl ;
//double MM;
TFile* filein = new TFile("readcheck.root");
TTree* t1;
t1 = (TTree*)filein->Get("Norm");
t1->SetBranchAddress("U1j",&U1j);
t1->SetBranchAddress("ampl",&Ampl);
//t1->SetBranchAddress("mm", &MM);
for(int i=0; i<t1->GetEntries(); i++)
{ t1->GetEntry(i);
cout<<"Amplitude[kstar892]: "<<(*Ampl)["kstar892"]<<endl;
for(int j=0; j<3; j++)
{ cout<<"U1j[j]: "<<(*U1j)[j]<<endl;;
}
cout<<endl;
}
}
//------------------------------------------------------------------------------
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided