CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/CommonTools/Utils/interface/cutParser.h

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