![]() |
|
|
Generated: 8 Jan 2009 |
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 // ============================================================================ 00012 #include "AIDA/IHistogram1D.h" 00013 #include "AIDA/IAxis.h" 00014 // ============================================================================ 00015 // GaudiKernel 00016 // ============================================================================ 00017 #include "GaudiKernel/DataObject.h" 00018 #include "GaudiKernel/IRegistry.h" 00019 // ============================================================================ 00020 // Local 00021 // ============================================================================ 00022 #include "GaudiUtils/HistoStats.h" 00023 #include "GaudiUtils/HistoTableFormat.h" 00024 // ============================================================================ 00025 // Boost 00026 // ============================================================================ 00027 #include "boost/format.hpp" 00028 // ============================================================================ 00034 // ============================================================================ 00035 namespace 00036 { 00037 // ========================================================================== 00038 // Examples of formats 00039 // ========================================================================== 00041 const std::string s_histoFormatStat = 00042 "| %2$-45.45s | %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ; 00043 // ========================================================================== 00045 const std::string s_histoFormatStatOnly = 00046 "| %3$=7d |%8$11.5g | %10$-11.5g|%12$11.5g |%14$11.5g |" ; 00047 // ========================================================================== 00049 const std::string s_histoFormatLineTitle = 00050 " %2$-45.45s mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ; 00051 // ========================================================================== 00053 const std::string s_histoFormatLineOnly = 00054 " mean/sigma/skew/kurtosis = %8$10.4g/%10$10.4g/%12$10.4g/%14$10.4g" ; 00055 // ========================================================================== 00057 const std::string s_histoFormatOld = 00058 " %2$-45.45s Ents/All=%7$5s/%3$5s<X>/sX=%8$.5g/%10$-.5g" ; 00059 // ========================================================================== 00061 const std::string s_histoFormatPathTitle = "| %1$-45.45s | %2$-45.45s | " ; 00062 // ========================================================================== 00064 const std::string s_histoFormatFull = 00065 "| %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|" ; 00066 // ========================================================================== 00067 // headers: 00068 // ========================================================================== 00070 const std::string s_histoFormatStatHeader = 00071 "| Title | # | Mean | RMS | Skewness | Kurtosis |" ; 00072 // ========================================================================== 00074 const std::string s_histoFormatStatOnlyHeader = 00075 "| # | Mean | RMS | Skewness | Kurtosis |" ; 00076 // ========================================================================== 00078 const std::string s_histoFormatLineTitleHeader = " Title " ; 00079 // ========================================================================== 00081 const std::string s_histoFormatLineOnlyHeader = "" ; 00082 // ========================================================================== 00084 const std::string s_histoFormatOldHeader = "" ; 00085 // ========================================================================== 00087 const std::string s_histoFormatPathTitleHeader = 00088 "| Path in Histogram Data Store | Title | "; 00089 // ========================================================================== 00091 const std::string s_histoFormatFullHeader = 00092 "| Path in Histogram Data Store | Title | # |Udflw/Ovflw| nEff | Sum | Mean+-Error | RMS+-Error | Skewness+-Error | Kurtosis+-Error |" ; 00093 // ========================================================================== 00094 } 00095 // ============================================================================ 00096 // get the format by enum 00097 // ============================================================================ 00098 std::string Gaudi::Utils::Histos::Formats::format ( const int ID ) 00099 { 00100 switch ( ID ) 00101 { 00102 case Old : return s_histoFormatOld ; 00103 case Full : return s_histoFormatFull ; 00104 case Stat : return s_histoFormatStat ; 00105 case StatOnly : return s_histoFormatStatOnly ; 00106 case LineTitle : return s_histoFormatLineTitle ; 00107 case LineOnly : return s_histoFormatLineOnly ; 00108 case PathTitle : return s_histoFormatPathTitle ; 00109 default : ; 00110 } 00112 return s_histoFormatStat ; 00113 } 00114 // ============================================================================ 00115 // get the recommended header by enum 00116 // ============================================================================ 00117 std::string Gaudi::Utils::Histos::Formats::header ( const int ID ) 00118 { 00119 switch ( ID ) 00120 { 00121 case Old : return s_histoFormatOldHeader ; 00122 case Full : return s_histoFormatFullHeader ; 00123 case Stat : return s_histoFormatStatHeader ; 00124 case StatOnly : return s_histoFormatStatOnlyHeader ; 00125 case LineTitle : return s_histoFormatLineTitleHeader ; 00126 case LineOnly : return s_histoFormatLineOnlyHeader ; 00127 case PathTitle : return s_histoFormatPathTitleHeader ; 00128 default : ; 00129 } 00131 return s_histoFormatStatHeader ; 00132 } 00133 // ============================================================================ 00134 // get the path in TES for AIDA histogram 00135 // ============================================================================ 00136 std::string Gaudi::Utils::Histos::path ( const AIDA::IBaseHistogram* aida ) 00137 { 00138 if ( 0 == aida ) { return "" ; } // RETURN 00139 const DataObject* object = dynamic_cast<const DataObject*>( aida ) ; 00140 if ( 0 == object ) { return "" ; } // RETURN 00141 IRegistry* registry = object->registry() ; 00142 if ( 0 == registry ) { return "" ; } // RETURN 00143 std::string _path = registry->identifier() ; 00144 std::string::size_type n = _path.find("/stat/") ; 00145 if ( 0 == n ) { return std::string(_path,6) ; } // RETURN 00146 return _path ; // RETURN 00147 } 00148 // ============================================================================ 00149 /* Make the string representation of the historgam 00150 * according to the specified format. 00151 */ 00152 // ============================================================================ 00153 std::string Gaudi::Utils::Histos::format 00154 ( const AIDA::IHistogram1D* histo , 00155 const std::string& fmt ) 00156 { 00157 if ( 0 == histo ) { return "<NULL>" ; } 00158 using namespace Gaudi::Utils ; 00159 using namespace boost::io ; 00160 boost::format _fmt ( fmt ) ; 00161 // allow various number of arguments 00162 _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ; 00163 00164 _fmt 00165 % ( "\"" + path ( histo ) + "\"" ) // 1) histogram path 00166 % ( "\"" + histo -> title () + "\"" ) // 2) title 00167 % histo -> allEntries () // 3) # entries 00168 % histo -> binEntries ( AIDA::IAxis::UNDERFLOW_BIN ) // 4) # underflow 00169 % histo -> binEntries ( AIDA::IAxis::OVERFLOW_BIN ) // 5) # overflow 00170 % histo -> equivalentBinEntries () // 6) equivalent entries 00171 % histo -> sumBinHeights () // 7) integral 00172 % histo -> mean () // 8) mean value 00173 % HistoStats:: meanErr ( histo ) // 9) error in mean 00174 % histo -> rms () // 10) rms 00175 % HistoStats::rmsErr ( histo ) // 11) error in rms 00176 % HistoStats::skewness ( histo ) // 12) skewness 00177 % HistoStats::skewnessErr ( histo ) // 13) error in skewness 00178 % HistoStats::kurtosis ( histo ) // 14) kurtosis 00179 % HistoStats::kurtosisErr ( histo ) ; // 15) error in kurtosis 00180 // 00181 return _fmt.str() ; 00182 } 00183 // ============================================================================ 00184 /* format a full row in table, including ID, label, path or any other 00185 * "extra" identifier in string form 00186 */ 00187 // ============================================================================ 00188 std::string Gaudi::Utils::Histos::format 00189 ( const AIDA::IHistogram1D* histo , 00190 const std::string& ID , 00191 const std::string& fmt1 , 00192 const std::string& fmt2 ) 00193 { 00194 using namespace boost::io ; 00195 boost::format _fmt ( fmt1 ) ; 00196 // allow various number of arguments 00197 _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ; 00198 // 00199 _fmt 00200 % ID // format ID 00201 % format ( histo , fmt2 ) ; // format the histogram 00202 // 00203 return _fmt.str() ; 00204 } 00205 // ============================================================================ 00206 // helper method to merge the headers for short format table 00207 // ============================================================================ 00208 std::string Gaudi::Utils::Histos::format 00209 ( const std::string& val1 , 00210 const std::string& val2 , 00211 const std::string& fmt ) 00212 { 00213 using namespace boost::io ; 00214 boost::format _fmt ( fmt ) ; 00215 // allow various number of arguments 00216 _fmt.exceptions ( all_error_bits ^ ( too_many_args_bit | too_few_args_bit ) ) ; 00217 // 00218 _fmt 00219 % val1 // format ID 00220 % val2 ; // format the histogram 00221 // 00222 return _fmt.str() ; 00223 } 00224 // ============================================================================ 00225 // default constructor 00226 // ============================================================================ 00227 Gaudi::Utils::Histos::Table::Table ( const int ID ) 00228 : m_header ( Gaudi::Utils::Histos::Formats::header ( ID ) ) 00229 , m_footer () 00230 , m_format ( Gaudi::Utils::Histos::Formats::format ( ID ) ) 00231 {} 00232 // ============================================================================ 00233 Gaudi::Utils::Histos::Table::Table 00234 ( const std::string& format , 00235 const std::string& header , 00236 const std::string& footer ) 00237 : m_header ( header ) 00238 , m_footer ( footer ) 00239 , m_format ( format ) 00240 {} 00241 // ============================================================================ 00242 // format the table row using the default format 00243 // ============================================================================ 00244 std::string Gaudi::Utils::Histos::Table::toString 00245 ( const AIDA::IHistogram1D* histo ) const 00246 { return Gaudi::Utils::Histos::format ( histo , format() ) ; } 00247 // ============================================================================ 00251 // ============================================================================ 00252 std::string Gaudi::Utils::Histos::Table::toString 00253 ( const AIDA::IHistogram1D* histo , 00254 const std::string& ID , 00255 const std::string& fmt ) const 00256 { return Gaudi::Utils::Histos::format ( histo , ID , fmt , format() ) ; } 00257 // ============================================================================ 00258 00259 // ============================================================================ 00260 // The END 00261 // ============================================================================