File indexing completed on 2025-04-26 09:01:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #pragma once
0012
0013 #include <Gaudi/Accumulators/StaticHistogram.h>
0014
0015 #include <Gaudi/Parsers/Factory.h>
0016 #include <GaudiKernel/ToStream.h>
0017
0018 #include <boost/spirit/include/qi.hpp>
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 namespace Gaudi {
0030 namespace Parsers {
0031
0032 namespace qi = boost::spirit::qi;
0033
0034 template <typename Iterator, typename Skipper, typename Arithmetic>
0035 struct AxisGrammar : qi::grammar<Iterator, Gaudi::Accumulators::Axis<Arithmetic>(), qi::locals<char>, Skipper> {
0036 using Axis = Gaudi::Accumulators::Axis<Arithmetic>;
0037 struct StoreNbinsOp {
0038 void operator()( Axis& res, unsigned int const& nBins ) const { res.setNumBins( nBins ); }
0039 };
0040 struct StoreMinValueOp {
0041 void operator()( Axis& res, Arithmetic const& minValue ) const { res.setMinValue( minValue ); }
0042 };
0043 struct StoreMaxValueOp {
0044 void operator()( Axis& res, Arithmetic const& maxValue ) const { res.setMaxValue( maxValue ); }
0045 };
0046 struct StoreTitleOp {
0047 void operator()( Axis& res, std::string const& title ) const { res.setTitle( title ); }
0048 };
0049 AxisGrammar() : AxisGrammar::base_type( axis ) {
0050 begin = enc::char_( '[' )[qi::_val = ']'] | enc::char_( '(' )[qi::_val = ')'];
0051 end = enc::char_( qi::_r1 );
0052 core = qi::int_[storeNbins( qi::_val, qi::_1 )] >> "," >> qi::double_[storeMinValue( qi::_val, qi::_1 )] >>
0053 "," >> qi::double_[storeMaxValue( qi::_val, qi::_1 )] >>
0054 -( "," >> title[storeTitle( qi::_val, qi::_1 )] );
0055 axis = begin[qi::_a = qi::_1] >> core[qi::_val = qi::_1] >> end( qi::_a );
0056 }
0057 qi::rule<Iterator, Axis(), qi::locals<char>, Skipper> axis;
0058 qi::rule<Iterator, Axis(), Skipper> core;
0059 qi::rule<Iterator, char()> begin;
0060 qi::rule<Iterator, void( char )> end;
0061 StringGrammar<Iterator, Skipper> title;
0062 ph::function<StoreNbinsOp> storeNbins;
0063 ph::function<StoreMinValueOp> storeMinValue;
0064 ph::function<StoreMaxValueOp> storeMaxValue;
0065 ph::function<StoreTitleOp> storeTitle;
0066 };
0067
0068 template <typename Iterator, typename Skipper, typename Arithmetic>
0069 struct Grammar_<Iterator, Gaudi::Accumulators::Axis<Arithmetic>, Skipper> {
0070 using Grammar = AxisGrammar<Iterator, Skipper, Arithmetic>;
0071 };
0072
0073
0074 template <typename Arithmetic>
0075 StatusCode parse( Gaudi::Accumulators::Axis<Arithmetic>& result, const std::string& input ) {
0076 return parse_( result, input );
0077 }
0078
0079 }
0080
0081 }