How to get pointer to a global variable (in cint)


I wonder how I could get a pointer to a global variable defined in cint. Something like in the code below. Here I declared variable “myVariable”. I tried TROOT::Get() method, but it doesn’t work. TGlobal::GetAddress yields something, but the result is not correct. What am I doing wrong?

root [0] TH1D *myVariable = new TH1D() root [1] myVariable (class TH1D*)0x9a1ba88 root [2] gROOT->Get("myVariable") (class TObject*)0x0 root [3] gROOT->GetGlobal("myVariable") (const class TGlobal*)0x9a57a00 root [4] gROOT->GetGlobal("myVariable")->GetAddress() (const void*)0x9a00e40

Many thanks, Kašpi.

myVariable could be a pointer to a global variable. It might be easier to read this way:

TH1D *ptr;
TH1D h;

[quote]What am I doing wrong? [/quote]I am not sure what you are trying to do.

[quote]wonder how I could get a pointer to a global variable defined in cint[/quote]Stringly speaking the answer is&myVariable


Yes, I should have explained why I am trying to do this seemingly awkward thing. I’m trying to develop an interface between ROOT and Asymptote drawing language ( I’m aiming at drawing ROOT objects (saved in ROOT files) with Asymptote. Now I’m in the phase when investigating possibilities for this interface, finally to pick up the best implementation. One of the ideas was to implement an Asymptote function to call a ROOT command, e.g.

RootExec("some command") --> TApplication::ProcessLine("some command")

In this way one could achieve loading an object from an file

RootExec("TFile *f = new TFile(\"...\")");
RootExec("TGraph *g = (TGraph *) f->Get(\"...\")");

Now we’re in a point when TGraph data need to be exported to Asymptote. The idea is to use an Asymptote function

where the “path” is an Asymptote object, basically representing a spline. The thing is that the implementation of the RootGetGraph method needs to get pointer to TGraph g given the string “g”. And that was my question…

Many thanks, Kašpi.

You can usevoid *addr = (void*)gROOT->ProcessLineFast("&g");