#ifndef ROOCFUNCTION4BINDING
#define ROOCFUNCTION4BINDING
#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 (*CFUNCD4DDDD)(Double_t,Double_t,Double_t,Double_t) ;
typedef Double_t (*CFUNCD4DDDI)(Double_t,Double_t,Double_t,Int_t) ;
typedef Double_t (*CFUNCD4DDDB)(Double_t,Double_t,Double_t,Bool_t) ;
RooAbsReal* bindFunction(const char* name,void* func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
RooAbsPdf* bindPdf(const char* name,void* func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
#ifndef __CINT__
RooAbsReal* bindFunction(const char* name,CFUNCD4DDDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
RooAbsReal* bindFunction(const char* name,CFUNCD4DDDI func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
RooAbsReal* bindFunction(const char* name,CFUNCD4DDDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD4DDDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD4DDDI func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD4DDDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z, RooAbsReal& w) ;
#endif
}
template<class VO, class VI1, class VI2, class VI3, class VI4>
class RooCFunction4Map {
public:
RooCFunction4Map() {} ;
void add(const char* name, VO (*ptr)(VI1,VI2,VI3,VI4), const char* arg1name="x", const char* arg2name="y",
const char* arg3name="z", const char* arg4name="w") {
_ptrmap[name] = ptr ;
_namemap[ptr] = name ;
_argnamemap[ptr].push_back(arg1name) ;
_argnamemap[ptr].push_back(arg2name) ;
_argnamemap[ptr].push_back(arg3name) ;
_argnamemap[ptr].push_back(arg4name) ;
}
const char* lookupName(VO (*ptr)(VI1,VI2,VI3,VI4)) {
return _namemap[ptr].c_str() ;
}
VO (*lookupPtr(const char* name))(VI1,VI2,VI3,VI4) {
return _ptrmap[name] ;
}
const char* lookupArgName(VO (*ptr)(VI1,VI2,VI3,VI4), 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" ;
case 3: return "w" ;
}
return "v" ;
}
private:
#ifndef __CINT__
std::map<std::string,VO (*)(VI1,VI2,VI3,VI4)> _ptrmap ;
std::map<VO (*)(VI1,VI2,VI3,VI4),std::string> _namemap ;
std::map<VO (*)(VI1,VI2,VI3,VI4),std::vector<std::string> > _argnamemap ;
#endif
} ;
template<class VO, class VI1, class VI2, class VI3, class VI4>
class RooCFunction4Ref : public TObject {
public:
RooCFunction4Ref(VO (*ptr)(VI1,VI2,VI3,VI4)=0) : _ptr(ptr) {
} ;
~RooCFunction4Ref() {} ;
VO operator()(VI1 x,VI2 y,VI3 z,VI4 w) const {
return (*_ptr)(x,y,z,w) ;
}
const char* name() const {
const char* result = fmap().lookupName(_ptr) ;
if (result && strlen(result)) {
return result ;
}
return Form("(0x%08x)",_ptr) ;
}
const char* argName(Int_t iarg) {
return fmap().lookupArgName(_ptr,iarg) ;
}
static RooCFunction4Map<VO,VI1,VI2,VI3,VI4>& fmap() {
if (!_fmap) {
_fmap = new RooCFunction4Map<VO,VI1,VI2,VI3,VI4> ;
}
return *_fmap ;
}
private:
static VO dummyFunction(VI1,VI2,VI3,VI4) {
return 0 ;
}
VO (*_ptr)(VI1,VI2,VI3,VI4) ;
static RooCFunction4Map<VO,VI1,VI2,VI3,VI4>* _fmap ;
ClassDef(RooCFunction4Ref,1)
} ;
template<class VO, class VI1, class VI2, class VI3, class VI4>
void RooCFunction4Ref<VO,VI1,VI2,VI3,VI4>::Streamer(TBuffer &R__b)
{
typedef ::RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> thisClass;
if (R__b.IsReading()) {
UInt_t R__s, R__c;
R__b.ReadVersion(&R__s, &R__c);
TString tmpName ;
tmpName.Streamer(R__b) ;
if (tmpName=="UNKNOWN") {
coutW(ObjectHandling) << "WARNING: Objected embeds function pointer to unknown function, object will not be functional" << 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" << 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%08x",_ptr)
<< " written object will not be functional when read back" << endl ;
tmpName="UNKNOWN" ;
}
tmpName.Streamer(R__b) ;
R__b.SetByteCount(R__c, kTRUE);
}
}
template<class VO,class VI1, class VI2, class VI3, class VI4>
class RooCFunction4Binding : public RooAbsReal {
public:
RooCFunction4Binding() {
} ;
RooCFunction4Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w);
RooCFunction4Binding(const RooCFunction4Binding& other, const char* name=0) ;
virtual TObject* clone(const char* newname) const { return new RooCFunction4Binding(*this,newname); }
inline virtual ~RooCFunction4Binding() { }
void printArgs(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:
RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> func ;
RooRealProxy x ;
RooRealProxy y ;
RooRealProxy z ;
RooRealProxy w ;
Double_t evaluate() const {
return func(x,y,z,w) ;
}
private:
ClassDef(RooCFunction4Binding,1)
};
template<class VO,class VI1, class VI2, class VI3, class VI4>
RooCFunction4Binding<VO,VI1,VI2,VI3,VI4>::RooCFunction4Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4),
RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w) :
RooAbsReal(name,title),
func(_func),
x(func.argName(0),func.argName(0),this,_x),
y(func.argName(1),func.argName(1),this,_y),
z(func.argName(2),func.argName(2),this,_z),
w(func.argName(3),func.argName(3),this,_w)
{
}
template<class VO,class VI1, class VI2, class VI3, class VI4>
RooCFunction4Binding<VO,VI1,VI2,VI3,VI4>::RooCFunction4Binding(const RooCFunction4Binding& other, const char* name) :
RooAbsReal(other,name),
func(other.func),
x("x",this,other.x),
y("y",this,other.y),
z("z",this,other.z),
w("w",this,other.w)
{
}
template<class VO,class VI1, class VI2, class VI3, class VI4>
class RooCFunction4PdfBinding : public RooAbsPdf {
public:
RooCFunction4PdfBinding() {
} ;
RooCFunction4PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w);
RooCFunction4PdfBinding(const RooCFunction4PdfBinding& other, const char* name=0) ;
virtual TObject* clone(const char* newname) const { return new RooCFunction4PdfBinding(*this,newname); }
inline virtual ~RooCFunction4PdfBinding() { }
void printArgs(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:
RooCFunction4Ref<VO,VI1,VI2,VI3,VI4> func ;
RooRealProxy x ;
RooRealProxy y ;
RooRealProxy z ;
RooRealProxy w ;
Double_t evaluate() const {
return func(x,y,z,w) ;
}
private:
ClassDef(RooCFunction4PdfBinding,1)
};
template<class VO,class VI1, class VI2, class VI3, class VI4>
RooCFunction4PdfBinding<VO,VI1,VI2,VI3,VI4>::RooCFunction4PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3,VI4),
RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z, RooAbsReal& _w) :
RooAbsPdf(name,title),
func(_func),
x(func.argName(0),func.argName(0),this,_x),
y(func.argName(1),func.argName(1),this,_y),
z(func.argName(2),func.argName(2),this,_z),
w(func.argName(3),func.argName(3),this,_w)
{
}
template<class VO,class VI1, class VI2, class VI3, class VI4>
RooCFunction4PdfBinding<VO,VI1,VI2,VI3,VI4>::RooCFunction4PdfBinding(const RooCFunction4PdfBinding& other, const char* name) :
RooAbsPdf(other,name),
func(other.func),
x("x",this,other.x),
y("y",this,other.y),
z("z",this,other.z),
w("w",this,other.w)
{
}
template <> void RooCFunction4Ref<Double_t,Double_t,Double_t,Double_t,Double_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4Binding<Double_t,Double_t,Double_t,Double_t,Double_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4PdfBinding<Double_t,Double_t,Double_t,Double_t,Double_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4Ref<Double_t,Double_t,Double_t,Double_t,Int_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4Binding<Double_t,Double_t,Double_t,Double_t,Int_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4PdfBinding<Double_t,Double_t,Double_t,Double_t,Int_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4Ref<Double_t,Double_t,Double_t,Double_t,Bool_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4Binding<Double_t,Double_t,Double_t,Double_t,Bool_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction4PdfBinding<Double_t,Double_t,Double_t,Double_t,Bool_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
#endif
Last change: Mon Aug 25 11:36:13 2008
Last generated: 2008-08-25 11:36
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.