Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
Functor.C
Go to the documentation of this file.
1 #include<TRInterface.h>
2 #include<TMath.h>
3 
4 typedef Double_t (*Function)(Double_t);
5 
6 class MyFunctor{
7 public:
8  MyFunctor(){
9  f=TMath::BesselY1;//here is the function that I want.
10  }
11  Double_t doEval(Double_t x) {
12  return f(x);
13  }
14 private:
15  Function f;
16 };
17 
18 ROOTR_MODULE(MyFunctorModule) {
19  ROOT::R::class_<MyFunctor>( "MyFunctor" )
20  .constructor()
21  .method( "doEval", &MyFunctor::doEval )
22 // .method( "otherMethod", &MyFunctor::otherMethod )//you can added more methods adding .method(name,pointer)
23  ;
24 }
25 
26 void Functor()
27 {
28  ROOT::R::TRInterface &r=ROOT::R::TRInterface::Instance();
29  r["MyFunctorModule"]<<LOAD_ROOTR_MODULE(MyFunctorModule);
30 
31  r<<"MyFunctor <- MyFunctorModule$MyFunctor";
32  r<<"u <- new(MyFunctor)";
33  r<<"print(u$doEval( 1 ))";
34  std::cout<<"value in ROOT = "<<TMath::BesselY1(1)<<std::endl;
35 }