Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CommonTools_Utils_formulaFunctionTwoArgsEvaluator_h
0002 #define CommonTools_Utils_formulaFunctionTwoArgsEvaluator_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     CommonTools/Utils
0006 // Class  :     formulaFunctionTwoArgsEvaluator
0007 //
0008 /**\class reco::formula::FunctionTwoArgsEvaluator formulaFunctionTwoArgsEvaluator.h "formulaFunctionTwoArgsEvaluator.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 FunctionTwoArgsEvaluator : public EvaluatorBase {
0033     public:
0034       template <typename T>
0035       FunctionTwoArgsEvaluator(std::shared_ptr<EvaluatorBase> iArg1, std::shared_ptr<EvaluatorBase> iArg2, T iFunc)
0036           : m_arg1(std::move(iArg1)), m_arg2(std::move(iArg2)), m_function(iFunc) {}
0037 
0038       // ---------- const member functions ---------------------
0039       double evaluate(double const* iVariables, double const* iParameters) const final {
0040         return m_function(m_arg1->evaluate(iVariables, iParameters), m_arg2->evaluate(iVariables, iParameters));
0041       }
0042       std::vector<std::string> abstractSyntaxTree() const final {
0043         auto ret = shiftAST(m_arg1->abstractSyntaxTree());
0044         for (auto& v : shiftAST(m_arg2->abstractSyntaxTree())) {
0045           ret.emplace_back(std::move(v));
0046         }
0047         ret.emplace(ret.begin(), "func 2 args");
0048         return ret;
0049       }
0050 
0051       FunctionTwoArgsEvaluator(const FunctionTwoArgsEvaluator&) = delete;
0052 
0053       const FunctionTwoArgsEvaluator& operator=(const FunctionTwoArgsEvaluator&) = delete;
0054 
0055     private:
0056       // ---------- member data --------------------------------
0057       std::shared_ptr<EvaluatorBase> m_arg1;
0058       std::shared_ptr<EvaluatorBase> m_arg2;
0059       std::function<double(double, double)> m_function;
0060     };
0061   }  // namespace formula
0062 }  // namespace reco
0063 
0064 #endif