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.

38  : m_className(iClassName), m_type(edm::TypeWithDict::byName(iClassName)) {
39  setExpression(iExpression);
40 }

References setExpression().

◆ ~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.

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 }

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

◆ expression()

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

Definition at line 107 of file FWExpressionEvaluator.cc.

107 { return m_expression; }

References m_expression.

◆ setClassName()

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

Definition at line 94 of file FWExpressionEvaluator.cc.

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 }

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

◆ setExpression()

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

Throws an FWExpressionException if there is a problem

Definition at line 64 of file FWExpressionEvaluator.cc.

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 }

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

Referenced by FWExpressionEvaluator(), and setClassName().

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().

FWExpressionEvaluator::m_expr
reco::parser::ExpressionPtr m_expr
Definition: FWExpressionEvaluator.h:59
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
reco::parser::baseExceptionWhat
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate 'what' message for the exception
Definition: Exception.h:36
fireworks::expression::oldToNewFormat
std::string oldToNewFormat(const std::string &iExpression)
Definition: expressionFormatHelpers.cc:25
boost::spirit::classic
Definition: DDPartSelection.cc:10
edm::ObjectWithDict
Definition: ObjectWithDict.h:17
FWExpressionEvaluator::m_expression
std::string m_expression
Definition: FWExpressionEvaluator.h:57
FWExpressionException
Definition: FWExpressionException.h:28
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:36
FWExpressionEvaluator::m_type
edm::TypeWithDict m_type
Definition: FWExpressionEvaluator.h:60
FWExpressionEvaluator::m_className
std::string m_className
Definition: FWExpressionEvaluator.h:58
fireworks::expression
Definition: expressionFormatHelpers.cc:24
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
dumpparser.parse
def parse(path, config)
Definition: dumpparser.py:13
edm::TypeWithDict
Definition: TypeWithDict.h:38
reco::parser::BaseException
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:33
FWExpressionEvaluator::setExpression
void setExpression(const std::string &)
Definition: FWExpressionEvaluator.cc:64
reco::parser::ExpressionPtr
std::shared_ptr< ExpressionBase > ExpressionPtr
Definition: ExpressionBase.h:25
fireworks::expression::indexFromNewFormatToOldFormat
long indexFromNewFormatToOldFormat(const std::string &iNewFormat, long iNewFormatIndex, const std::string &iOldFormat)
Definition: expressionFormatHelpers.cc:33
reco::parser::Grammar
Definition: Grammar.h:45
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37