Belle II Software  release-05-02-19
DecayStringGrammar.h
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2010 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Christian Oswald, Yo Sato *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #pragma once
12 #define BOOST_SPIRIT_UNICODE
13 #include <boost/spirit/include/qi.hpp>
14 #include <analysis/DecayDescriptor/DecayStringParticle.h>
15 #include <analysis/DecayDescriptor/DecayStringDecay.h>
16 #include <analysis/DecayDescriptor/DecayString.h>
17 #include <vector>
18 #include <string>
19 
20 namespace Belle2 {
31  template <typename Iterator>
32  struct DecayStringGrammar : boost::spirit::qi::grammar<Iterator, DecayString(), boost::spirit::unicode::space_type> {
33  DecayStringGrammar() : DecayStringGrammar::base_type(start)
34  {
35  using boost::spirit::unicode::char_;
36  using boost::spirit::unicode::string;
37  using boost::spirit::unicode::space;
38  using boost::spirit::qi::lit;
39  using boost::spirit::qi::lexeme;
40  using boost::spirit::repeat;
41 
42 
43  // Reserved characters for steering - cppcheck doesn't understand the
44  // boost::spirit syntax so we suppress warnings. we can't initialise
45  // these in the initialisation list because we need things from the
46  // namespace
47  //
48  // cppcheck-suppress incorrectCharBooleanError
49  // cppcheck-suppress useInitializationList
50  reserved = space || '^' || '[' || ']' || '>' || ':' || '.' || '?' || '!' || '@';
51 
52  // particle composed of selector, particle name, and user label: "^D_s+:label"
53  particle %= *selector >> lexeme[+(char_ - reserved)] >> -label;
54  // cppcheck-suppress useInitializationList
55  selector = string("^") | string("@") | string("(misID)") | string("(decay)");
56  label %= lit(":") >> lexeme[+(char_ - reserved)];
57 
58  // Arrow types
59  arrow %= string("->") | string("=direct=>") | string("=norad=>") | string("=exact=>");
60 
61  // Keyword for custom MC Matching
62  keyword = string("...") | string("?nu") | string("!nu") | string("?gamma") | string("!gamma") | string("?addbrems");
64 
65  // Basic decay: mother -> daughterlist
67  daughterdecay %= lit("[") >> decay >> lit("]");
70 
71  // This rule is where the parser starts
72  // The decay string can be either a single decay or a list of decays
73  start %= decay | particle;
74  }
76  boost::spirit::qi::rule<Iterator> reserved;
78  boost::spirit::qi::rule<Iterator, DecayStringParticle(), boost::spirit::unicode::space_type> particle;
80  boost::spirit::qi::rule<Iterator, std::string(), boost::spirit::unicode::space_type> selector;
82  boost::spirit::qi::rule<Iterator, std::string(), boost::spirit::unicode::space_type> label;
84  boost::spirit::qi::rule<Iterator, std::string(), boost::spirit::unicode::space_type> arrow;
86  boost::spirit::qi::rule<Iterator, std::string(), boost::spirit::unicode::space_type> keyword;
88  boost::spirit::qi::rule<Iterator, std::vector<std::string>(), boost::spirit::unicode::space_type> keywordlist;
90  boost::spirit::qi::rule<Iterator, DecayStringDecay(), boost::spirit::unicode::space_type> decay;
92  boost::spirit::qi::rule<Iterator, DecayStringDecay(), boost::spirit::unicode::space_type> daughterdecay;
94  boost::spirit::qi::rule<Iterator, DecayString(), boost::spirit::unicode::space_type> daughter;
96  boost::spirit::qi::rule<Iterator, std::vector<DecayString>(), boost::spirit::unicode::space_type> daughterlist;
98  boost::spirit::qi::rule<Iterator, DecayString(), boost::spirit::unicode::space_type> start;
99  };
101 }
Belle2::DecayStringGrammar::start
boost::spirit::qi::rule< Iterator, DecayString(), boost::spirit::unicode::space_type > start
The rule where the parser starts.
Definition: DecayStringGrammar.h:98
Belle2::DecayStringGrammar::arrow
boost::spirit::qi::rule< Iterator, std::string(), boost::spirit::unicode::space_type > arrow
Allowed arrow types.
Definition: DecayStringGrammar.h:84
Belle2::DecayStringParticle
Holds the information of a particle in the decay string.
Definition: DecayStringParticle.h:32
Belle2::DecayString
boost::variant< boost::recursive_wrapper< DecayStringDecay >, DecayStringParticle > DecayString
The DecayStringElement can be either a DecayStringDecay or a vector of mother particles.
Definition: DecayString.h:28
Belle2::DecayStringGrammar::label
boost::spirit::qi::rule< Iterator, std::string(), boost::spirit::unicode::space_type > label
Label that can be attached to a particle name, separated by the '/' symbol.
Definition: DecayStringGrammar.h:82
Belle2::DecayStringGrammar::daughterlist
boost::spirit::qi::rule< Iterator, std::vector< DecayString >), boost::spirit::unicode::space_type > daughterlist
The list of the daughters, i.e.
Definition: DecayStringGrammar.h:96
Belle2::Iterator
map< unsigned, const TOPSampleTimes * >::const_iterator Iterator
Iteratior for m_map.
Definition: TOPCalTimebase.cc:25
Belle2::DecayStringGrammar::selector
boost::spirit::qi::rule< Iterator, std::string(), boost::spirit::unicode::space_type > selector
Particles can be selected by preceeding '^' symbol.
Definition: DecayStringGrammar.h:80
Belle2::DecayStringGrammar::keywordlist
boost::spirit::qi::rule< Iterator, std::vector< std::string >), boost::spirit::unicode::space_type > keywordlist
The list of the keywords.
Definition: DecayStringGrammar.h:88
Belle2::DecayStringGrammar::particle
boost::spirit::qi::rule< Iterator, DecayStringParticle(), boost::spirit::unicode::space_type > particle
Particle in the decay string: 'selector name label'.
Definition: DecayStringGrammar.h:78
Belle2::DecayStringGrammar::decay
boost::spirit::qi::rule< Iterator, DecayStringDecay(), boost::spirit::unicode::space_type > decay
Syntax of a decay: 'mother arrow daughters ...'.
Definition: DecayStringGrammar.h:90
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DecayStringGrammar::daughterdecay
boost::spirit::qi::rule< Iterator, DecayStringDecay(), boost::spirit::unicode::space_type > daughterdecay
Syntax of decaying daughter particle.
Definition: DecayStringGrammar.h:92
Belle2::DecayStringGrammar::keyword
boost::spirit::qi::rule< Iterator, std::string(), boost::spirit::unicode::space_type > keyword
Syntax keyword.
Definition: DecayStringGrammar.h:86
Belle2::DecayStringGrammar
This class describes the grammar and the syntax elements of decay strings.
Definition: DecayStringGrammar.h:32
Belle2::DecayStringGrammar::daughter
boost::spirit::qi::rule< Iterator, DecayString(), boost::spirit::unicode::space_type > daughter
A daughter particle which can be either a plain particle or a decaying particle.
Definition: DecayStringGrammar.h:94
Belle2::DecayStringDecay
Holds the information of a decay.
Definition: DecayStringDecay.h:36
Belle2::DecayStringGrammar::reserved
boost::spirit::qi::rule< Iterator > reserved
Reserved characters that are not allowed in particle names or labels.
Definition: DecayStringGrammar.h:76