Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:19

0001 #ifndef CommonTools_Utils_formulaEvaluatorBase_h
0002 #define CommonTools_Utils_formulaEvaluatorBase_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     CommonTools/Utils
0006 // Class  :     reco::formula::EvaluatorBase
0007 //
0008 /**\class reco::formula::EvaluatorBase formulaEvaluatorBase.h "formulaEvaluatorBase.h"
0009 
0010  Description: Base class for formula evaluators
0011 
0012  Usage:
0013     Used as an internal detail on the reco::FormulaEvalutor class. 
0014     Base class for all objects used in the abstract evaluation tree where one node
0015     corresponds to one syntax element of the formula.
0016 
0017 */
0018 //
0019 // Original Author:  Christopher Jones
0020 //         Created:  Wed, 23 Sep 2015 16:26:00 GMT
0021 //
0022 
0023 // system include files
0024 #include <vector>
0025 #include <string>
0026 
0027 // user include files
0028 
0029 // forward declarations
0030 
0031 namespace reco {
0032   namespace formula {
0033     std::vector<std::string> shiftAST(std::vector<std::string> child);
0034     class EvaluatorBase {
0035     public:
0036       enum class Precedence {
0037         kIdentity = 1,
0038         kComparison = 2,
0039         kPlusMinus = 3,
0040         kMultDiv = 4,
0041         kPower = 5,
0042         kFunction = 6,  //default
0043         kParenthesis = 7,
0044         kUnaryMinusOperator = 8
0045       };
0046 
0047       EvaluatorBase();
0048       EvaluatorBase(Precedence);
0049       virtual ~EvaluatorBase();
0050 
0051       // ---------- const member functions ---------------------
0052       //inputs are considered to be 'arrays' which have already been validated to
0053       // be of the appropriate length
0054       virtual double evaluate(double const* iVariables, double const* iParameters) const = 0;
0055       virtual std::vector<std::string> abstractSyntaxTree() const = 0;
0056 
0057       unsigned int precedence() const { return m_precedence; }
0058       void setPrecedenceToParenthesis() { m_precedence = static_cast<unsigned int>(Precedence::kParenthesis); }
0059 
0060       EvaluatorBase(const EvaluatorBase&) = delete;
0061 
0062       const EvaluatorBase& operator=(const EvaluatorBase&) = delete;
0063 
0064     private:
0065       // ---------- member data --------------------------------
0066       unsigned int m_precedence;
0067     };
0068   }  // namespace formula
0069 }  // namespace reco
0070 
0071 #endif