CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Core/src/FWModelFilter.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Core
00004 // Class  :     FWModelFilter
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Fri Feb 29 13:39:56 PST 2008
00011 // $Id: FWModelFilter.cc,v 1.13 2010/09/01 18:49:00 amraktad Exp $
00012 //
00013 
00014 // system include files
00015 #include <sstream>
00016 
00017 #include "Reflex/Object.h"
00018 
00019 // user include files
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 // constants, enums and typedefs
00030 //
00031 
00032 //
00033 // static data member definitions
00034 //
00035 
00036 //
00037 // constructors and destructor
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 // FWModelFilter::FWModelFilter(const FWModelFilter& rhs)
00048 // {
00049 //    // do actual copying here;
00050 // }
00051 
00052 FWModelFilter::~FWModelFilter()
00053 {
00054 }
00055 
00056 //
00057 // assignment operators
00058 //
00059 // const FWModelFilter& FWModelFilter::operator=(const FWModelFilter& rhs)
00060 // {
00061 //   //An exception safe implementation is
00062 //   FWModelFilter temp(rhs);
00063 //   swap(rhs);
00064 //
00065 //   return *this;
00066 // }
00067 
00068 //
00069 // member functions
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       //Backwards compatibility with old format
00078       std::string temp = oldToNewFormat(iExpression);
00079 
00080       //now setup the parser
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             //std::cout <<"failed to parse "<<iExpression<<" because of syntax error"<<std::endl;
00091          }
00092       } catch(const reco::parser::BaseException& e) {
00093          //NOTE: need to calculate actual position before doing the regex
00094          throw FWExpressionException(reco::parser::baseExceptionWhat(e), indexFromNewFormatToOldFormat(temp,e.where-temp.c_str(),iExpression));
00095          //std::cout <<"failed to parse "<<iExpression<<" because "<<reco::parser::baseExceptionWhat(e)<<std::endl;
00096       }
00097    } else {
00098       m_expression=iExpression;
00099    }
00100 }
00101 
00102 void
00103 FWModelFilter::setClassName(const std::string& iClassName)
00104 {
00105    //NOTE: How do we handle the case where the filter was created before
00106    // the library for the class was loaded and therefore we don't have
00107    // a Reflex dictionary for it?
00108 
00109    m_className = iClassName;
00110    m_type = ROOT::Reflex::Type::ByName(iClassName);
00111    setExpression(m_expression);
00112 }
00113 
00114 //
00115 // const member functions
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 // static member functions
00142 //