Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix precedence error and added additional functions #11684

Merged
merged 1 commit into from Oct 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
157 changes: 99 additions & 58 deletions CommonTools/Utils/src/FormulaEvaluator.cc

Large diffs are not rendered by default.

50 changes: 34 additions & 16 deletions CommonTools/Utils/src/formulaBinaryOperatorEvaluator.h
Expand Up @@ -30,31 +30,51 @@ namespace reco {
namespace formula {
class BinaryOperatorEvaluatorBase : public EvaluatorBase {
public:
BinaryOperatorEvaluatorBase( Precedence iPrec) :
BinaryOperatorEvaluatorBase( std::shared_ptr<EvaluatorBase> iLHS,
std::shared_ptr<EvaluatorBase> iRHS,
Precedence iPrec) :
EvaluatorBase(iPrec),
m_lhs(iLHS),
m_rhs(iRHS) {}

BinaryOperatorEvaluatorBase(Precedence iPrec) :
EvaluatorBase(iPrec) {}
virtual void swapLeftEvaluator(std::unique_ptr<EvaluatorBase>& iNew) = 0;

void swapLeftEvaluator(std::shared_ptr<EvaluatorBase>& iNew ) {
m_lhs.swap(iNew);
}

void setLeftEvaluator(std::shared_ptr<EvaluatorBase> iOther) {
m_lhs = std::move(iOther);
}
void setRightEvaluator(std::shared_ptr<EvaluatorBase> iOther) {
m_rhs = std::move(iOther);
}

EvaluatorBase const* lhs() const { return m_lhs.get(); }
EvaluatorBase const* rhs() const { return m_rhs.get(); }

private:
std::shared_ptr<EvaluatorBase> m_lhs;
std::shared_ptr<EvaluatorBase> m_rhs;
};

template<typename Op>
class BinaryOperatorEvaluator : public BinaryOperatorEvaluatorBase
{

public:
BinaryOperatorEvaluator(std::unique_ptr<EvaluatorBase> iLHS,
std::unique_ptr<EvaluatorBase> iRHS,
BinaryOperatorEvaluator(std::shared_ptr<EvaluatorBase> iLHS,
std::shared_ptr<EvaluatorBase> iRHS,
Precedence iPrec):
BinaryOperatorEvaluatorBase(iPrec),
m_lhs(std::move(iLHS)),
m_rhs(std::move(iRHS)) {
}
BinaryOperatorEvaluatorBase(std::move(iLHS), std::move(iRHS), iPrec) {}

BinaryOperatorEvaluator(Precedence iPrec):
BinaryOperatorEvaluatorBase(iPrec) {}

// ---------- const member functions ---------------------
virtual double evaluate(double const* iVariables, double const* iParameters) const override final {
return m_operator(m_lhs->evaluate(iVariables,iParameters),m_rhs->evaluate(iVariables,iParameters));
}

void swapLeftEvaluator(std::unique_ptr<EvaluatorBase>& iNew ) override final {
m_lhs.swap(iNew);
return m_operator(lhs()->evaluate(iVariables,iParameters),rhs()->evaluate(iVariables,iParameters));
}

private:
Expand All @@ -63,8 +83,6 @@ namespace reco {
const BinaryOperatorEvaluator& operator=(const BinaryOperatorEvaluator&) = delete;

// ---------- member data --------------------------------
std::unique_ptr<EvaluatorBase> m_lhs;
std::unique_ptr<EvaluatorBase> m_rhs;
Op m_operator;

};
Expand Down
4 changes: 2 additions & 2 deletions CommonTools/Utils/src/formulaFunctionOneArgEvaluator.h
Expand Up @@ -34,7 +34,7 @@ namespace reco {

public:
template<typename T>
explicit FunctionOneArgEvaluator(std::unique_ptr<EvaluatorBase> iArg, T iFunc):
explicit FunctionOneArgEvaluator(std::shared_ptr<EvaluatorBase> iArg, T iFunc):
m_arg(std::move(iArg)),
m_function(iFunc) {}

Expand All @@ -49,7 +49,7 @@ namespace reco {
const FunctionOneArgEvaluator& operator=(const FunctionOneArgEvaluator&) = delete;

// ---------- member data --------------------------------
std::unique_ptr<EvaluatorBase> m_arg;
std::shared_ptr<EvaluatorBase> m_arg;
std::function<double(double)> m_function;
};
}
Expand Down
8 changes: 4 additions & 4 deletions CommonTools/Utils/src/formulaFunctionTwoArgsEvaluator.h
Expand Up @@ -34,8 +34,8 @@ namespace reco {

public:
template<typename T>
FunctionTwoArgsEvaluator(std::unique_ptr<EvaluatorBase> iArg1,
std::unique_ptr<EvaluatorBase> iArg2,
FunctionTwoArgsEvaluator(std::shared_ptr<EvaluatorBase> iArg1,
std::shared_ptr<EvaluatorBase> iArg2,
T iFunc):
m_arg1(std::move(iArg1)),
m_arg2(std::move(iArg2)),
Expand All @@ -54,8 +54,8 @@ namespace reco {
const FunctionTwoArgsEvaluator& operator=(const FunctionTwoArgsEvaluator&) = delete;

// ---------- member data --------------------------------
std::unique_ptr<EvaluatorBase> m_arg1;
std::unique_ptr<EvaluatorBase> m_arg2;
std::shared_ptr<EvaluatorBase> m_arg1;
std::shared_ptr<EvaluatorBase> m_arg2;
std::function<double(double,double)> m_function;
};
}
Expand Down
4 changes: 2 additions & 2 deletions CommonTools/Utils/src/formulaUnaryMinusEvaluator.h
Expand Up @@ -33,7 +33,7 @@ namespace reco {
{

public:
explicit UnaryMinusEvaluator(std::unique_ptr<EvaluatorBase> iArg):
explicit UnaryMinusEvaluator(std::shared_ptr<EvaluatorBase> iArg):
EvaluatorBase(Precedence::kUnaryMinusOperator ),
m_arg(std::move(iArg)) {}

Expand All @@ -48,7 +48,7 @@ namespace reco {
const UnaryMinusEvaluator& operator=(const UnaryMinusEvaluator&) = delete;

// ---------- member data --------------------------------
std::unique_ptr<EvaluatorBase> m_arg;
std::shared_ptr<EvaluatorBase> m_arg;
};
}
}
Expand Down