CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/PhysicsTools/Utilities/interface/RootFunctionAdapter.h

Go to the documentation of this file.
00001 #ifndef PhysicTools_Utilities_RootFunctionAdapter_h
00002 #define PhysicTools_Utilities_RootFunctionAdapter_h
00003 #include <vector>
00004 #include <boost/shared_ptr.hpp>
00005 #include "PhysicsTools/Utilities/interface/RootVarsAdapter.h"
00006 
00007 namespace root {
00008   namespace helper {
00009 
00010     template<typename F, unsigned int args>
00011     struct RootFunctionAdapter {
00012       RootFunctionAdapter() : f_(0) { }
00013       RootFunctionAdapter(F & f) : f_(&f) { }
00014       void addParameter(const boost::shared_ptr<double> & par) {
00015         pars_.push_back(par);
00016       }
00017       void setParameters(const double * pars) {
00018         for(size_t i = 0; i < pars_.size(); ++i) {
00019           *pars_[i] = pars[i];
00020         }
00021       }
00022       double operator()(const double * var) const {
00023         return RootVarsAdapter<F, args>::value(*f_, var);
00024       }
00025       size_t numberOfParameters() const {
00026         return pars_.size();
00027       }
00028     private:
00029       F * f_;
00030       std::vector<boost::shared_ptr<double> > pars_;
00031     };
00032     
00033   }
00034 
00035 }
00036 
00037 #endif