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