Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:01:17

0001 #ifndef CommonTools_Utils_ExpressionSelectorSetter_h
0002 #define CommonTools_Utils_ExpressionSelectorSetter_h
0003 /* \class reco::parser::ExpressionSelectorSetter
0004  *
0005  * Creates an implicit Binary selector setter by comparing an expression to 0
0006  *
0007  * \author original version: Chris Jones, Cornell, 
0008  *         adapted by Luca Lista, INFN
0009  *
0010  * \version $Revision: 1.2 $
0011  *
0012  */
0013 #include "CommonTools/Utils/interface/parser/SelectorStack.h"
0014 #include "CommonTools/Utils/interface/parser/ExpressionStack.h"
0015 #include "CommonTools/Utils/interface/parser/BinarySelector.h"
0016 #include "CommonTools/Utils/interface/parser/ExpressionNumber.h"
0017 #include "CommonTools/Utils/interface/parser/Comparison.h"
0018 #include "CommonTools/Utils/interface/parser/Exception.h"
0019 
0020 #include <functional>
0021 
0022 namespace reco {
0023   namespace parser {
0024     class ExpressionSelectorSetter {
0025     public:
0026       ExpressionSelectorSetter(SelectorStack& selStack, ExpressionStack& expStack)
0027           : selStack_(selStack), expStack_(expStack) {}
0028 
0029       void operator()(const char* begin, const char*) const {
0030         if (expStack_.empty())
0031           throw Exception(begin) << "Grammar error: empty expression stack. Please contact developer."
0032                                  << "\"";
0033         std::shared_ptr<ExpressionBase> rhs = expStack_.back();
0034         expStack_.pop_back();
0035         std::shared_ptr<ExpressionBase> lhs(new ExpressionNumber(0.0));
0036         std::shared_ptr<ComparisonBase> comp(new Comparison<std::not_equal_to<double> >());
0037 #ifdef BOOST_SPIRIT_DEBUG
0038         BOOST_SPIRIT_DEBUG_OUT << "pushing expression selector" << std::endl;
0039 #endif
0040         selStack_.push_back(SelectorPtr(new BinarySelector(lhs, comp, rhs)));
0041       }
0042 
0043     private:
0044       SelectorStack& selStack_;
0045       ExpressionStack& expStack_;
0046     };
0047   }  // namespace parser
0048 }  // namespace reco
0049 
0050 #endif