Logo ROOT  
Reference Guide
Functor.C
Go to the documentation of this file.
1 #include<TRInterface.h>
2 #include<TMath.h>
3 
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 {
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 }
f
#define f(i)
Definition: RSha256.hxx:122
TMath::BesselY1
Double_t BesselY1(Double_t x)
Bessel function Y0(x) for positive x.
Definition: TMath.cxx:1714
r
ROOT::R::TRInterface & r
Definition: Object.C:4
ROOT::R::TRInterface
Definition: TRInterface.h:137
x
Double_t x[n]
Definition: legend1.C:17
Function
Double_t(* Function)(Double_t)
Definition: Functor.C:4
TRInterface.h
ROOTR_MODULE
ROOTR_MODULE(MyFunctorModule)
Definition: Functor.C:18
Functor
void Functor()
Definition: Functor.C:26
ROOT::R::class_
Definition: RExports.h:144
LOAD_ROOTR_MODULE
#define LOAD_ROOTR_MODULE(NAME)
Definition: RExports.h:177
Double_t
double Double_t
Definition: RtypesCore.h:59
ROOT::R::TRInterface::Instance
static TRInterface & Instance()
static method to get an TRInterface instance reference
Definition: TRInterface.cxx:185
TMath.h