![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: HistoTableFormat.h,v 1.3 2007/11/16 15:29:02 hmd Exp $ 00002 // ============================================================================ 00003 #ifndef GAUDIUTILS_HISTOTABLEFORMAT_H 00004 #define GAUDIUTILS_HISTOTABLEFORMAT_H 1 00005 // ============================================================================ 00006 // forward declarations 00007 // ============================================================================ 00008 namespace AIDA 00009 { 00010 class IHistogram1D ; 00011 class IBaseHistogram ; 00012 } 00013 // ============================================================================ 00014 namespace Gaudi 00015 { 00016 namespace Utils 00017 { 00018 // ======================================================================== 00025 namespace Histos 00026 { 00027 // ====================================================================== 00052 namespace Formats 00053 { 00055 enum Format 00056 { 00057 Default = 0 , // default format 00058 Old , // "OLD"-line format: title,integral,#ent,mean,rms 00059 Full , // FULL format: all available 15 positions 00060 Stat , // title,#ent,mean,rms,skewness&kurtosis 00061 StatOnly , // #entries,mean,rms,skewness&kurtosis 00062 LineTitle , // line-format : title,mean,rms,skewness&kurtosis 00063 LineOnly , // line-format : mean,rms,skewness&kurtosis 00064 PathTitle // "PathTitle" : path & title 00065 } ; 00066 // ==================================================================== 00074 std::string format ( const int ID = Default ) ; 00075 // ==================================================================== 00083 std::string header ( const int ID = Default ) ; 00084 // ==================================================================== 00085 } // end of namespace Gaudi::Utils::Histos::Formats 00086 // ====================================================================== 00091 std::string path ( const AIDA::IBaseHistogram* aida ) ; 00092 // ====================================================================== 00131 std::string format 00132 ( const AIDA::IHistogram1D* histo , 00133 const std::string& fmt ) ; 00134 // ====================================================================== 00163 std::string format 00164 ( const AIDA::IHistogram1D* histo , 00165 const std::string& ID , 00166 const std::string& fmt1 , 00167 const std::string& fmt2 ) ; 00168 // ======================================================================== 00192 template <class HISTO, class STREAM, class TERMINATOR> 00193 inline STREAM& printList 00194 ( HISTO first , 00195 HISTO last , 00196 const std::string& fmt , 00197 STREAM& stream , 00198 TERMINATOR term ) 00199 { 00200 for ( ; first != last ; ++first ) 00201 { stream << format ( *first , fmt ) << term ; } // print table rows 00202 return stream ; // RETURN 00203 } 00204 // ====================================================================== 00228 template <class LIST, class STREAM, class TERMINATOR> 00229 inline STREAM& printList 00230 ( const LIST& histos , 00231 const std::string& fmt , 00232 STREAM& stream , 00233 TERMINATOR term ) 00234 { 00235 return printList 00236 ( histos.begin () , histos.end () , fmt , stream , term ) ; 00237 } 00238 // ====================================================================== 00283 template <class HISTO, class STREAM, class TERMINATOR> 00284 inline STREAM& printMap 00285 ( HISTO begin , 00286 HISTO end , 00287 const std::string& fmt1 , 00288 const std::string& fmt2 , 00289 STREAM& stream , 00290 TERMINATOR term ) 00291 { 00292 for ( ; begin != end ; ++begin ) 00293 { 00294 stream << format 00295 ( begin -> second , // the histogram 00296 begin -> first , // the key 00297 fmt1 , fmt2 ) << term ; 00298 } 00299 return stream ; 00300 } 00301 // ====================================================================== 00344 template <class MAP, class STREAM, class TERMINATOR> 00345 inline STREAM& printMap 00346 ( const MAP& histos , 00347 const std::string& fmt1 , 00348 const std::string& fmt2 , 00349 STREAM& stream , 00350 TERMINATOR term ) 00351 { 00352 return printMap 00353 ( histos.begin () , histos.end() , fmt1 , fmt2 , stream , term ) ; 00354 } 00355 // ====================================================================== 00360 std::string format 00361 ( const std::string& val1 , 00362 const std::string& val2 , 00363 const std::string& fmt ) ; 00364 // ====================================================================== 00371 // ======================================================================== 00372 class Table 00373 { 00374 public: 00376 Table ( const int ID = 0 ) ; 00378 Table 00379 ( const std::string& format , 00380 const std::string& header = "" , 00381 const std::string& footer = "" ) ; 00382 public: 00383 // ====================================================================== 00390 template <class HISTO, class STREAM, class TERMINATOR> 00391 STREAM& printList 00392 ( HISTO first , 00393 HISTO last , 00394 STREAM& stream , 00395 TERMINATOR term ) const 00396 { 00397 if ( !header().empty() ) { stream << header () << term ; } 00398 Gaudi::Utils::Histos::printList ( first , last , format() , stream , term ) ; 00399 if ( !footer().empty() ) { stream << footer () << term ; } 00400 return stream ; 00401 } 00402 // ====================================================================== 00403 public: 00416 template <class HISTO, class STREAM, class TERMINATOR> 00417 STREAM& printMap 00418 ( HISTO first , 00419 HISTO last , 00420 const std::string& fmt , 00421 const std::string& hval , 00422 STREAM& stream , 00423 TERMINATOR term ) const 00424 { 00425 if ( !hval.empty() || !header().empty() ) 00426 { stream << Gaudi::Utils::Histos::format ( hval , header() , fmt ) << term ; } 00427 return Gaudi::Utils::Histos::printMap 00428 ( first , last , fmt , format() , stream , term ) ; 00429 } 00430 // ====================================================================== 00431 public: 00432 // ====================================================================== 00434 const std::string& header () const { return m_header ; } 00435 // ====================================================================== 00437 const std::string& footer () const { return m_footer ; } 00438 // ====================================================================== 00440 const std::string& format () const { return m_format ; } 00441 // ====================================================================== 00442 public: 00443 // ====================================================================== 00445 void setHeader ( const std::string& v ) { m_header = v ; } 00446 // ====================================================================== 00448 void setFooter ( const std::string& v ) { m_footer = v ; } 00449 // ====================================================================== 00451 void setFormat ( const std::string& v ) { m_format = v ; } 00452 // ====================================================================== 00453 public : 00454 // ====================================================================== 00456 std::string toString ( const AIDA::IHistogram1D* histo ) const ; 00457 // ====================================================================== 00458 public: 00459 // ====================================================================== 00483 std::string toString 00484 ( const AIDA::IHistogram1D* histo , 00485 const std::string& ID , 00486 const std::string& fmt ) const ; 00487 // ====================================================================== 00488 public: 00489 // the table header 00490 std::string m_header ; 00491 // the table footer 00492 std::string m_footer ; 00493 // the default format 00494 std::string m_format ; 00495 // 00496 } ; 00497 } // end of namespace Gaudi::Utils::Histos 00498 } // end of namespace Gaudi::Utils 00499 } // end of namespace Gaudi 00500 // ============================================================================ 00501 // The END 00502 // ============================================================================ 00503 #endif // GAUDIUTILS_HISTOTABLEFORMAT_H 00504 // ============================================================================