Updating a TMultiGraph from a root file

Hi rooters,

I am trying to update a TMultiGraph from a root file and I am getting bus errors and I suspect this is an issue regarding ownership. The source of the error is similar to the following snippet:

TFile file("graphs.root","UPDATE");
TMultiGraph *multi_gr[n]; 

for(int i =0; i<n;i++){
  char *graph_names; // note the graph names are i dependent
  multi_gr[i] = (TMultiGraph*)(file.Get(graph_names)));  
  multi_gr[i]->Write("graph_names", TObject::kOverwrite);

From what I can tell there is no problem with “model_gr” which I add to “multi_gr” however when I “Get” graphs from “graphs.root” and over write them I am getting bus errors. I thought the issue was that Get has not create a copy of the original TMultiGraph stored in the root file, but even trying to clone the multigraph and writing after filling “multi_gr[i]” I still get the same errors.

any help would be much appreciated



To clarify the problem I am facing I have attached a working piece of code which is reproducing the problem I am facing. ANy help would be greatly appreciated


test_gr.cpp (1.06 KB)

[code]#include “TFile.h”
#include “TObject.h”
#include “TGraph.h”
#include “TMultiGraph.h”
#include “TRandom3.h”

TGraph *generate_graph(void)
double rnd, x, z;
double e = 0.3;
int nd = 500;

TRandom3 r(0);
TF1 *f1 = new TF1(“f1”, “1000.0 * (sin(x) / x + 0.21723363)”, -6., 6.);

TGraph *dte = new TGraph(nd);

// Fill the 1D graph
for (int i = 0; i < nd; i++) {
x = f1->GetRandom();
rnd = r.Uniform(-e, e); // Generate a random number in ]-e, e] range
z = f1->Eval(x) * (1. + rnd);
dte->SetPoint(i, x, z);

delete f1;

return dte;

void add_multi_graph(int i)
TMultiGraph *multi_gr;

TFile file(“graphs.root”, “UPDATE”);

#if 0 /* 0 or 1 /
i = i; // get rid of the compiler warning: unused parameter ‘i’
file.GetObject(“graphs”, multi_gr);
#else /
0 or 1 */
if (i == 0) multi_gr = ((TMultiGraph )0);
else file.GetObject(“graphs”, multi_gr);
#endif /
0 or 1 */

if (!multi_gr) multi_gr = new TMultiGraph();


multi_gr->Write(“graphs”, TObject::kOverwrite);


delete multi_gr;

#if defined(CINT) || defined(ACLIC)
// “ROOT Script” entry point.
int test_gr(void)
#else /* defined(CINT) || defined(ACLIC) /
// “Standalone Application” entry point.
int main(int /argc/, char ** /argv/)
#endif /
defined(CINT) || defined(ACLIC) */
int n = 3;

for(int i = 0; i < n; i++) {

return 0;