The Gaudi Framework  master (37c0b60a)
HistoTableFormat.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIUTILS_HISTOTABLEFORMAT_H
12 #define GAUDIUTILS_HISTOTABLEFORMAT_H 1
13 // ============================================================================
14 // Include files
15 // ============================================================================
16 #include <GaudiKernel/Kernel.h>
17 #include <string>
18 // ============================================================================
19 // forward declarations
20 // ============================================================================
21 namespace AIDA {
22  class IHistogram1D;
23  class IProfile1D;
24  class IBaseHistogram;
25 } // namespace AIDA
26 // ============================================================================
27 namespace Gaudi {
28  namespace Utils {
29  // ========================================================================
36  namespace Histos {
37  // ======================================================================
79  namespace Formats {
80  // ====================================================================
95  enum Format {
96  Default = 0, // default format
97  Old, // "OLD"-line format: title,integral,#ent,mean,rms
98  Full, // FULL format: the first 15 positions
99  FullStat, // Full statistical info (3-15)
100  Stat, // title,#ent,mean,rms,skewness&kurtosis
101  StatOnly, // #entries,mean,rms,skewness&kurtosis
102  Stat1, // #entries,mean+-,rms+-,skewness+-&kurtosis+-
103  ShapeOnly, // mean,rms,skewness,kurtosis,underflow&overflow fractions
104  Shape, // as ShapeOnly but with errors
105  LineTitle, // line-format : title,mean,rms,skewness&kurtosis
106  LineOnly, // line-format : mean,rms,skewness&kurtosis
107  PathTitle // "PathTitle" : path & title
108  };
109  // ====================================================================
117  GAUDI_API std::string format( const int ID = Default );
118  // ====================================================================
126  GAUDI_API std::string header( const int ID = Default );
127  // ====================================================================
128  } // namespace Formats
129  // ======================================================================
134  GAUDI_API std::string path( const AIDA::IBaseHistogram* aida );
135  // ======================================================================
174  GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& fmt );
175  // ======================================================================
199  GAUDI_API std::string format( const AIDA::IProfile1D* histo, const std::string& fmt );
200  // ======================================================================
229  GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt1,
230  const std::string& fmt2 );
231  // ======================================================================
260  GAUDI_API std::string format( const AIDA::IProfile1D* histo, const std::string& ID, const std::string& fmt1,
261  const std::string& fmt2 );
262  // ========================================================================
286  template <class HISTO, class STREAM, class TERMINATOR>
287  inline STREAM& printList( HISTO first, HISTO last, const std::string& fmt, STREAM& stream, TERMINATOR term ) {
288  for ( ; first != last; ++first ) { stream << format( *first, fmt ) << term; } // print table rows
289  return stream; // RETURN
290  }
291  // ======================================================================
315  template <class LIST, class STREAM, class TERMINATOR>
316  inline STREAM& printList( const LIST& histos, const std::string& fmt, STREAM& stream, TERMINATOR term ) {
317  return printList( histos.begin(), histos.end(), fmt, stream, term );
318  }
319  // ======================================================================
364  template <class HISTO, class STREAM, class TERMINATOR>
365  inline STREAM& printMap( HISTO begin, HISTO end, const std::string& fmt1, const std::string& fmt2, STREAM& stream,
366  TERMINATOR term ) {
367  for ( ; begin != end; ++begin ) {
368  stream << format( begin->second, // the histogram
369  begin->first, // the key
370  fmt1, fmt2 )
371  << term;
372  }
373  return stream;
374  }
375  // ======================================================================
418  template <class MAP, class STREAM, class TERMINATOR>
419  inline STREAM& printMap( const MAP& histos, const std::string& fmt1, const std::string& fmt2, STREAM& stream,
420  TERMINATOR term ) {
421  return printMap( histos.begin(), histos.end(), fmt1, fmt2, stream, term );
422  }
423  // ======================================================================
428  GAUDI_API std::string format( const std::string& val1, const std::string& val2, const std::string& fmt );
429  // ======================================================================
436  // ========================================================================
437  class GAUDI_API Table {
438  public:
440  Table( const int ID = 0 );
442  Table( const std::string& format, const std::string& header = "", const std::string& footer = "" );
443 
444  public:
445  // ======================================================================
452  template <class HISTO, class STREAM, class TERMINATOR>
453  STREAM& printList( HISTO first, HISTO last, STREAM& stream, TERMINATOR term ) const {
454  if ( !header().empty() ) { stream << header() << term; }
455  Gaudi::Utils::Histos::printList( first, last, format(), stream, term );
456  if ( !footer().empty() ) { stream << footer() << term; }
457  return stream;
458  }
459  // ======================================================================
460  public:
473  template <class HISTO, class STREAM, class TERMINATOR>
474  STREAM& printMap( HISTO first, HISTO last, const std::string& fmt, const std::string& hval, STREAM& stream,
475  TERMINATOR term ) const {
476  if ( !hval.empty() || !header().empty() ) {
477  stream << Gaudi::Utils::Histos::format( hval, header(), fmt ) << term;
478  }
479  return Gaudi::Utils::Histos::printMap( first, last, fmt, format(), stream, term );
480  }
481  // ======================================================================
482  public:
483  // ======================================================================
485  const std::string& header() const { return m_header; }
486  // ======================================================================
488  const std::string& footer() const { return m_footer; }
489  // ======================================================================
491  const std::string& format() const { return m_format; }
492  // ======================================================================
493  public:
494  // ======================================================================
496  void setHeader( std::string v ) { m_header = std::move( v ); }
497  // ======================================================================
499  void setFooter( std::string v ) { m_footer = std::move( v ); }
500  // ======================================================================
502  void setFormat( std::string v ) { m_format = std::move( v ); }
503  // ======================================================================
504  public:
505  // ======================================================================
507  std::string toString( const AIDA::IHistogram1D* histo ) const;
508  // ======================================================================
510  std::string toString( const AIDA::IProfile1D* histo ) const;
511  // ======================================================================
512  public:
513  // ======================================================================
537  std::string toString( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt ) const;
561  std::string toString( const AIDA::IProfile1D* histo, const std::string& ID, const std::string& fmt ) const;
562  // ======================================================================
563  public:
564  // the table header
566  // the table footer
568  // the default format
570  //
571  };
572  } // namespace Histos
573  } // namespace Utils
574 } // end of namespace Gaudi
575 // ============================================================================
576 // The END
577 // ============================================================================
578 #endif // GAUDIUTILS_HISTOTABLEFORMAT_H
AIDA
GaudiKernel.
Definition: Annotation.h:22
Write.stream
stream
Definition: Write.py:32
Gaudi::Utils::Histos::Formats::LineTitle
@ LineTitle
Definition: HistoTableFormat.h:105
std::string
STL class.
Gaudi::Utils::Histos::Formats::Stat1
@ Stat1
Definition: HistoTableFormat.h:102
std::move
T move(T... args)
Gaudi::Utils::Histos::Formats::Shape
@ Shape
Definition: HistoTableFormat.h:104
Gaudi::Utils::Histos::Formats::header
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
Definition: HistoTableFormat.cpp:186
Gaudi::Utils::Histos::Formats::Format
Format
the ID for predefined formats
Definition: HistoTableFormat.h:95
Gaudi::Utils::Histos::Table::m_format
std::string m_format
the defautl format
Definition: HistoTableFormat.h:569
Gaudi::Utils::Histos::printMap
STREAM & printMap(HISTO begin, HISTO end, const std::string &fmt1, const std::string &fmt2, STREAM &stream, TERMINATOR term)
Print the "associative sequence" (e.g.
Definition: HistoTableFormat.h:365
Gaudi::Utils::Histos::Table::setHeader
void setHeader(std::string v)
set new header
Definition: HistoTableFormat.h:496
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:136
Gaudi::Utils::Histos::Formats::Old
@ Old
Definition: HistoTableFormat.h:97
Gaudi::Utils::Histos::Formats::FullStat
@ FullStat
Definition: HistoTableFormat.h:99
Gaudi::Utils::Histos::Formats::ShapeOnly
@ ShapeOnly
Definition: HistoTableFormat.h:103
Gaudi::Utils::Histos::Table::setFormat
void setFormat(std::string v)
set new format
Definition: HistoTableFormat.h:502
Gaudi::Utils::Histos::Formats::LineOnly
@ LineOnly
Definition: HistoTableFormat.h:106
Gaudi::Utils::end
AttribStringParser::Iterator end(const AttribStringParser &)
Definition: AttribStringParser.h:139
Gaudi::Utils::Histos::Table::setFooter
void setFooter(std::string v)
set new footer
Definition: HistoTableFormat.h:499
Gaudi::Utils::Histos::Formats::Full
@ Full
Definition: HistoTableFormat.h:98
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition: __init__.py:1
Gaudi::Utils::Histos::Table
Definition: HistoTableFormat.h:437
Gaudi::Utils::Histos::Formats::StatOnly
@ StatOnly
Definition: HistoTableFormat.h:101
Gaudi::Utils::Histos::Table::format
const std::string & format() const
the format
Definition: HistoTableFormat.h:491
Gaudi::Utils::Histos::Formats::format
GAUDI_API std::string format(const int ID=Default)
get the format by enum
Definition: HistoTableFormat.cpp:153
Gaudi::Utils::Histos::Table::m_footer
std::string m_footer
the table footer
Definition: HistoTableFormat.h:567
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:353
Gaudi::Utils::Histos::Formats::Stat
@ Stat
Definition: HistoTableFormat.h:100
Gaudi::Utils::Histos::printList
STREAM & printList(HISTO first, HISTO last, const std::string &fmt, STREAM &stream, TERMINATOR term)
print the simple sequence (list-like) of histograms as table
Definition: HistoTableFormat.h:287
compareRootHistos.histos
histos
Definition: compareRootHistos.py:26
Gaudi::Utils::Histos::Formats::PathTitle
@ PathTitle
Definition: HistoTableFormat.h:107
Gaudi::Utils::Histos::Table::printList
STREAM & printList(HISTO first, HISTO last, STREAM &stream, TERMINATOR term) const
print the simple sequence of histograms as table
Definition: HistoTableFormat.h:453
Kernel.h
fmt
std::string::empty
T empty(T... args)
Properties.v
v
Definition: Properties.py:122
Gaudi::Utils::Histos::Table::m_header
std::string m_header
the table header
Definition: HistoTableFormat.h:565
Gaudi::Utils::Histos::Table::header
const std::string & header() const
the table header
Definition: HistoTableFormat.h:485
Gaudi::Utils::Histos::path
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
Definition: HistoTableFormat.cpp:218
Gaudi::Utils::Histos::Table::footer
const std::string & footer() const
the table footer
Definition: HistoTableFormat.h:488
Gaudi::Utils::Histos::Formats::Default
@ Default
Definition: HistoTableFormat.h:96
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::Utils::Histos::format
GAUDI_API std::string format(const AIDA::IHistogram1D *histo, const std::string &fmt)
Make the string representation of the histogram according to the specified format.
Definition: HistoTableFormat.cpp:233
Gaudi::Utils::Histos::Table::printMap
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::...
Definition: HistoTableFormat.h:474