File indexing completed on 2024-04-06 12:11:38
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <sstream>
0015
0016 #include "FWCore/Reflection/interface/ObjectWithDict.h"
0017
0018
0019 #include "Fireworks/Core/interface/FWExpressionEvaluator.h"
0020 #include "Fireworks/Core/interface/FWExpressionException.h"
0021 #include "CommonTools/Utils/interface/parser/Grammar.h"
0022 #include "CommonTools/Utils/interface/parser/Exception.h"
0023
0024 #include "Fireworks/Core/src/expressionFormatHelpers.h"
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 FWExpressionEvaluator::FWExpressionEvaluator(const std::string& iExpression, const std::string& iClassName)
0038 : m_className(iClassName), m_type(edm::TypeWithDict::byName(iClassName)) {
0039 setExpression(iExpression);
0040 }
0041
0042
0043
0044
0045
0046
0047 FWExpressionEvaluator::~FWExpressionEvaluator() {}
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 void FWExpressionEvaluator::setExpression(const std::string& iExpression) {
0065 if (m_type != edm::TypeWithDict() && !iExpression.empty()) {
0066 using namespace fireworks::expression;
0067
0068
0069 std::string temp = oldToNewFormat(iExpression);
0070
0071
0072 using namespace boost::spirit::classic;
0073 reco::parser::ExpressionPtr tmpPtr;
0074 reco::parser::Grammar grammar(tmpPtr, m_type);
0075 try {
0076 if (parse(temp.c_str(), grammar.use_parser<1>() >> end_p, space_p).full) {
0077 m_expr = tmpPtr;
0078 m_expression = iExpression;
0079 } else {
0080 throw FWExpressionException("syntax error", -1);
0081
0082 }
0083 } catch (const reco::parser::BaseException& e) {
0084
0085 throw FWExpressionException(reco::parser::baseExceptionWhat(e),
0086 indexFromNewFormatToOldFormat(temp, e.where - temp.c_str(), iExpression));
0087
0088 }
0089 } else {
0090 m_expression = iExpression;
0091 }
0092 }
0093
0094 void FWExpressionEvaluator::setClassName(const std::string& iClassName) {
0095
0096
0097
0098
0099 m_className = iClassName;
0100 m_type = edm::TypeWithDict::byName(iClassName);
0101 setExpression(m_expression);
0102 }
0103
0104
0105
0106
0107 const std::string& FWExpressionEvaluator::expression() const { return m_expression; }
0108
0109 double FWExpressionEvaluator::evalExpression(const void* iObject) const {
0110 if (m_expression.empty() || !m_expr.get()) {
0111 return 0;
0112 }
0113
0114 edm::ObjectWithDict o(m_type, const_cast<void*>(iObject));
0115 return m_expr->value(o);
0116 }
0117
0118
0119
0120