00001
00002
00003
00004
00005
00006 #include "TH1D.h"
00007 #include "TH2D.h"
00008 #include "TH1F.h"
00009 #include "TH2F.h"
00010
00011
00012
00013 #include "AIDA/IHistogram1D.h"
00014 #include "AIDA/IHistogram2D.h"
00015
00016
00017
00018 #include "GaudiKernel/ToStream.h"
00019
00020
00021
00022 #include "GaudiUtils/Aida2ROOT.h"
00023 #include "GaudiUtils/Histo2String.h"
00024 #include "GaudiUtils/HistoXML.h"
00025
00031
00032 namespace
00033 {
00034
00035 template <class HISTO>
00036 std::ostream& _toStream_1D_
00037 ( const HISTO& histo ,
00038 std::ostream& stream ,
00039 const bool asXML )
00040 {
00041 if ( asXML ) { return Gaudi::Utils::Histos::toXml ( histo , stream ) ; }
00042
00043 stream << "{ " ;
00044
00045 stream << "'name' : " ;
00046 Gaudi::Utils::toStream ( std::string ( histo.GetName () ) , stream ) << " , " ;
00047 stream << "'title' : " ;
00048 Gaudi::Utils::toStream ( std::string ( histo.GetTitle() ) , stream ) << " , " ;
00049
00050 const TAxis* axis = histo.GetXaxis() ;
00051 const unsigned int nBins = axis->GetNbins() ;
00052 if ( axis->IsVariableBinSize() )
00053 {
00054 const TArrayD* xbins = axis->GetXbins() ;
00055 const unsigned int xsize = xbins->GetSize() ;
00056 std::vector<double> edges ;
00057 for ( unsigned int iBin = 0 ; iBin < xsize ; ++iBin )
00058 { edges.push_back ( xbins->At( iBin ) ) ; }
00059
00060 stream << std::endl ;
00061 stream << "'edges' : " ;
00062 Gaudi::Utils::toStream ( edges , stream ) << " ," << std::endl;
00063 }
00064 else
00065 {
00066 stream << "'nbins' : " ;
00067 Gaudi::Utils::toStream ( nBins , stream ) << " , " ;
00068 stream << "'low' : " ;
00069 Gaudi::Utils::toStream ( axis->GetXmin () , stream ) << " , " ;
00070 stream << "'high' : " ;
00071 Gaudi::Utils::toStream ( axis->GetXmax () , stream ) << " , " << std::endl ;
00072 }
00073
00074 std::vector<std::pair<double,double> > bins ;
00075 for ( unsigned int iBin = 0 ; iBin <= nBins + 1 ; ++iBin )
00076 {
00077 bins.push_back ( std::make_pair( histo.GetBinContent( iBin ) ,
00078 histo.GetBinError ( iBin ) ) ) ;
00079 }
00080 stream << "'bins' : " ;
00081 Gaudi::Utils::toStream ( bins , stream ) ;
00082
00083 stream << " }" ;
00084
00085 return stream ;
00086 }
00087
00088 template <class HISTO>
00089 std::ostream& _toStream_2D_
00090 ( const HISTO& histo ,
00091 std::ostream& stream ,
00092 const bool asXML )
00093 {
00094 if ( asXML ) { return Gaudi::Utils::Histos::toXml ( histo , stream ) ; }
00095
00096 stream << "{ " ;
00097
00098 stream << "'name' : " ;
00099 Gaudi::Utils::toStream ( std::string( histo.GetName () ) , stream ) << " , " ;
00100 stream << "'title' : " ;
00101 Gaudi::Utils::toStream ( std::string( histo.GetTitle() ) , stream ) << " , " ;
00102
00103 const TAxis* xaxis = histo.GetXaxis() ;
00104 const int xBins = xaxis->GetNbins() ;
00105
00106 stream << std::endl << "'X' : { " ;
00107 if ( xaxis->IsVariableBinSize() )
00108 {
00109 const TArrayD* xbins = xaxis->GetXbins() ;
00110 const unsigned int xsize = xbins->GetSize() ;
00111 std::vector<double> edges ;
00112 for ( unsigned int iBin = 0 ; iBin < xsize ; ++iBin )
00113 { edges.push_back ( xbins->At( iBin ) ) ; }
00114
00115 stream << "'edges' : " ;
00116 Gaudi::Utils::toStream ( edges , stream ) << " }," << std::endl;
00117 }
00118 else
00119 {
00120 stream << "'nbins' : " ;
00121 Gaudi::Utils::toStream ( xBins , stream ) << " , " ;
00122 stream << "'low' : " ;
00123 Gaudi::Utils::toStream ( xaxis->GetXmin () , stream ) << " , " ;
00124 stream << "'high' : " ;
00125 Gaudi::Utils::toStream ( xaxis->GetXmax () , stream ) << " }, " << std::endl ;
00126 }
00127
00128 const TAxis* yaxis = histo.GetYaxis() ;
00129 const int yBins = yaxis->GetNbins() ;
00130
00131 stream << std::endl << "'Y' : { " ;
00132 if ( yaxis->IsVariableBinSize() )
00133 {
00134 const TArrayD* ybins = yaxis->GetXbins() ;
00135 const unsigned int ysize = ybins->GetSize() ;
00136 std::vector<double> edges ;
00137 for ( unsigned int iBin = 0 ; iBin < ysize ; ++iBin )
00138 { edges.push_back ( ybins->At( iBin ) ) ; }
00139
00140 stream << " 'edges' : " ;
00141 Gaudi::Utils::toStream ( edges , stream ) << " }," << std::endl;
00142 }
00143 else
00144 {
00145 stream << "'nbins' : " ;
00146 Gaudi::Utils::toStream ( yBins , stream ) << " , " ;
00147 stream << "'low' : " ;
00148 Gaudi::Utils::toStream ( yaxis->GetXmin () , stream ) << " , " ;
00149 stream << "'high' : " ;
00150 Gaudi::Utils::toStream ( yaxis->GetXmax () , stream ) << " }, " << std::endl ;
00151 }
00152
00153
00154 stream << "'bins' : " << std::endl << " [ " ;
00155 for ( int jBin = yBins + 1 ; jBin >= 0 ; --jBin )
00156 {
00157 if ( yBins + 1 != jBin ) { stream << std::endl ; }
00158 for ( int iBin = 0 ; iBin <= xBins + 1 ; ++iBin )
00159 {
00160
00161 Gaudi::Utils::toStream ( std::make_pair
00162 ( histo.GetBinContent( iBin , jBin ) ,
00163 histo.GetBinError ( iBin , jBin ) ) , stream ) ;
00164
00165 if ( xBins + 1 != iBin || 0 != jBin ) { stream << " , " ; }
00166 }
00167 }
00168 stream << " ]" ;
00169
00170 stream << " }" ;
00171
00172 return stream ;
00173 }
00174
00175 }
00176
00177
00178
00179
00180
00181
00182
00183 std::ostream& Gaudi::Utils::toStream
00184 ( const TH1D& histo ,
00185 std::ostream& stream ,
00186 const bool asXML ) { return _toStream_1D_ ( histo , stream , asXML ) ; }
00187
00188
00189
00190
00191
00192
00193
00194 std::ostream& Gaudi::Utils::toStream
00195 ( const TH1F& histo ,
00196 std::ostream& stream ,
00197 const bool asXML ) { return _toStream_1D_ ( histo , stream , asXML ) ; }
00198
00199
00200
00201
00202
00203
00204
00205 std::ostream& Gaudi::Utils::toStream
00206 ( const TH2D& histo ,
00207 std::ostream& stream ,
00208 const bool asXML ) { return _toStream_2D_ ( histo , stream , asXML ) ; }
00209
00210
00211
00212
00213
00214
00215
00216 std::ostream& Gaudi::Utils::toStream
00217 ( const TH2F& histo ,
00218 std::ostream& stream ,
00219 const bool asXML ) { return _toStream_2D_ ( histo , stream , asXML ) ; }
00220
00221
00222
00223
00224
00225
00226
00227 std::ostream& Gaudi::Utils::toStream
00228 ( const AIDA::IHistogram1D& histo ,
00229 std::ostream& stream ,
00230 const bool asXML )
00231 {
00232
00233 AIDA::IHistogram1D* aida = const_cast<AIDA::IHistogram1D*> ( &histo ) ;
00234
00235 const TH1D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
00236 if ( 0 == root ) { return stream ; }
00237
00238 return toStream ( *root , stream , asXML ) ;
00239 }
00240
00241
00242
00243
00244
00245
00246
00247 std::ostream& Gaudi::Utils::toStream
00248 ( const AIDA::IHistogram2D& histo ,
00249 std::ostream& stream ,
00250 const bool asXML )
00251 {
00252
00253 AIDA::IHistogram2D* aida = const_cast<AIDA::IHistogram2D*> ( &histo ) ;
00254
00255 const TH2D* root = Gaudi::Utils::Aida2ROOT::aida2root ( aida ) ;
00256 if ( 0 == root ) { return stream ; }
00257
00258 return toStream ( *root , stream , asXML ) ;
00259 }
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269 std::string Gaudi::Utils::toString
00270 ( const TH1D& histo ,
00271 const bool asXML )
00272 {
00273 std::ostringstream o ;
00274 toStream ( histo , o , asXML ) ;
00275 return o.str() ;
00276 }
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 std::string Gaudi::Utils::toString
00287 ( const TH1F& histo ,
00288 const bool asXML )
00289 {
00290 std::ostringstream o ;
00291 toStream ( histo , o , asXML ) ;
00292 return o.str() ;
00293 }
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 std::string Gaudi::Utils::toString
00304 ( const TH2D& histo ,
00305 const bool asXML )
00306 {
00307 std::ostringstream o ;
00308 toStream ( histo , o , asXML ) ;
00309 return o.str() ;
00310 }
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320 std::string Gaudi::Utils::toString
00321 ( const TH2F& histo ,
00322 const bool asXML )
00323 {
00324 std::ostringstream o ;
00325 toStream ( histo , o , asXML ) ;
00326 return o.str() ;
00327 }
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 std::string Gaudi::Utils::toString
00338 ( const AIDA::IHistogram1D& histo ,
00339 const bool asXML )
00340 {
00341 std::ostringstream o ;
00342 toStream ( histo , o , asXML ) ;
00343 return o.str() ;
00344 }
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 std::string Gaudi::Utils::toString
00355 ( const AIDA::IHistogram2D& histo ,
00356 const bool asXML )
00357 {
00358 std::ostringstream o ;
00359 toStream ( histo , o , asXML ) ;
00360 return o.str() ;
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 std::string Gaudi::Utils::toString ( const AIDA::IHistogram1D* histo )
00372 {
00373 if ( 0 == histo ) { return std::string ("{}") ; }
00374 return toString ( *histo ) ;
00375 }
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385 std::string Gaudi::Utils::toString ( AIDA::IHistogram1D* histo )
00386 {
00387 if ( 0 == histo ) { return std::string ("{}") ; }
00388 return toString ( *histo ) ;
00389 }
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399 std::string Gaudi::Utils::toString ( const TH1D* histo )
00400 {
00401 if ( 0 == histo ) { return std::string ("{}") ; }
00402 return toString ( *histo ) ;
00403 }
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413 std::string Gaudi::Utils::toString ( const TH2D* histo )
00414 {
00415 if ( 0 == histo ) { return std::string ("{}") ; }
00416 return toString ( *histo ) ;
00417 }
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 std::string Gaudi::Utils::toString ( TH1D* histo )
00428 {
00429 if ( 0 == histo ) { return std::string ("{}") ; }
00430 return toString ( *histo ) ;
00431 }
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441 std::string Gaudi::Utils::toString ( TH2D* histo )
00442 {
00443 if ( 0 == histo ) { return std::string ("{}") ; }
00444 return toString ( *histo ) ;
00445 }
00446
00447
00448