Hello,
I am having difficulty copying a TGraph2DErrors using its inherited Clone method. The trouble is when I write code like this.
TGraph2DErrors* GetGraphFromFile(TString file_name)
{
TGraph2DErrors *gr = 0;
TFile *f = new TFile(file_name.Data());
gr = dynamic_cast<TGraph2DErrors*>(f->Get("mygraph"));
if (gr!=0)
{
TGraph2DErrors* temp_gr = dynamic_cast<TGraph2DErrors*>(gr->Clone("temp_gr"));
gr = temp_gr;
}
f->Close();
return gr;
}
The result of the above returns a non-null ptr to my TGraph2DErrors object, but it now contains null data pointers fX, fY, …, and fEZ that cause segmentation faults. It appears that the TFile is claiming ownership over the TGraph2DErrors as it would a histogram or ttree. Can this be? If so how do I copy/clone the object for later use?
I have attached a more detailed example to demonstrate.
example.root (265 KB)
tgraph2derrors_copy_problem.cpp (1.82 KB)