11 #include "AIDA/IHistogram1D.h" 12 #include "AIDA/IHistogram2D.h" 13 #include "AIDA/IHistogram3D.h" 49 template <
typename Iterator,
typename Skipper>
50 class EdgeGrammar :
public qi::grammar<Iterator, Edges(), qi::locals<char>, Skipper>
61 inner = ( ( qi::lit(
"edges" ) |
"'edges'" |
"\"edges\"" ) >>
":" >>
edges[qi::_val *= qi::_1] ) |
63 inner_pairs = ( ( ( qi::lit(
"nbins" ) |
"'nbins'" |
"\"nbins\"" ) >>
":" >>
nbins[qi::_val /= qi::_1] ) |
64 ( ( qi::lit(
"low" ) |
"'low'" |
"\"low\"" ) >>
":" >>
low[qi::_val -= qi::_1] ) |
65 ( ( qi::lit(
"high" ) |
"'high'" |
"\"high\"" ) >>
":" >>
high[qi::_val += qi::_1] ) ) %
69 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
70 end = enc::char_( qi::_r1 );
78 qi::rule<Iterator, char()>
begin;
79 qi::rule<Iterator, void( char )>
end;
84 template <
typename Iterator,
typename Skipper>
85 class H1Grammar :
public qi::grammar<Iterator, H1(), qi::locals<char>, Skipper>
96 inner = ( ( ( qi::lit(
"name" ) |
"'name'" |
"\"name\"" ) >>
":" >>
name[qi::_val *= qi::_1] ) |
97 ( ( qi::lit(
"title" ) |
"'title'" |
"\"title\"" ) >>
":" >> title[qi::_val /= qi::_1] ) |
98 ( -( ( qi::lit(
"X" ) |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':' ) >>
99 edges[qi::_val &= qi::_1] ) |
100 ( ( qi::lit(
"nbins" ) |
"'nbins'" |
"\"nbins\"" ) >>
":" >>
nbins[qi::_val |= qi::_1] ) |
101 ( ( qi::lit(
"low" ) |
"'low'" |
"\"low\"" ) >>
":" >>
low[qi::_val -= qi::_1] ) |
102 ( ( qi::lit(
"high" ) |
"'high'" |
"\"high\"" ) >>
":" >>
high[qi::_val ^= qi::_1] ) |
103 ( ( qi::lit(
"bins" ) |
"'bins'" |
"\"bins\"" ) >>
':' >> bins[qi::_val += qi::_1] ) ) %
107 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
108 end = enc::char_( qi::_r1 );
119 qi::rule<Iterator, H1(), Skipper>
inner;
121 qi::rule<Iterator, void( char )>
end;
125 template <
typename Iterator,
typename Skipper>
126 class H2Grammar :
public qi::grammar<Iterator, H2(), qi::locals<char>, Skipper>
137 inner = ( ( ( qi::lit(
"name" ) |
"'name'" |
"\"name\"" ) >>
":" >>
name[qi::_val *= qi::_1] ) |
138 ( ( qi::lit(
"title" ) |
"'title'" |
"\"title\"" ) >>
":" >> title[qi::_val /= qi::_1] ) |
139 ( ( qi::lit(
"X" ) |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':' >>
edges[qi::_val &= qi::_1] ) |
140 ( ( qi::lit(
"Y" ) |
"'Y'" |
"\"Y\"" |
"y" |
"'y'" |
"\"y\"" ) >>
':' >>
edges[qi::_val |= qi::_1] ) |
141 ( ( qi::lit(
"bins" ) |
"'bins'" |
"\"bins\"" ) >>
':' >> bins[qi::_val += qi::_1] ) ) %
145 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
146 end = enc::char_( qi::_r1 );
154 qi::rule<Iterator, H2(), Skipper>
inner;
156 qi::rule<Iterator, void( char )>
end;
191 template <
class HISTO1>
207 H1P histo( h1.m_edges.edges.empty() ?
216 h1.m_edges.edges.size() - 1,
217 &h1.m_edges.edges.front() ) );
220 for (
unsigned int ibin = 0; ibin < h1.m_bins.size(); ++ibin ) {
221 histo->SetBinContent( ibin, h1.m_bins[ibin].first );
222 histo->SetBinError( ibin, h1.m_bins[ibin].second );
230 template <
class HISTO2>
245 H2P histo( h2.m_xedges.edges.empty() && h2.m_yedges.edges.empty()
255 : h2.m_xedges.edges.empty() && !h2.m_xedges.edges.empty()
262 &h2.m_yedges.edges.front() )
264 !h2.m_xedges.edges.empty() && h2.m_xedges.edges.empty()
268 &h2.m_xedges.edges.front(),
276 &h2.m_xedges.edges.front(),
278 &h2.m_yedges.edges.front() ) );
281 const int xBins = h2.m_xedges.nBins();
282 const int yBins = h2.m_yedges.nBins();
284 for (
int jBin = yBins + 1; jBin >= 0; --jBin ) {
285 for (
int iBin = 0; iBin <= xBins + 1; ++iBin ) {
286 histo->SetBinContent( iBin, jBin, h2.m_bins[ibin].first );
287 histo->SetBinError( iBin, jBin, h2.m_bins[ibin].second );
310 auto h1 = _parse_1D<TH1D>( input,
name );
314 result.SetName( name.
c_str() );
334 auto h1 = _parse_1D<TH1F>( input,
name );
338 result.SetName( name.
c_str() );
357 auto h2 = _parse_2D<TH2D>( input,
name );
361 result.SetName( name.
c_str() );
380 auto h2 = _parse_2D<TH2F>( input,
name );
384 result.SetName( name.
c_str() );
389 if ( std::string::npos != input.find(
'<' ) ) {
405 return parse( *result, input );
410 auto h1 = _parse_1D<TH1D>( input,
name );
412 result = h1.release();
413 result->SetName( name.
c_str() );
431 return parse( *result, input );
436 auto h2 = _parse_2D<TH2D>( input,
name );
438 result = h2.release();
439 result->SetName( name.
c_str() );
EdgeGrammar< Iterator, Skipper > edges
IntGrammar< Iterator, unsigned int, Skipper > nbins
RealGrammar< Iterator, double, Skipper > low
qi::rule< Iterator, char()> begin
constexpr static const auto FAILURE
GAUDI_API StatusCode fromXml(TH1D &result, const std::string &input)
parse the histogram from standard ROOT XML
qi::rule< Iterator, void(char)> end
StatusCode parse_(ResultT &result, const std::string &input)
qi::rule< Iterator, H2(), Skipper > inner
qi::rule< Iterator, char()> begin
qi::rule< Iterator, H1(), qi::locals< char >, Skipper > result
RealGrammar< Iterator, double, Skipper > low
qi::rule< Iterator, Edges(), qi::locals< char >, Skipper > result
RealGrammar< Iterator, double, Skipper > high
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
VectorGrammar< Iterator, std::vector< double >, Skipper > edges
std::vector< double > Edges
qi::rule< Iterator, Edges(), Skipper > inner_pairs
StringGrammar< Iterator, Skipper > title
StringGrammar< Iterator, Skipper > title
qi::rule< Iterator, void(char)> end
VectorGrammar< Iterator, std::vector< std::pair< double, double > >, Skipper > bins
This class is used for returning status codes from appropriate routines.
qi::rule< Iterator, Edges(), Skipper > inner
qi::rule< Iterator, H2(), qi::locals< char >, Skipper > result
static TH1D * aida2root(AIDA::IHistogram1D *aida)
get the underlying pointer for 1D-histogram
qi::rule< Iterator, H1(), Skipper > inner
constexpr static const auto SUCCESS
qi::rule< Iterator, void(char)> end
VectorGrammar< Iterator, std::vector< std::pair< double, double > >, Skipper > bins
EdgeGrammar< Iterator, Skipper > edges
Helper functions to set/get the application return code.
IntGrammar< Iterator, unsigned int, Skipper > nbins
qi::rule< Iterator, char()> begin
REGISTER_GRAMMAR(GaudiMath::Interpolation::Type, InterpolGrammar)