![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: ParseHistos.cpp,v 1.3 2008/10/28 14:02:18 marcocle Exp $ 00002 // ============================================================================ 00003 // Include files 00004 // ============================================================================ 00005 // GaudiKernel 00006 // ============================================================================ 00007 #include "GaudiKernel/HistoDef.h" 00008 #include "GaudiKernel/HistoProperty.h" 00009 // ============================================================================ 00010 // local 00011 // ============================================================================ 00012 #include "Parsers.icpp" 00013 // ============================================================================ 00020 // ============================================================================ 00021 namespace Gaudi 00022 { 00023 namespace Parsers 00024 { 00025 // ======================================================================== 00044 class Histo1DGrammar 00045 : public grammar<Histo1DGrammar, 00046 ClosureGrammar<Gaudi::Histo1DDef>::context_t> 00047 { 00048 public: 00049 // the actual type of the target 00050 typedef Gaudi::Histo1DDef ResultT; 00051 public: 00053 void matchLow ( const double low ) const 00054 { this -> val() . setLowEdge ( low ) ; } 00055 void matchHigh ( const double high ) const 00056 { this -> val() . setHighEdge ( high ) ; } 00057 void matchTitle ( const std::string& title ) const 00058 { this -> val() . setTitle ( title ) ; } 00059 void matchBins ( const int bins ) const 00060 { this -> val() . setBins ( bins ) ; } 00061 public: 00062 template <typename ScannerT> 00063 struct definition 00064 { 00065 typedef Gaudi::Parsers::Histo1DGrammar H1G; 00066 definition( H1G const &self) 00067 { 00068 val1 = sG [boost::bind(&H1G::matchTitle , &self , _1 ) ] 00069 >> "," >> rG [boost::bind(&H1G::matchLow , &self , _1 ) ] 00070 >> "," >> rG [boost::bind(&H1G::matchHigh , &self , _1 ) ] 00071 >> !( "," >> iG [boost::bind(&H1G::matchBins , &self , _1 ) ] ) ; 00072 00073 val2 = rG [boost::bind(&H1G::matchLow , &self , _1 ) ] 00074 >> "," >> rG [boost::bind(&H1G::matchHigh , &self , _1 ) ] 00075 >> "," >> sG [boost::bind(&H1G::matchTitle , &self , _1 ) ] 00076 >> !( "," >> iG [boost::bind(&H1G::matchBins , &self , _1 ) ] ) ; 00077 00078 val3 = rG [boost::bind(&H1G::matchLow , &self , _1 ) ] 00079 >> "," >> rG [boost::bind(&H1G::matchHigh , &self , _1 ) ] 00080 >> !( "," >> iG [boost::bind(&H1G::matchBins , &self , _1 ) ] ) 00081 >> !( "," >> sG [boost::bind(&H1G::matchTitle , &self , _1 ) ] ) ; 00082 00083 histogram = "(" >> ( val1 || val2 || val3 ) >> ")"; 00084 } 00085 RealGrammar<> rG ; 00086 IntGrammar<> iG ; 00087 StringGrammar sG ; 00088 boost::spirit::rule<ScannerT> const& start() const { return histogram;} 00089 rule<ScannerT> histogram ; 00090 rule<ScannerT> val1,val2,val3 ; 00091 }; 00092 }; 00093 } // end of namespace Gaudi::Parsers 00094 } // end of namespace Gaudi 00095 // ============================================================================ 00096 /* helper function, needed for the implementation of "Histogram Property" 00097 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 00098 * @author Alexander MAZUROV Alexander.Mazurov@gmail.com 00099 * @date 2007-09-17 00100 */ 00101 // ============================================================================ 00102 StatusCode Gaudi::Parsers::parse 00103 ( Gaudi::Histo1DDef& histo , 00104 const std::string& input ) 00105 { 00106 Histo1DGrammar g; 00107 const bool full = 00108 boost::spirit::parse 00109 ( createIterator(input), 00110 IteratorT(), 00111 g[var(histo)=arg1], 00112 SkipperGrammar()).full; 00113 // 00114 return full && histo.ok() ? StatusCode::SUCCESS : StatusCode::FAILURE ; 00115 } 00116 // ============================================================================ 00125 // ============================================================================ 00126 StatusCode Gaudi::Parsers::parse 00127 ( std::map<std::string,Gaudi::Histo1DDef>& histos , 00128 const std::string& input ) 00129 { 00130 MapGrammar<StringGrammar,Histo1DGrammar> g; 00131 const bool full = boost::spirit::parse 00132 ( createIterator(input), 00133 IteratorT() , 00134 g[var(histos)=arg1], 00135 SkipperGrammar() ).full; 00136 // 00137 if ( !full ) { return StatusCode::FAILURE ; } // RETURN 00138 // 00139 for ( std::map<std::string,Gaudi::Histo1DDef>::const_iterator 00140 ih = histos.begin() ; histos.end() != ih ; ++ih ) 00141 { if ( !ih->second.ok() ) { return StatusCode::FAILURE ; } } // RETURN 00142 // 00143 return StatusCode::SUCCESS ; // RETURN 00144 } 00145 // ============================================================================ 00146 00147 // ============================================================================ 00148 // The END 00149 // ============================================================================