12 #ifndef ROOCFUNCTION3BINDING
13 #define ROOCFUNCTION3BINDING
30 typedef Double_t (*CFUNCD3DDD)(Double_t,Double_t,Double_t) ;
31 typedef Double_t (*CFUNCD3DDB)(Double_t,Double_t,Bool_t) ;
32 typedef Double_t (*CFUNCD3DII)(Double_t,Int_t,Int_t) ;
33 typedef Double_t (*CFUNCD3UDU)(UInt_t,Double_t,UInt_t) ;
34 typedef Double_t (*CFUNCD3UDD)(UInt_t,Double_t,Double_t) ;
35 typedef Double_t (*CFUNCD3UUD)(UInt_t,UInt_t,Double_t) ;
37 RooAbsReal* bindFunction(
const char* name,CFUNCD3DDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
38 RooAbsReal* bindFunction(
const char* name,CFUNCD3DDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
39 RooAbsReal* bindFunction(
const char* name,CFUNCD3DII func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
40 RooAbsReal* bindFunction(
const char* name,CFUNCD3UDU func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
41 RooAbsReal* bindFunction(
const char* name,CFUNCD3UDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
42 RooAbsReal* bindFunction(
const char* name,CFUNCD3UUD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
43 RooAbsPdf* bindPdf(
const char* name,CFUNCD3DDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
44 RooAbsPdf* bindPdf(
const char* name,CFUNCD3DDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
45 RooAbsPdf* bindPdf(
const char* name,CFUNCD3DII func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
46 RooAbsPdf* bindPdf(
const char* name,CFUNCD3UDU func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
47 RooAbsPdf* bindPdf(
const char* name,CFUNCD3UDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
48 RooAbsPdf* bindPdf(
const char* name,CFUNCD3UUD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
52 template<
class VO,
class VI1,
class VI2,
class VI3>
53 class RooCFunction3Map {
55 RooCFunction3Map() {} ;
57 void add(
const char* name, VO (*ptr)(VI1,VI2,VI3),
const char* arg1name=
"x",
const char* arg2name=
"y",
const char* arg3name=
"z") {
60 _namemap[ptr] = name ;
61 _argnamemap[ptr].push_back(arg1name) ;
62 _argnamemap[ptr].push_back(arg2name) ;
63 _argnamemap[ptr].push_back(arg3name) ;
67 const char* lookupName(VO (*ptr)(VI1,VI2,VI3)) {
69 return _namemap[ptr].c_str() ;
72 VO (*lookupPtr(
const char* name))(VI1,VI2,VI3) {
74 return _ptrmap[name] ;
77 const char* lookupArgName(VO (*ptr)(VI1,VI2,VI3), UInt_t iarg) {
80 if (iarg<_argnamemap[ptr].size()) {
81 return (_argnamemap[ptr])[iarg].c_str() ;
94 std::map<std::string,VO (*)(VI1,VI2,VI3)> _ptrmap ;
95 std::map<VO (*)(VI1,VI2,VI3),std::string> _namemap ;
96 std::map<VO (*)(VI1,VI2,VI3),std::vector<std::string> > _argnamemap ;
101 template<
class VO,
class VI1,
class VI2,
class VI3>
102 class RooCFunction3Ref :
public TObject {
104 RooCFunction3Ref(VO (*ptr)(VI1,VI2,VI3)=0) : _ptr(ptr) {
107 ~RooCFunction3Ref() {} ;
109 VO operator()(VI1 x,VI2 y, VI3 z)
const {
111 return (*_ptr)(x,y,z) ;
114 const char* name()
const {
118 const char* result = fmap().lookupName(_ptr) ;
119 if (result && strlen(result)) {
127 temp._funcptr = _ptr;
128 return Form(
"(%p)",temp._ptr) ;
131 const char* argName(Int_t iarg) {
133 return fmap().lookupArgName(_ptr,iarg) ;
136 static RooCFunction3Map<VO,VI1,VI2,VI3>& fmap() {
139 _fmap =
new RooCFunction3Map<VO,VI1,VI2,VI3> ;
146 static VO dummyFunction(VI1,VI2,VI3) {
153 typedef VO (*func_t)(VI1,VI2,VI3) ;
156 static RooCFunction3Map<VO,VI1,VI2,VI3>* _fmap ;
158 ClassDef(RooCFunction3Ref,1)
162 template<
class VO,
class VI1,
class VI2,
class VI3>
163 RooCFunction3Map<VO,VI1,VI2,VI3>* RooCFunction3Ref<VO,VI1,VI2,VI3>::_fmap = 0;
167 template<
class VO,
class VI1,
class VI2,
class VI3>
168 void RooCFunction3Ref<VO,VI1,VI2,VI3>::Streamer(TBuffer &R__b)
179 typedef ::RooCFunction3Ref<VO,VI1,VI2,VI3> thisClass;
182 if (R__b.IsReading()) {
185 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
189 tmpName.Streamer(R__b) ;
191 if (tmpName==
"UNKNOWN" && R__v>0) {
193 coutW(ObjectHandling) <<
"WARNING: Objected embeds function pointer to unknown function, object will not be functional" << std::endl ;
194 _ptr = dummyFunction ;
199 _ptr = fmap().lookupPtr(tmpName.Data()) ;
202 coutW(ObjectHandling) <<
"ERROR: Objected embeds pointer to function named " << tmpName
203 <<
" but no such function is registered, object will not be functional" << std::endl ;
208 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
213 R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
216 TString tmpName = fmap().lookupName(_ptr) ;
217 if (tmpName.Length()==0) {
223 temp._funcptr = _ptr;
224 coutW(ObjectHandling) <<
"WARNING: Cannot persist unknown function pointer " << Form(
"%p",temp._ptr)
225 <<
" written object will not be functional when read back" << std::endl ;
230 tmpName.Streamer(R__b) ;
232 R__b.SetByteCount(R__c, kTRUE);
239 template<
class VO,
class VI1,
class VI2,
class VI3>
240 class RooCFunction3Binding :
public RooAbsReal {
242 RooCFunction3Binding() {
245 RooCFunction3Binding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z);
246 RooCFunction3Binding(
const RooCFunction3Binding& other,
const char* name=0) ;
247 virtual TObject* clone(
const char* newname)
const {
return new RooCFunction3Binding(*
this,newname); }
248 inline virtual ~RooCFunction3Binding() { }
250 void printArgs(std::ostream& os)
const {
252 os <<
"[ function=" << func.name() <<
" " ;
253 for (Int_t i=0 ; i<numProxies() ; i++) {
254 RooAbsProxy* p = getProxy(i) ;
255 if (!TString(p->name()).BeginsWith(
"!")) {
265 RooCFunction3Ref<VO,VI1,VI2,VI3> func ;
270 Double_t evaluate()
const {
277 ClassDef(RooCFunction3Binding,1)
282 template<
class VO,
class VI1,
class VI2,
class VI3>
283 RooCFunction3Binding<VO,VI1,VI2,VI3>::RooCFunction3Binding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3),
284 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z) :
285 RooAbsReal(name,title),
287 x(func.argName(0),func.argName(0),this,_x),
288 y(func.argName(1),func.argName(1),this,_y),
289 z(func.argName(2),func.argName(2),this,_z)
298 template<
class VO,
class VI1,
class VI2,
class VI3>
299 RooCFunction3Binding<VO,VI1,VI2,VI3>::RooCFunction3Binding(
const RooCFunction3Binding& other,
const char* name) :
300 RooAbsReal(other,name),
310 template<
class VO,
class VI1,
class VI2,
class VI3>
311 class RooCFunction3PdfBinding :
public RooAbsPdf {
313 RooCFunction3PdfBinding() {
316 RooCFunction3PdfBinding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z);
317 RooCFunction3PdfBinding(
const RooCFunction3PdfBinding& other,
const char* name=0) ;
318 virtual TObject* clone(
const char* newname)
const {
return new RooCFunction3PdfBinding(*
this,newname); }
319 inline virtual ~RooCFunction3PdfBinding() { }
321 void printArgs(std::ostream& os)
const {
323 os <<
"[ function=" << func.name() <<
" " ;
324 for (Int_t i=0 ; i<numProxies() ; i++) {
325 RooAbsProxy* p = getProxy(i) ;
326 if (!TString(p->name()).BeginsWith(
"!")) {
336 RooCFunction3Ref<VO,VI1,VI2,VI3> func ;
341 Double_t evaluate()
const {
348 ClassDef(RooCFunction3PdfBinding,1)
353 template<
class VO,
class VI1,
class VI2,
class VI3>
354 RooCFunction3PdfBinding<VO,VI1,VI2,VI3>::RooCFunction3PdfBinding(
const char *name,
const char *title, VO (*_func)(VI1,VI2,VI3),
355 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z) :
356 RooAbsPdf(name,title),
358 x(func.argName(0),func.argName(0),this,_x),
359 y(func.argName(1),func.argName(1),this,_y),
360 z(func.argName(2),func.argName(2),this,_z)
369 template<
class VO,
class VI1,
class VI2,
class VI3>
370 RooCFunction3PdfBinding<VO,VI1,VI2,VI3>::RooCFunction3PdfBinding(
const RooCFunction3PdfBinding& other,
const char* name) :
371 RooAbsPdf(other,name),