Re: [ROOT] root as extension language

From: Axel Naumann (axel@fnal.gov)
Date: Mon Mar 24 2003 - 10:04:44 MET


Hi Ruediger,

> Basically all I need at the moment is a way to call root from within
> my (C++ / gcc 3.2) program when needed and let it execute a script,
> that in addition must have access to some data supplied by the program
> and be able to return the (floating point) result of running the script -
>  i.e. a single double.
> 
> double EVA::customValue(void) // evaluation function used in Evol. Algorithm;
>                                              //  this is compiled code
> {
>    double result=
>     
>  commandToRunRoot("/where/script/resides/script.cc",stlVectorWithDoubles);
>  return result;
> }

Translated to existing root methods it could look something like this:
double EVA::customValue(void) {
   double result = gROOT->ProcessLineFast(
     Form("/where/script/resides/script.cc(%p);",
       &stlVectorWithDoubles));
   return result;
}

Your script will have to look like this:
double script(std::vector<double>* pvec){
...
}

> I believe that this can be done in a much more elegant way with root, and
> would like to ask you for a pointer to some good examples or any other
> available information.

Have a look at
   http://root.cern.ch/root/html/TROOT.html#TROOT:ProcessLine
and its neighbors ProcessLineSync and ProcessLineFast, depending on how 
you want that script to be executed (in parallel or synchronously). 
Watch out with the different ways in which these methods return the 
script's result.

Cheers, Axel.



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:10 MET