File indexing completed on 2024-04-06 12:01:19
0001 #include "CommonTools/Utils/interface/cutParser.h"
0002 #include "CommonTools/Utils/src/AnyObjSelector.h"
0003 #include "CommonTools/Utils/interface/parser/Grammar.h"
0004 #include "FWCore/Utilities/interface/EDMException.h"
0005
0006 using namespace reco::parser;
0007 bool reco::parser::cutParser(const edm::TypeWithDict& t, const std::string& cut, SelectorPtr& sel, bool lazy = false) {
0008 bool justBlanks = true;
0009 for (std::string::const_iterator c = cut.begin(); c != cut.end(); ++c) {
0010 if (*c != ' ') {
0011 justBlanks = false;
0012 break;
0013 }
0014 }
0015 if (justBlanks) {
0016 sel = SelectorPtr(new AnyObjSelector);
0017 return true;
0018 } else {
0019 using namespace boost::spirit::classic;
0020 Grammar grammar(sel, t, lazy);
0021 bool returnValue = false;
0022 const char* startingFrom = cut.c_str();
0023 try {
0024 returnValue = parse(startingFrom, grammar.use_parser<0>() >> end_p, space_p).full;
0025 } catch (BaseException& e) {
0026 throw edm::Exception(edm::errors::Configuration)
0027 << "Cut parser error:" << baseExceptionWhat(e) << " (char " << e.where - startingFrom << ")\n"
0028 << "Cut string was " << cut;
0029 }
0030 return returnValue;
0031 }
0032 }