21 #include <AIDA/IHistogram1D.h>
22 #include <AIDA/IHistogram2D.h>
23 #include <AIDA/IHistogram3D.h>
57 template <
typename Iterator,
typename Skipper>
58 class EdgeGrammar :
public qi::grammar<Iterator, Edges(), qi::locals<char>, Skipper> {
67 inner = ( ( qi::lit(
"edges" ) |
"'edges'" |
"\"edges\"" ) >>
":" >>
edges[qi::_val *= qi::_1] ) |
69 inner_pairs = ( ( ( qi::lit(
"nbins" ) |
"'nbins'" |
"\"nbins\"" ) >>
":" >>
nbins[qi::_val /= qi::_1] ) |
70 ( ( qi::lit(
"low" ) |
"'low'" |
"\"low\"" ) >>
":" >>
low[qi::_val -= qi::_1] ) |
71 ( ( qi::lit(
"high" ) |
"'high'" |
"\"high\"" ) >>
":" >>
high[qi::_val += qi::_1] ) ) %
75 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
76 end = enc::char_( qi::_r1 );
90 template <
typename Iterator,
typename Skipper>
91 class H1Grammar :
public qi::grammar<Iterator, H1(), qi::locals<char>, Skipper> {
100 inner = ( ( ( qi::lit(
"name" ) |
"'name'" |
"\"name\"" ) >>
":" >>
name[qi::_val *= qi::_1] ) |
101 ( ( qi::lit(
"title" ) |
"'title'" |
"\"title\"" ) >>
":" >>
title[qi::_val /= qi::_1] ) |
102 ( -( ( qi::lit(
"X" ) |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':' ) >>
103 edges[qi::_val &= qi::_1] ) |
104 ( ( qi::lit(
"nbins" ) |
"'nbins'" |
"\"nbins\"" ) >>
":" >>
nbins[qi::_val |= qi::_1] ) |
105 ( ( qi::lit(
"low" ) |
"'low'" |
"\"low\"" ) >>
":" >>
low[qi::_val -= qi::_1] ) |
106 ( ( qi::lit(
"high" ) |
"'high'" |
"\"high\"" ) >>
":" >>
high[qi::_val ^= qi::_1] ) |
107 ( ( qi::lit(
"bins" ) |
"'bins'" |
"\"bins\"" ) >>
':' >>
bins[qi::_val += qi::_1] ) ) %
111 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
112 end = enc::char_( qi::_r1 );
129 template <
typename Iterator,
typename Skipper>
130 class H2Grammar :
public qi::grammar<Iterator, H2(), qi::locals<char>, Skipper> {
139 inner = ( ( ( qi::lit(
"name" ) |
"'name'" |
"\"name\"" ) >>
":" >>
name[qi::_val *= qi::_1] ) |
140 ( ( qi::lit(
"title" ) |
"'title'" |
"\"title\"" ) >>
":" >>
title[qi::_val /= qi::_1] ) |
141 ( ( qi::lit(
"X" ) |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':' >>
edges[qi::_val &= qi::_1] ) |
142 ( ( qi::lit(
"Y" ) |
"'Y'" |
"\"Y\"" |
"y" |
"'y'" |
"\"y\"" ) >>
':' >>
edges[qi::_val |= qi::_1] ) |
143 ( ( qi::lit(
"bins" ) |
"'bins'" |
"\"bins\"" ) >>
':' >>
bins[qi::_val += qi::_1] ) ) %
147 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
148 end = enc::char_( qi::_r1 );
164 template <
typename Iterator,
typename Skipper>
165 class H3Grammar :
public qi::grammar<Iterator, H3(), qi::locals<char>, Skipper> {
174 inner = ( ( ( qi::lit(
"name" ) |
"'name'" |
"\"name\"" ) >>
":" >>
name[qi::_val *= qi::_1] ) |
175 ( ( qi::lit(
"title" ) |
"'title'" |
"\"title\"" ) >>
":" >>
title[qi::_val /= qi::_1] ) |
176 ( ( qi::lit(
"X" ) |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':' >>
edges[qi::_val &= qi::_1] ) |
177 ( ( qi::lit(
"Y" ) |
"'Y'" |
"\"Y\"" |
"y" |
"'y'" |
"\"y\"" ) >>
':' >>
edges[qi::_val |= qi::_1] ) |
178 ( ( qi::lit(
"Z" ) |
"'Z'" |
"\"Z\"" |
"z" |
"'z'" |
"\"z\"" ) >>
':' >>
edges[qi::_val -= qi::_1] ) |
179 ( ( qi::lit(
"bins" ) |
"'bins'" |
"\"bins\"" ) >>
':' >>
bins[qi::_val += qi::_1] ) ) %
183 enc::char_(
'[' )[qi::_val =
']'] | enc::char_(
'{' )[qi::_val =
'}'] | enc::char_(
'(' )[qi::_val =
')'];
184 end = enc::char_( qi::_r1 );
207 StatusCode _parse( H1& h1, std::string_view input ) {
215 StatusCode _parse( H2& h2, std::string_view input ) {
223 StatusCode _parse( H3& h3, std::string_view input ) {
230 template <
class HISTO1>
239 if ( sc.
isFailure() || !h1.ok() ) {
return H1P(); }
243 H1P histo( h1.m_edges.edges.empty() ?
252 h1.m_edges.edges.size() - 1,
253 &h1.m_edges.edges.front() ) );
256 for (
unsigned int ibin = 0; ibin < h1.m_bins.size(); ++ibin ) {
257 histo->SetBinContent( ibin, h1.m_bins[ibin].first );
258 histo->SetBinError( ibin, h1.m_bins[ibin].second );
266 template <
class HISTO2>
274 if ( sc.
isFailure() || !h2.ok() ) {
return H2P(); }
278 H2P histo( h2.m_xedges.edges.empty() && h2.m_yedges.edges.empty()
288 : h2.m_xedges.edges.empty() && !h2.m_xedges.edges.empty()
295 &h2.m_yedges.edges.front() )
297 !h2.m_xedges.edges.empty() && h2.m_xedges.edges.empty()
301 &h2.m_xedges.edges.front(),
309 &h2.m_xedges.edges.front(),
311 &h2.m_yedges.edges.front() ) );
314 const int xBins = h2.m_xedges.nBins();
315 const int yBins = h2.m_yedges.nBins();
317 for (
int jBin = yBins + 1; jBin >= 0; --jBin ) {
318 for (
int iBin = 0; iBin <= xBins + 1; ++iBin ) {
319 histo->SetBinContent( iBin, jBin, h2.m_bins[ibin].first );
320 histo->SetBinError( iBin, jBin, h2.m_bins[ibin].second );
330 template <
class HISTO3>
338 if ( sc.
isFailure() || !h3.ok() ) {
return H3P(); }
342 H3P histo( h3.m_xedges.edges.empty() || h3.m_yedges.edges.empty() || h3.m_zedges.edges.empty() ?
358 &h3.m_xedges.edges.front(),
360 &h3.m_yedges.edges.front(), h3.m_zedges.nBins(),
361 &h3.m_zedges.edges.front() ) );
364 const int xBins = h3.m_xedges.nBins();
365 const int yBins = h3.m_yedges.nBins();
366 const int zBins = h3.m_yedges.nBins();
368 for (
int kBin = 0; kBin <= zBins + 1; ++kBin ) {
369 for (
int jBin = yBins + 1; jBin >= 0; --jBin ) {
370 for (
int iBin = 0; iBin <= xBins + 1; ++iBin ) {
371 histo->SetBinContent( iBin, jBin, kBin, h3.m_bins[ibin].first );
372 histo->SetBinError( iBin, jBin, kBin, h3.m_bins[ibin].second );
395 auto h1 = _parse_1D<TH1D>( input,
name );
399 result.SetName(
name.c_str() );
418 auto h1 = _parse_1D<TH1F>( input,
name );
422 result.SetName(
name.c_str() );
440 auto h2 = _parse_2D<TH2D>( input,
name );
444 result.SetName(
name.c_str() );
462 auto h2 = _parse_2D<TH2F>( input,
name );
466 result.SetName(
name.c_str() );
485 auto h3 = _parse_3D<TH3D>( input,
name );
489 result.SetName(
name.c_str() );
507 auto h3 = _parse_3D<TH3F>( input,
name );
511 result.SetName(
name.c_str() );
528 if ( result ) {
return parse( *result, input ); }
532 auto h1 = _parse_1D<TH1D>( input,
name );
534 result = h1.release();
535 result->SetName(
name.c_str() );
551 if ( result ) {
return parse( *result, input ); }
555 auto h2 = _parse_2D<TH2D>( input,
name );
557 result = h2.release();
558 result->SetName(
name.c_str() );
574 if ( result ) {
return parse( *result, input ); }
578 auto h3 = _parse_3D<TH3D>( input,
name );
580 result = h3.release();
581 result->SetName(
name.c_str() );