#ifndef ROOCFUNCTION2BINDING
#define ROOCFUNCTION2BINDING
#include "TString.h"
#include "RooAbsReal.h"
#include "RooAbsPdf.h"
#include "RooRealProxy.h"
#include "RooMsgService.h"
#include <string>
#include <map>
#include <vector>
namespace RooFit {
typedef Double_t (*CFUNCD2DD)(Double_t,Double_t) ;
typedef Double_t (*CFUNCD2ID)(Int_t,Double_t) ;
typedef Double_t (*CFUNCD2UD)(UInt_t,Double_t) ;
typedef Double_t (*CFUNCD2DI)(Double_t,Int_t) ;
typedef Double_t (*CFUNCD2II)(Int_t,Int_t) ;
RooAbsReal* bindFunction(const char* name,CFUNCD2DD func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsReal* bindFunction(const char* name,CFUNCD2ID func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsReal* bindFunction(const char* name,CFUNCD2UD func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsReal* bindFunction(const char* name,CFUNCD2DI func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsReal* bindFunction(const char* name,CFUNCD2II func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD2DD func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD2ID func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD2UD func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD2DI func,RooAbsReal& x, RooAbsReal& y) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD2II func,RooAbsReal& x, RooAbsReal& y) ;
}
template<class VO, class VI1, class VI2>
class RooCFunction2Map {
public:
RooCFunction2Map() {} ;
void add(const char* name, VO (*ptr)(VI1,VI2), const char* arg1name="x", const char* arg2name="y") {
_ptrmap[name] = ptr ;
_namemap[ptr] = name ;
_argnamemap[ptr].push_back(arg1name) ;
_argnamemap[ptr].push_back(arg2name) ;
}
const char* lookupName(VO (*ptr)(VI1,VI2)) {
return _namemap[ptr].c_str() ;
}
VO (*lookupPtr(const char* name))(VI1,VI2) {
return _ptrmap[name] ;
}
const char* lookupArgName(VO (*ptr)(VI1,VI2), UInt_t iarg) {
if (iarg<_argnamemap[ptr].size()) {
return (_argnamemap[ptr])[iarg].c_str() ;
}
switch (iarg) {
case 0: return "x" ;
case 1: return "y" ;
case 2: return "z" ;
}
return "w" ;
}
private:
#ifndef __CINT__
std::map<std::string,VO (*)(VI1,VI2)> _ptrmap ;
std::map<VO (*)(VI1,VI2),std::string> _namemap ;
std::map<VO (*)(VI1,VI2),std::vector<std::string> > _argnamemap ;
#endif
} ;
template<class VO, class VI1, class VI2>
class RooCFunction2Ref : public TObject {
public:
RooCFunction2Ref(VO (*ptr)(VI1,VI2)=0) : _ptr(ptr) {
} ;
~RooCFunction2Ref() {} ;
VO operator()(VI1 x,VI2 y) const {
return (*_ptr)(x,y) ;
}
const char* name() const {
const char* result = fmap().lookupName(_ptr) ;
if (result && strlen(result)) {
return result ;
}
union {
void *_ptr;
func_t _funcptr;
} temp;
temp._funcptr = _ptr;
return Form("(%p)",temp._ptr) ;
}
const char* argName(Int_t iarg) {
return fmap().lookupArgName(_ptr,iarg) ;
}
static RooCFunction2Map<VO,VI1,VI2>& fmap() {
if (!_fmap) {
_fmap = new RooCFunction2Map<VO,VI1,VI2> ;
}
return *_fmap ;
}
private:
static VO dummyFunction(VI1,VI2) {
return 0 ;
}
typedef VO (*func_t)(VI1,VI2);
func_t _ptr;
static RooCFunction2Map<VO,VI1,VI2>* _fmap ;
ClassDef(RooCFunction2Ref,1)
} ;
template<class VO, class VI1, class VI2>
void RooCFunction2Ref<VO,VI1,VI2>::Streamer(TBuffer &R__b)
{
typedef ::RooCFunction2Ref<VO,VI1,VI2> thisClass;
if (R__b.IsReading()) {
UInt_t R__s, R__c;
Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
TString tmpName ;
tmpName.Streamer(R__b) ;
if (tmpName=="UNKNOWN" && R__v>0) {
coutW(ObjectHandling) << "WARNING: Objected embeds function pointer to unknown function, object will not be functional" << std::endl ;
_ptr = dummyFunction ;
} else {
_ptr = fmap().lookupPtr(tmpName.Data()) ;
if (_ptr==0) {
coutW(ObjectHandling) << "ERROR: Objected embeds pointer to function named " << tmpName
<< " but no such function is registered, object will not be functional" << std::endl ;
}
}
R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
} else {
UInt_t R__c;
R__c = R__b.WriteVersion(thisClass::IsA(), kTRUE);
TString tmpName = fmap().lookupName(_ptr) ;
if (tmpName.Length()==0) {
coutW(ObjectHandling) << "WARNING: Cannot persist unknown function pointer " << Form("0x%lx", (ULong_t)_ptr)
<< " written object will not be functional when read back" << std::endl ;
tmpName="UNKNOWN" ;
}
tmpName.Streamer(R__b) ;
R__b.SetByteCount(R__c, kTRUE);
}
}
template<class VO,class VI1, class VI2>
class RooCFunction2Binding : public RooAbsReal {
public:
RooCFunction2Binding() {
} ;
RooCFunction2Binding(const char *name, const char *title, VO (*_func)(VI1,VI2), RooAbsReal& _x, RooAbsReal& _y);
RooCFunction2Binding(const RooCFunction2Binding& other, const char* name=0) ;
virtual TObject* clone(const char* newname) const { return new RooCFunction2Binding(*this,newname); }
inline virtual ~RooCFunction2Binding() { }
void printArgs(std::ostream& os) const {
os << "[ function=" << func.name() << " " ;
for (Int_t i=0 ; i<numProxies() ; i++) {
RooAbsProxy* p = getProxy(i) ;
if (!TString(p->name()).BeginsWith("!")) {
p->print(os) ;
os << " " ;
}
}
os << "]" ;
}
protected:
RooCFunction2Ref<VO,VI1,VI2> func ;
RooRealProxy x ;
RooRealProxy y ;
Double_t evaluate() const {
return func(x,y) ;
}
private:
ClassDef(RooCFunction2Binding,1)
};
template<class VO,class VI1, class VI2>
RooCFunction2Binding<VO,VI1,VI2>::RooCFunction2Binding(const char *name, const char *title, VO (*_func)(VI1,VI2),
RooAbsReal& _x, RooAbsReal& _y) :
RooAbsReal(name,title),
func(_func),
x(func.argName(0),func.argName(0),this,_x),
y(func.argName(1),func.argName(1),this,_y)
{
}
template<class VO,class VI1, class VI2>
RooCFunction2Binding<VO,VI1,VI2>::RooCFunction2Binding(const RooCFunction2Binding& other, const char* name) :
RooAbsReal(other,name),
func(other.func),
x("x",this,other.x),
y("y",this,other.y)
{
}
template<class VO,class VI1, class VI2>
class RooCFunction2PdfBinding : public RooAbsPdf {
public:
RooCFunction2PdfBinding() {
} ;
RooCFunction2PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2), RooAbsReal& _x, RooAbsReal& _y);
RooCFunction2PdfBinding(const RooCFunction2PdfBinding& other, const char* name=0) ;
virtual TObject* clone(const char* newname) const { return new RooCFunction2PdfBinding(*this,newname); }
inline virtual ~RooCFunction2PdfBinding() { }
void printArgs(std::ostream& os) const {
os << "[ function=" << func.name() << " " ;
for (Int_t i=0 ; i<numProxies() ; i++) {
RooAbsProxy* p = getProxy(i) ;
if (!TString(p->name()).BeginsWith("!")) {
p->print(os) ;
os << " " ;
}
}
os << "]" ;
}
protected:
RooCFunction2Ref<VO,VI1,VI2> func ;
RooRealProxy x ;
RooRealProxy y ;
Double_t evaluate() const {
return func(x,y) ;
}
private:
ClassDef(RooCFunction2PdfBinding,1)
};
template<class VO,class VI1, class VI2>
RooCFunction2PdfBinding<VO,VI1,VI2>::RooCFunction2PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2),
RooAbsReal& _x, RooAbsReal& _y) :
RooAbsPdf(name,title),
func(_func),
x(func.argName(0),func.argName(0),this,_x),
y(func.argName(1),func.argName(1),this,_y)
{
}
template<class VO,class VI1, class VI2>
RooCFunction2PdfBinding<VO,VI1,VI2>::RooCFunction2PdfBinding(const RooCFunction2PdfBinding& other, const char* name) :
RooAbsPdf(other,name),
func(other.func),
x("x",this,other.x),
y("y",this,other.y)
{
}
#endif
RooCFunction2Binding.h:10 RooCFunction2Binding.h:11 RooCFunction2Binding.h:12 RooCFunction2Binding.h:13 RooCFunction2Binding.h:14 RooCFunction2Binding.h:15 RooCFunction2Binding.h:16 RooCFunction2Binding.h:17 RooCFunction2Binding.h:18 RooCFunction2Binding.h:19 RooCFunction2Binding.h:20 RooCFunction2Binding.h:21 RooCFunction2Binding.h:22 RooCFunction2Binding.h:23 RooCFunction2Binding.h:24 RooCFunction2Binding.h:25 RooCFunction2Binding.h:26 RooCFunction2Binding.h:27 RooCFunction2Binding.h:28 RooCFunction2Binding.h:29 RooCFunction2Binding.h:30 RooCFunction2Binding.h:31 RooCFunction2Binding.h:32 RooCFunction2Binding.h:33 RooCFunction2Binding.h:34 RooCFunction2Binding.h:35 RooCFunction2Binding.h:36 RooCFunction2Binding.h:37 RooCFunction2Binding.h:38 RooCFunction2Binding.h:39 RooCFunction2Binding.h:40 RooCFunction2Binding.h:41 RooCFunction2Binding.h:42 RooCFunction2Binding.h:43 RooCFunction2Binding.h:44 RooCFunction2Binding.h:45 RooCFunction2Binding.h:46 RooCFunction2Binding.h:47 RooCFunction2Binding.h:48 RooCFunction2Binding.h:49 RooCFunction2Binding.h:50 RooCFunction2Binding.h:51 RooCFunction2Binding.h:52 RooCFunction2Binding.h:53 RooCFunction2Binding.h:54 RooCFunction2Binding.h:55 RooCFunction2Binding.h:56 RooCFunction2Binding.h:57 RooCFunction2Binding.h:58 RooCFunction2Binding.h:59 RooCFunction2Binding.h:60 RooCFunction2Binding.h:61 RooCFunction2Binding.h:62 RooCFunction2Binding.h:63 RooCFunction2Binding.h:64 RooCFunction2Binding.h:65 RooCFunction2Binding.h:66 RooCFunction2Binding.h:67 RooCFunction2Binding.h:68 RooCFunction2Binding.h:69 RooCFunction2Binding.h:70 RooCFunction2Binding.h:71 RooCFunction2Binding.h:72 RooCFunction2Binding.h:73 RooCFunction2Binding.h:74 RooCFunction2Binding.h:75 RooCFunction2Binding.h:76 RooCFunction2Binding.h:77 RooCFunction2Binding.h:78 RooCFunction2Binding.h:79 RooCFunction2Binding.h:80 RooCFunction2Binding.h:81 RooCFunction2Binding.h:82 RooCFunction2Binding.h:83 RooCFunction2Binding.h:84 RooCFunction2Binding.h:85 RooCFunction2Binding.h:86 RooCFunction2Binding.h:87 RooCFunction2Binding.h:88 RooCFunction2Binding.h:89 RooCFunction2Binding.h:90 RooCFunction2Binding.h:91 RooCFunction2Binding.h:92 RooCFunction2Binding.h:93 RooCFunction2Binding.h:94 RooCFunction2Binding.h:95 RooCFunction2Binding.h:96 RooCFunction2Binding.h:97 RooCFunction2Binding.h:98 RooCFunction2Binding.h:99 RooCFunction2Binding.h:100 RooCFunction2Binding.h:101 RooCFunction2Binding.h:102 RooCFunction2Binding.h:103 RooCFunction2Binding.h:104 RooCFunction2Binding.h:105 RooCFunction2Binding.h:106 RooCFunction2Binding.h:107 RooCFunction2Binding.h:108 RooCFunction2Binding.h:109 RooCFunction2Binding.h:110 RooCFunction2Binding.h:111 RooCFunction2Binding.h:112 RooCFunction2Binding.h:113 RooCFunction2Binding.h:114 RooCFunction2Binding.h:115 RooCFunction2Binding.h:116 RooCFunction2Binding.h:117 RooCFunction2Binding.h:118 RooCFunction2Binding.h:119 RooCFunction2Binding.h:120 RooCFunction2Binding.h:121 RooCFunction2Binding.h:122 RooCFunction2Binding.h:123 RooCFunction2Binding.h:124 RooCFunction2Binding.h:125 RooCFunction2Binding.h:126 RooCFunction2Binding.h:127 RooCFunction2Binding.h:128 RooCFunction2Binding.h:129 RooCFunction2Binding.h:130 RooCFunction2Binding.h:131 RooCFunction2Binding.h:132 RooCFunction2Binding.h:133 RooCFunction2Binding.h:134 RooCFunction2Binding.h:135 RooCFunction2Binding.h:136 RooCFunction2Binding.h:137 RooCFunction2Binding.h:138 RooCFunction2Binding.h:139 RooCFunction2Binding.h:140 RooCFunction2Binding.h:141 RooCFunction2Binding.h:142 RooCFunction2Binding.h:143 RooCFunction2Binding.h:144 RooCFunction2Binding.h:145 RooCFunction2Binding.h:146 RooCFunction2Binding.h:147 RooCFunction2Binding.h:148 RooCFunction2Binding.h:149 RooCFunction2Binding.h:150 RooCFunction2Binding.h:151 RooCFunction2Binding.h:152 RooCFunction2Binding.h:153 RooCFunction2Binding.h:154 RooCFunction2Binding.h:155 RooCFunction2Binding.h:156 RooCFunction2Binding.h:157 RooCFunction2Binding.h:158 RooCFunction2Binding.h:159 RooCFunction2Binding.h:160 RooCFunction2Binding.h:161 RooCFunction2Binding.h:162 RooCFunction2Binding.h:163 RooCFunction2Binding.h:164 RooCFunction2Binding.h:165 RooCFunction2Binding.h:166 RooCFunction2Binding.h:167 RooCFunction2Binding.h:168 RooCFunction2Binding.h:169 RooCFunction2Binding.h:170 RooCFunction2Binding.h:171 RooCFunction2Binding.h:172 RooCFunction2Binding.h:173 RooCFunction2Binding.h:174 RooCFunction2Binding.h:175 RooCFunction2Binding.h:176 RooCFunction2Binding.h:177 RooCFunction2Binding.h:178 RooCFunction2Binding.h:179 RooCFunction2Binding.h:180 RooCFunction2Binding.h:181 RooCFunction2Binding.h:182 RooCFunction2Binding.h:183 RooCFunction2Binding.h:184 RooCFunction2Binding.h:185 RooCFunction2Binding.h:186 RooCFunction2Binding.h:187 RooCFunction2Binding.h:188 RooCFunction2Binding.h:189 RooCFunction2Binding.h:190 RooCFunction2Binding.h:191 RooCFunction2Binding.h:192 RooCFunction2Binding.h:193 RooCFunction2Binding.h:194 RooCFunction2Binding.h:195 RooCFunction2Binding.h:196 RooCFunction2Binding.h:197 RooCFunction2Binding.h:198 RooCFunction2Binding.h:199 RooCFunction2Binding.h:200 RooCFunction2Binding.h:201 RooCFunction2Binding.h:202 RooCFunction2Binding.h:203 RooCFunction2Binding.h:204 RooCFunction2Binding.h:205 RooCFunction2Binding.h:206 RooCFunction2Binding.h:207 RooCFunction2Binding.h:208 RooCFunction2Binding.h:209 RooCFunction2Binding.h:210 RooCFunction2Binding.h:211 RooCFunction2Binding.h:212 RooCFunction2Binding.h:213 RooCFunction2Binding.h:214 RooCFunction2Binding.h:215 RooCFunction2Binding.h:216 RooCFunction2Binding.h:217 RooCFunction2Binding.h:218 RooCFunction2Binding.h:219 RooCFunction2Binding.h:220 RooCFunction2Binding.h:221 RooCFunction2Binding.h:222 RooCFunction2Binding.h:223 RooCFunction2Binding.h:224 RooCFunction2Binding.h:225 RooCFunction2Binding.h:226 RooCFunction2Binding.h:227 RooCFunction2Binding.h:228 RooCFunction2Binding.h:229 RooCFunction2Binding.h:230 RooCFunction2Binding.h:231 RooCFunction2Binding.h:232 RooCFunction2Binding.h:233 RooCFunction2Binding.h:234 RooCFunction2Binding.h:235 RooCFunction2Binding.h:236 RooCFunction2Binding.h:237 RooCFunction2Binding.h:238 RooCFunction2Binding.h:239 RooCFunction2Binding.h:240 RooCFunction2Binding.h:241 RooCFunction2Binding.h:242 RooCFunction2Binding.h:243 RooCFunction2Binding.h:244 RooCFunction2Binding.h:245 RooCFunction2Binding.h:246 RooCFunction2Binding.h:247 RooCFunction2Binding.h:248 RooCFunction2Binding.h:249 RooCFunction2Binding.h:250 RooCFunction2Binding.h:251 RooCFunction2Binding.h:252 RooCFunction2Binding.h:253 RooCFunction2Binding.h:254 RooCFunction2Binding.h:255 RooCFunction2Binding.h:256 RooCFunction2Binding.h:257 RooCFunction2Binding.h:258 RooCFunction2Binding.h:259 RooCFunction2Binding.h:260 RooCFunction2Binding.h:261 RooCFunction2Binding.h:262 RooCFunction2Binding.h:263 RooCFunction2Binding.h:264 RooCFunction2Binding.h:265 RooCFunction2Binding.h:266 RooCFunction2Binding.h:267 RooCFunction2Binding.h:268 RooCFunction2Binding.h:269 RooCFunction2Binding.h:270 RooCFunction2Binding.h:271 RooCFunction2Binding.h:272 RooCFunction2Binding.h:273 RooCFunction2Binding.h:274 RooCFunction2Binding.h:275 RooCFunction2Binding.h:276 RooCFunction2Binding.h:277 RooCFunction2Binding.h:278 RooCFunction2Binding.h:279 RooCFunction2Binding.h:280 RooCFunction2Binding.h:281 RooCFunction2Binding.h:282 RooCFunction2Binding.h:283 RooCFunction2Binding.h:284 RooCFunction2Binding.h:285 RooCFunction2Binding.h:286 RooCFunction2Binding.h:287 RooCFunction2Binding.h:288 RooCFunction2Binding.h:289 RooCFunction2Binding.h:290 RooCFunction2Binding.h:291 RooCFunction2Binding.h:292 RooCFunction2Binding.h:293 RooCFunction2Binding.h:294 RooCFunction2Binding.h:295 RooCFunction2Binding.h:296 RooCFunction2Binding.h:297 RooCFunction2Binding.h:298 RooCFunction2Binding.h:299 RooCFunction2Binding.h:300 RooCFunction2Binding.h:301 RooCFunction2Binding.h:302 RooCFunction2Binding.h:303 RooCFunction2Binding.h:304 RooCFunction2Binding.h:305 RooCFunction2Binding.h:306 RooCFunction2Binding.h:307 RooCFunction2Binding.h:308 RooCFunction2Binding.h:309 RooCFunction2Binding.h:310 RooCFunction2Binding.h:311 RooCFunction2Binding.h:312 RooCFunction2Binding.h:313 RooCFunction2Binding.h:314 RooCFunction2Binding.h:315 RooCFunction2Binding.h:316 RooCFunction2Binding.h:317 RooCFunction2Binding.h:318 RooCFunction2Binding.h:319 RooCFunction2Binding.h:320 RooCFunction2Binding.h:321 RooCFunction2Binding.h:322 RooCFunction2Binding.h:323 RooCFunction2Binding.h:324 RooCFunction2Binding.h:325 RooCFunction2Binding.h:326 RooCFunction2Binding.h:327 RooCFunction2Binding.h:328 RooCFunction2Binding.h:329 RooCFunction2Binding.h:330 RooCFunction2Binding.h:331 RooCFunction2Binding.h:332 RooCFunction2Binding.h:333 RooCFunction2Binding.h:334 RooCFunction2Binding.h:335 RooCFunction2Binding.h:336 RooCFunction2Binding.h:337 RooCFunction2Binding.h:338 RooCFunction2Binding.h:339 RooCFunction2Binding.h:340 RooCFunction2Binding.h:341 RooCFunction2Binding.h:342 RooCFunction2Binding.h:343 RooCFunction2Binding.h:344 RooCFunction2Binding.h:345 RooCFunction2Binding.h:346 RooCFunction2Binding.h:347 RooCFunction2Binding.h:348 RooCFunction2Binding.h:349 RooCFunction2Binding.h:350 RooCFunction2Binding.h:351 RooCFunction2Binding.h:352 RooCFunction2Binding.h:353 RooCFunction2Binding.h:354 RooCFunction2Binding.h:355 RooCFunction2Binding.h:356