Is gPad defined?

gPad, the pointer to the current pad, is not defined from the time ROOT starts up until a pad is created.

What is the proper way for a script to determine whether or not gPad is defined?

I tried looking in gROOT->GetListOfGlobals(), or bypassing gPad by using gROOT->GetSelectedPad(), but neither of these works as I thought it would. In particular, gROOT->GetListOfGlobals() does not always seem to contain gPad even when gPad is defined, nor is gROOT->GetSelectedPad() always equal to gPad when the latter is defined.


For various technical reasons, gPad is defined in the interpreter only when it is non-zero (i.e. after you created the first canvas/pad).


Yes, I know that. My question is, how can a script determine whether gPad is defined?

Create a TCanvas object


All right, let me clarify: How can a script determine whether gPad exists, without modifying its value if it does?

Does it work to check if gROOT->GetListOfCanvases()->LastIndex() == -1 ?

Yes this should work