![]() |
|
|
Generated: 18 Jul 2008 |
00001 // $Id: ParseHistos.cpp,v 1.1 2007/09/26 16:13:42 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 const bool full = 00107 boost::spirit::parse 00108 ( createIterator(input), 00109 IteratorT(), 00110 Histo1DGrammar()[var(histo)=arg1], 00111 SkipperGrammar()).full; 00112 // 00113 return full && histo.ok() ? StatusCode::SUCCESS : StatusCode::FAILURE ; 00114 } 00115 // ============================================================================ 00124 // ============================================================================ 00125 StatusCode Gaudi::Parsers::parse 00126 ( std::map<std::string,Gaudi::Histo1DDef>& histos , 00127 const std::string& input ) 00128 { 00129 const bool full = boost::spirit::parse 00130 ( createIterator(input), 00131 IteratorT() , 00132 MapGrammar<StringGrammar,Histo1DGrammar>() [var(histos)=arg1], 00133 SkipperGrammar() ).full; 00134 // 00135 if ( !full ) { return StatusCode::FAILURE ; } // RETURN 00136 // 00137 for ( std::map<std::string,Gaudi::Histo1DDef>::const_iterator 00138 ih = histos.begin() ; histos.end() != ih ; ++ih ) 00139 { if ( !ih->second.ok() ) { return StatusCode::FAILURE ; } } // RETURN 00140 // 00141 return StatusCode::SUCCESS ; // RETURN 00142 } 00143 // ============================================================================ 00144 00145 // ============================================================================ 00146 // The END 00147 // ============================================================================