forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Functor.C
35 lines (30 loc) · 846 Bytes
/
Functor.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<TRInterface.h>
#include<TMath.h>
typedef Double_t (*Function)(Double_t);
class MyFunctor{
public:
MyFunctor(){
f=TMath::BesselY1;//here is the function that I want.
}
Double_t doEval(Double_t x) {
return f(x);
}
private:
Function f;
};
ROOTR_MODULE(MyFunctorModule) {
ROOT::R::class_<MyFunctor>( "MyFunctor" )
.constructor()
.method( "doEval", &MyFunctor::doEval )
// .method( "otherMethod", &MyFunctor::otherMethod )//you can added more methods adding .method(name,pointer)
;
}
void Functor()
{
ROOT::R::TRInterface &r=ROOT::R::TRInterface::Instance();
r["MyFunctorModule"]<<LOAD_ROOTR_MODULE(MyFunctorModule);
r<<"MyFunctor <- MyFunctorModule$MyFunctor";
r<<"u <- new(MyFunctor)";
r<<"print(u$doEval( 1 ))";
std::cout<<"value in ROOT = "<<TMath::BesselY1(1)<<std::endl;
}