CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
reco::FormulaEvaluator Class Reference

#include <FormulaEvaluator.h>

Public Member Functions

std::vector< std::string > abstractSyntaxTree () const
 
template<typename V , typename P >
double evaluate (V const &iVariables, P const &iParameters) const
 
 FormulaEvaluator (std::string const &iFormula)
 
unsigned int numberOfParameters () const
 
unsigned int numberOfVariables () const
 

Private Member Functions

double evaluate (double const *iVariables, double const *iParameters) const
 
void throwWrongNumberOfParameters (size_t) const
 
void throwWrongNumberOfVariables (size_t) const
 

Private Attributes

std::shared_ptr< formula::EvaluatorBase const > m_evaluator
 
unsigned int m_nParameters = 0
 
unsigned int m_nVariables = 0
 

Detailed Description

Definition at line 67 of file FormulaEvaluator.h.

Constructor & Destructor Documentation

◆ FormulaEvaluator()

FormulaEvaluator::FormulaEvaluator ( std::string const &  iFormula)
explicit

Definition at line 902 of file FormulaEvaluator.cc.

902  {
903  //remove white space
905  formula.reserve(iFormula.size());
906  std::copy_if(iFormula.begin(), iFormula.end(), std::back_inserter(formula), [](const char iC) { return iC != ' '; });
907 
908  auto info = s_expressionFinder.createEvaluator(
909  formula.begin(), formula.end(), std::shared_ptr<reco::formula::BinaryOperatorEvaluatorBase>());
910 
911  if (info.nextParseIndex != static_cast<int>(formula.size()) or info.top.get() == nullptr) {
912  auto lastIndex = info.nextParseIndex;
913  if (formula.size() != iFormula.size()) {
914  lastIndex = 0;
915  for (decltype(info.nextParseIndex) index = 0; index < info.nextParseIndex; ++index, ++lastIndex) {
916  while (iFormula[lastIndex] != formula[index]) {
917  assert(iFormula[lastIndex] == ' ');
918  ++lastIndex;
919  }
920  }
921  }
922  throw cms::Exception("FormulaEvaluatorParseError")
923  << "While parsing '" << iFormula << "' could not parse beyond '"
924  << std::string(iFormula.begin(), iFormula.begin() + lastIndex) << "'";
925  }
926 
927  DEBUG_STATE("DONE parsing");
928  printAST(info.top.get());
929 
930  m_evaluator = std::move(info.top);
931  m_nVariables = info.maxNumVariables;
932  m_nParameters = info.maxNumParameters;
933 }

References cms::cuda::assert(), DEBUG_STATE, Exception, pfMETCorrectionType0_cfi::formula, info(), lastIndex, m_evaluator, m_nParameters, m_nVariables, eostools::move(), or, and AlCaHLTBitMon_QueryRunRegistry::string.

Member Function Documentation

◆ abstractSyntaxTree()

std::vector< std::string > FormulaEvaluator::abstractSyntaxTree ( ) const

Definition at line 951 of file FormulaEvaluator.cc.

951 { return m_evaluator->abstractSyntaxTree(); }

References m_evaluator.

◆ evaluate() [1/2]

double FormulaEvaluator::evaluate ( double const *  iVariables,
double const *  iParameters 
) const
private

Definition at line 938 of file FormulaEvaluator.cc.

938  {
939  return m_evaluator->evaluate(iVariables, iParameters);
940 }

References m_evaluator.

◆ evaluate() [2/2]

template<typename V , typename P >
double reco::FormulaEvaluator::evaluate ( V const &  iVariables,
P const &  iParameters 
) const
inline

◆ numberOfParameters()

unsigned int reco::FormulaEvaluator::numberOfParameters ( ) const
inline

◆ numberOfVariables()

unsigned int reco::FormulaEvaluator::numberOfVariables ( ) const
inline

Definition at line 84 of file FormulaEvaluator.h.

84 { return m_nVariables; }

References m_nVariables.

Referenced by TotemTimingConversions::voltSamples().

◆ throwWrongNumberOfParameters()

void FormulaEvaluator::throwWrongNumberOfParameters ( size_t  iSize) const
private

Definition at line 946 of file FormulaEvaluator.cc.

946  {
947  throw cms::Exception("WrongNumParameters")
948  << "FormulaEvaluator expected at least " << m_nParameters << " but was passed only " << iSize;
949 }

References Exception, and m_nParameters.

Referenced by evaluate().

◆ throwWrongNumberOfVariables()

void FormulaEvaluator::throwWrongNumberOfVariables ( size_t  iSize) const
private

Definition at line 942 of file FormulaEvaluator.cc.

942  {
943  throw cms::Exception("WrongNumVariables")
944  << "FormulaEvaluator expected at least " << m_nVariables << " but was passed only " << iSize;
945 }

References Exception, and m_nVariables.

Referenced by evaluate().

Member Data Documentation

◆ m_evaluator

std::shared_ptr<formula::EvaluatorBase const> reco::FormulaEvaluator::m_evaluator
private

Definition at line 94 of file FormulaEvaluator.h.

Referenced by abstractSyntaxTree(), evaluate(), and FormulaEvaluator().

◆ m_nParameters

unsigned int reco::FormulaEvaluator::m_nParameters = 0
private

◆ m_nVariables

unsigned int reco::FormulaEvaluator::m_nVariables = 0
private
DEBUG_STATE
#define DEBUG_STATE(_v_)
Definition: FormulaEvaluator.cc:50
pfMETCorrectionType0_cfi.formula
formula
Definition: pfMETCorrectionType0_cfi.py:46
reco::FormulaEvaluator::m_nVariables
unsigned int m_nVariables
Definition: FormulaEvaluator.h:95
cms::cuda::assert
assert(be >=bs)
info
static const TGPicture * info(bool iBackgroundIsBlack)
Definition: FWCollectionSummaryWidget.cc:153
reco::FormulaEvaluator::throwWrongNumberOfParameters
void throwWrongNumberOfParameters(size_t) const
Definition: FormulaEvaluator.cc:946
lastIndex
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:12
reco::FormulaEvaluator::m_evaluator
std::shared_ptr< formula::EvaluatorBase const > m_evaluator
Definition: FormulaEvaluator.h:94
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
reco::FormulaEvaluator::throwWrongNumberOfVariables
void throwWrongNumberOfVariables(size_t) const
Definition: FormulaEvaluator.cc:942
eostools.move
def move(src, dest)
Definition: eostools.py:511
reco::FormulaEvaluator::evaluate
double evaluate(V const &iVariables, P const &iParameters) const
Definition: FormulaEvaluator.h:73
Exception
Definition: hltDiff.cc:246
reco::formula::startingAddress
double const * startingAddress(ArrayAdaptor const &iV)
Definition: FormulaEvaluator.h:42
or
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
reco::FormulaEvaluator::m_nParameters
unsigned int m_nParameters
Definition: FormulaEvaluator.h:96