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 ( std::string const &  iFormula)
explicit

Definition at line 753 of file FormulaEvaluator.cc.

References DEBUG_STATE, Exception, EcalElecEmulTccOnlyExample_cfg::formula, info(), lastIndex, eostools::move(), or, and AlCaHLTBitMon_QueryRunRegistry::string.

754 {
755  //remove white space
757  formula.reserve(iFormula.size());
758  std::copy_if(iFormula.begin(), iFormula.end(), std::back_inserter(formula), [](const char iC) { return iC != ' '; } );
759 
760  auto info = s_expressionFinder.createEvaluator(formula.begin(), formula.end(),std::shared_ptr<reco::formula::BinaryOperatorEvaluatorBase>());
761 
762  if(info.nextParseIndex != static_cast<int>(formula.size()) or info.top.get() == nullptr) {
763  auto lastIndex = info.nextParseIndex;
764  if(formula.size() != iFormula.size()) {
765  lastIndex =0;
766  for(decltype(info.nextParseIndex) index=0; index < info.nextParseIndex; ++index, ++lastIndex) {
767  while(iFormula[lastIndex] != formula[index]) {
768  assert(iFormula[lastIndex]==' ');
769  ++lastIndex;
770  }
771  }
772  }
773  throw cms::Exception("FormulaEvaluatorParseError")<<"While parsing '"<<iFormula<<"' could not parse beyond '"<<std::string(iFormula.begin(),iFormula.begin()+lastIndex) <<"'";
774  }
775 
776  DEBUG_STATE("DONE parsing");
777  printAST(info.top.get());
778 
779  m_evaluator = std::move(info.top);
780  m_nVariables = info.maxNumVariables;
781  m_nParameters = info.maxNumParameters;
782 }
static const TGPicture * info(bool iBackgroundIsBlack)
#define DEBUG_STATE(_v_)
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
static std::atomic< unsigned int > lastIndex
Definition: DDValue.cc:12
std::shared_ptr< formula::EvaluatorBase const > m_evaluator
def move(src, dest)
Definition: eostools.py:511

Member Function Documentation

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

Definition at line 803 of file FormulaEvaluator.cc.

803  {
804  return m_evaluator->abstractSyntaxTree();
805 }
std::shared_ptr< formula::EvaluatorBase const > m_evaluator
template<typename V , typename P >
double reco::FormulaEvaluator::evaluate ( V const &  iVariables,
P const &  iParameters 
) const
inline

Definition at line 75 of file FormulaEvaluator.h.

References reco::formula::startingAddress().

Referenced by SimpleJetCorrector::correctionBin(), SimpleJetCorrector::invert(), main(), CTPPSTimingTrackRecognition< TRACK_TYPE, HIT_TYPE >::producePartialTracks(), ETLElectronicsSim::run(), and TotemTimingConversions::voltSamples().

75  {
76  if (m_nVariables > iVariables.size()) {
77  throwWrongNumberOfVariables(iVariables.size());
78  }
79  if (m_nParameters > iParameters.size()) {
80  throwWrongNumberOfParameters(iParameters.size());
81  }
82  return evaluate( formula::startingAddress(iVariables),
83  formula::startingAddress(iParameters));
84  }
double evaluate(V const &iVariables, P const &iParameters) const
void throwWrongNumberOfParameters(size_t) const
double const * startingAddress(ArrayAdaptor const &iV)
void throwWrongNumberOfVariables(size_t) const
double FormulaEvaluator::evaluate ( double const *  iVariables,
double const *  iParameters 
) const
private

Definition at line 788 of file FormulaEvaluator.cc.

789 {
790  return m_evaluator->evaluate(iVariables, iParameters);
791 }
std::shared_ptr< formula::EvaluatorBase const > m_evaluator
unsigned int reco::FormulaEvaluator::numberOfParameters ( ) const
inline
unsigned int reco::FormulaEvaluator::numberOfVariables ( ) const
inline

Definition at line 87 of file FormulaEvaluator.h.

Referenced by TotemTimingConversions::voltSamples().

87 { return m_nVariables; }
void FormulaEvaluator::throwWrongNumberOfParameters ( size_t  iSize) const
private

Definition at line 798 of file FormulaEvaluator.cc.

References Exception.

798  {
799  throw cms::Exception("WrongNumParameters")<<"FormulaEvaluator expected at least "<<m_nParameters<<" but was passed only "<<iSize;
800 }
void FormulaEvaluator::throwWrongNumberOfVariables ( size_t  iSize) const
private

Definition at line 794 of file FormulaEvaluator.cc.

References Exception.

794  {
795  throw cms::Exception("WrongNumVariables")<<"FormulaEvaluator expected at least "<<m_nVariables<<" but was passed only "<<iSize;
796 }

Member Data Documentation

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

Definition at line 97 of file FormulaEvaluator.h.

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

Definition at line 99 of file FormulaEvaluator.h.

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

Definition at line 98 of file FormulaEvaluator.h.