Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-30 02:32:45

0001 #ifndef CommonTools_Utils_formulaFunctionOneArgEvaluator_h
0002 #define CommonTools_Utils_formulaFunctionOneArgEvaluator_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     CommonTools/Utils
0006 // Class  :     formulaFunctionOneArgEvaluator
0007 //
0008 /**\class reco::formula::FunctionOneArgEvaluator formulaFunctionOneArgEvaluator.h "formulaFunctionOneArgEvaluator.h"
0009 
0010  Description: [one line class summary]
0011 
0012  Usage:
0013     <usage>
0014 
0015 */
0016 //
0017 // Original Author:  Christopher Jones
0018 //         Created:  Wed, 23 Sep 2015 17:41:33 GMT
0019 //
0020 
0021 // system include files
0022 #include <memory>
0023 #include <functional>
0024 
0025 // user include files
0026 #include "formulaEvaluatorBase.h"
0027 
0028 // forward declarations
0029 
0030 namespace reco {
0031   namespace formula {
0032     class FunctionOneArgEvaluator : public EvaluatorBase {
0033     public:
0034       template <typename T>
0035       explicit FunctionOneArgEvaluator(std::shared_ptr<EvaluatorBase> iArg, T iFunc)
0036           : m_arg(std::move(iArg)), m_function(iFunc) {}
0037 
0038       // ---------- const member functions ---------------------
0039       double evaluate(double const* iVariables, double const* iParameters) const final {
0040         return m_function(m_arg->evaluate(iVariables, iParameters));
0041       }
0042       std::vector<std::string> abstractSyntaxTree() const final {
0043         auto ret = shiftAST(m_arg->abstractSyntaxTree());
0044         ret.emplace(ret.begin(), "func 1 arg");
0045         return ret;
0046       }
0047 
0048       FunctionOneArgEvaluator(const FunctionOneArgEvaluator&) = delete;
0049 
0050       const FunctionOneArgEvaluator& operator=(const FunctionOneArgEvaluator&) = delete;
0051 
0052     private:
0053       // ---------- member data --------------------------------
0054       std::shared_ptr<EvaluatorBase> m_arg;
0055       std::function<double(double)> m_function;
0056     };
0057   }  // namespace formula
0058 }  // namespace reco
0059 
0060 #endif