CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/CommonTools/CandAlgos/src/decayParser.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     CandCombiner
00004 // Class  :     decayParser
00005 // 
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author:  
00010 //         Created:  Sun Aug  7 20:26:31 EDT 2005
00011 // $Id: decayParser.cc,v 1.2 2009/05/08 12:54:35 llista Exp $
00012 //
00013 #include "CommonTools/CandAlgos/interface/decayParser.h"
00014 #include <vector>
00015 
00016 using namespace boost::spirit;
00017 using namespace std;
00018 using namespace boost::spirit::classic;
00019 namespace cand {
00020   namespace parser {
00021     
00022     class ModeSetter {
00023     public:
00024       ModeSetter( vector<ConjInfo>& iVect, ConjInfo::Mode iMode) : 
00025         conjInfo_(iVect), mode_(iMode) {}
00026       void operator()( const char ) const {
00027         conjInfo_.back().mode_ = mode_;
00028       }
00029     private:
00030       vector<ConjInfo>& conjInfo_;
00031       ConjInfo::Mode mode_;
00032     };
00033     
00034     typedef scanner_policies<skip_parser_iteration_policy<nothing_parser, 
00035                                                           iteration_policy>, 
00036                              match_policy, action_policy> ScannerPolicy;
00037     typedef scanner<const char*, ScannerPolicy > ScannerUsed_1;
00038     typedef rule<ScannerUsed_1> Rule_1;
00039     
00040     bool decayParser( const string& iValue, vector<ConjInfo>& oStrings ) {
00041       using namespace boost::spirit;
00042       
00043       Rule_1 label = ((+alnum_p) >> *ch_p(':') >> *ch_p('_') >>*alnum_p)[push_back_a(oStrings)];
00044       Rule_1 conj =  (ch_p('@') >> !((ch_p('b')>>ch_p('a')>>ch_p('r')[ModeSetter(oStrings,ConjInfo::kBar)] )| 
00045                                      ch_p('+')[ModeSetter(oStrings,ConjInfo::kPlus)] | 
00046                                      ch_p('-')[ModeSetter(oStrings,ConjInfo::kMinus)]) );
00047       
00048       return parse( iValue.c_str(),
00049                     (
00050                      (label >> ! conj)
00051                      % blank_p
00052                      )
00053                     ,
00054                     nothing_p).full;
00055     }
00056   }
00057 }