13 #ifndef ROOCFUNCTION4BINDING
14 #define ROOCFUNCTION4BINDING
30 typedef Double_t (*CFUNCD4DDDD)(Double_t,Double_t,Double_t,Double_t) ;
31 typedef Double_t (*CFUNCD4DDDI)(Double_t,Double_t,Double_t,Int_t) ;
32 typedef Double_t (*CFUNCD4DDDB)(Double_t,Double_t,Double_t,Bool_t) ;
34 RooAbsReal* bindFunction(
const char* name,CFUNCD4DDDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
35 RooAbsReal* bindFunction(
const char* name,CFUNCD4DDDI func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
36 RooAbsReal* bindFunction(
const char* name,CFUNCD4DDDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
37 RooAbsPdf* bindPdf(
const char* name,CFUNCD4DDDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
38 RooAbsPdf* bindPdf(
const char* name,CFUNCD4DDDI func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
39 RooAbsPdf* bindPdf(
const char* name,CFUNCD4DDDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
44 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
45 class RooCFunction4Map {
47 RooCFunction4Map() {} ;
49 void add(
const char* name, VO (*ptr)(VI1,VI2,VI3,VI4),
const char* arg1name=
"x",
const char* arg2name=
"y",
50 const char* arg3name=
"z",
const char* arg4name=
"w") {
53 _namemap[ptr] = name ;
54 _argnamemap[ptr].push_back(arg1name) ;
55 _argnamemap[ptr].push_back(arg2name) ;
56 _argnamemap[ptr].push_back(arg3name) ;
57 _argnamemap[ptr].push_back(arg4name) ;
61 const char* lookupName(VO (*ptr)(VI1,VI2,VI3,VI4)) {
63 return _namemap[ptr].c_str() ;
66 VO (*lookupPtr(
const char* name))(VI1,VI2,VI3,VI4) {
68 return _ptrmap[name] ;
71 const char* lookupArgName(VO (*ptr)(VI1,VI2,VI3,VI4), UInt_t iarg) {
74 if (iarg<_argnamemap[ptr].size()) {
75 return (_argnamemap[ptr])[iarg].c_str() ;
89 std::map<std::string,VO (*)(VI1,VI2,VI3,VI4)> _ptrmap ;
90 std::map<VO (*)(VI1,VI2,VI3,VI4),std::string> _namemap ;
91 std::map<VO (*)(VI1,VI2,VI3,VI4),std::vector<std::string> > _argnamemap ;
97 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
98 class RooCFunction4Ref :
public TObject {
100 RooCFunction4Ref(VO (*ptr)(VI1,VI2,VI3,VI4)=0) : _ptr(ptr) {
103 ~RooCFunction4Ref() {} ;
105 VO operator()(VI1 x,VI2 y,VI3 z,VI4 w)
const {
107 return (*_ptr)(x,y,z,w) ;
110 const char* name()
const {
114 const char* result = fmap().lookupName(_ptr) ;
115 if (result && strlen(result)) {
123 temp._funcptr = _ptr;
124 return Form(
"(%p)",temp._ptr) ;
127 const char* argName(Int_t iarg) {
129 return fmap().lookupArgName(_ptr,iarg) ;
132 static RooCFunction4Map<VO,VI1,VI2,VI3,VI4>& fmap() {
135 _fmap =
new RooCFunction4Map<VO,VI1,VI2,VI3,VI4> ;
141 static VO dummyFunction(VI1,VI2,VI3,VI4) {
148 typedef VO (*func_t)(VI1,VI2,VI3,VI4);
151 static RooCFunction4Map<VO,VI1,VI2,VI3,VI4>* _fmap ;
153 ClassDef(RooCFunction4Ref,1)
157 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
158 RooCFunction4Map<VO,VI1,VI2,VI3,VI4>* RooCFunction4Ref<VO,VI1,VI2,VI3,VI4>::_fmap = 0;
160 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
161 void RooCFunction4Ref<VO,VI1,VI2,VI3,VI4>::Streamer(TBuffer &R__b)
172 typedef ::RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> thisClass;
175 if (R__b.IsReading()) {
178 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
182 tmpName.Streamer(R__b) ;
184 if (tmpName==
"UNKNOWN" && R__v>0) {
186 coutW(ObjectHandling) <<
"WARNING: Objected embeds function pointer to unknown function, object will not be functional" << std::endl ;
187 _ptr = dummyFunction ;
192 _ptr = fmap().lookupPtr(tmpName.Data()) ;
195 coutW(ObjectHandling) <<
"ERROR: Objected embeds pointer to function named " << tmpName
196 <<
" but no such function is registered, object will not be functional" << std::endl ;
201 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
206 R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
209 TString tmpName = fmap().lookupName(_ptr) ;
210 if (tmpName.Length()==0) {
211 coutW(ObjectHandling) <<
"WARNING: Cannot persist unknown function pointer " << Form(
"0x%lx",(ULong_t)_ptr)
212 <<
" written object will not be functional when read back" << std::endl ;
217 tmpName.Streamer(R__b) ;
219 R__b.SetByteCount(R__c, kTRUE);
226 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
227 class RooCFunction4Binding :
public RooAbsReal {
229 RooCFunction4Binding() {
232 RooCFunction4Binding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3,VI4), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w);
233 RooCFunction4Binding(
const RooCFunction4Binding& other,
const char* name=0) ;
234 virtual TObject* clone(
const char* newname)
const {
return new RooCFunction4Binding(*
this,newname); }
235 inline virtual ~RooCFunction4Binding() { }
237 void printArgs(std::ostream& os)
const {
239 os <<
"[ function=" << func.name() <<
" " ;
240 for (Int_t i=0 ; i<numProxies() ; i++) {
241 RooAbsProxy* p = getProxy(i) ;
242 if (!TString(p->name()).BeginsWith(
"!")) {
252 RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> func ;
258 Double_t evaluate()
const {
260 return func(x,y,z,w) ;
265 ClassDef(RooCFunction4Binding,1)
269 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
270 RooCFunction4Binding<VO,VI1,VI2,VI3,VI4>::RooCFunction4Binding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3,VI4),
271 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w) :
272 RooAbsReal(name,title),
274 x(func.argName(0),func.argName(0),this,_x),
275 y(func.argName(1),func.argName(1),this,_y),
276 z(func.argName(2),func.argName(2),this,_z),
277 w(func.argName(3),func.argName(3),this,_w)
286 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
287 RooCFunction4Binding<VO,VI1,VI2,VI3,VI4>::RooCFunction4Binding(
const RooCFunction4Binding& other,
const char* name) :
288 RooAbsReal(other,name),
299 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
300 class RooCFunction4PdfBinding :
public RooAbsPdf {
302 RooCFunction4PdfBinding() {
305 RooCFunction4PdfBinding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3,VI4), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w);
306 RooCFunction4PdfBinding(
const RooCFunction4PdfBinding& other,
const char* name=0) ;
307 virtual TObject* clone(
const char* newname)
const {
return new RooCFunction4PdfBinding(*
this,newname); }
308 inline virtual ~RooCFunction4PdfBinding() { }
310 void printArgs(std::ostream& os)
const {
312 os <<
"[ function=" << func.name() <<
" " ;
313 for (Int_t i=0 ; i<numProxies() ; i++) {
314 RooAbsProxy* p = getProxy(i) ;
315 if (!TString(p->name()).BeginsWith(
"!")) {
325 RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> func ;
331 Double_t evaluate()
const {
333 return func(x,y,z,w) ;
338 ClassDef(RooCFunction4PdfBinding,1)
342 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
343 RooCFunction4PdfBinding<VO,VI1,VI2,VI3,VI4>::RooCFunction4PdfBinding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3,VI4),
344 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w) :
345 RooAbsPdf(name,title),
347 x(func.argName(0),func.argName(0),this,_x),
348 y(func.argName(1),func.argName(1),this,_y),
349 z(func.argName(2),func.argName(2),this,_z),
350 w(func.argName(3),func.argName(3),this,_w)
359 template<
class VO,
class VI1,
class VI2,
class VI3,
class VI4>
360 RooCFunction4PdfBinding<VO,VI1,VI2,VI3,VI4>::RooCFunction4PdfBinding(
const RooCFunction4PdfBinding& other,
const char* name) :
361 RooAbsPdf(other,name),