2 #ifndef GAUDIKERNEL_GRAMMARSV2_H 3 #define GAUDIKERNEL_GRAMMARSV2_H 1 5 #pragma GCC system_header 21 #include <boost/fusion/include/std_pair.hpp> 22 #include <boost/fusion/include/unused.hpp> 23 #include <boost/spirit/include/qi.hpp> 25 #include <boost/spirit/include/phoenix_core.hpp> 26 #include <boost/spirit/include/phoenix_operator.hpp> 28 #include <boost/type_traits.hpp> 29 #include <boost/utility/enable_if.hpp> 31 #include <boost/spirit/repository/include/qi_confix.hpp> 50 namespace ph = boost::phoenix;
51 namespace qi = sp::qi;
52 namespace enc = sp::ascii;
53 namespace rep = sp::repository;
60 template <
typename Iterator,
typename T,
typename Skipper,
class Enable =
void>
71 #define REGISTER_GRAMMAR( ResultType, GrammarName ) \ 72 template <typename Iterator, typename Skipper> \ 73 struct Grammar_<Iterator, ResultType, Skipper> { \ 74 typedef GrammarName<Iterator, Skipper> Grammar; \ 77 template <
typename Iterator>
78 struct SkipperGrammar : qi::grammar<Iterator> {
81 comments = enc::space | rep::confix(
"/*",
"*/" )[*( qi::char_ -
"*/" )] |
82 rep::confix(
"//", ( sp::eol | sp::eoi ) )[*( qi::char_ - ( sp::eol | sp::eoi ) )];
84 qi::rule<Iterator> comments;
87 template <
typename Iterator,
typename Skipper>
88 struct StringGrammar : qi::grammar<Iterator, std::string(), qi::locals<char>, Skipper> {
94 begin_quote = enc::char_(
"\"'" );
95 quote = enc::char_( qi::_r1 );
97 str = qi::lexeme[begin_quote[qi::_a = qi::_1] >
98 *( ( enc::char_(
'\\' ) >> quote( qi::_a ) )[qi::_val += qi::_a] |
99 ( enc::char_[qi::_val += qi::_1] - quote( qi::_a ) ) ) > quote( qi::_a )];
102 qi::rule<Iterator, std::string(), qi::locals<char>,
Skipper> str;
103 qi::rule<Iterator, char()> begin_quote;
104 qi::rule<Iterator, void( char )> quote;
110 template <
typename Iterator,
typename Skipper>
115 ch = qi::int_parser<char>() |
'\'' >> ( qi::char_ -
'\'' ) >>
'\'';
117 qi::rule<Iterator, char(), Skipper>
ch;
121 template <
typename Iterator,
typename Skipper>
122 struct BoolGrammar : qi::grammar<Iterator, bool(), Skipper> {
126 boolean_literal = ( qi::lit(
"true" ) |
"True" |
"TRUE" |
"1" )[qi::_val =
true] |
127 ( qi::lit(
"false" ) |
"False" |
"FALSE" |
"0" )[qi::_val =
false];
133 template <
typename Iterator,
typename RT,
typename Skipper>
138 integer = qi::int_parser<RT>()[qi::_val = qi::_1] >> -qi::no_case[qi::char_(
'L' )];
145 template <
typename Iterator,
typename T,
typename Skipper>
150 template <
typename Iterator,
typename RT,
typename Skipper>
151 struct RealGrammar : qi::grammar<Iterator, RT(), Skipper> {
154 qi::rule<Iterator, RT(), Skipper>
real;
159 template <
typename Iterator,
typename T,
typename Skipper>
166 template <
typename T>
170 template <
typename T>
174 template <
typename T,
typename... Ts>
179 template <
typename T,
typename... Ts>
186 template <
typename Iterator,
typename TupleT, std::
size_t N,
typename Skipper>
188 : qi::grammar<Iterator, TupleT(), qi::locals<typename tuple_get_first_type<TupleT>::type>, Skipper> {
195 template <
typename A,
typename B = boost::fusion::unused_type,
typename C = boost::fusion::unused_type,
196 typename D = boost::fusion::unused_type>
202 void operator()( ResultT& res, HeadT& head, TailT& tail )
const 211 tup = grHead[qi::_a = qi::_1] >>
',' >> grLast[op( qi::_val, qi::_a, qi::_1 )];
217 qi::rule<Iterator, ResultT(), qi::locals<HeadT>,
Skipper>
tup;
218 ph::function<Operations>
op;
221 template <
typename Iterator,
typename TupleT,
typename Skipper>
228 template <
typename A,
typename B = boost::fusion::unused_type,
typename C = boost::fusion::unused_type,
229 typename D = boost::fusion::unused_type>
237 std::get<0>( res ) = val;
246 qi::rule<Iterator, ResultT(), Skipper>
tup;
247 ph::function<Operations>
op;
251 template <
typename Iterator,
typename TupleT, std::
size_t N,
typename Skipper>
252 struct TupleGrammar : qi::grammar<Iterator, TupleT(), qi::locals<char>, Skipper> {
256 begin = enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'(' )[qi::_val =
')'];
257 end = enc::char_( qi::_r1 );
259 tup =
begin[qi::_a = qi::_1] >> grTuple[qi::_val = qi::_1] >>
end( qi::_a );
263 qi::rule<Iterator, void( char )>
end;
264 qi::rule<Iterator, ResultT(), qi::locals<char>,
Skipper>
tup;
276 template <
typename Iterator,
typename VectorT,
typename Skipper>
277 struct VectorGrammar : qi::grammar<Iterator, VectorT(), qi::locals<char>, Skipper> {
284 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
285 end = enc::char_( qi::_r1 );
286 list = elementGrammar %
',';
287 vec =
begin[qi::_a = qi::_1] >> -list[qi::_val = qi::_1] >>
end( qi::_a );
292 qi::rule<Iterator, void( char )>
end;
294 qi::rule<Iterator, ResultT(), qi::locals<char>, Skipper>
vec;
295 qi::rule<Iterator, ResultT(), Skipper>
list;
301 template <
typename Iterator,
typename InnerT,
typename AllocatorT,
typename Skipper>
308 template <
typename Iterator,
typename InnerT,
typename AllocatorT,
typename Skipper>
315 template <
typename Iterator,
typename InnerT,
typename CompareT,
typename AllocatorT,
typename Skipper>
321 template <
typename Iterator,
typename PairT,
typename Skipper>
322 struct PairGrammar : qi::grammar<Iterator, PairT(), qi::locals<char>, Skipper> {
338 begin = enc::char_(
'(' )[qi::_val =
')'] | enc::char_(
'[' )[qi::_val =
']'];
339 end = qi::char_( qi::_r1 );
340 pair =
begin[qi::_a = qi::_1] >> pair_in[qi::_val = qi::_1] >>
end( qi::_a );
341 pair_in = key >> qi::lit( delimeter ) >> value;
347 qi::rule<Iterator, void( char )>
end;
348 qi::rule<Iterator, ResultT(), qi::locals<char>, Skipper>
pair;
349 qi::rule<Iterator, ResultT(), Skipper>
pair_in;
356 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename Skipper>
361 template <
typename Iterator,
typename MapT,
typename Skipper>
365 typedef typename MapT::key_type
KeyT;
376 template <
typename A,
typename B = boost::fusion::unused_type,
typename C = boost::fusion::unused_type,
377 typename D = boost::fusion::unused_type>
382 void operator()( ResultT& res,
const VectorPairT& vec )
const 384 for (
auto cur = vec.
begin(); cur != vec.
end(); ++cur ) {
395 pair = key[op( qi::_val, qi::_1,
tag_key() )] > ( qi::lit(
':' ) |
'=' ) >
397 list = -( pair % enc::char_(
',' ) );
398 map = ( (
'[' >> list >>
']' ) | (
'{' >> list >>
'}' ) )[op( qi::_val, qi::_1 )];
403 qi::rule<Iterator, PairT(), Skipper>
pair;
404 qi::rule<Iterator, VectorPairT(), Skipper>
list;
405 qi::rule<Iterator, ResultT(), Skipper>
map;
406 ph::function<Operations>
op;
412 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename KeyCompareT,
typename AllocatorT,
420 template <
typename Iterator,
typename KeyT,
typename ValueT,
typename KeyCompareT,
typename AllocatorT,
426 template <
typename Iterator,
typename Po
intT,
typename Skipper>
432 template <
typename A,
typename B = boost::fusion::unused_type,
typename C = boost::fusion::unused_type,
433 typename D = boost::fusion::unused_type>
437 void operator()( ResultT& res,
const Scalar& scalar,
const char xyz )
const 457 point = list | (
'(' >> list >>
')' ) | (
'[' >> list >>
']' );
458 list = -( enc::no_case[qi::lit(
"x" ) | qi::lit(
"px" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'x' )] >>
459 ',' >> -( enc::no_case[qi::lit(
"y" ) | qi::lit(
"py" )] >>
':' ) >>
460 scalar[op( qi::_val, qi::_1,
'y' )] >>
',' >>
461 -( enc::no_case[qi::lit(
"z" ) | qi::lit(
"pz" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'z' )];
464 qi::rule<Iterator, ResultT(), Skipper>
point, list;
466 ph::function<Operations>
op;
472 template <
typename Iterator,
typename T1,
typename T2,
typename Skipper>
479 template <
typename Iterator,
typename T1,
typename T2,
typename Skipper>
484 template <
typename Iterator,
typename Po
intT,
typename Skipper>
490 template <
typename A,
typename B = boost::fusion::unused_type,
typename C = boost::fusion::unused_type,
491 typename D = boost::fusion::unused_type>
496 void operator()( ResultT& res,
const ScalarT& scalar,
const char xyz )
const 517 res.SetPx( xyz.Px() );
518 res.SetPy( xyz.Py() );
519 res.SetPz( xyz.Pz() );
525 point4d = list4d | (
'(' >> list4d >>
')' ) | (
'[' >> list4d >>
']' );
526 list4d = ( point3d[op( qi::_val, qi::_1 )] >> enc::char_(
";," ) >> e[op( qi::_val, qi::_1,
'e' )] ) |
527 ( e[op( qi::_val, qi::_1,
'e' )] >> enc::char_(
";," ) >> point3d[op( qi::_val, qi::_1 )] );
528 e = -( enc::no_case[enc::char_(
"te" )] >>
':' ) >> scalar[qi::_val = qi::_1];
530 point3d = list3d | (
'(' >> list3d >>
')' ) | (
'[' >> list3d >>
']' );
531 list3d = -( enc::no_case[qi::lit(
"x" ) | qi::lit(
"px" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'x' )] >>
532 ',' >> -( enc::no_case[qi::lit(
"y" ) | qi::lit(
"py" )] >>
':' ) >>
533 scalar[op( qi::_val, qi::_1,
'y' )] >>
',' >>
534 -( enc::no_case[qi::lit(
"z" ) | qi::lit(
"pz" )] >>
':' ) >> scalar[op( qi::_val, qi::_1,
'z' )];
537 qi::rule<Iterator, ResultT(), Skipper> point3d,
point4d, list3d, list4d;
538 qi::rule<Iterator, ScalarT(), Skipper>
e;
540 ph::function<Operations>
op;
546 template <
typename Iterator,
typename T1,
typename Skipper>
551 template <
typename Iterator,
typename Skipper>
552 struct Histo1DGrammar : qi::grammar<Iterator, Gaudi::Histo1DDef(), qi::locals<char>, Skipper> {
556 template <
typename A,
typename B = boost::fusion::unused_type,
typename C = boost::fusion::unused_type,
557 typename D = boost::fusion::unused_type>
562 void operator()( ResultT& res,
const double& val,
const char lh )
const 566 res.setLowEdge( val );
569 res.setHighEdge( val );
575 void operator()( ResultT& res,
int val )
const { res.setBins( val ); }
581 val1 = title[op( qi::_val, qi::_1 )] >>
',' >> qi::double_[op( qi::_val, qi::_1,
'l' )] >>
',' >>
582 qi::double_[op( qi::_val, qi::_1,
'h' )] >> -(
',' >> qi::int_[op( qi::_val, qi::_1 )] );
583 val2 = qi::double_[op( qi::_val, qi::_1,
'l' )] >>
',' >> qi::double_[op( qi::_val, qi::_1,
'h' )] >>
',' >>
584 title[op( qi::_val, qi::_1 )] >> -(
',' >> qi::int_[op( qi::_val, qi::_1 )] );
585 val3 = qi::double_[op( qi::_val, qi::_1,
'l' )] >>
',' >> qi::double_[op( qi::_val, qi::_1,
'h' )] >>
586 -(
',' >> title[op( qi::_val, qi::_1 )] ) >> -(
',' >> qi::int_[op( qi::_val, qi::_1 )] );
587 begin = enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'(' )[qi::_val =
')'];
588 end = enc::char_( qi::_r1 );
589 hist = begin[qi::_a = qi::_1] >> ( val1 | val2 | val3 )[qi::_val = qi::_1] >>
end( qi::_a );
592 qi::rule<Iterator, ResultT(), qi::locals<char>, Skipper>
hist;
593 qi::rule<Iterator, ResultT(), Skipper> val1, val2,
val3;
595 qi::rule<Iterator, void( char )>
end;
597 ph::function<Operations>
op;
603 template <
typename Iterator,
typename Skipper>
604 struct KeyValueGrammar : qi::grammar<Iterator, std::pair<std::string, std::string>(), Skipper> {
616 pair = gstring >>
":" >> +enc::char_;
620 qi::rule<Iterator, ResultT(), Skipper>
pair;
qi::rule< Iterator, char()> begin
qi::rule< Iterator, ResultT(), Skipper > pair
VectorGrammar< Iterator, std::vector< InnerT, AllocatorT >, Skipper > Grammar
qi::rule< Iterator, ResultT(), Skipper > val3
qi::rule< Iterator, VectorPairT(), Skipper > list
StringGrammar< Iterator, Skipper > gstring
void init(const std::string &delimeter)
MapGrammar< Iterator, std::map< KeyT, ValueT, KeyCompareT, AllocatorT >, Skipper > Grammar
void operator()(ResultT &res, const ScalarT &scalar, const char xyz) const
void operator()(ResultT &res, const std::string &title) const
Grammar_< Iterator, ScalarT, Skipper >::Grammar scalar
PairT::second_type second_type
The namespace threadpool contains a thread pool and related utility classes.
Grammar_< Iterator, typename PairT::first_type, Skipper >::Grammar key
qi::rule< Iterator, ResultT(), Skipper > point
RealGrammar< Iterator, T, Skipper > Grammar
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > pair
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > tup
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > vec
struct GAUDI_API vector
Parametrisation class for vector-like implementation.
void operator()(ResultT &res, const typename std::tuple_element< 0, ResultT >::type &val) const
SkipperGrammar< IteratorT > Skipper
qi::rule< Iterator, ResultT(), qi::locals< HeadT >, Skipper > tup
ph::function< Operations > op
MapT::mapped_type MappedT
StringGrammar< Iterator, Skipper > title
qi::rule< Iterator, ResultT(), Skipper > map
TupleInnerGrammar< Iterator, TailT, N-1, Skipper > grLast
void operator()(ResultT &res) const
BOOST_MPL_ASSERT_MSG(false, GRAMMAR_FOR_TYPE_DOES_NOT_EXISTS,(T))
The helper class to represent the efficient "key" for access.
qi::rule< Iterator, ScalarT(), Skipper > e
auto begin(reverse_wrapper< T > &w)
PairGrammar(const std::string &delimeter)
Grammar_< Iterator, typename VectorT::value_type, Skipper >::Grammar elementGrammar
Grammar_< Iterator, HeadT, Skipper >::Grammar grHead
void operator()(ResultT &res, const double &val, const char lh) const
qi::rule< Iterator, char()> begin
struct GAUDI_API map
Parametrisation class for map-like implementation.
qi::rule< Iterator, void(char)> end
std::pair< KeyT, MappedT > PairT
ph::function< Operations > op
Pnt3DGrammar< Iterator, ROOT::Math::DisplacementVector3D< T1, T2 >, Skipper > Grammar
VectorGrammar< Iterator, std::list< InnerT, AllocatorT >, Skipper > Grammar
Grammar_< Iterator, typename PairT::second_type, Skipper >::Grammar value
void operator()(ResultT &res, const Scalar &scalar, const char xyz) const
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
qi::rule< Iterator, ResultT(), qi::locals< char >, Skipper > hist
qi::rule< Iterator, ResultT(), Skipper > pair_in
PairT::first_type first_type
tuple_get_first_type< TupleT >::type HeadT
qi::rule< Iterator, ResultT(), Skipper > point4d
qi::rule< Iterator, PairT(), Skipper > pair
MapGrammar< Iterator, GaudiUtils::VectorMap< KeyT, ValueT, KeyCompareT, AllocatorT >, Skipper > Grammar
auto end(reverse_wrapper< T > &w)
qi::rule< Iterator, ResultT(), Skipper > list
std::string::const_iterator DefaultIterator
IntGrammar< Iterator, T, Skipper > Grammar
void operator()(PairT &res, const KeyT &key, tag_key) const
Pnt4DGrammar< Iterator, ROOT::Math::LorentzVector< T1 >, Skipper > Grammar
Grammar_< Iterator, typename MapT::key_type, Skipper >::Grammar key
void operator()(ResultT &res, int val) const
enc::space_type DefaultSkipper
std::vector< PairT > VectorPairT
qi::rule< Iterator, void(char)> end
qi::rule< Iterator, bool(), Skipper > boolean_literal
boost::spirit::classic::position_iterator2< ForwardIterator > Iterator
PairGrammar< Iterator, std::pair< KeyT, ValueT >, Skipper > Grammar
void operator()(ResultT &res, const VectorPairT &vec) const
ph::function< Operations > op
void operator()(ResultT &res, const ResultT &xyz) const
Forward declarations for the functions in SerializeSTL.h.
tuple_remove_first_type< TupleT >::type TailT
qi::rule< Iterator, char(), Skipper > ch
TupleInnerGrammar< Iterator, TupleT, N, Skipper > grTuple
qi::rule< Iterator, void(char)> end
Grammar_< Iterator, typename std::tuple_element< 0, ResultT >::type, Skipper >::Grammar grFirst
qi::rule< Iterator, char()> begin
ph::function< Operations > op
Pnt3DGrammar< Iterator, ROOT::Math::PositionVector3D< T1, T2 >, Skipper > Grammar
VectorGrammar< Iterator, std::set< InnerT, CompareT, AllocatorT >, Skipper > Grammar
Grammar_< Iterator, typename MapT::mapped_type, Skipper >::Grammar value
qi::rule< Iterator, RT(), Skipper > real
qi::rule< Iterator, RT(), Skipper > integer
void operator()(ResultT &res, HeadT &head, TailT &tail) const
qi::rule< Iterator, char()> begin
qi::rule< Iterator, void(char)> end
void operator()(PairT &res, const MappedT &value, tag_mapped) const
Helper functions to set/get the application return code.
Gaudi::Histo1DDef ResultT
std::pair< std::string, std::string > ResultT
ph::function< Operations > op
qi::rule< Iterator, ResultT(), Skipper > tup
Grammar_< Iterator, Scalar, Skipper >::Grammar scalar
ph::function< Operations > op
REGISTER_GRAMMAR(GaudiMath::Interpolation::Type, InterpolGrammar)