Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <sstream>
00016
00017 #include "Reflex/Object.h"
00018
00019
00020 #include "Fireworks/Core/interface/FWModelFilter.h"
00021 #include "Fireworks/Core/interface/FWExpressionException.h"
00022
00023 #include "CommonTools/Utils/src/Grammar.h"
00024 #include "CommonTools/Utils/interface/Exception.h"
00025
00026 #include "Fireworks/Core/src/expressionFormatHelpers.h"
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 FWModelFilter::FWModelFilter(const std::string& iExpression,
00040 const std::string& iClassName) :
00041 m_className(iClassName),
00042 m_type(ROOT::Reflex::Type::ByName(iClassName))
00043 {
00044 setExpression(iExpression);
00045 }
00046
00047
00048
00049
00050
00051
00052 FWModelFilter::~FWModelFilter()
00053 {
00054 }
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071 void
00072 FWModelFilter::setExpression(const std::string& iExpression)
00073 {
00074 if(m_type != ROOT::Reflex::Type() && iExpression.size()) {
00075 using namespace fireworks::expression;
00076
00077
00078 std::string temp = oldToNewFormat(iExpression);
00079
00080
00081 using namespace boost::spirit::classic;
00082 reco::parser::SelectorPtr tmpPtr;
00083 reco::parser::Grammar grammar(tmpPtr,m_type);
00084 try {
00085 if(parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
00086 m_selector = tmpPtr;
00087 m_expression = iExpression;
00088 } else {
00089 throw FWExpressionException("syntax error", -1);
00090
00091 }
00092 } catch(const reco::parser::BaseException& e) {
00093
00094 throw FWExpressionException(reco::parser::baseExceptionWhat(e), indexFromNewFormatToOldFormat(temp,e.where-temp.c_str(),iExpression));
00095
00096 }
00097 } else {
00098 m_expression=iExpression;
00099 }
00100 }
00101
00102 void
00103 FWModelFilter::setClassName(const std::string& iClassName)
00104 {
00105
00106
00107
00108
00109 m_className = iClassName;
00110 m_type = ROOT::Reflex::Type::ByName(iClassName);
00111 setExpression(m_expression);
00112 }
00113
00114
00115
00116
00117 const std::string&
00118 FWModelFilter::expression() const
00119 {
00120 return m_expression;
00121 }
00122
00123 bool
00124 FWModelFilter::passesFilter(const void* iObject) const
00125 {
00126 if(m_expression.empty() || !m_selector.get()) {
00127 return true;
00128 }
00129
00130 ROOT::Reflex::Object o(m_type, const_cast<void *>(iObject));
00131 return (*m_selector)(o);
00132 }
00133
00134 bool
00135 FWModelFilter::trivialFilter() const
00136 {
00137 return m_expression.empty();
00138 }
00139
00140
00141
00142