Steering mechanism with cint api

Dear Cint experts,

It came into my mind to use Cint to realise a steering mechanism (I don’t want to write a class to steer something as it it suggested in theROOT talk.): A script where variables and objects are defined is loaded and evaluated using Cint API functions. Please have a look at the attached packed tar-file where you can find an example showing how I’m doing this. I make use of the API function G__what_type because it is very useful for this purpose. In the documentation this function is called a debug function. So I wonder if this function is save and if you recommend to use it this way. Perhaps one can improve this function to make it save (Is enough memory reserved for objects I want to steer?). Realising a steering mechanism using Cint has got a lot of advantages: it is easy to code, it has got a small overhead, one can steer any object,… So I really would like to use Cint this way but only if it is save on long terms.

What is your opinion on that? Perhaps you can think of a better solution (The steering script/file should be as simple as in my solution and the same functionality should be provided.)?

Greetings and many thanks in advance,

Martin
Steering.tar.gz (2.79 KB)

Hello,

I already answer this question by e-mail. For not leaving open questions in this forum, I’ll copy my answer here.


Hello Martin,

I am happy to answer your question.

Using Cint as a steering mechanism is good. Cint is made for that kind
of needs.

You are asking about G__what_type() API. In fact, it is a obsolete interface.
So, I do not recommend using it. Please use G__TypeInfo instead. Your
GetPtr() function will look like below. (just concept, I did not verify this)
For API documentation, please read cint/doc/ref.txt.

Thank you
Masa Goto

// -I $CINTSYSDIR -I $CINTSYSDIR/src
#include “G__ci.h”
#include “Api.h”

void* H1CintSteer::GetPtr(char* name, char* type)
{
G__value obj = G__calc(name);
if(!obj.type) {
cout<<"<== H1CintSteer ==> Variable ‘"<<name<<"’ is not defined!"<<endl;
return NULL;
}

G__TypeInfo type(obj);
if(strcmp(type.Name(),type)==0) {
cout<<"<== H1CintSteer ==> Reading of variable ‘"<<name<<"’ of type ‘"<<type<<"’ successful!"<<endl;
} else {
cout<<"<== H1CintSteer ==> Variable ‘"<<name<<"’ is not defined as ‘"<<type<<"’! It is of type ’ “<<mytype<<”’!"<<endl;
return NULL;
}

void *ptr = obj.ref; // or possibly ptr=obj.obj.i

return ptr;
}