#include "TGraph.h" #include "TFile.h" void root_problem() { double x[] = {0, 1, 2, 3}; double y[] = {0, 1, 4, 9}; TGraph *g = new TGraph(4, x, y); const char dirName[] = "first>second"; const char objName[] = "g"; char path[100]; sprintf(path, "%s/%s", dirName, objName); TFile *f = new TFile("root_problem.root", "recreate"); gDirectory = f->mkdir(dirName); g->Write(objName); delete f; f = new TFile("root_problem.root"); g = (TGraph *) f->Get(path); printf("g = %p\n", g); // -> NULL TDirectory *d = (TDirectory *) f->Get(dirName); g = (TGraph *) d->Get(objName); printf("g = %p\n", g); // -> OK delete f; }