(1) I tried using the Tcint class & could get the function source code compiled ok. But I am not able to correctly pass the parameters via Execute() to this function.
(2) Also, how can I get the return value of the function (say return value of "MyFunction") I am executing?
My test program is attached here for your review. May I please know, what wrong am I doing here? Means, how should I set the 2nd parameter of Execute call correctly, so that it can pass those arguments correctly to my defined function "MyFunction"?
I compiled this test program as below.
/usr/bin/g++ -g -D_DEBUG -c -fPIC -D_GNU_SOURCE -D_REENTRANT -D_VMT -D_VNIX -D__LINUX__ -D_INTEL_X86_ -I. -I/home/gborse/pxm/root/include -I/home/gborse/pxm/analyzer-1.4.9/src -ggdb -g3 -I/home/gborse/pxm/include usecint.cpp
/usr/bin/g++ -g3 -ggdb usecint.o -L/home/gborse/pxm/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lNormAna -lHallA -lscaler -ldc -lpthread -lm -ldl -rdynamic -L/home/gborse/pxm/lib/Linux_2.4.21-9.0.1.ELsmp -lrt -o usecint.exe
Its output is like this on my machine:
gborse_at_njl36a-7003:~/pxm/parserroot>./usecint.exe
Funciton definition = [int MyFunction(int size, int vol, int ADV,char* prod, char* ordClient){
if((size<1000)&&(vol<(0.001 * ADV)) && (prod=="Stock")&&strstr("ABCD,EFGH,HIJK,NEWONE,song,JUNK,DONE",ordClient))
return 11;
else
return 10;
}
]
Create TCint object
pcint->ProcessLine result 0
Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0: Warning: Illegal numerical expression 101001000000StockDONE :0:Execute of MyFunction returned 0
Thanks,
Ganesh
-----Original Message-----
From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch] On Behalf Of Borse, Ganesh
Sent: 06 December 2007 13:33
To: 'Axel Naumann'
Cc: Rene Brun; roottalk_at_root.cern.ch; 'cint_at_root.cern.ch'
Subject: RE: [CINT] Re: [ROOT] Embedding CINT in C++ application
-----Original Message-----
From: Axel Naumann [mailto:Axel.Naumann_at_cern.ch]
Sent: 05 December 2007 18:03
To: Borse, Ganesh
Cc: Rene Brun; roottalk_at_root.cern.ch; 'cint_at_root.cern.ch'
Subject: Re: [CINT] Re: [ROOT] Embedding CINT in C++ application
Hi,
the bytecode never goes to file - it is generated and stays in memory. The C++ code does, but the OS should cache it, so disk latency should not matter.
Cheers, Axel.
Borse, Ganesh wrote:
> What about disk latency when accessing the byte code from the file?
>
> -----Original Message-----
> From: owner-roottalk_at_root.cern.ch [mailto:owner-roottalk_at_root.cern.ch]
> On Behalf Of Axel Naumann
> Sent: 05 December 2007 17:46
> To: Borse, Ganesh
> Cc: Rene Brun; roottalk_at_root.cern.ch; 'cint_at_root.cern.ch'
> Subject: Re: [CINT] Re: [ROOT] Embedding CINT in C++ application
>
> Hi,
>
> you could write it to a temporary file. If you call it e.g.
> "tempAHGHJGJ.C" and wrap your code in a function "tempAHGHJGJ()" you can simply do gInterpreter->ProcessLine(".x tempAHGHJGJ.C"). This file will be run with bytecode optimization.
>
> Cheers, Axel.
>
> Borse, Ganesh wrote:
>> ProcessLine would be slower because every call to ProcessLine will parse the expression & then execute it. >> >> Is it possible to do the onetime parsing (& compile) of such expression & then execute that byte code later multiple times? >> >> E.g. I wrap this expression in a function like below: >> >> const char *myFuncSrc=\ >> "int MyFunction(int size, int vol, int ADV,char* prod, char* >> ordClient)\ {\ >> if((size < 1000) && (vol < (0.001 * ADV)) && (prod == "Stock") && strstr("ABCD,EFGH,HIJK,NEWONE,song,JUNK,DONE",ordClient))\ >> return 1;\ >> else\ >> return 0;\ >> }" >> // Parse & Compile this function >> gInterpreter->ProcessLine(myFuncSrc); >> while(1){ >> // --- data for variables come in from client application over a socket connection >> char* argv[]=; // populate the input arguments.... >> Int result=0; >> gInterpreter->Execute("MyFunction",argv,&result); >> printf("result %d\n",result); >> } >> >> How do we do this kind of actions with Tinterpreter or other APIs of cint? >> Sorry for long list of questions. >> >> Thanks & Regards, >> Ganesh >> -----Original Message----- >> From: Axel Naumann [mailto:Axel.Naumann_at_cern.ch] >> Sent: 05 December 2007 17:09 >> To: Rene Brun >> Cc: Borse, Ganesh; roottalk_at_root.cern.ch; 'cint_at_root.cern.ch' >> Subject: Re: [CINT] Re: [ROOT] Embedding CINT in C++ application >> >> ...or, for more of C++ including variable declaration etc, pass your C++ code as a string to ROOT's gInterpreter>ProcessLine(). gInterpreter is ROOT's global TCint object; a high level interface to CINT. See <http://root.cern.ch/root/html/TCint#TCint:ProcessLine> If you weant to do the same with CINT stand-alone then please let us know. >> >> Cheers, Axel. >> >> Rene Brun wrote: >>> ROOT provides two classes (TFormula and TTreeFormula) for doing >>> exactly what you want to do. >>> see examples of use with ROOT Trees in the Users Guide >>> ftp://root.cern.ch/root/doc/12Trees.pdf >>> at section "Simple Analysis using Trees" at page 213 and following >>> >>> Rene Brun >>> >>> Borse, Ganesh wrote: >>>> Hi, >>>> Is it possible to embed ROOT CINT in C++ application & use it for >>>> doing dynamic expressions parsing, compilation and then multiple >>>> run time evaluations those expressions? >>>> >>>> I can see the root/bin/cint has all its logic in >>>> root/lib/libCint.so, with ldd command. >>>> >>>> E.g, I have the expressions as below: >>>> ((size < 1000) && (vol < (0.001 * ADV)) && (prod == "Stock") && >>>> strstr("ABCD,EFGH,HIJK,NEWONE,song,JUNK,DONE",ordClient)) >>>> >>>> The variables size, ADV, vol, etc. will be changing at runtime. >>>> So, I would like to create function which will take these variables >>>> as input arguments & return the result of evaluated expression. >>>> >>>> Since, these expressions, the number & type of these variables is >>>> not at compilation time, I cannot create & compile these function >>>> at compiling my application. >>>> >>>> Hence, I need to use some kind of interpreter which can take these >>>> expressions, etc as source code & compile them. >>>> >>>> I tried to use Python & Perl interpreters for embedding them in C++ >>>> application. But they don't provide the required performance level. >>>> >>>> Also, the syntax of the expressions is to be same that in these >>>> scripting languages. Hence, it is little tedious to use them. >>>> >>>> May you please guide me, if I can use cint for this? >>>> What are the functions, APIs & include headers, etc. I need to use >>>> for this? >>>> >>>> A sample program of the same thing which I am doing with Cpython >>>> API (embedding Python in C) is attached here. >>>> >>>> Thanks and Regards, >>>> Ganesh >>>> <<testeval.cpp>> >>>> >>>> =================================================================== >>>> = >>>> = >>>> ========= >>>> >>>> Please access the attached hyperlink for an important electronic >>>> communications disclaimer: >>>> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html >>>> =================================================================== >>>> = >>>> = >>>> ========= >>>> >>>> >> ===================================================================== >> = ======== Please access the attached hyperlink for an important >> electronic communications disclaimer: >> >> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html >> ===================================================================== >> = >> ======== >> >>
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
This archive was generated by hypermail 2.2.0 : Thu Dec 06 2007 - 17:50:02 CET