Safe G__value conversion to const char* and TObject*


I wonder how G__value can safely be converted to string or TObject*. For int and double there are the functions G__int() and G__double(), but nothing for string and TObject*. I found that the following trick works

G__value v = ...
const char *str = (const char*) v.obj.i;
TObject *o = (TObject *) v.obj.i;

However, I don’t find it too safe… Is there anything better I can do?

Furthermore, I’ve got one more question regarding type identification. I know there is G__value::type and G__TypeInfo::Name(). The latter method (often) gives a human understandable result. But converting integer information to string and then performing string comparison is a bit cumbersome in my opinion. Moreover, for class pointers (TH1D*, TAxis*, etc.) the G__TypeInfo::Name results in “const enum*” which doesn’t meet my expectations. Second possibility is to base the type identification on G__value::type. Is there somewhere a table relating a value to a type?

Many thanks, Kašpi.

Could you explain what is the problem that you are trying to solve? may be there are better solutions than the one you are exploring now ::slight_smile:



I’m writing a ROOT interface to the Asymptote drawing language ( The goal is to allow Asymptote for loading (from ROOT files) and drawing ROOT objects, such as TH1D, TGraph, etc.

The Asymptote language is also a C++ like language. In my opinion, the most flexible interface is
a) to represent a generic ROOT object (descedant of TObject) by an Asymptote object, which
b) would allow for calling ROOT methods from Asymptote.
The point b) is achieved by CINT API. My question is related to a little doubt how to interpret a result of G__CallFunc::Execute.

Thanks again, Kašpi.

Why not simply generating the dictionary for the asymptote classes and call these classes from a ROOT prompt ? This should be simpler and more efficient.


There several reasons why, in my opinion, this is not the right way.

  1. Asymptote is C++ like, but it is not C++. The language is designed to perform well when producing graphics and hence it deviates from C++ significantly. Thus the dictionary generation might be a challenge.

  2. Asymptote is an interpreted language. A script is executed by a virtual machine. The script may define new classes. I’m not sure if/how a runtime generation of dictionaries would work.

  3. Your solution would be convenient to easily access Asymptote objects from ROOT. But I’m aiming at the opposite direction: to access ROOT objects from Asymptote.

Am I right?

Thanks, Kašpi.


What you are trying to do is akin to Wim’s work for python (see $ROOTSYS/bindings/pyroot).

G__value is part of CINT and as thus does not know (directly) about any of ROOT’s construct (TObject).

The ‘type’ is G__Value is actually a ‘tuple’ composed of information from tagnum, typenum, type, isconst and obj.reftype. An ‘easier’ interface is to use G__TypeInfo:G__TypeInfo ti( v );