The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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// ============================================================================
20namespace AIDA {
21 class IHistogram1D;
22 class IProfile1D;
23 class IBaseHistogram;
24} // namespace AIDA
25// ============================================================================
26namespace 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 // ========================================================================
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// ============================================================================
#define GAUDI_API
Definition Kernel.h:49
GAUDI_API std::string format(const char *,...)
MsgStream format utility "a la sprintf(...)".
Definition MsgStream.cpp:93
const std::string & format() const
the format
std::string m_footer
the table footer
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::...
Table(const int ID=0)
constructor from enum
void setFooter(std::string v)
set new footer
std::string m_format
the defautl format
void setHeader(std::string v)
set new header
std::string m_header
the table header
const std::string & footer() const
the table footer
void setFormat(std::string v)
set new format
const std::string & header() const
the table header
STREAM & printList(HISTO first, HISTO last, STREAM &stream, TERMINATOR term) const
print the simple sequence of histograms as table
The 15 format fields are predefined now:
GAUDI_API std::string format(const int ID=Default)
get the format by enum
GAUDI_API std::string header(const int ID=Default)
get the recommended header by enum
Format
the ID for predefined formats
Collection of useful utilities for manipulations with AIDA hisgograms.
Definition HistoDump.h:27
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.
STREAM & printList(HISTO first, HISTO last, const std::string &fmt, STREAM &stream, TERMINATOR term)
print the simple sequence (list-like) of histograms as table
STREAM & printMap(HISTO begin, HISTO end, const std::string &fmt1, const std::string &fmt2, STREAM &stream, TERMINATOR term)
Print the "associative sequence" (e.g.
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
std::string toString(const TYPE &obj)
the generic implementation of the type conversion to the string
Definition ToStream.h:326
AttribStringParser::Iterator begin(const AttribStringParser &parser)
AttribStringParser::Iterator end(const AttribStringParser &)
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition __init__.py:1