Skip to content

Commit

Permalink
Revert "Merge pull request cms-sw#11584 from Dr15Jones/replaceTFormua…
Browse files Browse the repository at this point in the history
…lInSimpleJetCorrector"

This reverts commit d302bd9, reversing
changes made to fd763e1.
  • Loading branch information
slava77devel committed Oct 7, 2015
1 parent f56b7b1 commit 516d96a
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 335 deletions.
22 changes: 1 addition & 21 deletions CommonTools/Utils/interface/FormulaEvaluator.h
Expand Up @@ -28,23 +28,6 @@
// forward declarations
namespace reco {
namespace formula {
struct ArrayAdaptor {
ArrayAdaptor(double const* iStart, size_t iSize):
m_start(iStart), m_size(iSize) {}
size_t size() const { return m_size; }
bool empty() const {return m_size == 0; }
double const* start() const { return m_start; }
private:
double const* m_start;
size_t m_size;
};
inline double const* startingAddress(ArrayAdaptor const& iV) {
if(iV.empty()) {
return nullptr;
}
return iV.start();
}

class EvaluatorBase;
inline double const* startingAddress(std::vector<double> const& iV) {
if(iV.empty()) {
Expand All @@ -69,7 +52,6 @@ namespace reco {
public:
explicit FormulaEvaluator(std::string const& iFormula);

// ---------- const member functions ---------------------
template<typename V, typename P>
double evaluate( V const& iVariables, P const& iParameters) const {
if (m_nVariables > iVariables.size()) {
Expand All @@ -81,9 +63,7 @@ namespace reco {
return evaluate( formula::startingAddress(iVariables),
formula::startingAddress(iParameters));
}

unsigned int numberOfParameters() const { return m_nParameters; }
unsigned int numberOfVariables() const { return m_nVariables; }
// ---------- const member functions ---------------------

private:
double evaluate(double const* iVariables, double const* iParameters) const;
Expand Down
71 changes: 9 additions & 62 deletions CommonTools/Utils/src/FormulaEvaluator.cc
Expand Up @@ -122,7 +122,7 @@ namespace {


info.nextParseIndex = endIndex+2;
info.maxNumParameters = value+1;
info.maxNumParameters = value;
info.evaluator = std::unique_ptr<reco::formula::EvaluatorBase>( new reco::formula::ParameterEvaluator(value));
} catch ( std::invalid_argument ) {}

Expand Down Expand Up @@ -256,7 +256,7 @@ namespace {
}
//need to account for closing parenthesis
++leftEvaluatorInfo.nextParseIndex;
leftEvaluatorInfo.evaluator->setPrecedenceToParenthesis();
leftEvaluatorInfo.evaluator->setPrecidenceToParenthesis();
if( iBegin+leftEvaluatorInfo.nextParseIndex == iEnd) {
return leftEvaluatorInfo;
}
Expand Down Expand Up @@ -304,7 +304,7 @@ namespace {

template<typename Op>
EvaluatorInfo createBinaryOperatorEvaluatorT(int iSymbolLength,
reco::formula::EvaluatorBase::Precedence iPrec,
reco::formula::EvaluatorBase::Precidence iPrec,
ExpressionFinder const& iEF,
std::unique_ptr<reco::formula::EvaluatorBase> iLHS,
std::string::const_iterator iBegin,
Expand All @@ -316,7 +316,7 @@ namespace {
return evalInfo;
}

if( static_cast<unsigned int>(iPrec) >= evalInfo.evaluator->precedence() ) {
if( static_cast<unsigned int>(iPrec) >= evalInfo.evaluator->precidence() ) {
auto b = dynamic_cast<reco::formula::BinaryOperatorEvaluatorBase*>( evalInfo.evaluator.get() );
assert(b != nullptr);
std::unique_ptr<reco::formula::EvaluatorBase> temp;
Expand Down Expand Up @@ -350,7 +350,7 @@ namespace {

if(*iBegin == '+') {
return createBinaryOperatorEvaluatorT<std::plus<double>>(1,
reco::formula::EvaluatorBase::Precedence::kPlusMinus,
reco::formula::EvaluatorBase::Precidence::kPlusMinus,
iEF,
std::move(iLHS),
iBegin,
Expand All @@ -359,23 +359,23 @@ namespace {

else if(*iBegin == '-') {
return createBinaryOperatorEvaluatorT<std::minus<double>>(1,
reco::formula::EvaluatorBase::Precedence::kPlusMinus,
reco::formula::EvaluatorBase::Precidence::kPlusMinus,
iEF,
std::move(iLHS),
iBegin,
iEnd);
}
else if(*iBegin == '*') {
return createBinaryOperatorEvaluatorT<std::multiplies<double>>(1,
reco::formula::EvaluatorBase::Precedence::kMultDiv,
reco::formula::EvaluatorBase::Precidence::kMultDiv,
iEF,
std::move(iLHS),
iBegin,
iEnd);
}
else if(*iBegin == '/') {
return createBinaryOperatorEvaluatorT<std::divides<double>>(1,
reco::formula::EvaluatorBase::Precedence::kMultDiv,
reco::formula::EvaluatorBase::Precidence::kMultDiv,
iEF,
std::move(iLHS),
iBegin,
Expand All @@ -384,66 +384,13 @@ namespace {

else if(*iBegin == '^') {
return createBinaryOperatorEvaluatorT<power>(1,
reco::formula::EvaluatorBase::Precedence::kMultDiv,
reco::formula::EvaluatorBase::Precidence::kMultDiv,
iEF,
std::move(iLHS),
iBegin,
iEnd);
}
else if (*iBegin =='<' and iBegin+1 != iEnd and *(iBegin+1) == '=') {
return createBinaryOperatorEvaluatorT<std::less_equal<double>>(2,
reco::formula::EvaluatorBase::Precedence::kComparison,
iEF,
std::move(iLHS),
iBegin,
iEnd);

}
else if (*iBegin =='>' and iBegin+1 != iEnd and *(iBegin+1) == '=') {
return createBinaryOperatorEvaluatorT<std::greater_equal<double>>(2,
reco::formula::EvaluatorBase::Precedence::kComparison,
iEF,
std::move(iLHS),
iBegin,
iEnd);

}
else if (*iBegin =='<' ) {
return createBinaryOperatorEvaluatorT<std::less<double>>(1,
reco::formula::EvaluatorBase::Precedence::kComparison,
iEF,
std::move(iLHS),
iBegin,
iEnd);

}
else if (*iBegin =='>' ) {
return createBinaryOperatorEvaluatorT<std::greater<double>>(1,
reco::formula::EvaluatorBase::Precedence::kComparison,
iEF,
std::move(iLHS),
iBegin,
iEnd);

}
else if (*iBegin =='=' and iBegin+1 != iEnd and *(iBegin+1) == '=' ) {
return createBinaryOperatorEvaluatorT<std::equal_to<double>>(2,
reco::formula::EvaluatorBase::Precedence::kIdentity,
iEF,
std::move(iLHS),
iBegin,
iEnd);

}
else if (*iBegin =='!' and iBegin+1 != iEnd and *(iBegin+1) == '=' ) {
return createBinaryOperatorEvaluatorT<std::not_equal_to<double>>(2,
reco::formula::EvaluatorBase::Precedence::kIdentity,
iEF,
std::move(iLHS),
iBegin,
iEnd);

}
return evalInfo;
}

Expand Down
5 changes: 2 additions & 3 deletions CommonTools/Utils/src/formulaBinaryOperatorEvaluator.h
Expand Up @@ -30,19 +30,18 @@ namespace reco {
namespace formula {
class BinaryOperatorEvaluatorBase : public EvaluatorBase {
public:
BinaryOperatorEvaluatorBase( Precedence iPrec) :
BinaryOperatorEvaluatorBase( Precidence iPrec) :
EvaluatorBase(iPrec) {}
virtual void swapLeftEvaluator(std::unique_ptr<EvaluatorBase>& iNew) = 0;
};

template<typename Op>
class BinaryOperatorEvaluator : public BinaryOperatorEvaluatorBase
{

public:
BinaryOperatorEvaluator(std::unique_ptr<EvaluatorBase> iLHS,
std::unique_ptr<EvaluatorBase> iRHS,
Precedence iPrec):
Precidence iPrec):
BinaryOperatorEvaluatorBase(iPrec),
m_lhs(std::move(iLHS)),
m_rhs(std::move(iRHS)) {
Expand Down
6 changes: 3 additions & 3 deletions CommonTools/Utils/src/formulaEvaluatorBase.cc
Expand Up @@ -28,12 +28,12 @@
// constructors and destructor
//
reco::formula::EvaluatorBase::EvaluatorBase():
m_precedence(static_cast<unsigned int>(Precedence::kFunction))
m_precidence(static_cast<unsigned int>(Precidence::kFunction))
{
}

reco::formula::EvaluatorBase::EvaluatorBase(Precedence iPrec):
m_precedence(static_cast<unsigned int>(iPrec))
reco::formula::EvaluatorBase::EvaluatorBase(Precidence iPrec):
m_precidence(static_cast<unsigned int>(iPrec))
{
}

Expand Down
24 changes: 11 additions & 13 deletions CommonTools/Utils/src/formulaEvaluatorBase.h
Expand Up @@ -32,36 +32,34 @@ namespace reco {
{

public:
enum class Precedence {
kIdentity = 1,
kComparison=2,
kPlusMinus = 3,
kMultDiv = 4,
kPower = 5,
kFunction = 6, //default
kParenthesis = 7,
kUnaryMinusOperator = 8
enum class Precidence {
kPlusMinus = 1,
kMultDiv = 2,
kPower = 3,
kFunction = 4, //default
kParenthesis = 5,
kUnaryMinusOperator = 6
};

EvaluatorBase();
EvaluatorBase(Precedence);
EvaluatorBase(Precidence);
virtual ~EvaluatorBase();

// ---------- const member functions ---------------------
//inputs are considered to be 'arrays' which have already been validated to
// be of the appropriate length
virtual double evaluate(double const* iVariables, double const* iParameters) const = 0;

unsigned int precedence() const { return m_precedence; }
void setPrecedenceToParenthesis() { m_precedence = static_cast<unsigned int>(Precedence::kParenthesis); }
unsigned int precidence() const { return m_precidence; }
void setPrecidenceToParenthesis() { m_precidence = static_cast<unsigned int>(Precidence::kParenthesis); }

private:
EvaluatorBase(const EvaluatorBase&) = delete;

const EvaluatorBase& operator=(const EvaluatorBase&) = delete;

// ---------- member data --------------------------------
unsigned int m_precedence;
unsigned int m_precidence;
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion CommonTools/Utils/src/formulaUnaryMinusEvaluator.h
Expand Up @@ -34,7 +34,7 @@ namespace reco {

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

// ---------- const member functions ---------------------
Expand Down

0 comments on commit 516d96a

Please sign in to comment.