Warning, file /include/root/RooCFunction3Binding.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOCFUNCTION3BINDING
0013 #define ROOCFUNCTION3BINDING
0014
0015 #include "RooAbsReal.h"
0016 #include "RooRealProxy.h"
0017 #include "RooMsgService.h"
0018 #include "RooAbsPdf.h"
0019
0020 #include "TBuffer.h"
0021 #include "TString.h"
0022
0023 #include <string>
0024 #include <map>
0025 #include <vector>
0026
0027
0028 namespace RooFit {
0029
0030 typedef double (*CFUNCD3DDD)(double,double,double) ;
0031 typedef double (*CFUNCD3DDB)(double,double,bool) ;
0032 typedef double (*CFUNCD3DII)(double,Int_t,Int_t) ;
0033 typedef double (*CFUNCD3UDU)(UInt_t,double,UInt_t) ;
0034 typedef double (*CFUNCD3UDD)(UInt_t,double,double) ;
0035 typedef double (*CFUNCD3UUD)(UInt_t,UInt_t,double) ;
0036
0037 RooAbsReal* bindFunction(const char* name,CFUNCD3DDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0038 RooAbsReal* bindFunction(const char* name,CFUNCD3DDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0039 RooAbsReal* bindFunction(const char* name,CFUNCD3DII func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0040 RooAbsReal* bindFunction(const char* name,CFUNCD3UDU func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0041 RooAbsReal* bindFunction(const char* name,CFUNCD3UDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0042 RooAbsReal* bindFunction(const char* name,CFUNCD3UUD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0043 RooAbsPdf* bindPdf(const char* name,CFUNCD3DDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0044 RooAbsPdf* bindPdf(const char* name,CFUNCD3DDB func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0045 RooAbsPdf* bindPdf(const char* name,CFUNCD3DII func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0046 RooAbsPdf* bindPdf(const char* name,CFUNCD3UDU func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0047 RooAbsPdf* bindPdf(const char* name,CFUNCD3UDD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0048 RooAbsPdf* bindPdf(const char* name,CFUNCD3UUD func,RooAbsReal& x, RooAbsReal& y, RooAbsReal& z) ;
0049
0050 }
0051
0052 template<class VO, class VI1, class VI2, class VI3>
0053 class RooCFunction3Map {
0054 public:
0055 RooCFunction3Map() {} ;
0056
0057 void add(const char* name, VO (*ptr)(VI1,VI2,VI3), const char* arg1name="x", const char* arg2name="y", const char* arg3name="z") {
0058
0059 _ptrmap[name] = ptr ;
0060 _namemap[ptr] = name ;
0061 _argnamemap[ptr].push_back(arg1name) ;
0062 _argnamemap[ptr].push_back(arg2name) ;
0063 _argnamemap[ptr].push_back(arg3name) ;
0064 }
0065
0066
0067 const char* lookupName(VO (*ptr)(VI1,VI2,VI3)) {
0068
0069 return _namemap[ptr].c_str() ;
0070 }
0071
0072 VO (*lookupPtr(const char* name))(VI1,VI2,VI3) {
0073
0074 return _ptrmap[name] ;
0075 }
0076
0077 const char* lookupArgName(VO (*ptr)(VI1,VI2,VI3), UInt_t iarg) {
0078
0079
0080 if (iarg<_argnamemap[ptr].size()) {
0081 return (_argnamemap[ptr])[iarg].c_str() ;
0082 }
0083 switch (iarg) {
0084 case 0: return "x" ;
0085 case 1: return "y" ;
0086 case 2: return "z" ;
0087 }
0088 return "w" ;
0089 }
0090
0091 private:
0092
0093 std::map<std::string,VO (*)(VI1,VI2,VI3)> _ptrmap ;
0094 std::map<VO (*)(VI1,VI2,VI3),std::string> _namemap ;
0095 std::map<VO (*)(VI1,VI2,VI3),std::vector<std::string> > _argnamemap ;
0096 } ;
0097
0098
0099 template<class VO, class VI1, class VI2, class VI3>
0100 class RooCFunction3Ref : public TObject {
0101 public:
0102 RooCFunction3Ref(VO (*ptr)(VI1,VI2,VI3)=nullptr) : _ptr(ptr) {
0103
0104 } ;
0105
0106 VO operator()(VI1 x,VI2 y, VI3 z) const {
0107
0108 return (*_ptr)(x,y,z) ;
0109 }
0110
0111 const char* name() const {
0112
0113
0114
0115 const char* result = fmap().lookupName(_ptr) ;
0116 if (result && strlen(result)) {
0117 return result ;
0118 }
0119
0120 union {
0121 void *_ptr;
0122 func_t _funcptr;
0123 } temp;
0124 temp._funcptr = _ptr;
0125 return Form("(%p)",temp._ptr) ;
0126 }
0127
0128 const char* argName(Int_t iarg) {
0129
0130 return fmap().lookupArgName(_ptr,iarg) ;
0131 }
0132
0133 static RooCFunction3Map<VO,VI1,VI2,VI3>& fmap() {
0134
0135 if (!_fmap) {
0136 _fmap = new RooCFunction3Map<VO,VI1,VI2,VI3> ;
0137 }
0138 return *_fmap ;
0139 }
0140
0141 private:
0142
0143 static VO dummyFunction(VI1,VI2,VI3) {
0144
0145
0146 return 0 ;
0147 }
0148
0149
0150 typedef VO (*func_t)(VI1,VI2,VI3) ;
0151 func_t _ptr;
0152
0153 static RooCFunction3Map<VO,VI1,VI2,VI3>* _fmap ;
0154
0155 ClassDefOverride(RooCFunction3Ref,1)
0156 } ;
0157
0158
0159 template<class VO, class VI1, class VI2, class VI3>
0160 RooCFunction3Map<VO,VI1,VI2,VI3>* RooCFunction3Ref<VO,VI1,VI2,VI3>::_fmap = nullptr;
0161
0162
0163
0164 template<class VO, class VI1, class VI2, class VI3>
0165 void RooCFunction3Ref<VO,VI1,VI2,VI3>::Streamer(TBuffer &R__b)
0166 {
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 typedef ::RooCFunction3Ref<VO,VI1,VI2,VI3> thisClass;
0177
0178
0179 if (R__b.IsReading()) {
0180
0181 UInt_t R__s;
0182 UInt_t R__c;
0183 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
0184
0185
0186 TString tmpName ;
0187 tmpName.Streamer(R__b) ;
0188
0189 if (tmpName=="UNKNOWN" && R__v>0) {
0190
0191 coutW(ObjectHandling) << "WARNING: Objected embeds function pointer to unknown function, object will not be functional" << std::endl ;
0192 _ptr = dummyFunction ;
0193
0194 } else {
0195
0196
0197 _ptr = fmap().lookupPtr(tmpName.Data()) ;
0198
0199 if (_ptr==nullptr) {
0200 coutW(ObjectHandling) << "ERROR: Objected embeds pointer to function named " << tmpName
0201 << " but no such function is registered, object will not be functional" << std::endl ;
0202 }
0203 }
0204
0205
0206 R__b.CheckByteCount(R__s, R__c, thisClass::IsA());
0207
0208 } else {
0209
0210 UInt_t R__c;
0211 R__c = R__b.WriteVersion(thisClass::IsA(), true);
0212
0213
0214 TString tmpName = fmap().lookupName(_ptr) ;
0215 if (tmpName.Length()==0) {
0216
0217 union {
0218 void *_ptr;
0219 func_t _funcptr;
0220 } temp;
0221 temp._funcptr = _ptr;
0222 coutW(ObjectHandling) << "WARNING: Cannot persist unknown function pointer " << Form("%p",temp._ptr)
0223 << " written object will not be functional when read back" << std::endl ;
0224 tmpName="UNKNOWN" ;
0225 }
0226
0227
0228 tmpName.Streamer(R__b) ;
0229
0230 R__b.SetByteCount(R__c, true);
0231
0232 }
0233 }
0234
0235
0236
0237 template<class VO,class VI1, class VI2, class VI3>
0238 class RooCFunction3Binding : public RooAbsReal {
0239 public:
0240 RooCFunction3Binding() {
0241
0242 } ;
0243 RooCFunction3Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z);
0244 RooCFunction3Binding(const RooCFunction3Binding& other, const char* name=nullptr) ;
0245 TObject* clone(const char* newname) const override { return new RooCFunction3Binding(*this,newname); }
0246
0247 void printArgs(std::ostream& os) const override {
0248
0249 os << "[ function=" << func.name() << " " ;
0250 for (Int_t i=0 ; i<numProxies() ; i++) {
0251 RooAbsProxy* p = getProxy(i) ;
0252 if (!TString(p->name()).BeginsWith("!")) {
0253 p->print(os) ;
0254 os << " " ;
0255 }
0256 }
0257 os << "]" ;
0258 }
0259
0260 protected:
0261
0262 RooCFunction3Ref<VO,VI1,VI2,VI3> func ;
0263 RooRealProxy x ;
0264 RooRealProxy y ;
0265 RooRealProxy z ;
0266
0267 double evaluate() const override {
0268
0269 return func(x,y,z) ;
0270 }
0271
0272 private:
0273
0274 ClassDefOverride(RooCFunction3Binding,1)
0275 };
0276
0277
0278
0279 template<class VO,class VI1, class VI2, class VI3>
0280 RooCFunction3Binding<VO,VI1,VI2,VI3>::RooCFunction3Binding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3),
0281 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z) :
0282 RooAbsReal(name,title),
0283 func(_func),
0284 x(func.argName(0),func.argName(0),this,_x),
0285 y(func.argName(1),func.argName(1),this,_y),
0286 z(func.argName(2),func.argName(2),this,_z)
0287 {
0288
0289
0290
0291
0292 }
0293
0294
0295 template<class VO,class VI1, class VI2, class VI3>
0296 RooCFunction3Binding<VO,VI1,VI2,VI3>::RooCFunction3Binding(const RooCFunction3Binding& other, const char* name) :
0297 RooAbsReal(other,name),
0298 func(other.func),
0299 x("x",this,other.x),
0300 y("y",this,other.y),
0301 z("z",this,other.z)
0302 {
0303
0304 }
0305
0306
0307 template<class VO,class VI1, class VI2, class VI3>
0308 class RooCFunction3PdfBinding : public RooAbsPdf {
0309 public:
0310 RooCFunction3PdfBinding() {
0311
0312 } ;
0313 RooCFunction3PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3), RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z);
0314 RooCFunction3PdfBinding(const RooCFunction3PdfBinding& other, const char* name=nullptr) ;
0315 TObject* clone(const char* newname) const override { return new RooCFunction3PdfBinding(*this,newname); }
0316
0317 void printArgs(std::ostream& os) const override {
0318
0319 os << "[ function=" << func.name() << " " ;
0320 for (Int_t i=0 ; i<numProxies() ; i++) {
0321 RooAbsProxy* p = getProxy(i) ;
0322 if (!TString(p->name()).BeginsWith("!")) {
0323 p->print(os) ;
0324 os << " " ;
0325 }
0326 }
0327 os << "]" ;
0328 }
0329
0330 protected:
0331
0332 RooCFunction3Ref<VO,VI1,VI2,VI3> func ;
0333 RooRealProxy x ;
0334 RooRealProxy y ;
0335 RooRealProxy z ;
0336
0337 double evaluate() const override {
0338
0339 return func(x,y,z) ;
0340 }
0341
0342 private:
0343
0344 ClassDefOverride(RooCFunction3PdfBinding,1)
0345 };
0346
0347
0348
0349 template<class VO,class VI1, class VI2, class VI3>
0350 RooCFunction3PdfBinding<VO,VI1,VI2,VI3>::RooCFunction3PdfBinding(const char *name, const char *title, VO (*_func)(VI1,VI2,VI3),
0351 RooAbsReal& _x, RooAbsReal& _y, RooAbsReal& _z) :
0352 RooAbsPdf(name,title),
0353 func(_func),
0354 x(func.argName(0),func.argName(0),this,_x),
0355 y(func.argName(1),func.argName(1),this,_y),
0356 z(func.argName(2),func.argName(2),this,_z)
0357 {
0358
0359
0360
0361
0362 }
0363
0364
0365 template<class VO,class VI1, class VI2, class VI3>
0366 RooCFunction3PdfBinding<VO,VI1,VI2,VI3>::RooCFunction3PdfBinding(const RooCFunction3PdfBinding& other, const char* name) :
0367 RooAbsPdf(other,name),
0368 func(other.func),
0369 x("x",this,other.x),
0370 y("y",this,other.y),
0371 z("z",this,other.z)
0372 {
0373
0374 }
0375
0376 #endif