11 #include "AIDA/IHistogram1D.h"
12 #include "AIDA/IHistogram2D.h"
13 #include "AIDA/IHistogram3D.h"
17 #include "boost/bind.hpp"
53 template<
typename Iterator,
typename Skipper>
54 class EdgeGrammar :
public qi::grammar<Iterator, Edges(), qi::locals<char>,
66 ( ( qi::lit(
"edges") |
"'edges'" |
"\"edges\"" )
67 >>
":" >>
edges[qi::_val *= qi::_1] )
70 ((( qi::lit(
"nbins") |
"'nbins'" |
"\"nbins\"")
71 >>
":" >>
nbins [ qi::_val /= qi::_1 ])
73 (( qi::lit(
"low") |
"'low'" |
"\"low\"" )
74 >>
":" >>
low [qi::_val -= qi::_1])
76 (( qi::lit(
"high") |
"'high'" |
"\"high\"" )
77 >>
":" >>
high [qi::_val += qi::_1])) %
',';
79 begin = enc::char_(
'[')[qi::_val=
']']
80 | enc::char_(
'{')[qi::_val=
'}']
81 | enc::char_(
'(')[qi::_val=
')'];
82 end = enc::char_(qi::_r1);
84 >>
inner[qi::_val = qi::_1]
92 qi::rule<Iterator, char()>
begin;
93 qi::rule<Iterator, void(char)>
end;
98 template<
typename Iterator,
typename Skipper>
99 class H1Grammar :
public qi::grammar<Iterator, H1(), qi::locals<char>,
111 (((qi::lit(
"name") |
"'name'" |
"\"name\"" )
112 >>
":" >>
name[qi::_val *= qi::_1 ])
114 (( qi::lit(
"title") |
"'title'" |
"\"title\"" )
115 >>
":" >>
title [ qi::_val /= qi::_1 ])
117 ( -(( qi::lit(
"X") |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':' )
118 >>
edges [ qi::_val &= qi::_1 ])
120 (( qi::lit(
"nbins") |
"'nbins'" |
"\"nbins\"" )
121 >>
":" >>
nbins [qi::_val |= qi::_1])
123 (( qi::lit(
"low") |
"'low'" |
"\"low\"" )
124 >>
":" >>
low [qi::_val -= qi::_1])
126 (( qi::lit(
"high") |
"'high'" |
"\"high\"" )
127 >>
":" >>
high [qi::_val ^= qi::_1])
129 (( qi::lit(
"bins") |
"'bins'" |
"\"bins\"" )
130 >>
':' >>
bins [qi::_val += qi::_1])) %
',';
132 begin = enc::char_(
'[')[qi::_val=
']']
133 | enc::char_(
'{')[qi::_val=
'}']
134 | enc::char_(
'(')[qi::_val=
')'];
135 end = enc::char_(qi::_r1);
137 >>
inner[qi::_val = qi::_1]
150 qi::rule<Iterator, H1(), Skipper>
inner;
152 qi::rule<Iterator, void(char)>
end;
157 template<
typename Iterator,
typename Skipper>
158 class H2Grammar :
public qi::grammar<Iterator, H2(), qi::locals<char>,
170 ((( qi::lit(
"name") |
"'name'" |
"\"name\"" )
171 >>
":" >>
name [qi::_val *= qi::_1])
173 (( qi::lit(
"title") |
"'title'" |
"\"title\"" )
174 >>
":" >>
title [qi::_val /= qi::_1])
176 (( qi::lit(
"X") |
"'X'" |
"\"X\"" |
"x" |
"'x'" |
"\"x\"" ) >>
':'
177 >>
edges [qi::_val &= qi::_1 ])
179 (( qi::lit(
"Y") |
"'Y'" |
"\"Y\"" |
"y" |
"'y'" |
"\"y\"" ) >>
':'
180 >>
edges [qi::_val |= qi::_1 ])
182 (( qi::lit(
"bins") |
"'bins'" |
"\"bins\"" )
183 >>
':' >>
bins [ qi::_val += qi::_1 ])) %
',';
185 begin = enc::char_(
'[')[qi::_val=
']']
186 | enc::char_(
'{')[qi::_val=
'}']
187 | enc::char_(
'(')[qi::_val=
')'];
188 end = enc::char_(qi::_r1);
190 >>
inner[qi::_val = qi::_1]
191 >>
end(qi::_a)) |
inner[qi::_val = qi::_1];
199 qi::rule<Iterator, H2(), Skipper>
inner;
201 qi::rule<Iterator, void(char)>
end;
215 StatusCode _parse ( H1&
h1 ,
const std::string& input ) {
223 StatusCode _parse ( H2&
h2 ,
const std::string& input) {
230 template <
class HISTO1>
231 std::auto_ptr<HISTO1>
232 _parse_1D (
const std::string& input , std::string& name )
235 typedef std::auto_ptr<HISTO1> H1P ;
241 if ( sc.
isFailure() || !h1.ok() ) {
return H1P() ; }
246 ( h1.m_edges.edges.empty() ?
253 h1.m_title .c_str() ,
254 h1.m_edges.edges.size() -1 ,
255 &h1.m_edges.edges.front() ) ) ;
258 for (
unsigned int ibin = 0 ; ibin < h1.m_bins.size() ; ++ibin )
260 histo -> SetBinContent ( ibin , h1.m_bins[ibin].first ) ;
261 histo -> SetBinError ( ibin , h1.m_bins[ibin].second ) ;
269 template <
class HISTO2>
270 std::auto_ptr<HISTO2> _parse_2D (
const std::string& input , std::string& name )
273 typedef std::auto_ptr<HISTO2> H2P ;
278 if ( sc.
isFailure() || !h2.ok() ) {
return H2P() ; }
283 ( h2.m_xedges.edges.empty() &&
284 h2.m_yedges.edges.empty() ?
293 h2.m_xedges.edges.empty() && !h2.m_xedges.edges.empty() ?
299 h2.m_yedges.nBins() ,
300 &h2.m_yedges.edges.front() ) :
301 !h2.m_xedges.edges.empty() && h2.m_xedges.edges.empty() ?
304 h2.m_xedges.nBins() ,
305 &h2.m_xedges.edges.front() ,
311 h2.m_xedges.nBins() ,
312 &h2.m_xedges.edges.front() ,
313 h2.m_yedges.nBins() ,
314 &h2.m_yedges.edges.front() ) ) ;
317 const int xBins = h2.m_xedges.nBins() ;
318 const int yBins = h2.m_yedges.nBins() ;
320 for (
int jBin = yBins + 1 ; jBin >= 0 ; --jBin )
322 for (
int iBin = 0 ; iBin <= xBins + 1 ; ++iBin )
324 histo -> SetBinContent ( iBin , jBin , h2.m_bins[ibin].first ) ;
325 histo -> SetBinError ( iBin , jBin , h2.m_bins[ibin].second ) ;
344 ( TH1D& result ,
const std::string& input )
349 std::auto_ptr<TH1D> h1 = _parse_1D<TH1D> ( input , name ) ;
353 h1->Copy ( result ) ;
354 result.SetName ( name.c_str () ) ;
359 if ( std::string::npos != input.find(
'<') )
372 ( TH1F& result ,
const std::string& input )
377 std::auto_ptr<TH1F> h1 = _parse_1D<TH1F> ( input , name ) ;
381 h1->Copy ( result ) ;
382 result.SetName ( name.c_str () ) ;
387 if ( std::string::npos != input.find(
'<') )
400 ( TH2D& result ,
const std::string& input )
404 std::auto_ptr<TH2D> h2 = _parse_2D<TH2D> ( input , name ) ;
408 h2->Copy ( result ) ;
409 result.SetName ( name.c_str () ) ;
414 if ( std::string::npos != input.find(
'<') )
427 ( TH2F& result ,
const std::string& input )
431 std::auto_ptr<TH2F> h2 = _parse_2D<TH2F> ( input , name ) ;
435 h2->Copy ( result ) ;
436 result.SetName ( name.c_str () ) ;
441 if ( std::string::npos != input.find(
'<') )
454 ( TH1D*& result ,
const std::string& input )
456 if ( 0 != result ) {
return parse ( *result , input ) ; }
460 std::auto_ptr<TH1D> h1 = _parse_1D<TH1D> ( input , name ) ;
463 result = h1.release() ;
464 result->SetName ( name.c_str() ) ;
469 if ( std::string::npos != input.find(
'<') )
482 ( TH2D*& result ,
const std::string& input )
484 if ( 0 != result ) {
return parse ( *result , input ) ; }
488 std::auto_ptr<TH2D> h2 = _parse_2D<TH2D> ( input , name ) ;
491 result = h2.release() ;
492 result->SetName ( name.c_str() ) ;
497 if ( std::string::npos != input.find(
'<') )
510 ( AIDA::IHistogram1D& result ,
const std::string& input )
516 return parse ( *root , input ) ;
526 ( AIDA::IHistogram2D& result ,
const std::string& input )
532 return parse ( *root , input ) ;
EdgeGrammar< Iterator, Skipper > edges
IntGrammar< Iterator, unsigned int, Skipper > nbins
RealGrammar< Iterator, double, Skipper > low
qi::rule< Iterator, char()> begin
qi::rule< Iterator, void(char)> end
GAUDI_API StatusCode fromXml(TH1D &result, const std::string &input)
parse the histogram from standard ROOT XML
StatusCode parse_(ResultT &result, const std::string &input)
qi::rule< Iterator, H2(), Skipper > inner
REGISTER_GRAMMAR(std::string, StringGrammar)
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
The valid represenation of string values are:
bool isFailure() const
Test for a status code of FAILURE.
StringGrammar< Iterator, Skipper > title
StringGrammar< Iterator, Skipper > name
StringGrammar< Iterator, Skipper > title
StringGrammar< Iterator, Skipper > name
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
The valid represenation of vector are:
Skipping spaces and comments.
qi::rule< Iterator, void(char)> end
qi::rule< Iterator, void(char)> end
This is a number of static methods for bootstrapping the Gaudi framework.
VectorGrammar< Iterator, std::vector< std::pair< double, double > >, Skipper > bins
EdgeGrammar< Iterator, Skipper > edges
RealGrammar< Iterator, double, Skipper > high
IntGrammar< Iterator, unsigned int, Skipper > nbins
qi::rule< Iterator, char()> begin