CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
FWExpressionEvaluator Class Reference

#include <Fireworks/Core/interface/FWExpressionEvaluator.h>

Public Member Functions

double evalExpression (const void *) const
 
const std::string & expression () const
 
 FWExpressionEvaluator (const std::string &iExpression, const std::string &iClassName)
 
void setClassName (const std::string &)
 
void setExpression (const std::string &)
 
virtual ~FWExpressionEvaluator ()
 

Private Attributes

std::string m_className
 
reco::parser::ExpressionPtr m_expr
 
std::string m_expression
 
edm::TypeWithDict m_type
 

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 33 of file FWExpressionEvaluator.h.

Constructor & Destructor Documentation

◆ FWExpressionEvaluator()

FWExpressionEvaluator::FWExpressionEvaluator ( const std::string &  iExpression,
const std::string &  iClassName 
)

Definition at line 37 of file FWExpressionEvaluator.cc.

References setExpression().

38  : m_className(iClassName), m_type(edm::TypeWithDict::byName(iClassName)) {
39  setExpression(iExpression);
40 }
void setExpression(const std::string &)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74

◆ ~FWExpressionEvaluator()

FWExpressionEvaluator::~FWExpressionEvaluator ( )
virtual

Definition at line 47 of file FWExpressionEvaluator.cc.

47 {}

Member Function Documentation

◆ evalExpression()

double FWExpressionEvaluator::evalExpression ( const void *  iObject) const

Definition at line 109 of file FWExpressionEvaluator.cc.

References m_expr, m_expression, m_type, and EcalTangentSkim_cfg::o.

109  {
110  if (m_expression.empty() || !m_expr.get()) {
111  return 0;
112  }
113 
114  edm::ObjectWithDict o(m_type, const_cast<void*>(iObject));
115  return m_expr->value(o);
116 }
reco::parser::ExpressionPtr m_expr

◆ expression()

const std::string & FWExpressionEvaluator::expression ( ) const

Definition at line 107 of file FWExpressionEvaluator.cc.

References m_expression.

107 { return m_expression; }

◆ setClassName()

void FWExpressionEvaluator::setClassName ( const std::string &  iClassName)

Definition at line 94 of file FWExpressionEvaluator.cc.

References edm::TypeWithDict::byName(), m_className, m_expression, m_type, and setExpression().

94  {
95  //NOTE: How do we handle the case where the filter was created before
96  // the library for the class was loaded and therefore we don't have
97  // a dictionary for it?
98 
99  m_className = iClassName;
100  m_type = edm::TypeWithDict::byName(iClassName);
102 }
void setExpression(const std::string &)
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74

◆ setExpression()

void FWExpressionEvaluator::setExpression ( const std::string &  iExpression)

Throws an FWExpressionException if there is a problem

Definition at line 64 of file FWExpressionEvaluator.cc.

References reco::parser::baseExceptionWhat(), MillePedeFileConverter_cfg::e, fireworks::expression::indexFromNewFormatToOldFormat(), m_expr, m_expression, m_type, fireworks::expression::oldToNewFormat(), parse(), AlCaHLTBitMon_QueryRunRegistry::string, and groupFilesInBlocks::temp.

Referenced by FWExpressionEvaluator(), and setClassName().

64  {
65  if (m_type != edm::TypeWithDict() && !iExpression.empty()) {
66  using namespace fireworks::expression;
67 
68  //Backwards compatibility with old format
69  std::string temp = oldToNewFormat(iExpression);
70 
71  //now setup the parser
72  using namespace boost::spirit::classic;
74  reco::parser::Grammar grammar(tmpPtr, m_type);
75  try {
76  if (parse(temp.c_str(), grammar.use_parser<1>() >> end_p, space_p).full) {
77  m_expr = tmpPtr;
78  m_expression = iExpression;
79  } else {
80  throw FWExpressionException("syntax error", -1);
81  //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
82  }
83  } catch (const reco::parser::BaseException& e) {
84  //NOTE: need to calculate actual position before doing the regex
86  indexFromNewFormatToOldFormat(temp, e.where - temp.c_str(), iExpression));
87  //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
88  }
89  } else {
90  m_expression = iExpression;
91  }
92 }
reco::parser::ExpressionPtr m_expr
long indexFromNewFormatToOldFormat(const std::string &iNewFormat, long iNewFormatIndex, const std::string &iOldFormat)
vector< string > parse(string line, const string &delimiter)
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:33
std::shared_ptr< ExpressionBase > ExpressionPtr
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate &#39;what&#39; message for the exception
Definition: Exception.h:36
std::string oldToNewFormat(const std::string &iExpression)

Member Data Documentation

◆ m_className

std::string FWExpressionEvaluator::m_className
private

Definition at line 58 of file FWExpressionEvaluator.h.

Referenced by setClassName().

◆ m_expr

reco::parser::ExpressionPtr FWExpressionEvaluator::m_expr
private

Definition at line 59 of file FWExpressionEvaluator.h.

Referenced by evalExpression(), and setExpression().

◆ m_expression

std::string FWExpressionEvaluator::m_expression
private

Definition at line 57 of file FWExpressionEvaluator.h.

Referenced by evalExpression(), expression(), setClassName(), and setExpression().

◆ m_type

edm::TypeWithDict FWExpressionEvaluator::m_type
private

Definition at line 60 of file FWExpressionEvaluator.h.

Referenced by evalExpression(), setClassName(), and setExpression().