The Gaudi Framework  v30r3 (a5ef0a68)
HistoTableFormat.h
Go to the documentation of this file.
1 #ifndef GAUDIUTILS_HISTOTABLEFORMAT_H
2 #define GAUDIUTILS_HISTOTABLEFORMAT_H 1
3 // ============================================================================
4 // Include files
5 // ============================================================================
6 #include "GaudiKernel/Kernel.h"
7 #include <string>
8 // ============================================================================
9 // forward declarations
10 // ============================================================================
11 namespace AIDA
12 {
13  class IHistogram1D;
14  class IBaseHistogram;
15 }
16 // ============================================================================
17 namespace Gaudi
18 {
19  namespace Utils
20  {
21  // ========================================================================
28  namespace Histos
29  {
30  // ======================================================================
72  namespace Formats
73  {
74  // ====================================================================
89  enum Format {
90  Default = 0, // default format
91  Old, // "OLD"-line format: title,integral,#ent,mean,rms
92  Full, // FULL format: the first 15 positions
93  FullStat, // Full statistical info (3-15)
94  Stat, // title,#ent,mean,rms,skewness&kurtosis
95  StatOnly, // #entries,mean,rms,skewness&kurtosis
96  Stat1, // #entries,mean+-,rms+-,skewness+-&kurtosis+-
97  ShapeOnly, // mean,rms,skewness,kurtosis,underflow&overflow fractions
98  Shape, // as ShapeOnly but with errors
99  LineTitle, // line-format : title,mean,rms,skewness&kurtosis
100  LineOnly, // line-format : mean,rms,skewness&kurtosis
101  PathTitle // "PathTitle" : path & title
102  };
103  // ====================================================================
111  GAUDI_API std::string format( const int ID = Default );
112  // ====================================================================
120  GAUDI_API std::string header( const int ID = Default );
121  // ====================================================================
122  } // end of namespace Gaudi::Utils::Histos::Formats
123  // ======================================================================
128  GAUDI_API std::string path( const AIDA::IBaseHistogram* aida );
129  // ======================================================================
168  GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& fmt );
169  // ======================================================================
198  GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt1,
199  const std::string& fmt2 );
200  // ========================================================================
224  template <class HISTO, class STREAM, class TERMINATOR>
225  inline STREAM& printList( HISTO first, HISTO last, const std::string& fmt, STREAM& stream, TERMINATOR term )
226  {
227  for ( ; first != last; ++first ) {
228  stream << format( *first, fmt ) << term;
229  } // print table rows
230  return stream; // RETURN
231  }
232  // ======================================================================
256  template <class LIST, class STREAM, class TERMINATOR>
257  inline STREAM& printList( const LIST& histos, const std::string& fmt, STREAM& stream, TERMINATOR term )
258  {
259  return printList( histos.begin(), histos.end(), fmt, stream, term );
260  }
261  // ======================================================================
306  template <class HISTO, class STREAM, class TERMINATOR>
307  inline STREAM& printMap( HISTO begin, HISTO end, const std::string& fmt1, const std::string& fmt2, STREAM& stream,
308  TERMINATOR term )
309  {
310  for ( ; begin != end; ++begin ) {
311  stream << format( begin->second, // the histogram
312  begin->first, // the key
313  fmt1, fmt2 )
314  << term;
315  }
316  return stream;
317  }
318  // ======================================================================
361  template <class MAP, class STREAM, class TERMINATOR>
362  inline STREAM& printMap( const MAP& histos, const std::string& fmt1, const std::string& fmt2, STREAM& stream,
363  TERMINATOR term )
364  {
365  return printMap( histos.begin(), histos.end(), fmt1, fmt2, stream, term );
366  }
367  // ======================================================================
372  GAUDI_API std::string format( const std::string& val1, const std::string& val2, const std::string& fmt );
373  // ======================================================================
380  // ========================================================================
382  {
383  public:
385  Table( const int ID = 0 );
387  Table( const std::string& format, const std::string& header = "", const std::string& footer = "" );
388 
389  public:
390  // ======================================================================
397  template <class HISTO, class STREAM, class TERMINATOR>
398  STREAM& printList( HISTO first, HISTO last, STREAM& stream, TERMINATOR term ) const
399  {
400  if ( !header().empty() ) {
401  stream << header() << term;
402  }
403  Gaudi::Utils::Histos::printList( first, last, format(), stream, term );
404  if ( !footer().empty() ) {
405  stream << footer() << term;
406  }
407  return stream;
408  }
409  // ======================================================================
410  public:
423  template <class HISTO, class STREAM, class TERMINATOR>
424  STREAM& printMap( HISTO first, HISTO last, const std::string& fmt, const std::string& hval, STREAM& stream,
425  TERMINATOR term ) const
426  {
427  if ( !hval.empty() || !header().empty() ) {
428  stream << Gaudi::Utils::Histos::format( hval, header(), fmt ) << term;
429  }
430  return Gaudi::Utils::Histos::printMap( first, last, fmt, format(), stream, term );
431  }
432  // ======================================================================
433  public:
434  // ======================================================================
436  const std::string& header() const { return m_header; }
437  // ======================================================================
439  const std::string& footer() const { return m_footer; }
440  // ======================================================================
442  const std::string& format() const { return m_format; }
443  // ======================================================================
444  public:
445  // ======================================================================
447  void setHeader( std::string v ) { m_header = std::move( v ); }
448  // ======================================================================
450  void setFooter( std::string v ) { m_footer = std::move( v ); }
451  // ======================================================================
453  void setFormat( std::string v ) { m_format = std::move( v ); }
454  // ======================================================================
455  public:
456  // ======================================================================
458  std::string toString( const AIDA::IHistogram1D* histo ) const;
459  // ======================================================================
460  public:
461  // ======================================================================
485  std::string toString( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt ) const;
486  // ======================================================================
487  public:
488  // the table header
490  // the table footer
492  // the default format
494  //
495  };
496  } // end of namespace Gaudi::Utils::Histos
497  } // end of namespace Gaudi::Utils
498 } // end of namespace Gaudi
499 // ============================================================================
500 // The END
501 // ============================================================================
502 #endif // GAUDIUTILS_HISTOTABLEFORMAT_H
503 // ============================================================================
helper namespace to collect useful definitions, types, constants and functions, related to manipulati...
STREAM & printMap(HISTO begin, HISTO end, const std::string &fmt1, const std::string &fmt2, STREAM &stream, TERMINATOR term)
Print the "associative sequence" (e.g.
T empty(T...args)
STREAM & printMap(const MAP &histos, const std::string &fmt1, const std::string &fmt2, STREAM &stream, TERMINATOR term)
Print the "associative sequence" (e.g.
std::string m_header
the table header
void setHeader(std::string v)
set new header
GAUDI_API std::string format(const AIDA::IHistogram1D *histo, const std::string &fmt)
Make the string representation of the historgam according to the specified format.
STREAM & printMap(HISTO first, HISTO last, const std::string &fmt, const std::string &hval, STREAM &stream, TERMINATOR term) const
print as table the content of the accociative map (key->histogram) with the key, convertible to std::...
void setFormat(std::string v)
set new format
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
GaudiKernel.
Definition: Fill.h:10
const std::string & header() const
the table header
STL class.
GAUDI_API std::string format(const std::string &val1, const std::string &val2, const std::string &fmt)
helper method to merge the headers for short format table
STREAM & printList(HISTO first, HISTO last, STREAM &stream, TERMINATOR term) const
print the simple sequence of histograms as table
const std::string & format() const
the format
Simple class for the customizeble printout of the histogram tables.
std::string m_footer
the table footer
T move(T...args)
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
void setFooter(std::string v)
set new footer
STREAM & printList(HISTO first, HISTO last, const std::string &fmt, STREAM &stream, TERMINATOR term)
print the simple sequence (list-like) of histograms as table
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Format
the ID for predefined formats
#define GAUDI_API
Definition: Kernel.h:104
Helper functions to set/get the application return code.
Definition: __init__.py:1
std::string m_format
the defautl format
std::string toString(const Type &)
STREAM & printList(const LIST &histos, const std::string &fmt, STREAM &stream, TERMINATOR term)
print the simple container of histograms as table
const std::string & footer() const
the table footer