#ifndef ROOCFUNCTION1BINDING
#define ROOCFUNCTION1BINDING
#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 (*CFUNCD1D)(Double_t) ;
typedef Double_t (*CFUNCD1I)(Int_t) ;
RooAbsReal* bindFunction(const char* name,void* func,RooAbsReal& x) ;
RooAbsPdf* bindPdf(const char* name,void* func,RooAbsReal& x) ;
#ifndef __CINT__
RooAbsReal* bindFunction(const char* name,CFUNCD1D func,RooAbsReal& x) ;
RooAbsReal* bindFunction(const char* name,CFUNCD1I func,RooAbsReal& x) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD1D func,RooAbsReal& x) ;
RooAbsPdf* bindPdf(const char* name,CFUNCD1I func,RooAbsReal& x) ;
#endif
}
template<class VO, class VI>
class RooCFunction1Map {
public:
RooCFunction1Map() {} ;
void add(const char* name, VO (*ptr)(VI), const char* arg1name="x") {
_ptrmap[name] = ptr ;
_namemap[ptr] = name ;
_argnamemap[ptr].push_back(arg1name) ;
}
const char* lookupName(VO (*ptr)(VI)) {
return _namemap[ptr].c_str() ;
}
VO (*lookupPtr(const char* name))(VI) {
return _ptrmap[name] ;
}
const char* lookupArgName(VO (*ptr)(VI), 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 (*)(VI)> _ptrmap ;
std::map<VO (*)(VI),std::string> _namemap ;
std::map<VO (*)(VI),std::vector<std::string> > _argnamemap ;
#endif
} ;
template<class VO, class VI>
class RooCFunction1Ref : public TObject {
public:
RooCFunction1Ref(VO (*ptr)(VI)=0) : _ptr(ptr) {
} ;
~RooCFunction1Ref() {} ;
VO operator()(VI x) const {
return (*_ptr)(x) ;
}
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 RooCFunction1Map<VO,VI>& fmap() {
if (!_fmap) {
_fmap = new RooCFunction1Map<VO,VI> ;
}
return *_fmap ;
}
private:
static VO dummyFunction(VI) {
return 0 ;
}
VO (*_ptr)(VI) ;
static RooCFunction1Map<VO,VI>* _fmap ;
ClassDef(RooCFunction1Ref,1)
} ;
template<class VO, class VI>
void RooCFunction1Ref<VO,VI>::Streamer(TBuffer &R__b)
{
typedef ::RooCFunction1Ref<VO,VI> 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 VI>
class RooCFunction1Binding : public RooAbsReal {
public:
RooCFunction1Binding() {
} ;
RooCFunction1Binding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x);
RooCFunction1Binding(const RooCFunction1Binding& other, const char* name=0) ;
virtual TObject* clone(const char* newname) const { return new RooCFunction1Binding(*this,newname); }
inline virtual ~RooCFunction1Binding() { }
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:
RooCFunction1Ref<VO,VI> func ;
RooRealProxy x ;
Double_t evaluate() const {
return func(x) ;
}
private:
ClassDef(RooCFunction1Binding,1)
};
template<class VO,class VI>
RooCFunction1Binding<VO,VI>::RooCFunction1Binding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x) :
RooAbsReal(name,title),
func(_func),
x(func.argName(0),func.argName(0),this,_x)
{
}
template<class VO,class VI>
RooCFunction1Binding<VO,VI>::RooCFunction1Binding(const RooCFunction1Binding& other, const char* name) :
RooAbsReal(other,name),
func(other.func),
x("x",this,other.x)
{
}
template<class VO,class VI>
class RooCFunction1PdfBinding : public RooAbsPdf {
public:
RooCFunction1PdfBinding() {
} ;
RooCFunction1PdfBinding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x);
RooCFunction1PdfBinding(const RooCFunction1PdfBinding& other, const char* name=0) ;
virtual TObject* clone(const char* newname) const { return new RooCFunction1PdfBinding(*this,newname); }
inline virtual ~RooCFunction1PdfBinding() { }
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:
RooCFunction1Ref<VO,VI> func ;
RooRealProxy x ;
Double_t evaluate() const {
return func(x) ;
}
private:
ClassDef(RooCFunction1PdfBinding,1)
};
template<class VO,class VI>
RooCFunction1PdfBinding<VO,VI>::RooCFunction1PdfBinding(const char *name, const char *title, VO (*_func)(VI), RooAbsReal& _x) :
RooAbsPdf(name,title),
func(_func),
x(func.argName(0),func.argName(0),this,_x)
{
}
template<class VO,class VI>
RooCFunction1PdfBinding<VO,VI>::RooCFunction1PdfBinding(const RooCFunction1PdfBinding& other, const char* name) :
RooAbsPdf(other,name),
func(other.func),
x("x",this,other.x)
{
}
template <> void RooCFunction1Ref<Double_t,Double_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction1Binding<Double_t,Double_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction1PdfBinding<Double_t,Double_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction1Ref<Double_t,Int_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction1Binding<Double_t,Int_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
template <> void RooCFunction1PdfBinding<Double_t,Int_t>::ShowMembers(TMemberInspector &R__insp, char *R__parent) ;
#endif
Last change: Mon Aug 25 11:35:19 2008
Last generated: 2008-08-25 11:35
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.