Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

HistoTableFormat.cpp

Go to the documentation of this file.
00001 // $Id: HistoTableFormat.cpp,v 1.2 2008/04/03 22:12:27 marcocle Exp $
00002 // ============================================================================
00003 // Include files
00004 // ============================================================================
00005 // STD & STL
00006 // ============================================================================
00007 #include <string>
00008 #include <cmath>
00009 // ============================================================================
00010 // AIDA
00011 // ============================================================================
00013 #include <vector>
00014 #include "GaudiKernel/Kernel.h"
00015 #define class class GAUDI_API
00016 #include "AIDA/IHistogram1D.h"
00017 #include "AIDA/IAxis.h"
00018 #undef class
00019 // ============================================================================
00020 // GaudiKernel
00021 // ============================================================================
00022 #include "GaudiKernel/DataObject.h"
00023 #include "GaudiKernel/IRegistry.h"
00024 // ============================================================================
00025 // Local
00026 // ============================================================================
00027 #include "GaudiUtils/HistoStats.h"
00028 #include "GaudiUtils/HistoTableFormat.h"
00029 // ============================================================================
00030 // Boost
00031 // ============================================================================
00032 #include "boost/format.hpp"
00033 // ============================================================================
00039 // ============================================================================
00040 namespace
00041 {
00042   // ==========================================================================
00043   // Examples of formats
00044   // ==========================================================================
00046   const std::string s_histoFormatStat       =
00047     "| %2$-45.45s | %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
00048   // ==========================================================================
00050   const std::string s_histoFormatStatOnly   =
00051     "| %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ;
00052   // ==========================================================================
00054   const std::string s_histoFormatStat1   =
00055     "| %3$=7d |%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|" ;
00056   // ==========================================================================
00060   const std::string s_histoFormatShapeOnly   =
00061   "|%8$11.5g |%10$11.5g |%12$11.5g |%14$11.5g |%19$11.5g/%21$-11.5g|" ;
00062   // ==========================================================================
00067   const std::string s_histoFormatShape      =
00068   "|%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|%19$9.3g+-%20$-9.3g|%21$9.3g+-%22$-9.3g|" ;
00069   // ==========================================================================
00071   const std::string s_histoFormatLineTitle  =
00072     " %2$-45.45s mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
00073   // ==========================================================================
00075   const std::string s_histoFormatLineOnly   =
00076     " mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ;
00077   // ==========================================================================
00079   const std::string s_histoFormatOld        =
00080     " %2$-45.45s    Ents/All=%7$5s/%3$5s<X>/sX=%8$.5g/%10$-.5g" ;
00081   // ==========================================================================
00083   const std::string s_histoFormatPathTitle = "| %1$-45.45s | %2$-45.45s | " ;
00084   // ==========================================================================
00086   const std::string s_histoFormatFull       =
00087     "| %1$-45.45s | %2$-45.45s | %3$=7d |%4$5d/%5$-5d|%6$9.3g | %7$-9.3g|%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|" ;
00089   const std::string s_histoFormatFullStat   =
00090     "| %3$=7d |%4$5d/%5$-5d|%6$9.3g | %7$-9.3g|%8$9.3g+-%9$-9.3g|%10$9.3g+-%11$-9.3g|%12$9.3g+-%13$-9.3g|%14$9.3g+-%15$-9.3g|" ;
00091   // ==========================================================================
00092   // headers:
00093   // ==========================================================================
00095   const std::string s_histoFormatStatHeader =
00096     "|   Title                                       |    #    |     Mean   |    RMS     |  Skewness  |  Kurtosis  |" ;
00097   // ==========================================================================
00099   const std::string s_histoFormatStatOnlyHeader =
00100     "|    #    |     Mean   |    RMS     |  Skewness  |  Kurtosis  |" ;
00101   // ==========================================================================
00103   const std::string s_histoFormatStat1Header    =
00104     "|    #    |     Mean+-Error    |      RMS+-Error    | Skewness+-Error    | Kurtosis+-Error    |" ;
00105   // ==========================================================================
00107   const std::string s_histoFormatShapeOnlyHeader =
00108   "|     Mean   |    RMS     |  Skewness  |  Kurtosis  | Underflow%/Overflow%  |" ;
00109   // ==========================================================================
00111   const std::string s_histoFormatShapeHeader =
00112   "|        Mean        |         RMS        |      Skewness      |     Kurtosis       |    Underflow [%]   |    Overflow [%]    |" ;
00113   // ==========================================================================
00115   const std::string s_histoFormatLineTitleHeader = "  Title " ;
00116   // ==========================================================================
00118   const std::string s_histoFormatLineOnlyHeader  = "" ;
00119   // ==========================================================================
00121   const std::string s_histoFormatOldHeader       = "" ;
00122   // ==========================================================================
00124   const std::string s_histoFormatPathTitleHeader =
00125     "| Path in Histogram Data Store   |  Title                         | ";
00126   // ==========================================================================
00128   const std::string s_histoFormatFullHeader =
00129     "| Path in Histogram Data Store   |  Title                         |    #    |Udflw/Ovflw|    nEff  | Sum      |     Mean+-Error    |      RMS+-Error    | Skewness+-Error    | Kurtosis+-Error    |" ;
00130   // ==========================================================================
00132   const std::string s_histoFormatFullStatHeader =
00133     "|    #    |Udflw/Ovflw|    nEff  | Sum      |     Mean+-Error    |      RMS+-Error    | Skewness+-Error    | Kurtosis+-Error    |" ;
00134   // ==========================================================================
00135 }
00136 // ============================================================================
00137 // get the format by enum
00138 // ============================================================================
00139 std::string Gaudi::Utils::Histos::Formats::format ( const int ID )
00140 {
00141   switch ( ID )
00142   {
00143   case Old       : return s_histoFormatOld       ;
00144   case Full      : return s_histoFormatFull      ;
00145   case FullStat  : return s_histoFormatFullStat  ;
00146   case Stat      : return s_histoFormatStat      ;
00147   case StatOnly  : return s_histoFormatStatOnly  ;
00148   case Stat1     : return s_histoFormatStat1     ;
00149   case ShapeOnly : return s_histoFormatShapeOnly ;
00150   case Shape     : return s_histoFormatShape     ;
00151   case LineTitle : return s_histoFormatLineTitle ;
00152   case LineOnly  : return s_histoFormatLineOnly  ;
00153   case PathTitle : return s_histoFormatPathTitle ;
00154   default        : ;
00155   }
00157   return s_histoFormatStat ;
00158 }
00159 // ============================================================================
00160 // get the recommended header by enum
00161 // ============================================================================
00162 std::string Gaudi::Utils::Histos::Formats::header ( const int ID  )
00163 {
00164   switch ( ID )
00165   {
00166   case Old       : return s_histoFormatOldHeader       ;
00167   case Full      : return s_histoFormatFullHeader      ;
00168   case FullStat  : return s_histoFormatFullStatHeader  ;
00169   case Stat      : return s_histoFormatStatHeader      ;
00170   case Stat1     : return s_histoFormatStat1Header     ;
00171   case StatOnly  : return s_histoFormatStatOnlyHeader  ;
00172   case ShapeOnly : return s_histoFormatShapeOnlyHeader ;
00173   case Shape     : return s_histoFormatShapeHeader     ;
00174   case LineTitle : return s_histoFormatLineTitleHeader ;
00175   case LineOnly  : return s_histoFormatLineOnlyHeader  ;
00176   case PathTitle : return s_histoFormatPathTitleHeader ;
00177   default        : ;
00178   }
00180   return s_histoFormatStatHeader ;
00181 }
00182 // ============================================================================
00183 // get the path in TES for AIDA histogram
00184 // ============================================================================
00185 std::string Gaudi::Utils::Histos::path ( const AIDA::IBaseHistogram* aida )
00186 {
00187   if ( 0 == aida     ) { return "" ; }                          // RETURN
00188   const DataObject* object   = dynamic_cast<const DataObject*>( aida ) ;
00189   if ( 0 == object   ) { return "" ; }                          // RETURN
00190   IRegistry*        registry = object->registry() ;
00191   if ( 0 == registry ) { return "" ; }                          // RETURN
00192   std::string _path = registry->identifier() ;
00193   std::string::size_type n = _path.find("/stat/") ;
00194   if ( 0 == n ) { return std::string(_path,6) ; }               // RETURN
00195   return _path ;                                                // RETURN
00196 }
00197 // ============================================================================
00198 /*  Make the string representation of the historgam
00199  *  according to the specified format.
00200  */
00201 // ============================================================================
00202 std::string Gaudi::Utils::Histos::format
00203 ( const AIDA::IHistogram1D* histo  ,
00204   const std::string&        fmt    )
00205 {
00206   if ( 0 == histo ) { return "<NULL>" ; }
00207   using namespace Gaudi::Utils ;
00208   using namespace boost::io ;
00209   boost::format _fmt ( fmt ) ;
00210   // allow various number of arguments
00211   _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00212 
00213   _fmt
00214     % ( "\"" + path ( histo )    + "\"" )   //  1) histogram path
00215     % ( "\"" + histo -> title () + "\"" )   //  2) title
00216     % histo -> allEntries            ()     //  3) # entries
00217     % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) // 4) # underflow
00218     % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN  ) // 5) # overflow
00219     % histo -> equivalentBinEntries  ()     //  6) equivalent entries
00220     % histo -> sumBinHeights         ()     //  7) integral
00221     % histo -> mean                  ()     //  8) mean value
00222     % HistoStats:: meanErr    ( histo )     //  9) error in mean
00223     % histo -> rms                   ()     // 10) rms
00224     % HistoStats::rmsErr      ( histo )     // 11) error in rms
00225     % HistoStats::skewness    ( histo )     // 12) skewness
00226     % HistoStats::skewnessErr ( histo )     // 13) error in skewness
00227     % HistoStats::kurtosis    ( histo )     // 14) kurtosis
00228     % HistoStats::kurtosisErr ( histo )     // 15) error in kurtosis
00229     //
00230     % histo -> sumAllBinHeights      ()     // 16) full integral (in and out range)
00231     % HistoStats::sumAllBinHeightErr ( histo ) // 17) error on 16
00232     % HistoStats::sumBinHeightErr    ( histo ) // 18) error on  7
00233     //
00234     % ( 100 * HistoStats::underflowEntriesFrac     ( histo ) ) // 19) fraction of underflow entries
00235     % ( 100 * HistoStats::underflowEntriesFracErr  ( histo ) ) // 20) error on 19
00236     % ( 100 * HistoStats::overflowEntriesFrac      ( histo ) ) // 21) fraction of overflow entries
00237     % ( 100 * HistoStats::overflowEntriesFracErr   ( histo ) ) // 22) error on 21
00238     //
00239     % HistoStats::underflowIntegralFrac    ( histo ) // 23) fraction of underflow integral
00240     % HistoStats::underflowIntegralFracErr ( histo ) // 24) error on 23
00241     % HistoStats::overflowIntegralFrac     ( histo ) // 25) fraction of overflow intergal
00242     % HistoStats::overflowIntegralFracErr  ( histo ) ; // 26) error on 25
00243   //
00244   return _fmt.str() ;
00245 }
00246 // ============================================================================
00247 /* format a full row in table, including ID, label, path or any other
00248  *  "extra" identifier in string form
00249  */
00250 // ============================================================================
00251 std::string Gaudi::Utils::Histos::format
00252 ( const AIDA::IHistogram1D* histo  ,
00253   const std::string&        ID     ,
00254   const std::string&        fmt1   ,
00255   const std::string&        fmt2   )
00256 {
00257   using namespace boost::io ;
00258   boost::format _fmt ( fmt1 ) ;
00259   // allow various number of arguments
00260   _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00261   //
00262   _fmt
00263     % ID                         // format ID
00264     % format ( histo , fmt2 )  ; // format the histogram
00265   //
00266   return _fmt.str() ;
00267 }
00268 // ============================================================================
00269 // helper method to merge the headers for short format table
00270 // ============================================================================
00271 std::string Gaudi::Utils::Histos::format
00272 ( const std::string& val1 ,
00273   const std::string& val2 ,
00274   const std::string& fmt  )
00275 {
00276   using namespace boost::io ;
00277   boost::format _fmt ( fmt ) ;
00278   // allow various number of arguments
00279   _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ;
00280   //
00281   _fmt
00282     % val1   // format ID
00283     % val2 ; // format the histogram
00284   //
00285   return _fmt.str() ;
00286 }
00287 // ============================================================================
00288 // default constructor
00289 // ============================================================================
00290 Gaudi::Utils::Histos::Table::Table ( const int ID )
00291   : m_header ( Gaudi::Utils::Histos::Formats::header ( ID ) )
00292   , m_footer ()
00293   , m_format ( Gaudi::Utils::Histos::Formats::format ( ID ) )
00294 {}
00295 // ============================================================================
00296 Gaudi::Utils::Histos::Table::Table
00297 (  const std::string& format ,
00298    const std::string& header ,
00299    const std::string& footer )
00300   : m_header ( header )
00301   , m_footer ( footer )
00302   , m_format ( format )
00303 {}
00304 // ============================================================================
00305 // format the table row using the default format
00306 // ============================================================================
00307 std::string Gaudi::Utils::Histos::Table::toString
00308 ( const AIDA::IHistogram1D* histo  ) const
00309 { return Gaudi::Utils::Histos::format ( histo , format() ) ; }
00310 // ============================================================================
00314 // ============================================================================
00315 std::string Gaudi::Utils::Histos::Table::toString
00316 ( const AIDA::IHistogram1D* histo  ,
00317   const std::string&        ID     ,
00318   const std::string&        fmt    ) const
00319 { return Gaudi::Utils::Histos::format ( histo , ID , fmt , format() ) ; }
00320 // ============================================================================
00321 
00322 // ============================================================================
00323 // The END
00324 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:25:05 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004