Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HistoTableFormat.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 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 #pragma once
12 // ============================================================================
13 // Include files
14 // ============================================================================
15 #include <GaudiKernel/Kernel.h>
16 #include <string>
17 // ============================================================================
18 // forward declarations
19 // ============================================================================
20 namespace AIDA {
21  class IHistogram1D;
22  class IProfile1D;
23  class IBaseHistogram;
24 } // namespace AIDA
25 // ============================================================================
26 namespace Gaudi {
27  namespace Utils {
28  // ========================================================================
35  namespace Histos {
36  // ======================================================================
78  namespace Formats {
79  // ====================================================================
94  enum Format {
95  Default = 0, // default format
96  Old, // "OLD"-line format: title,integral,#ent,mean,rms
97  Full, // FULL format: the first 15 positions
98  FullStat, // Full statistical info (3-15)
99  Stat, // title,#ent,mean,rms,skewness&kurtosis
100  StatOnly, // #entries,mean,rms,skewness&kurtosis
101  Stat1, // #entries,mean+-,rms+-,skewness+-&kurtosis+-
102  ShapeOnly, // mean,rms,skewness,kurtosis,underflow&overflow fractions
103  Shape, // as ShapeOnly but with errors
104  LineTitle, // line-format : title,mean,rms,skewness&kurtosis
105  LineOnly, // line-format : mean,rms,skewness&kurtosis
106  PathTitle // "PathTitle" : path & title
107  };
108  // ====================================================================
116  GAUDI_API std::string format( const int ID = Default );
117  // ====================================================================
125  GAUDI_API std::string header( const int ID = Default );
126  // ====================================================================
127  } // namespace Formats
128  // ======================================================================
133  GAUDI_API std::string path( const AIDA::IBaseHistogram* aida );
134  // ======================================================================
173  GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& fmt );
174  // ======================================================================
198  GAUDI_API std::string format( const AIDA::IProfile1D* histo, const std::string& fmt );
199  // ======================================================================
228  GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt1,
229  const std::string& fmt2 );
230  // ======================================================================
259  GAUDI_API std::string format( const AIDA::IProfile1D* histo, const std::string& ID, const std::string& fmt1,
260  const std::string& fmt2 );
261  // ========================================================================
285  template <class HISTO, class STREAM, class TERMINATOR>
286  inline STREAM& printList( HISTO first, HISTO last, const std::string& fmt, STREAM& stream, TERMINATOR term ) {
287  for ( ; first != last; ++first ) { stream << format( *first, fmt ) << term; } // print table rows
288  return stream; // RETURN
289  }
290  // ======================================================================
314  template <class LIST, class STREAM, class TERMINATOR>
315  inline STREAM& printList( const LIST& histos, const std::string& fmt, STREAM& stream, TERMINATOR term ) {
316  return printList( histos.begin(), histos.end(), fmt, stream, term );
317  }
318  // ======================================================================
363  template <class HISTO, class STREAM, class TERMINATOR>
364  inline STREAM& printMap( HISTO begin, HISTO end, const std::string& fmt1, const std::string& fmt2, STREAM& stream,
365  TERMINATOR term ) {
366  for ( ; begin != end; ++begin ) {
367  stream << format( begin->second, // the histogram
368  begin->first, // the key
369  fmt1, fmt2 )
370  << term;
371  }
372  return stream;
373  }
374  // ======================================================================
417  template <class MAP, class STREAM, class TERMINATOR>
418  inline STREAM& printMap( const MAP& histos, const std::string& fmt1, const std::string& fmt2, STREAM& stream,
419  TERMINATOR term ) {
420  return printMap( histos.begin(), histos.end(), fmt1, fmt2, stream, term );
421  }
422  // ======================================================================
427  GAUDI_API std::string format( const std::string& val1, const std::string& val2, const std::string& fmt );
428  // ======================================================================
435  // ========================================================================
436  class GAUDI_API Table {
437  public:
439  Table( const int ID = 0 );
441  Table( const std::string& format, const std::string& header = "", const std::string& footer = "" );
442 
443  public:
444  // ======================================================================
451  template <class HISTO, class STREAM, class TERMINATOR>
452  STREAM& printList( HISTO first, HISTO last, STREAM& stream, TERMINATOR term ) const {
453  if ( !header().empty() ) { stream << header() << term; }
454  Gaudi::Utils::Histos::printList( first, last, format(), stream, term );
455  if ( !footer().empty() ) { stream << footer() << term; }
456  return stream;
457  }
458  // ======================================================================
459  public:
472  template <class HISTO, class STREAM, class TERMINATOR>
473  STREAM& printMap( HISTO first, HISTO last, const std::string& fmt, const std::string& hval, STREAM& stream,
474  TERMINATOR term ) const {
475  if ( !hval.empty() || !header().empty() ) {
476  stream << Gaudi::Utils::Histos::format( hval, header(), fmt ) << term;
477  }
478  return Gaudi::Utils::Histos::printMap( first, last, fmt, format(), stream, term );
479  }
480  // ======================================================================
481  public:
482  // ======================================================================
484  const std::string& header() const { return m_header; }
485  // ======================================================================
487  const std::string& footer() const { return m_footer; }
488  // ======================================================================
490  const std::string& format() const { return m_format; }
491  // ======================================================================
492  public:
493  // ======================================================================
495  void setHeader( std::string v ) { m_header = std::move( v ); }
496  // ======================================================================
498  void setFooter( std::string v ) { m_footer = std::move( v ); }
499  // ======================================================================
501  void setFormat( std::string v ) { m_format = std::move( v ); }
502  // ======================================================================
503  public:
504  // ======================================================================
506  std::string toString( const AIDA::IHistogram1D* histo ) const;
507  // ======================================================================
509  std::string toString( const AIDA::IProfile1D* histo ) const;
510  // ======================================================================
511  public:
512  // ======================================================================
536  std::string toString( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt ) const;
560  std::string toString( const AIDA::IProfile1D* histo, const std::string& ID, const std::string& fmt ) const;
561  // ======================================================================
562  public:
563  // the table header
564  std::string m_header;
565  // the table footer
566  std::string m_footer;
567  // the default format
568  std::string m_format;
569  //
570  };
571  } // namespace Histos
572  } // namespace Utils
573 } // end of namespace Gaudi
574 // ============================================================================
575 // The END
576 // ============================================================================
AIDA
Definition: Annotation.h:21
Write.stream
stream
Definition: Write.py:32
Gaudi::Utils::Histos::Formats::LineTitle
@ LineTitle
Definition: HistoTableFormat.h:104
Gaudi::Utils::Histos::Formats::Stat1
@ Stat1
Definition: HistoTableFormat.h:101
Gaudi::Utils::Histos::Formats::Shape
@ Shape
Definition: HistoTableFormat.h:103
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:94
Gaudi::Utils::Histos::Table::m_format
std::string m_format
the defautl format
Definition: HistoTableFormat.h:568
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:364
Gaudi::Utils::Histos::Table::setHeader
void setHeader(std::string v)
set new header
Definition: HistoTableFormat.h:495
Gaudi::Utils::begin
AttribStringParser::Iterator begin(const AttribStringParser &parser)
Definition: AttribStringParser.h:135
Gaudi::Utils::Histos::Formats::Old
@ Old
Definition: HistoTableFormat.h:96
Gaudi::Utils::Histos::Formats::FullStat
@ FullStat
Definition: HistoTableFormat.h:98
Gaudi::Utils::Histos::Formats::ShapeOnly
@ ShapeOnly
Definition: HistoTableFormat.h:102
Gaudi::Utils::Histos::Table::setFormat
void setFormat(std::string v)
set new format
Definition: HistoTableFormat.h:501
Gaudi::Utils::Histos::Formats::LineOnly
@ LineOnly
Definition: HistoTableFormat.h:105
Gaudi::Utils::end
AttribStringParser::Iterator end(const AttribStringParser &)
Definition: AttribStringParser.h:138
Gaudi::Utils::Histos::Table::setFooter
void setFooter(std::string v)
set new footer
Definition: HistoTableFormat.h:498
Gaudi::Utils::Histos::Formats::Full
@ Full
Definition: HistoTableFormat.h:97
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:436
Gaudi::Utils::Histos::Formats::StatOnly
@ StatOnly
Definition: HistoTableFormat.h:100
Gaudi::Utils::Histos::Table::format
const std::string & format() const
the format
Definition: HistoTableFormat.h:490
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:566
Gaudi::Utils::toString
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition: ToStream.h:326
Gaudi::Utils::Histos::Formats::Stat
@ Stat
Definition: HistoTableFormat.h:99
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:286
compareRootHistos.histos
histos
Definition: compareRootHistos.py:26
Gaudi::Utils::Histos::Formats::PathTitle
@ PathTitle
Definition: HistoTableFormat.h:106
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:452
Kernel.h
fmt
Properties.v
v
Definition: Properties.py:122
Gaudi::Utils::Histos::Table::m_header
std::string m_header
the table header
Definition: HistoTableFormat.h:564
Gaudi::Utils::Histos::Table::header
const std::string & header() const
the table header
Definition: HistoTableFormat.h:484
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:487
Gaudi::Utils::Histos::Formats::Default
@ Default
Definition: HistoTableFormat.h:95
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
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:473