CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWModelFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWModelFilter
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Fri Feb 29 13:39:56 PST 2008
11 //
12 
13 // system include files
14 #include <sstream>
15 
17 
18 // user include files
21 
24 
26 
27 //
28 // constants, enums and typedefs
29 //
30 
31 //
32 // static data member definitions
33 //
34 
35 //
36 // constructors and destructor
37 //
39  const std::string& iClassName) :
40  m_className(iClassName),
41  m_type(edm::TypeWithDict::byName(iClassName))
42 {
43  setExpression(iExpression);
44 }
45 
46 // FWModelFilter::FWModelFilter(const FWModelFilter& rhs)
47 // {
48 // // do actual copying here;
49 // }
50 
52 {
53 }
54 
55 //
56 // assignment operators
57 //
58 // const FWModelFilter& FWModelFilter::operator=(const FWModelFilter& rhs)
59 // {
60 // //An exception safe implementation is
61 // FWModelFilter temp(rhs);
62 // swap(rhs);
63 //
64 // return *this;
65 // }
66 
67 //
68 // member functions
69 //
70 void
72 {
73  if(m_type != edm::TypeWithDict() && iExpression.size()) {
74  using namespace fireworks::expression;
75 
76  //Backwards compatibility with old format
77  std::string temp = oldToNewFormat(iExpression);
78 
79  //now setup the parser
80  using namespace boost::spirit::classic;
82  reco::parser::Grammar grammar(tmpPtr,m_type);
83  try {
84  if(parse(temp.c_str(), grammar.use_parser<0>() >> end_p, space_p).full) {
85  m_selector = tmpPtr;
86  m_expression = iExpression;
87  } else {
88  throw FWExpressionException("syntax error", -1);
89  //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
90  }
91  } catch(const reco::parser::BaseException& e) {
92  //NOTE: need to calculate actual position before doing the regex
94  //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
95  }
96  } else {
97  m_expression=iExpression;
98  }
99 }
100 
101 void
103 {
104  //NOTE: How do we handle the case where the filter was created before
105  // the library for the class was loaded and therefore we don't have
106  // a dictionary for it?
107 
108  m_className = iClassName;
109  m_type = edm::TypeWithDict::byName(iClassName);
111 }
112 
113 //
114 // const member functions
115 //
116 const std::string&
118 {
119  return m_expression;
120 }
121 
122 bool
123 FWModelFilter::passesFilter(const void* iObject) const
124 {
125  if(m_expression.empty() || !m_selector.get()) {
126  return true;
127  }
128 
129  edm::ObjectWithDict o(m_type, const_cast<void *>(iObject));
130  return (*m_selector)(o);
131 }
132 
133 bool
135 {
136  return m_expression.empty();
137 }
138 
139 //
140 // static member functions
141 //
bool passesFilter(const void *) const
long indexFromNewFormatToOldFormat(const std::string &iNewFormat, long iNewFormatIndex, const std::string &iOldFormat)
reco::parser::SelectorPtr m_selector
Definition: FWModelFilter.h:62
boost::spirit::classic::parser_error< reco::parser::SyntaxErrors > BaseException
Definition: Exception.h:37
Evaluator * parse(const T &text)
edm::TypeWithDict m_type
Definition: FWModelFilter.h:63
const std::string & expression() const
FWModelFilter(const std::string &iExpression, const std::string &iClassName)
std::string m_className
Definition: FWModelFilter.h:61
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:60
std::string m_expression
Definition: FWModelFilter.h:60
bool trivialFilter() const
void setClassName(const std::string &)
const char * baseExceptionWhat(const BaseException &e)
returns the appropriate &#39;what&#39; message for the exception
Definition: Exception.h:40
boost::shared_ptr< SelectorBase > SelectorPtr
Definition: SelectorPtr.h:17
void setExpression(const std::string &)
size_t size() const
std::string oldToNewFormat(const std::string &iExpression)
virtual ~FWModelFilter()