Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:20

0001 #ifndef PhysicsTools_Utilities_RootFunctionHelper_h
0002 #define PhysicsTools_Utilities_RootFunctionHelper_h
0003 /* Warning: this class users a static cache, so multiple
0004  * instances of the same type would have the same cacke.
0005  * This should be fixed to handle more general cases
0006  *
0007  */
0008 #include "PhysicsTools/Utilities/interface/RootFunctionAdapter.h"
0009 
0010 namespace root {
0011   namespace helper {
0012     struct null_t;
0013 
0014     template <typename F, unsigned int args, typename Tag = null_t>
0015     struct RootFunctionHelper {
0016       typedef double (*root_function)(const double *, const double *);
0017       static root_function fun(F &f) {
0018         adapter_ = RootFunctionAdapter<F, args>(f);
0019         return &fun_;
0020       }
0021       static void addParameter(const std::shared_ptr<double> &par) { adapter_.addParameter(par); }
0022 
0023     private:
0024       static double fun_(const double *x, const double *par) {
0025         adapter_.setParameters(par);
0026         return adapter_(x);
0027       }
0028       static RootFunctionAdapter<F, args> adapter_;
0029     };
0030 
0031     template <typename F, unsigned int args, typename Tag>
0032     RootFunctionAdapter<F, args> RootFunctionHelper<F, args, Tag>::adapter_;
0033   }  // namespace helper
0034 }  // namespace root
0035 
0036 #endif