CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CommonTools/Utils/src/cutParser.cc

Go to the documentation of this file.
00001 #include "CommonTools/Utils/interface/cutParser.h"
00002 #include "CommonTools/Utils/src/AnyObjSelector.h"
00003 #include "CommonTools/Utils/src/Grammar.h"
00004 #include "FWCore/Utilities/interface/EDMException.h"
00005 
00006 using namespace reco::parser;
00007 bool reco::parser::cutParser(const Reflex::Type &t, const std::string & cut, SelectorPtr & sel, bool lazy=false) {
00008     bool justBlanks = true;
00009     for(std::string::const_iterator c = cut.begin(); c != cut.end(); ++c) {
00010         if(*c != ' ') { justBlanks = false; break; }
00011     }
00012     if(justBlanks) {
00013         sel = SelectorPtr(new AnyObjSelector);
00014         return true;
00015     } else {
00016         using namespace boost::spirit::classic;
00017         Grammar grammar(sel, t, lazy);
00018         bool returnValue = false;
00019         const char* startingFrom =cut.c_str();
00020         try {
00021             returnValue = parse(startingFrom, grammar.use_parser<0>() >> end_p, space_p).full;
00022         } 
00023         catch(BaseException& e) {
00024             throw edm::Exception(edm::errors::Configuration)<<"Cut parser error:"<<baseExceptionWhat(e)<<" (char "<<e.where-startingFrom<<")\n";
00025         }
00026         return returnValue;
00027     }
00028 } 
00029