|
||||
File indexing completed on 2025-01-18 09:57:46
0001 /***********************************************************************************\ 0002 * (c) Copyright 1998-2019 CERN for the benefit of the LHCb and ATLAS collaborations * 0003 * * 0004 * This software is distributed under the terms of the Apache version 2 licence, * 0005 * copied verbatim in the file "LICENSE". * 0006 * * 0007 * In applying this licence, CERN does not waive the privileges and immunities * 0008 * granted to it by virtue of its status as an Intergovernmental Organization * 0009 * or submit itself to any jurisdiction. * 0010 \***********************************************************************************/ 0011 #ifndef GAUDIUTILS_HISTOTABLEFORMAT_H 0012 #define GAUDIUTILS_HISTOTABLEFORMAT_H 1 0013 // ============================================================================ 0014 // Include files 0015 // ============================================================================ 0016 #include "GaudiKernel/Kernel.h" 0017 #include <string> 0018 // ============================================================================ 0019 // forward declarations 0020 // ============================================================================ 0021 namespace AIDA { 0022 class IHistogram1D; 0023 class IProfile1D; 0024 class IBaseHistogram; 0025 } // namespace AIDA 0026 // ============================================================================ 0027 namespace Gaudi { 0028 namespace Utils { 0029 // ======================================================================== 0030 /** @namespace Gaudi::Utils::Histos 0031 * Collection of useful utilities for manipulations with 0032 * AIDA hisgograms 0033 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0034 * @date 2007-08-08 0035 */ 0036 namespace Histos { 0037 // ====================================================================== 0038 /** @namespace Gaudi::Utils::Histos::Formats 0039 * 0040 * The 15 format fields are predefined now: 0041 * 0042 * - 1 : the histogram path in transient store (without '/stat/') 0043 * - 2 : the histogram title 0044 * - 3 : number of ALL entries 0045 * - 4 : number of UNDERFLOW entries 0046 * - 5 : number of OVERFLOW entries 0047 * - 6 : the statistics of equivalent entries 0048 * - 7 : the full integral in range 0049 * - 8 : mean value 0050 * - 9 : the estimated uncertainty in the mean value 0051 * - 10 : rms value 0052 * - 11 : the estimated uncertainty in the rms value 0053 * - 12 : skewness value 0054 * - 13 : the estimated uncertainty in the skewness value 0055 * - 14 : kurtosis value 0056 * - 15 : the estimated uncertainty in the kurtosis value 0057 * - 16 : full intergal (in and out-range) 0058 * - 17 : error on the full intergal (16) 0059 * - 18 : error on the full intergal in range (7) 0060 * - 19 : fraction of overflow entries [%] 0061 * - 20 : (binomial) error on fraction of overflow entries [%] 0062 * - 21 : fraction of underflow entries [%] 0063 * - 22 : (binomial) error on fraction of underflow entries [%] 0064 * - 23 : fraction of overflow integral 0065 * - 24 : error on fraction of overflow integral 0066 * - 25 : fraction of underflow integral 0067 * - 26 : error on fraction of underflow integral 0068 * 0069 * @see Gauid::Utils::HistoStats 0070 * 0071 * Unlike parameters 3-7 & 16-19, the parameters 0072 * 8-15 and 19-26 are sensitive only to 0073 * the shape of the distribution. 0074 * 0075 * Simple collection of predefiend formats for the histogram 0076 * @author Vanya BELYAEV ibelyaev@physics.syed.edu 0077 * @date 2007-08-07 0078 */ 0079 namespace Formats { 0080 // ==================================================================== 0081 /** the ID for predefined formats 0082 * - Default : the default format 0083 * - Old : the old-style format (title,integra,entries,mean,rms) 0084 * - Full : FULL information (all 15 predefiend values) 0085 * - FullStat : FULL statistical information (all 13 statistical values) 0086 * - Stat : title, #entries,mean, rms, skewness&kurtosis 0087 * - StatOnly : #entries,mean, rms, skewness&kurtosis 0088 * - Stat1 : #entries,mean+-, rms+-, skewness+-&kurtosis+- 0089 * - ShapeOnly : mean,rms,skewness,kurtosis,underflow&overflow fractions 0090 * - Shape : as ShapeOnly but with errors 0091 * - LineTitle : line-format title, mean,rms,skewness&kurtosis 0092 * - LineOnly : line-format mean,rms,skewness&kurtosis 0093 * - PathTitle : path & title 0094 */ 0095 enum Format { 0096 Default = 0, // default format 0097 Old, // "OLD"-line format: title,integral,#ent,mean,rms 0098 Full, // FULL format: the first 15 positions 0099 FullStat, // Full statistical info (3-15) 0100 Stat, // title,#ent,mean,rms,skewness&kurtosis 0101 StatOnly, // #entries,mean,rms,skewness&kurtosis 0102 Stat1, // #entries,mean+-,rms+-,skewness+-&kurtosis+- 0103 ShapeOnly, // mean,rms,skewness,kurtosis,underflow&overflow fractions 0104 Shape, // as ShapeOnly but with errors 0105 LineTitle, // line-format : title,mean,rms,skewness&kurtosis 0106 LineOnly, // line-format : mean,rms,skewness&kurtosis 0107 PathTitle // "PathTitle" : path & title 0108 }; 0109 // ==================================================================== 0110 /** get the format by enum 0111 * @see Gaudi::Utils::Histos::Formats::Format 0112 * @param ID the format idenfifier 0113 * @return format associated with ID 0114 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0115 * @date 2007-08-08 0116 */ 0117 GAUDI_API std::string format( const int ID = Default ); 0118 // ==================================================================== 0119 /** get the recommended header by enum 0120 * @see Gaudi::Utils::Histos::Formats::Format 0121 * @param ID the format idenfifier 0122 * @return header associated with ID 0123 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0124 * @date 2007-08-08 0125 */ 0126 GAUDI_API std::string header( const int ID = Default ); 0127 // ==================================================================== 0128 } // namespace Formats 0129 // ====================================================================== 0130 /** get the path in THS for AIDA histogram 0131 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0132 * @date 2007-08-08 0133 */ 0134 GAUDI_API std::string path( const AIDA::IBaseHistogram* aida ); 0135 // ====================================================================== 0136 /** Make the string representation of the histogram 0137 * according to the specified format. 0138 * The method could be used to access/print various quantities 0139 * 0140 * @code 0141 * 0142 * using namespace Gaudi::Utils::Histos ; 0143 * 0144 * const AIDA::IHistogram1D* histo = ... ; 0145 * 0146 * // print title in a free format: 0147 * std::cout << format ( histo , "%2%" ) << std::endl ; 0148 * 0149 * // print the path in HTS in a free format: 0150 * std::cout << format ( histo , " path in HTS: %1% " ) << std::endl ; 0151 * 0152 * // print the formatted nEntries/Overflow/Underflow: 0153 * std::cout << 0154 * format ( histo , " #nEntries/Overflow/Underflow=%3%/%4%/%5%" ) 0155 * << std::endl ; 0156 * 0157 * // print the formatted Mean+-ErrorMean: 0158 * std::cout << 0159 * format ( histo , " Mean+-Error=(%8%+-%9%)" ) 0160 * << std::endl ; 0161 * 0162 * // print the skewness and kurtosis: 0163 * std::cout << 0164 * format ( histo , " Skewness/Kurtosis=%12%/%14% " ) 0165 * << std::endl ; 0166 * 0167 * @endcode 0168 * 0169 * @param histo reference to the histogram 0170 * @param fmt the printout format 0171 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0172 * @date 2007-08-08 0173 */ 0174 GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& fmt ); 0175 // ====================================================================== 0176 /** Make the string representation of the profile histogram 0177 * according to the specified format. 0178 * The method could be used to access/print various quantities 0179 * 0180 * @code 0181 * 0182 * using namespace Gaudi::Utils::Histos ; 0183 * 0184 * const AIDA::IProfile1D* histo = ... ; 0185 * 0186 * // print title in a free format: 0187 * std::cout << format ( histo , "%2%" ) << std::endl ; 0188 * 0189 * // print the path in HTS in a free format: 0190 * std::cout << format ( histo , " path in HTS: %1% " ) << std::endl ; 0191 * 0192 * @endcode 0193 * 0194 * @param histo reference to the histogram 0195 * @param fmt the printout format 0196 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0197 * @date 2007-08-08 0198 */ 0199 GAUDI_API std::string format( const AIDA::IProfile1D* histo, const std::string& fmt ); 0200 // ====================================================================== 0201 /** format a full row in table, including ID, label, path or any other 0202 * "extra" identifier in string form 0203 * 0204 * @code 0205 * 0206 * using namespace Gaudi::Utils::Histos 0207 * const AIDA::IHistogram1D* histo = ... ; 0208 * 0209 * // define short format 0210 * const std::string fmt1 = " |%1$-30.30s %|33t| %2" ; 0211 * 0212 * // define format for the histogram 0213 * const std::string fmt2 = ... ; 0214 * 0215 * info () << 0216 * format ( "My Histo" , histo , fmt1 , fmt2 ) 0217 * << endmsg ; 0218 * 0219 * @endcode 0220 * 0221 * @param histo pointer to the histogram 0222 * @param ID historgam ID, title, label or other extra information 0223 * @param fmt1 "short" format used for the table 0224 * @param fmt2 format used for the histogram printout 0225 * @return formatted row 0226 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0227 * @date 2007-08-08 0228 */ 0229 GAUDI_API std::string format( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt1, 0230 const std::string& fmt2 ); 0231 // ====================================================================== 0232 /** format a full row in table, including ID, label, path or any other 0233 * "extra" identifier in string form 0234 * 0235 * @code 0236 * 0237 * using namespace Gaudi::Utils::Histos 0238 * const AIDA::IProfile1D* histo = ... ; 0239 * 0240 * // define short format 0241 * const std::string fmt1 = " |%1$-30.30s %|33t| %2" ; 0242 * 0243 * // define format for the histogram 0244 * const std::string fmt2 = ... ; 0245 * 0246 * info () << 0247 * format ( "My Histo" , histo , fmt1 , fmt2 ) 0248 * << endmsg ; 0249 * 0250 * @endcode 0251 * 0252 * @param histo pointer to the histogram 0253 * @param ID historgam ID, title, label or other extra information 0254 * @param fmt1 "short" format used for the table 0255 * @param fmt2 format used for the histogram printout 0256 * @return formatted row 0257 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0258 * @date 2007-08-08 0259 */ 0260 GAUDI_API std::string format( const AIDA::IProfile1D* histo, const std::string& ID, const std::string& fmt1, 0261 const std::string& fmt2 ); 0262 // ======================================================================== 0263 /** print the simple sequence (list-like) of histograms as table 0264 * 0265 * @code 0266 * 0267 * SEQUENCE histos = ... ; 0268 * 0269 * // print a table with three colums path, title and #entries 0270 * 0271 * Gaudi::Utils::Histos::printList 0272 * ( histos.begin () , 0273 * histos.end () , 0274 * " | %1$|-40.40s | %2$-30.30s | %3$=7d | " , 0275 * std::cout , 0276 * '\n' ) ; 0277 * 0278 * @endcode 0279 * 0280 * @param first begin-iterator for the sequence 0281 * @param last end-iterator for the sequence 0282 * @param stream the stream to be used for printout 0283 * @param term the terminmator for the stream 0284 * @param fmt the format to be used 0285 */ 0286 template <class HISTO, class STREAM, class TERMINATOR> 0287 inline STREAM& printList( HISTO first, HISTO last, const std::string& fmt, STREAM& stream, TERMINATOR term ) { 0288 for ( ; first != last; ++first ) { stream << format( *first, fmt ) << term; } // print table rows 0289 return stream; // RETURN 0290 } 0291 // ====================================================================== 0292 /** print the simple container of histograms as table 0293 * 0294 * @code 0295 * 0296 * using namespace Gaudi::Utils::Histos ; 0297 * 0298 * SEQUENCE histos = ... ; 0299 * 0300 * // print a table with three columns: path, title and #entries 0301 * 0302 * printList 0303 * ( histos , 0304 * " | %1$|-40.40s | %2$-30.30s | %3$=7d | " , 0305 * std::cout , 0306 * '\n' ) ; 0307 * 0308 * @endcode 0309 * 0310 * @param histos the sequence of histograms 0311 * @param stream the stream to be used for printout 0312 * @param term the terminmator for the stream 0313 * @param fmt the format to be used 0314 */ 0315 template <class LIST, class STREAM, class TERMINATOR> 0316 inline STREAM& printList( const LIST& histos, const std::string& fmt, STREAM& stream, TERMINATOR term ) { 0317 return printList( histos.begin(), histos.end(), fmt, stream, term ); 0318 } 0319 // ====================================================================== 0320 /** Print the "associative sequence" (e.g. part of std:map) of 0321 * histograms as table: 0322 * 0323 * @code 0324 * 0325 * using namespace Gaudi::Utils::Histos ; 0326 * 0327 * const std::map<std::string,AIDA::IHistogram1D*>& m = ... ; 0328 * 0329 * printMap 0330 * ( m.begin () , 0331 * m.end () , 0332 * "| %1$-10.10s | %2% " , // short format 0333 * Gaudi::Utils::Histos::Formats::histoFormatOnly , 0334 * always() , 0335 * endmsg ) ; 0336 * 0337 * @endcode 0338 * 0339 * Print only mean and rms: 0340 * 0341 * @code 0342 * 0343 * using namespace Gaudi::Utils::Histos ; 0344 * 0345 * const std::map<GaudiAlg::ID,AIDA::IHistogram1D*>& m = ... ; 0346 * 0347 * printMap 0348 * ( m.begin () , 0349 * m.end () , 0350 * "| %1$-10.10s | %2% " , // short format 0351 * " %8$10.5g+-%10$-10.5g|", // mean+-rms 0352 * always() , 0353 * endmsg ) ; 0354 * 0355 * @endcode 0356 * 0357 * @param begin 'begin'-iterator for the mapping sequence 0358 * @param end 'end'-iterator for the mapping sequence 0359 * @param fmt1 'short' format for the table printout 0360 * @param fmt3 format for the printout of the histogram 0361 * @param stream the stream for printout 0362 * @param term stream terminator 0363 */ 0364 template <class HISTO, class STREAM, class TERMINATOR> 0365 inline STREAM& printMap( HISTO begin, HISTO end, const std::string& fmt1, const std::string& fmt2, STREAM& stream, 0366 TERMINATOR term ) { 0367 for ( ; begin != end; ++begin ) { 0368 stream << format( begin->second, // the histogram 0369 begin->first, // the key 0370 fmt1, fmt2 ) 0371 << term; 0372 } 0373 return stream; 0374 } 0375 // ====================================================================== 0376 /** Print the "associative sequence" (e.g. part of std:map) of 0377 * histograms as table: 0378 * 0379 * @code 0380 * 0381 * using namespace Gaudi::Utils::Histos ; 0382 * 0383 * const std::map<std::string,AIDA::IHistogram1D*>& m = ... ; 0384 * 0385 * printMap 0386 * ( m , 0387 * "| %1$-10.10s | %2% " , // short format 0388 * Gaudi::Utils::Histos::Formats::histoFormatOnly , 0389 * always() , 0390 * endmsg ) ; 0391 * 0392 * @endcode 0393 * 0394 * Print only mean and rms: 0395 * 0396 * @code 0397 * 0398 * using namespace Gaudi::Utils::Histos ; 0399 * 0400 * const std::map<GaudiAlg::ID,AIDA::IHistogram1D*>& m = ... ; 0401 * 0402 * printMap 0403 * ( m , 0404 * "| %1$-10.10s | %2% " , // short format 0405 * " %8$10.5g+-%10$-10.5g|", // mean+-rms 0406 * always() , 0407 * endmsg ) ; 0408 * 0409 * @endcode 0410 * 0411 * @param begin 'begin'-iterator for the mapping sequence 0412 * @param end 'end'-iterator for the mapping sequence 0413 * @param fmt1 'short' format for the table printout 0414 * @param fmt3 format for the printout of the histogram 0415 * @param stream the stream for printout 0416 * @param term stream terminator 0417 */ 0418 template <class MAP, class STREAM, class TERMINATOR> 0419 inline STREAM& printMap( const MAP& histos, const std::string& fmt1, const std::string& fmt2, STREAM& stream, 0420 TERMINATOR term ) { 0421 return printMap( histos.begin(), histos.end(), fmt1, fmt2, stream, term ); 0422 } 0423 // ====================================================================== 0424 /** helper method to merge the headers for short format table 0425 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0426 * @date 2007-08-07 0427 */ 0428 GAUDI_API std::string format( const std::string& val1, const std::string& val2, const std::string& fmt ); 0429 // ====================================================================== 0430 /** @class Table HistoTableFormat.h GaudiUtils/HistoTableFormat.h 0431 * Simple class for the customizeble printout of the histogram tables 0432 * 0433 * @author Vanya BELYAEV ibelyaev@physics.syr.edu 0434 * @date 2007-08-07 0435 */ 0436 // ======================================================================== 0437 class GAUDI_API Table { 0438 public: 0439 /// constructor from enum 0440 Table( const int ID = 0 ); 0441 /// Constructor from the format, header and footer 0442 Table( const std::string& format, const std::string& header = "", const std::string& footer = "" ); 0443 0444 public: 0445 // ====================================================================== 0446 /** print the simple sequence of histograms as table 0447 * @param first begin-iterator for the sequence 0448 * @param last end-iterator for the sequence 0449 * @param stream the stream to be used for printout 0450 * @param term the terminmator for the stream 0451 */ 0452 template <class HISTO, class STREAM, class TERMINATOR> 0453 STREAM& printList( HISTO first, HISTO last, STREAM& stream, TERMINATOR term ) const { 0454 if ( !header().empty() ) { stream << header() << term; } 0455 Gaudi::Utils::Histos::printList( first, last, format(), stream, term ); 0456 if ( !footer().empty() ) { stream << footer() << term; } 0457 return stream; 0458 } 0459 // ====================================================================== 0460 public: 0461 /** print as table the content of the accociative map 0462 * (key->histogram) with the key, convertible to std::string 0463 * 0464 * The default format is used for histogram prinout 0465 * 0466 * @param first 'begin'-iterator for the mapping sequence 0467 * @param last 'end'-iterator for the mapping sequence 0468 * @param fmt 'short' format for the table printout 0469 * @param hval the name of the "key"-column 0470 * @param stream the stream for printout 0471 * @param term stream terminator 0472 */ 0473 template <class HISTO, class STREAM, class TERMINATOR> 0474 STREAM& printMap( HISTO first, HISTO last, const std::string& fmt, const std::string& hval, STREAM& stream, 0475 TERMINATOR term ) const { 0476 if ( !hval.empty() || !header().empty() ) { 0477 stream << Gaudi::Utils::Histos::format( hval, header(), fmt ) << term; 0478 } 0479 return Gaudi::Utils::Histos::printMap( first, last, fmt, format(), stream, term ); 0480 } 0481 // ====================================================================== 0482 public: 0483 // ====================================================================== 0484 /// the table header 0485 const std::string& header() const { return m_header; } 0486 // ====================================================================== 0487 /// the table footer 0488 const std::string& footer() const { return m_footer; } 0489 // ====================================================================== 0490 /// the format 0491 const std::string& format() const { return m_format; } 0492 // ====================================================================== 0493 public: 0494 // ====================================================================== 0495 /// set new header 0496 void setHeader( std::string v ) { m_header = std::move( v ); } 0497 // ====================================================================== 0498 /// set new footer 0499 void setFooter( std::string v ) { m_footer = std::move( v ); } 0500 // ====================================================================== 0501 /// set new format 0502 void setFormat( std::string v ) { m_format = std::move( v ); } 0503 // ====================================================================== 0504 public: 0505 // ====================================================================== 0506 /// make the string representation according to the default format 0507 std::string toString( const AIDA::IHistogram1D* histo ) const; 0508 // ====================================================================== 0509 /// make the string representation according to the default format 0510 std::string toString( const AIDA::IProfile1D* histo ) const; 0511 // ====================================================================== 0512 public: 0513 // ====================================================================== 0514 /** format a full row in table, including ID, label, path or any other 0515 * "extra" identifier 0516 * 0517 * @code 0518 * 0519 * using namespace Gaudi::Utils::Histos ; 0520 * 0521 * const Table& table = ... ; 0522 * 0523 * const AIDA::IHistogram1D* histo = ... ; 0524 * 0525 * // define short format 0526 * const std::string fmt1 = " |%1$-30.30s %|33t| %2" ; 0527 * 0528 * info () << table.toString ( "My Histo" , histo , fmt ) ; 0529 * 0530 * @endcode 0531 * 0532 * @param histo pointer to the histogram 0533 * @param ID historgam ID, title, label or other extra infomration 0534 * @param fmt "short" format used for the table 0535 * @return formatted row 0536 */ 0537 std::string toString( const AIDA::IHistogram1D* histo, const std::string& ID, const std::string& fmt ) const; 0538 /** format a full row in table, including ID, label, path or any other 0539 * "extra" identifier 0540 * 0541 * @code 0542 * 0543 * using namespace Gaudi::Utils::Histos ; 0544 * 0545 * const Table& table = ... ; 0546 * 0547 * const AIDA::IProfile1D* histo = ... ; 0548 * 0549 * // define short format 0550 * const std::string fmt1 = " |%1$-30.30s %|33t| %2" ; 0551 * 0552 * info () << table.toString ( "My Histo" , histo , fmt ) ; 0553 * 0554 * @endcode 0555 * 0556 * @param histo pointer to the histogram 0557 * @param ID historgam ID, title, label or other extra infomration 0558 * @param fmt "short" format used for the table 0559 * @return formatted row 0560 */ 0561 std::string toString( const AIDA::IProfile1D* histo, const std::string& ID, const std::string& fmt ) const; 0562 // ====================================================================== 0563 public: 0564 // the table header 0565 std::string m_header; ///< the table header 0566 // the table footer 0567 std::string m_footer; ///< the table footer 0568 // the default format 0569 std::string m_format; ///< the defautl format 0570 // 0571 }; 0572 } // namespace Histos 0573 } // namespace Utils 0574 } // end of namespace Gaudi 0575 // ============================================================================ 0576 // The END 0577 // ============================================================================ 0578 #endif // GAUDIUTILS_HISTOTABLEFORMAT_H
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |