Gaudi Framework, version v20r2

Generated: 18 Jul 2008

GaudiHistos.icpp

Go to the documentation of this file.
00001 // $Id: GaudiHistos.icpp,v 1.15 2008/05/15 08:50:32 marcocle Exp $
00002 // ============================================================================
00003 #ifndef GAUDIALG_GAUDIHISTOS_ICPP
00004 #define GAUDIALG_GAUDIHISTOS_ICPP 1
00005 // ============================================================================
00006 /* @file
00007  *
00008  *  Implementation file for class : GaudiHistos
00009  *
00010  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
00011  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
00012  *  @date   2005-08-08
00013  */
00014 // ============================================================================
00015 // STD & STL
00016 // ============================================================================
00017 #include <algorithm>
00018 #include <string>
00019 #include <vector>
00020 #include <set>
00021 // ============================================================================
00022 // GaudiKernel
00023 // ============================================================================
00024 #include "GaudiKernel/MsgStream.h"
00025 #include "GaudiKernel/IHistogramSvc.h"
00026 // ============================================================================
00027 // GaudiUtils
00028 // ============================================================================
00029 #include "GaudiUtils/HistoTableFormat.h"
00030 // ============================================================================
00031 // GaudiAlg
00032 // ============================================================================
00033 #include "GaudiAlg/GaudiHistos.h"
00034 #include "GaudiAlg/CheckForNaN.h"
00035 #include "GaudiAlg/Print.h"
00036 #include "GaudiAlg/Fill.h"
00037 // ============================================================================
00038 // forward declarations from AIDA
00039 // ============================================================================
00040 namespace AIDA
00041 {
00042   class IBaseHistogram ;
00043   class IHistogram     ;
00044   class IHistogram1D   ;
00045   class IHistogram2D   ;
00046   class IHistogram3D   ;
00047   class IProfile       ;
00048   class IProfile1D     ;
00049   class IProfile2D     ;
00050 }
00051 // ============================================================================
00052 // Destructor
00053 // ============================================================================
00054 template <class PBASE>
00055 GaudiHistos<PBASE>::~GaudiHistos() {}
00056 // =============================================================================
00057 // Constructor initialisation and job options
00058 // =============================================================================
00059 template <class PBASE>
00060 void GaudiHistos<PBASE>::initGaudiHistosConstructor()
00061 {
00062   // SWITCH ON/OFF the histograms
00063   this->declareProperty
00064     ( "HistoProduce"          ,
00065       m_produceHistos = true  ,
00066       "Swith on/off the production of histograms "   ) ;
00067   // print the histograms at finalization
00068   this->declareProperty
00069     ( "HistoPrint"            ,
00070       m_histosPrint   = true  ,
00071       "Switch on/off the printout of histograms at finalization"    ) ;
00072   // check for NaN/Finite
00073   this->declareProperty
00074     ( "HistoCheckForNaN"      ,
00075       m_checkForNaN   = true  ,
00076       "Swicth on/off the checks for NaN and Infinity for histogram fill" ) ;
00077   // for HBOOK persistency, 'true' can be useful
00078   this->declareProperty
00079     ( "HistoSplitDir"         ,
00080       m_splitHistoDir = false ,
00081       "Split long directory names into short pieces (suitable for HBOOK)" );
00082   // general OffSet for histogram ID
00083   this->declareProperty
00084     ( "HistoOffSet"           ,
00085       m_histoOffSet   =   0   ,
00086       "OffSet for automatically assigned histogram numerical identifiers " ) ;
00087   // top level histogram directory
00088   this->declareProperty
00089     ( "HistoTopDir"           ,
00090       m_histoTopDir   =   ""  ,
00091       "Top level histogram directory (take care that it ends with '/')" ) ;
00092   // histogram directory
00093   this->declareProperty
00094     ( "HistoDir"             ,
00095       m_histoDir      = this->name() ,
00096       "Histogram Directory" ) ;
00097   // control output level of histograms
00098   this->declareProperty ( "FullDetail"            , m_fullDetail    = false ) ;
00099   // monitor histograms
00100   this->declareProperty ( "MonitorHistograms"     , m_declareMoniHists = true ) ;
00101   // format for 1D-histograms printout
00102   this->declareProperty
00103     ( "FormatFor1DHistoTable" ,
00104       m_histo1DTableFormat   = Gaudi::Utils::Histos::Formats::format () ,
00105       "Format string for printout of 1D histograms"      ) ;
00106   // "short" format for 1D-histograms printout
00107   this->declareProperty
00108     ( "ShortFormatFor1DHistoTable" ,
00109       m_histo1DTableFormatShort   = " | %1$-25.25s %2%"  ,
00110       "Format string for printout of 1D histograms"      ) ;
00111   // the header for 1D-histogram tabkle
00112   this->declareProperty
00113     ( "HeaderFor1DHistoTable" ,
00114       m_histo1DTableHeader   = Gaudi::Utils::Histos::Formats::header () ,
00115       "The table header for printout of 1D histograms "  ) ;
00116   this->declareProperty
00117     ( "UseSequencialNumericAutoIDs", m_useNumericAutoIDs = false,
00118       "Flag to allow users to switch back to the old style of creating numerical automatic IDs" );
00119   m_idReplaceInfo.clear();
00120   m_idReplaceInfo["/"] = "=SLASH=";
00121   this->declareProperty
00122     ( "AutoStringIDPurgeMap", m_idReplaceInfo,
00123       "Map of strings to search and replace when using the title as the basis of automatically generated literal IDs" );
00124 }
00125 // ============================================================================
00126 // Initialise Histogramming
00127 // ============================================================================
00128 template <class PBASE>
00129 StatusCode GaudiHistos<PBASE>::initialize()
00130 {
00131   // initialize base class
00132   const StatusCode sc = PBASE::initialize();
00133   if ( sc.isFailure() ) return sc;
00134 
00135   // produce histograms?
00136   if ( !produceHistos() )
00137   {
00138     this->debug() << "Histogram production is switched OFF" << endreq;
00139     return sc;
00140   }
00141 
00142   // check the validity of histogram service
00143   if ( 0 == this->histoSvc() )
00144   { return this->Error("initialize():: IHistogramSvc* is invalid"); }
00145 
00146   // Warn if the user has decided to use numerical automatic IDs
00147   if ( useNumericAutoIDs() )
00148   {
00149     this ->
00150       Warning( "Using numerical automatic IDs. These are not guaranteed to be totally deterministic. Use with care...",
00151                StatusCode::SUCCESS );
00152   }
00153 
00154   // Finally, print the location histogram will be written to
00155   Print 
00156     ( "The histogram path is set to be '" + histoPath() + "'", 
00157       StatusCode( StatusCode::SUCCESS, true )  , MSG::DEBUG );
00158   
00159   return sc;
00160 }
00161 // ============================================================================
00162 // Finalise Histogramming
00163 // ============================================================================
00164 template <class PBASE>
00165 StatusCode GaudiHistos<PBASE>::finalize()
00166 {
00167 
00168   if ( produceHistos() )
00169   {
00170 
00171     // Count how many histos of each type
00172     if ( !noHistos() )
00173     {
00174       const unsigned int n1D  = histo1DMapNumID().size()+histo1DMapLitID().size();
00175       const unsigned int n2D  = histo2DMapNumID().size()+histo2DMapLitID().size();
00176       const unsigned int n3D  = histo3DMapNumID().size()+histo3DMapLitID().size();
00177       const unsigned int n1DP = profile1DMapNumID().size()+profile1DMapLitID().size();
00178       const unsigned int n2DP = profile2DMapNumID().size()+profile2DMapLitID().size();
00179       const unsigned int total = n1D+n2D+n3D+n1DP+n2DP;
00180       if ( total>0 )
00181       {
00182         this->always() << "Booked " << total << " Histogram(s) : ";
00183         if ( n1D>0  ) this->always() << "1D=" << n1D << " ";
00184         if ( n2D>0  ) this->always() << "2D=" << n2D << " ";
00185         if ( n3D>0  ) this->always() << "3D=" << n3D << " ";
00186         if ( n1DP>0 ) this->always() << "1DProf=" << n1DP << " ";
00187         if ( n2DP>0 ) this->always() << "2DProf=" << n2DP << " ";
00188         this->always() << endreq;
00189       }
00190     }
00191 
00192     // detailed printing
00193     if ( histosPrint() ) { printHistos() ; }
00194 
00195   }
00196 
00197   // clear all maps
00198   m_histo1DMapTitle   .clear() ;
00199   m_histo2DMapTitle   .clear() ;
00200   m_histo3DMapTitle   .clear() ;
00201   m_histo1DMapNumID   .clear() ;
00202   m_histo1DMapLitID   .clear() ;
00203   m_histo2DMapNumID   .clear() ;
00204   m_histo2DMapLitID   .clear() ;
00205   m_histo3DMapNumID   .clear() ;
00206   m_histo3DMapLitID   .clear() ;
00207   m_profile1DMapTitle .clear() ;
00208   m_profile2DMapTitle .clear() ;
00209   m_profile1DMapNumID .clear() ;
00210   m_profile1DMapLitID .clear() ;
00211   m_profile2DMapNumID .clear() ;
00212   m_profile2DMapLitID .clear() ;
00213 
00214   // finalize base class
00215   return PBASE::finalize();
00216 }
00217 // ============================================================================
00218 // perform the actual detailed printout of histograms
00219 // ============================================================================
00220 template <class PBASE>
00221 int GaudiHistos<PBASE>::printHistos ( const MSG::Level level ) const
00222 {
00223   // temporary storage
00224   std::set<const AIDA::IBaseHistogram*> histos   ;
00225   std::set<const AIDA::IBaseHistogram*> profiles ;
00226 
00227   using namespace Gaudi::Utils::Histos ;
00228 
00229   if ( noHistos() )
00230   { if (this->msgLevel(MSG::DEBUG)) this->msgStream(level) << "No histograms are booked" << endreq ; }
00231   else
00232   {
00233     MsgStream & msg = this->msgStream(level);
00234 
00235     // Printout all histograms
00236     // Note, each must appear in either the numeric or literal map
00237 
00238     Gaudi::Utils::Histos::Table table
00239       ( m_histo1DTableFormat ,
00240         m_histo1DTableHeader ) ;
00241 
00242     if ( !histo1DMapNumID().empty() || !histo1DMapLitID().empty() )
00243     {
00244       msg << "List of booked 1D histograms in directory         "
00245           << "\"" << histoPath() << "\" :-"  ;
00246 
00247       if ( !table.header().empty() )
00248       {
00249         msg << std::endl << Gaudi::Utils::Histos::format
00250           ( "ID" , table.header() , m_histo1DTableFormatShort ) ;
00251       }
00252       {
00253         for ( Histo1DMapNumID::const_iterator entry = histo1DMapNumID().begin() ;
00254               histo1DMapNumID().end() != entry ; ++entry )
00255         {
00256           AIDA::IHistogram1D* aida = entry->second ;
00257           if ( 0 == aida )
00258           { this->error() << "IHistogram1D points to NULL" << endreq ; continue ; }
00259           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
00260           histos.insert ( toBase ( aida  ) ) ;
00261           // format and print the row
00262           msg << std::endl << table.toString
00263             ( aida                      ,
00264               HistoID ( entry->first )  ,
00265               m_histo1DTableFormatShort ) ;
00266         }
00267       }
00268       {
00269         for ( Histo1DMapLitID::const_iterator entry = histo1DMapLitID().begin() ;
00270               histo1DMapLitID().end() != entry ; ++entry )
00271         {
00272           AIDA::IHistogram1D* aida = entry->second ;
00273           if ( 0 == aida )
00274           { this->error() << "IHistogram1D points to NULL" << endreq ; continue ; }
00275           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
00276           histos.insert ( toBase ( aida  ) ) ;
00277           // format and print the row
00278           msg << std::endl << table.toString
00279             ( aida                      ,
00280               entry->first              ,
00281               m_histo1DTableFormatShort ) ;
00282         }
00283       }
00284       msg << endreq ;
00285     }
00286     if ( !histo2DMapNumID().empty() || !histo2DMapLitID().empty() )
00287     {
00288       msg << "List of booked 2D histograms in directory         "
00289           << "\"" << histoPath() << "\" :-" ;
00290       {
00291         for ( Histo2DMapNumID::const_iterator entry = histo2DMapNumID().begin() ;
00292               histo2DMapNumID().end() != entry ; ++entry )
00293         {
00294           AIDA::IHistogram2D* aida = entry->second ;
00295           if ( 0 == aida )
00296           { this->error() << "IHistogram2D points to NULL" << endreq ; continue ; }
00297           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
00298           histos.insert ( toBase ( aida  ) ) ;
00299           msg << std::endl 
00300               << GaudiAlg::Print2D::toString ( aida , entry->first );
00301         }
00302       }
00303       {
00304         for ( Histo2DMapLitID::const_iterator entry = histo2DMapLitID().begin() ;
00305               histo2DMapLitID().end() != entry ; ++entry )
00306         {
00307           AIDA::IHistogram2D* aida = entry->second ;
00308           if ( 0 == aida )
00309           { this->error() << "IHistogram2D points to NULL" << endreq ; continue ; }
00310           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
00311           histos.insert ( toBase ( aida  ) ) ;
00312           msg << std::endl 
00313               << GaudiAlg::Print2D::toString ( aida , entry->first );
00314         }
00315       }
00316       msg << endreq ;
00317     }
00318     
00319     if ( !histo3DMapNumID().empty() || !histo3DMapLitID().empty() )
00320     {
00321       msg << "List of booked 3D histograms in directory         "
00322           << "\"" << histoPath() << "\" :-" ;
00323       {
00324         for ( Histo3DMapNumID::const_iterator entry = histo3DMapNumID().begin() ;
00325               histo3DMapNumID().end() != entry ; ++entry )
00326         {
00327           AIDA::IHistogram3D* aida = entry->second ;
00328           if ( 0 == aida )
00329           { this->error() << "IHistogram3D points to NULL" << endreq ; continue ; }
00330           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
00331           histos.insert ( toBase ( aida  ) ) ;
00332           msg << std::endl << GaudiAlg::Print3D::toString ( aida , entry->first );
00333         }
00334       }
00335       {
00336         for ( Histo3DMapLitID::const_iterator entry = histo3DMapLitID().begin() ;
00337               histo3DMapLitID().end() != entry ; ++entry )
00338         {
00339           AIDA::IHistogram3D* aida = entry->second ;
00340           if ( 0 == aida )
00341           { this->error() << "IHistogram3D points to NULL" << endreq ; continue ; }
00342           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
00343           histos.insert ( toBase ( aida  ) ) ;
00344           msg << std::endl << GaudiAlg::Print3D::toString ( aida , entry->first ) ;
00345         }
00346       }
00347       msg << endreq ;
00348     }
00349     if ( !profile1DMapNumID().empty() || !profile1DMapLitID().empty() )
00350     {
00351       msg << "List of booked 1D profile histograms in directory "
00352           << "\"" << histoPath() << "\" :-" ;
00353       {
00354         for ( Profile1DMapNumID::const_iterator entry = profile1DMapNumID().begin() ;
00355               profile1DMapNumID().end() != entry ; ++entry )
00356         {
00357           AIDA::IProfile1D*   aida = entry->second ;
00358           if ( 0 == aida )
00359           { this->error() << "IProfile1D points to NULL" << endreq ; continue ; }
00360           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
00361           profiles.insert ( toBase ( aida  ) ) ;
00362           msg << std::endl << GaudiAlg::Print1DProf::toString  ( aida , entry->first );
00363         }
00364       }
00365       {
00366         for ( Profile1DMapLitID::const_iterator entry = profile1DMapLitID().begin() ;
00367               profile1DMapLitID().end() != entry ; ++entry )
00368         {
00369           AIDA::IProfile1D*   aida = entry->second ;
00370           if ( 0 == aida )
00371           { this->error() << "IProfile1D points to NULL" << endreq ; continue ; }
00372           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
00373           profiles.insert ( toBase ( aida  ) ) ;
00374           msg << std::endl << GaudiAlg::Print1DProf::toString ( aida , entry->first );
00375         }
00376       }
00377       msg << endreq ;
00378     }
00379     if ( !profile2DMapNumID().empty() || !profile2DMapLitID().empty() )
00380     {
00381       msg << "List of booked 2D profile histograms in directory "
00382           << "\"" << histoPath() << "\" :-" ;
00383       {
00384         for ( Profile2DMapNumID::const_iterator entry = profile2DMapNumID().begin() ;
00385               profile2DMapNumID().end() != entry ; ++entry )
00386         {
00387           AIDA::IProfile2D*   aida = entry->second ;
00388           if ( 0 == aida )
00389           { this->error() << "IProfile2D points to NULL" << endreq ; continue ; }
00390           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
00391           profiles.insert ( toBase ( aida  ) ) ;
00392           msg << std::endl << GaudiAlg::Print2DProf::toString ( aida , entry->first );
00393         }
00394       }
00395       {
00396         for ( Profile2DMapLitID::const_iterator entry = profile2DMapLitID().begin() ;
00397               profile2DMapLitID().end() != entry ; ++entry )
00398         {
00399           AIDA::IProfile2D*   aida = entry->second ;
00400           if ( 0 == aida )
00401           { this->error() << "IProfile2D points to NULL" << endreq ; continue ; }
00402           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
00403           profiles.insert ( toBase ( aida  ) ) ;
00404           msg << std::endl << GaudiAlg::Print2DProf::toString ( aida , entry->first );
00405         }
00406       }
00407       msg << endreq ;
00408     }
00409 
00410   }
00411   return histos.size() + profiles.size() ;
00412 }
00413 // ============================================================================
00414 // Check if all histogram maps are empty
00415 // ============================================================================
00416 template <class PBASE>
00417 bool GaudiHistos<PBASE>::noHistos() const
00418 {
00419   return ( histo1DMapTitle()   .empty() &&
00420            histo2DMapTitle()   .empty() &&
00421            histo3DMapTitle()   .empty() &&
00422            profile1DMapTitle() .empty() &&
00423            profile2DMapTitle() .empty() &&
00424            histo1DMapNumID()   .empty() &&
00425            histo1DMapLitID()   .empty() &&
00426            histo2DMapNumID()   .empty() &&
00427            histo2DMapLitID()   .empty() &&
00428            histo3DMapNumID()   .empty() &&
00429            histo3DMapLitID()   .empty() &&
00430            profile1DMapNumID() .empty() &&
00431            profile1DMapLitID() .empty() &&
00432            profile2DMapNumID() .empty() &&
00433            profile2DMapLitID() .empty() );
00434 }
00435 // ============================================================================
00436 
00437 // ============================================================================
00438 // Declare a histogram to the monitor service
00439 // ============================================================================
00440 template <class PBASE>
00441 void GaudiHistos<PBASE>::monitorHisto
00442 ( const AIDA::IBaseHistogram* hist,
00443   const HistoID& ID ) const
00444 {
00445   if ( hist && m_declareMoniHists )
00446   {
00447     if ( this->msgLevel(MSG::DEBUG) )
00448     {
00449       this->debug() << "Monitoring histogram '"
00450                     << ID.idAsString() << "' desc = '"
00451                     << Gaudi::Utils::Histos::htitle  ( hist ) << endreq;
00452     }
00453     this->declareInfo ( histoPath()+"/"+ID.idAsString() ,
00454                         hist            ,
00455                         Gaudi::Utils::Histos::htitle ( hist ) ) ;
00456   }
00457 }
00458 // ============================================================================
00459 // ==================================== 1D ====================================
00460 // ============================================================================
00461 // book the 1D histogram (book on demand)
00462 // ============================================================================
00463 template <class PBASE>
00464 AIDA::IHistogram1D*  GaudiHistos<PBASE>::book1D
00465 ( const std::string&  title        ,
00466   const double        low          ,
00467   const double        high         ,
00468   const unsigned long bins         ) const
00469 {
00470   // exist?
00471   AIDA::IHistogram1D* hist = histo1D ( title ) ;
00472   // histogram is already booked
00473   if( 0 != hist      )                           { return hist ; } // RETURN !!
00474 
00475   // propose the histogram ID
00476   HistoID ID;
00477   newHistoID( title, ID );
00478 
00479   // Create a new histogram and return
00480   return this -> book1D ( ID, title, low, high, bins );
00481 }
00482 // ============================================================================
00483 // book the 1D histogram with forced ID (book on demand)
00484 // ============================================================================
00485 template <class PBASE>
00486 AIDA::IHistogram1D*  GaudiHistos<PBASE>::book1D
00487 ( const HistoID&                ID     ,
00488   const std::string&            title  ,
00489   const double                  low    ,
00490   const double                  high   ,
00491   const unsigned long           bins   ) const
00492 {
00493   // Check ID
00494   if (ID.undefined())
00495   { 
00496     this->Error("Undefined Histogram ID : Title='"+title+"'"); 
00497     return NULL; 
00498   }
00499 
00500   // exist?
00501   AIDA::IHistogram1D* hist = histo1D ( ID ) ;
00502   // histogram is already booked
00503   if ( 0 != hist       )                         { return hist ; } // RETURN !!
00504 
00505   // Histogram title
00506   const std::string & htitle =
00507     ( title.empty() ? "Unnamed 1D Histogram ID="+ID.idAsString() : title ) ;
00508 
00509   // book the histogram
00510   if ( ID.numeric() )
00511   {
00512     hist = this->histoSvc() -> book ( histoPath()  ,
00513                                       ID.numericID() ,
00514                                       htitle       ,
00515                                       bins         ,
00516                                       low          ,
00517                                       high         ) ;
00518   }
00519   else if ( ID.literal() )
00520   {
00521     hist = this->histoSvc() -> book ( histoPath()+"/"+
00522                                       ID.literalID() ,
00523                                       htitle         ,
00524                                       bins           ,
00525                                       low            ,
00526                                       high         ) ;
00527   }
00528 
00529   // check OK
00530   if( 0 == hist )
00531   { this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() +
00532                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
00533 
00534   // add histogram into histogram storages
00535   if      ( ID.numeric() )
00536   { m_histo1DMapNumID [ ID.numericID() ] = hist ; }
00537   else if ( ID.literal() )
00538   { m_histo1DMapLitID [ ID.literalID() ] = hist ; }
00539   m_histo1DMapTitle [ title ] = hist ;
00540 
00541   // Declare to monitoring service
00542   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
00543 
00544   // Printout and return
00545   if ( this->msgLevel(MSG::DEBUG) )
00546   { this->debug() << "Booked 1D Histogram : ID='" << ID
00547                   << "' Path=" << histoPath()
00548                   << " Title='"
00549                   << Gaudi::Utils::Histos::htitle ( hist )
00550                   << "'" << endreq; }
00551   return hist ;
00552 }
00553 // ============================================================================
00554 // fill the 1D histogram with the value and weight
00555 // ============================================================================
00556 template <class PBASE>
00557 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill
00558 ( AIDA::IHistogram1D*  histo  ,
00559   const double         value  ,
00560   const double         weight ,
00561   const std::string&   title  ) const
00562 {
00563   if ( 0 != histo && produceHistos() )
00564   {
00565     if ( !checkForNaN() )
00566     { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
00567     else if  ( lfin ( value ) && lfin ( weight ) )
00568     { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
00569     else if  ( lnan ( value ) || lnan ( weight ) )
00570     {
00571       this -> Warning
00572         ("fill():: 'NaN'      value is skipped from the histogram '"
00573          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
00574     }
00575     else
00576     {
00577       this -> Warning
00578         ("fill():: 'Infinite' value is skipped from the histogram '"
00579          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
00580     }
00581   }
00582   // return
00583   return histo ;
00584 }
00585 // ============================================================================
00586 // ==================================== 2D ====================================
00587 // ============================================================================
00588 // book the 2D histogram (book on demand)
00589 // ============================================================================
00590 template <class PBASE>
00591 AIDA::IHistogram2D*  GaudiHistos<PBASE>::book2D
00592 ( const std::string&  title   ,
00593   const double        lowX    ,
00594   const double        highX   ,
00595   const unsigned long binsX   ,
00596   const double        lowY    ,
00597   const double        highY   ,
00598   const unsigned long binsY   ) const
00599 {
00600   // exist?
00601   AIDA::IHistogram2D* hist = histo2D ( title ) ;
00602   // histogram is already booked
00603   if( 0 != hist      )                                { return hist ; } // RETURN !!
00604 
00605   // propose the histogram ID
00606   HistoID ID;
00607   newHistoID( title, ID );
00608 
00609   // Create a new histogram and return
00610   return this -> book2D ( ID, title, lowX, highX, binsX, lowY, highY, binsY );
00611 }
00612 // ============================================================================
00613 // book the 2D histogram with forced ID (book on demand)
00614 // ============================================================================
00615 template <class PBASE>
00616 AIDA::IHistogram2D*  GaudiHistos<PBASE>::book2D
00617 ( const HistoID&      ID           ,
00618   const std::string&  title   ,
00619   const double        lowX    ,
00620   const double        highX   ,
00621   const unsigned long binsX   ,
00622   const double        lowY    ,
00623   const double        highY   ,
00624   const unsigned long binsY   ) const
00625 {
00626   // Check ID
00627   if (ID.undefined())
00628   { 
00629     this->Error("Undefined Histogram ID : Title='"+title+"'"); 
00630     return NULL;
00631   }
00632 
00633   // exist?
00634   AIDA::IHistogram2D* hist = histo2D( ID ) ;
00635   // histogram is already booked
00636   if( 0 != hist       )                         { return hist ; } // RETURN !!
00637 
00638   // Histogram title
00639   const std::string & htitle =
00640     ( title.empty() ? "Unnamed 2D Histogram ID="+ID.idAsString() : title ) ;
00641 
00642   // book the histogram
00643   if ( ID.numeric() )
00644   {
00645     hist = this->histoSvc() -> book ( histoPath()  ,
00646                                       ID.numericID() ,
00647                                       htitle       ,
00648                                       binsX        ,
00649                                       lowX         ,
00650                                       highX        ,
00651                                       binsY        ,
00652                                       lowY         ,
00653                                       highY        ) ;
00654   }
00655   else if ( ID.literal() )
00656   {
00657     hist = this->histoSvc() -> book ( histoPath()+"/"+
00658                                       ID.literalID() ,
00659                                       htitle       ,
00660                                       binsX        ,
00661                                       lowX         ,
00662                                       highX        ,
00663                                       binsY        ,
00664                                       lowY         ,
00665                                       highY        ) ;
00666   }
00667 
00668   // Check OK
00669   if( 0 == hist )
00670   { this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() +
00671                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
00672 
00673   // add histogram into histogram storages
00674   if      ( ID.numeric() )
00675   { m_histo2DMapNumID [ ID.numericID() ] = hist ; }
00676   else if ( ID.literal() )
00677   { m_histo2DMapLitID [ ID.literalID() ] = hist ; }
00678   m_histo2DMapTitle [ title ] = hist ;
00679 
00680   // Declare to monitoring service
00681   monitorHisto( Gaudi::Utils::Histos::toBase ( hist) , ID );
00682 
00683   // Printout and return
00684   if ( this->msgLevel(MSG::DEBUG) )
00685   { this->debug() << "Booked 2D Histogram : ID='"
00686                   << ID << "' Path=" << histoPath()
00687                   << " Title='"
00688                   << Gaudi::Utils::Histos::htitle ( hist )
00689                   << "'" << endreq; }
00690   // return
00691   return hist ;
00692 }
00693 // ============================================================================
00694 // fill the 2D histogram with the values and weight
00695 // ============================================================================
00696 template <class PBASE>
00697 AIDA::IHistogram2D* GaudiHistos<PBASE>::fill
00698 ( AIDA::IHistogram2D* histo  ,
00699   const double        valueX ,
00700   const double        valueY ,
00701   const double        weight ,
00702   const std::string&  title  ) const
00703 {
00704   if ( 0 != histo && produceHistos() )
00705   {
00706     if ( !checkForNaN() )
00707     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ) ; }
00708     else if  ( lfin ( valueX ) && lfin ( valueY ) && lfin ( weight ) )
00709     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ) ; }
00710     else if  ( lnan ( valueX ) || lnan ( valueY ) || lnan ( weight ) )
00711     {
00712       this -> Warning
00713         ("fill():: 'NaN'      value is skipped from the histogram '"
00714          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
00715     }
00716     else
00717     {
00718       this -> Warning
00719         ("fill():: 'Infinite' value is skipped from the histogram '"
00720          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
00721     }
00722   }
00723   // return
00724   return histo ;
00725 }
00726 // ============================================================================
00727 // ==================================== 3D ====================================
00728 // ============================================================================
00729 // book the 3D histogram (book on demand)
00730 // ============================================================================
00731 template <class PBASE>
00732 AIDA::IHistogram3D*  GaudiHistos<PBASE>::book3D
00733 ( const std::string&  title   ,
00734   const double        lowX    ,
00735   const double        highX   ,
00736   const unsigned long binsX   ,
00737   const double        lowY    ,
00738   const double        highY   ,
00739   const unsigned long binsY   ,
00740   const double        lowZ    ,
00741   const double        highZ   ,
00742   const unsigned long binsZ   ) const
00743 {
00744   // exist?
00745   AIDA::IHistogram3D* hist = histo3D ( title ) ;
00746   // histogram is already booked
00747   if( 0 != hist      )                           { return hist ; } // RETURN !!
00748 
00749   // propose the histogram ID
00750   HistoID ID;
00751   newHistoID( title, ID );
00752 
00753   // Create a new histogram and return
00754   return this -> book3D ( ID, title,
00755                           lowX, highX, binsX,
00756                           lowY, highY, binsY,
00757                           lowZ, highZ, binsZ );
00758 }
00759 // ============================================================================
00760 // book the 3D histogram with forced ID (book on demand)
00761 // ============================================================================
00762 template <class PBASE>
00763 AIDA::IHistogram3D*  GaudiHistos<PBASE>::book3D
00764 ( const HistoID&      ID           ,
00765   const std::string&  title   ,
00766   const double        lowX    ,
00767   const double        highX   ,
00768   const unsigned long binsX   ,
00769   const double        lowY    ,
00770   const double        highY   ,
00771   const unsigned long binsY   ,
00772   const double        lowZ    ,
00773   const double        highZ   ,
00774   const unsigned long binsZ   ) const
00775 {
00776   // Check ID
00777   if (ID.undefined())
00778   { 
00779     this->Error("Undefined Histogram ID : Title='"+title+"'");
00780     return NULL;
00781   }
00782 
00783   // exist?
00784   AIDA::IHistogram3D* hist = histo3D( ID ) ;
00785   // histogram is already booked
00786   if( 0 != hist       )                        { return hist ; } // RETURN !!
00787 
00788   // Histogram title
00789   const std::string & htitle =
00790     ( title.empty() ? "Unnamed 3D Histogram ID="+ID.idAsString() : title ) ;
00791 
00792   // book the histogram
00793   if ( ID.numeric() )
00794   {
00795     hist = this->histoSvc() -> book ( histoPath()  ,
00796                                       ID.numericID() ,
00797                                       htitle       ,
00798                                       binsX        ,
00799                                       lowX         ,
00800                                       highX        ,
00801                                       binsY        ,
00802                                       lowY         ,
00803                                       highY        ,
00804                                       binsZ        ,
00805                                       lowZ         ,
00806                                       highZ        ) ;
00807   }
00808   else if ( ID.literal() )
00809   {
00810     hist = this->histoSvc() -> book ( histoPath()+"/"+
00811                                       ID.literalID() ,
00812                                       htitle       ,
00813                                       binsX        ,
00814                                       lowX         ,
00815                                       highX        ,
00816                                       binsY        ,
00817                                       lowY         ,
00818                                       highY        ,
00819                                       binsZ        ,
00820                                       lowZ         ,
00821                                       highZ        ) ;
00822   }
00823 
00824   // Check OK
00825   if( 0 == hist )
00826   { this->Error( "IHistogram3D* points to NULL! ID='" + ID.idAsString() +
00827                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
00828 
00829   // add histogram into histogram storages
00830   if      ( ID.numeric() )
00831   { m_histo3DMapNumID [ ID.numericID() ] = hist ; }
00832   else if ( ID.literal() )
00833   { m_histo3DMapLitID [ ID.literalID() ] = hist ; }
00834   m_histo3DMapTitle [ title ] = hist ;
00835 
00836   // Declare to monitoring service
00837   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
00838 
00839   // Printout and return
00840   if ( this->msgLevel(MSG::DEBUG) )
00841   { this->debug() << "Booked 3D Histogram : ID='"
00842                   << ID << "' Path=" << histoPath()
00843                   << " Title='"
00844                   << Gaudi::Utils::Histos::htitle ( hist )
00845                   << "'" << endreq; }
00846   return hist ;
00847 }
00848 // ============================================================================
00849 // fill the 3D histogram with the values and weight
00850 // ============================================================================
00851 template <class PBASE>
00852 AIDA::IHistogram3D* GaudiHistos<PBASE>::fill
00853 ( AIDA::IHistogram3D* histo  ,
00854   const double        valueX ,
00855   const double        valueY ,
00856   const double        valueZ ,
00857   const double        weight ,
00858   const std::string&  title  ) const
00859 {
00860   if ( 0 != histo && produceHistos() )
00861   {
00862     if ( !checkForNaN() )
00863     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ) ; }
00864     else if  ( lfin ( valueX ) && lfin ( valueY ) &&
00865                lfin ( valueZ ) && lfin ( weight ) )
00866     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ) ; }
00867     else if  ( lnan ( valueX ) || lnan ( valueY ) ||
00868                lnan ( valueZ ) || lnan ( weight ) )
00869     {
00870       this -> Warning
00871         ("fill():: 'NaN'      value is skipped from the histogram '"
00872          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
00873     }
00874     else
00875     {
00876       this -> Warning
00877         ("fill():: 'Infinite' value is skipped from the histogram '"
00878          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
00879     }
00880   }
00881   // return
00882   return histo ;
00883 }
00884 // ============================================================================
00885 // =========================== Profile Histograms =============================
00886 // ============================================================================
00887 // book the 1D profile histogram (book on demand)
00888 // ============================================================================
00889 template <class PBASE>
00890 AIDA::IProfile1D*  GaudiHistos<PBASE>::bookProfile1D
00891 ( const std::string&  title        ,
00892   const double        low          ,
00893   const double        high         ,
00894   const unsigned long bins         ) const
00895 {
00896   // exist?
00897   AIDA::IProfile1D* hist = profile1D ( title ) ;
00898   // histogram is already booked
00899   if( 0 != hist      )                              { return hist ; } // RETURN !!
00900 
00901   // propose the histogram ID
00902   HistoID ID;
00903   newHistoID( title, ID );
00904 
00905   // Book the histo and return
00906   return this -> bookProfile1D ( ID, title, low, high, bins );
00907 }
00908 // ============================================================================
00909 // book the 1D profile histogram with forced ID (book on demand)
00910 // ============================================================================
00911 template <class PBASE>
00912 AIDA::IProfile1D*  GaudiHistos<PBASE>::bookProfile1D
00913 ( const HistoID&      ID           ,
00914   const std::string&  title        ,
00915   const double        low          ,
00916   const double        high         ,
00917   const unsigned long bins         ) const
00918 {
00919   // Check ID
00920   if (ID.undefined())
00921   { 
00922     this->Error("Undefined Histogram ID : Title='"+title+"'"); 
00923     return NULL;
00924   }
00925 
00926   // exist?
00927   AIDA::IProfile1D* hist = profile1D ( ID ) ;
00928   // histogram is already booked
00929   if( 0 != hist       )                         { return hist ; } // RETURN !!
00930 
00931   // Histogram title
00932   const std::string & htitle =
00933     ( title.empty() ?
00934       "Unnamed 1D Profile Histogram ID="+ID.idAsString() : title ) ;
00935 
00936   // book the histogram
00937   if ( ID.numeric() )
00938   {
00939     hist = this->histoSvc() -> bookProf ( histoPath()  ,
00940                                           ID.numericID() ,
00941                                           htitle       ,
00942                                           bins         ,
00943                                           low          ,
00944                                           high         ) ;
00945   }
00946   else if ( ID.literal() )
00947   {
00948     hist = this->histoSvc() -> bookProf ( histoPath()+"/"+
00949                                           ID.literalID() ,
00950                                           htitle       ,
00951                                           bins         ,
00952                                           low          ,
00953                                           high         ) ;
00954   }
00955 
00956   // test ok
00957   if( 0 == hist )
00958   { this->Error( "IProfile1D* points to NULL! ID='" + ID.idAsString() +
00959                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
00960 
00961   // add histogram into histogram storages
00962   if      ( ID.numeric() )
00963   { m_profile1DMapNumID [ ID.numericID() ] = hist ; }
00964   else if ( ID.literal() )
00965   { m_profile1DMapLitID [ ID.literalID() ] = hist ; }
00966   m_profile1DMapTitle [ title ] = hist ;
00967 
00968   // Declare to monitoring service
00969   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
00970 
00971   // printout and return
00972   if ( this->msgLevel(MSG::DEBUG) )
00973   { this->debug() << "Booked 1D Profile Histogram : ID='"
00974                   << ID << "' Path=" << histoPath()
00975                   << " Title='"
00976                   << Gaudi::Utils::Histos::htitle ( hist )
00977                   << "'" << endreq; }
00978   return hist ;
00979 }
00980 // ============================================================================
00981 // fill the 1D profile histogram with the value and weight
00982 // ============================================================================
00983 template <class PBASE>
00984 AIDA::IProfile1D* GaudiHistos<PBASE>::fill
00985 ( AIDA::IProfile1D*    histo  ,
00986   const double         valueX ,
00987   const double         valueY ,
00988   const double         weight ,
00989   const std::string&   title  ) const
00990 {
00991   if ( 0 != histo && produceHistos() )
00992   {
00993     if ( !checkForNaN() )
00994     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ); }
00995     else if  ( lfin ( valueX ) && lfin ( valueY ) && lfin ( weight ) )
00996     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ); }
00997     else if  ( lnan ( valueX ) || lnan ( valueY ) || lnan ( weight ) )
00998     {
00999       this -> Warning
01000         ("fill():: 'NaN'      value is skipped from the histogram '"
01001          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
01002     }
01003     else
01004     {
01005       this -> Warning
01006         ("fill():: 'Infinite' value is skipped from the histogram '"
01007          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
01008     }
01009   }
01010   // return
01011   return histo ;
01012 }
01013 // ============================================================================
01014 // book the 2D profile histogram (book on demand)
01015 // ============================================================================
01016 template <class PBASE>
01017 AIDA::IProfile2D*  GaudiHistos<PBASE>::bookProfile2D
01018 ( const std::string&  title        ,
01019   const double        lowX         ,
01020   const double        highX        ,
01021   const unsigned long binsX        ,
01022   const double        lowY         ,
01023   const double        highY        ,
01024   const unsigned long binsY         ) const
01025 {
01026   // exist?
01027   AIDA::IProfile2D* hist = profile2D ( title ) ;
01028   // histogram is already booked
01029   if( 0 != hist      )                          { return hist ; } // RETURN !!
01030 
01031   // propose the histogram ID
01032   HistoID ID;
01033   newHistoID( title, ID );
01034 
01035   // book histogram and return
01036   return this -> bookProfile2D ( ID, title, lowX, highX, binsX, lowY, highY, binsY );
01037 }
01038 // ============================================================================
01039 // book the 2D profile histogram with forced ID (book on demand)
01040 // ============================================================================
01041 template <class PBASE>
01042 AIDA::IProfile2D*  GaudiHistos<PBASE>::bookProfile2D
01043 ( const HistoID&      ID           ,
01044   const std::string&  title        ,
01045   const double        lowX         ,
01046   const double        highX        ,
01047   const unsigned long binsX        ,
01048   const double        lowY         ,
01049   const double        highY        ,
01050   const unsigned long binsY         ) const
01051 {
01052   // Check ID
01053   if (ID.undefined())
01054   { 
01055     this->Error("Undefined Histogram ID : Title='"+title+"'"); 
01056     return NULL;
01057   }
01058 
01059   // exist?
01060   AIDA::IProfile2D* hist = profile2D ( ID ) ;
01061   // histogram is already booked
01062   if( 0 != hist )                               { return hist ; } // RETURN !!
01063 
01064   // Histogram title
01065   const std::string & htitle =
01066     ( title.empty() ?
01067       "Unnamed 2D Profile Histogram ID="+ID.idAsString() : title ) ;
01068 
01069   // book the histogram
01070   if ( ID.numeric() )
01071   {
01072     hist = this->histoSvc() -> bookProf ( histoPath() ,
01073                                           ID.numericID() ,
01074                                           htitle      ,
01075                                           binsX       ,
01076                                           lowX        ,
01077                                           highX       ,
01078                                           binsY       ,
01079                                           lowY        ,
01080                                           highY        ) ;
01081   }
01082   else if ( ID.literal() )
01083   {
01084     hist = this->histoSvc() -> bookProf ( histoPath()+"/"+
01085                                           ID.literalID() ,
01086                                           htitle      ,
01087                                           binsX       ,
01088                                           lowX        ,
01089                                           highX       ,
01090                                           binsY       ,
01091                                           lowY        ,
01092                                           highY        ) ;
01093   }
01094 
01095   // test OK
01096   if( 0 == hist )
01097   { this->Error( "IProfile2D* points to NULL! ID='" + ID.idAsString() +
01098                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
01099 
01100   // add histogram into histogram storages
01101   if      ( ID.numeric() )
01102   { m_profile2DMapNumID [ ID.numericID() ] = hist ; }
01103   else if ( ID.literal() )
01104   { m_profile2DMapLitID [ ID.literalID() ] = hist ; }
01105   m_profile2DMapTitle [ title ] = hist ;
01106 
01107   // Declare to monitoring service
01108   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
01109 
01110   // printout and return
01111   if ( this->msgLevel(MSG::DEBUG) )
01112   {  this->debug() << "Booked 2D Profile Histogram : ID='" << ID
01113                    << "' Path=" << histoPath()
01114                    << " Title='"
01115                    << Gaudi::Utils::Histos::htitle ( hist )
01116                    << "'" << endreq; }
01117   return hist ;
01118 }
01119 // ============================================================================
01120 // fill the 2D profile histogram with the value and weight
01121 // ============================================================================
01122 template <class PBASE>
01123 AIDA::IProfile2D* GaudiHistos<PBASE>::fill
01124 ( AIDA::IProfile2D*    histo  ,
01125   const double         valueX ,
01126   const double         valueY ,
01127   const double         valueZ ,
01128   const double         weight ,
01129   const std::string&   title  ) const
01130 {
01131   if ( 0 != histo && produceHistos() )
01132   {
01133     if ( !checkForNaN() )
01134     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ); }
01135     else if  ( lfin ( valueX ) && lfin ( valueY ) &&
01136                lfin ( valueZ ) && lfin ( weight ) )
01137     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ); }
01138     else if  ( lnan ( valueX ) || lnan ( valueY ) ||
01139                lnan ( valueZ ) || lnan ( weight ) )
01140     {
01141       this -> Warning
01142         ("fill():: 'NaN'      value is skipped from the histogram '"
01143          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
01144     }
01145     else
01146     {
01147       this -> Warning
01148         ("fill():: 'Infinite' value is skipped from the histogram '"
01149          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
01150     }
01151   }
01152   // return
01153   return histo ;
01154 }
01155 // ============================================================================
01156 // fill the 1D histogram (book on demand)
01157 // ============================================================================
01158 template <class PBASE>
01159 AIDA::IHistogram1D*
01160 GaudiHistos<PBASE>::plot1D
01161 ( const double        value  ,
01162   const std::string&  title  ,
01163   const double        low    ,
01164   const double        high   ,
01165   const unsigned long bins   ,
01166   const double        weight ) const
01167 {
01168   AIDA::IHistogram1D * h(0);
01169   if ( produceHistos() )
01170   {
01171     // retrieve or book the histogram
01172     h = histo1D ( title ) ;
01173     if ( 0 == h )     { h = book1D  ( title , low , high , bins ) ; }
01174     // fill the histogram
01175     h = fill ( h , value , weight , title );
01176   }
01177   return h;
01178 }
01179 // ============================================================================
01180 // fill the 1D histogram with forced ID assignment (book on demand)
01181 // ============================================================================
01182 template <class PBASE>
01183 AIDA::IHistogram1D*
01184 GaudiHistos<PBASE>::plot1D
01185 ( const double        value  ,
01186   const HistoID&      ID     ,
01187   const std::string&  title  ,
01188   const double        low    ,
01189   const double        high   ,
01190   const unsigned long bins   ,
01191   const double        weight ) const
01192 {
01193   AIDA::IHistogram1D* h(0);
01194   if ( produceHistos() )
01195   {
01196     // retrieve or book the histogram
01197     h = histo1D ( ID ) ;
01198     if ( 0 == h ) {  h = book1D ( ID , title , low , high , bins ) ; }
01199     // fill
01200     h = fill ( h , value , weight , title ) ;
01201   }
01202   return h;
01203 }
01204 // ============================================================================
01205 // fill the 2D histogram (book on demand)
01206 // ============================================================================
01207 template <class PBASE>
01208 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D
01209 ( const double        valueX       ,
01210   const double        valueY       ,
01211   const std::string&  title        ,
01212   const double        lowX         ,
01213   const double        highX        ,
01214   const double        lowY         ,
01215   const double        highY        ,
01216   const unsigned long binsX        ,
01217   const unsigned long binsY        ,
01218   const double        weight       ) const
01219 {
01220   AIDA::IHistogram2D * h(0);
01221   if ( produceHistos() )
01222   {
01223     // retrieve or book the histogram
01224     h = histo2D ( title ) ;
01225     if ( 0 == h )
01226     { h = book2D ( title , lowX , highX , binsX , lowY , highY , binsY ) ; }
01227     // fill the histogram
01228     h = fill ( h , valueX , valueY , weight , title ) ;
01229   }
01230   return h;
01231 }
01232 // ============================================================================
01233 // fill the 2D histogram with forced ID assignment (book on demand)
01234 // ============================================================================
01235 template <class PBASE>
01236 AIDA::IHistogram2D*  GaudiHistos<PBASE>::plot2D
01237 ( const double        valueX       ,
01238   const double        valueY       ,
01239   const HistoID&      ID           ,
01240   const std::string&  title        ,
01241   const double        lowX         ,
01242   const double        highX        ,
01243   const double        lowY         ,
01244   const double        highY        ,
01245   const unsigned long binsX        ,
01246   const unsigned long binsY        ,
01247   const double        weight       ) const
01248 {
01249   AIDA::IHistogram2D * h(0);
01250   // produce histograms ?
01251   if ( produceHistos() )
01252   {
01253     // retrieve or book the histogram
01254     h = histo2D ( ID ) ;
01255     if ( 0 == h ) { h = book2D ( ID   , title ,
01256                                  lowX , highX , binsX ,
01257                                  lowY , highY , binsY ) ; }
01258     // fill the histogram
01259     h = fill ( h , valueX , valueY , weight , title ) ;
01260   }
01261   return h;
01262 }
01263 // ============================================================================
01264 // fill the 3D histogram (book on demand)
01265 // ============================================================================
01266 template <class PBASE>
01267 AIDA::IHistogram3D*  GaudiHistos<PBASE>::plot3D
01268 ( const double        valueX       ,
01269   const double        valueY       ,
01270   const double        valueZ       ,
01271   const std::string&  title        ,
01272   const double        lowX         ,
01273   const double        highX        ,
01274   const double        lowY         ,
01275   const double        highY        ,
01276   const double        lowZ         ,
01277   const double        highZ        ,
01278   const unsigned long binsX        ,
01279   const unsigned long binsY        ,
01280   const unsigned long binsZ        ,
01281   const double        weight       ) const
01282 {
01283   AIDA::IHistogram3D * h(0);
01284   if ( produceHistos() )
01285   {
01286     // retrieve or book the histogram
01287     h = histo3D ( title ) ;
01288     if ( 0 == h ) { h = book3D ( title ,
01289                                  lowX , highX , binsX ,
01290                                  lowY , highY , binsY ,
01291                                  lowZ , highZ , binsZ ) ; }
01292     // fill the histogram
01293     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
01294   }
01295   return h;
01296 }
01297 // ============================================================================
01298 // fill the 3D histogram with forced ID assignment (book on demand)
01299 // ============================================================================
01300 template <class PBASE>
01301 AIDA::IHistogram3D* GaudiHistos<PBASE>::plot3D
01302 ( const double        valueX       ,
01303   const double        valueY       ,
01304   const double        valueZ       ,
01305   const HistoID&      ID           ,
01306   const std::string&  title        ,
01307   const double        lowX         ,
01308   const double        highX        ,
01309   const double        lowY         ,
01310   const double        highY        ,
01311   const double        lowZ         ,
01312   const double        highZ        ,
01313   const unsigned long binsX        ,
01314   const unsigned long binsY        ,
01315   const unsigned long binsZ        ,
01316   const double        weight       ) const
01317 {
01318   AIDA::IHistogram3D * h(0);
01319   if ( produceHistos() )
01320   {
01321     // retrieve or book the histogram
01322     h = histo3D ( ID ) ;
01323     if ( 0 == h ) { h = book3D ( ID , title ,
01324                                  lowX , highX , binsX ,
01325                                  lowY , highY , binsY ,
01326                                  lowZ , highZ , binsZ ) ; }
01327     // fill the histogram
01328     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
01329   }
01330   return h;
01331 }
01332 // ============================================================================
01333 // fill the 1D profile histogram (book on demand)
01334 // ============================================================================
01335 template <class PBASE>
01336 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D
01337 ( const double        valueX       ,
01338   const double        valueY       ,
01339   const std::string&  title        ,
01340   const double        lowX         ,
01341   const double        highX        ,
01342   const unsigned long binsX        ,
01343   const double        weight       ) const
01344 {
01345   AIDA::IProfile1D * h(0);
01346   if ( produceHistos() )
01347   {
01348     // retrieve or book the histogram
01349     h = profile1D ( title ) ;
01350     if ( 0 == h ) { h = bookProfile1D ( title , lowX , highX , binsX ) ; }
01351     // fill the histogram
01352     h = fill ( h , valueX , valueY , weight , title ) ;
01353   }
01354   return h;
01355 }
01356 // ============================================================================
01357 // fill the 1D profile histogram with forced ID assignment (book on demand)
01358 // ============================================================================
01359 template <class PBASE>
01360 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D
01361 ( const double        valueX       ,
01362   const double        valueY       ,
01363   const HistoID&      ID           ,
01364   const std::string&  title        ,
01365   const double        lowX         ,
01366   const double        highX        ,
01367   const unsigned long binsX        ,
01368   const double        weight       ) const
01369 {
01370   AIDA::IProfile1D * h(0);
01371   if ( produceHistos() )
01372   {
01373     // retrieve or book the histogram
01374     h = profile1D ( ID ) ;
01375     if ( 0 == h ) { h = bookProfile1D ( ID , title , lowX , highX , binsX ) ; }
01376     // fill the histogram
01377     h = fill ( h , valueX , valueY , weight , title ) ;
01378   }
01379   return h;
01380 }
01381 // ============================================================================
01382 // fill the 2D profile histogram (book on demand)
01383 // ============================================================================
01384 template <class PBASE>
01385 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D
01386 ( const double        valueX       ,
01387   const double        valueY       ,
01388   const double        valueZ       ,
01389   const std::string&  title        ,
01390   const double        lowX         ,
01391   const double        highX        ,
01392   const double        lowY         ,
01393   const double        highY        ,
01394   const unsigned long binsX        ,
01395   const unsigned long binsY        ,
01396   const double        weight       ) const
01397 {
01398   AIDA::IProfile2D * h(0);
01399   if ( produceHistos() )
01400   {
01401     // retrieve or book the histogram
01402     h = profile2D ( title ) ;
01403     if ( 0 == h ) { h = bookProfile2D ( title ,
01404                                         lowX , highX , binsX ,
01405                                         lowY , highY , binsY ) ; }
01406     // fill the histogram
01407     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
01408   }
01409   return h;
01410 }
01411 // ============================================================================
01412 // fill the 2D profile histogram with forced ID assignment (book on demand)
01413 // ============================================================================
01414 template <class PBASE>
01415 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D
01416 ( const double        valueX       ,
01417   const double        valueY       ,
01418   const double        valueZ       ,
01419   const HistoID&      ID           ,
01420   const std::string&  title        ,
01421   const double        lowX         ,
01422   const double        highX        ,
01423   const double        lowY         ,
01424   const double        highY        ,
01425   const unsigned long binsX        ,
01426   const unsigned long binsY        ,
01427   const double        weight       ) const
01428 {
01429   AIDA::IProfile2D * h(0);
01430   if ( produceHistos() )
01431   {
01432     // retrieve or book the histogram
01433     h = profile2D ( ID ) ;
01434     if ( 0 == h ) { h = bookProfile2D ( ID , title ,
01435                                         lowX , highX , binsX ,
01436                                         lowY , highY , binsY ) ; }
01437     // fill the histogram
01438     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
01439   }
01440   return h;
01441 }
01442 // ============================================================================
01443 // book the 1D histogram
01444 // ============================================================================
01445 template <class PBASE>
01446 AIDA::IHistogram1D*
01447 GaudiHistos<PBASE>::book
01448 ( const Gaudi::Histo1DDef& hdef ) const
01449 {
01450   return book1D ( hdef.title    () ,
01451                   hdef.lowEdge  () ,
01452                   hdef.highEdge () ,
01453                   hdef.bins     () ) ;
01454 }
01455 // ============================================================================
01456 // book the 1D histogram with forced ID
01457 // ============================================================================
01458 template <class PBASE>
01459 AIDA::IHistogram1D*
01460 GaudiHistos<PBASE>::book
01461 ( const HistoID&           ID   ,
01462   const Gaudi::Histo1DDef& hdef ) const
01463 {
01464   return book1D ( ID               ,
01465                   hdef.title    () ,
01466                   hdef.lowEdge  () ,
01467                   hdef.highEdge () ,
01468                   hdef.bins     () ) ;
01469 }
01470 // ============================================================================
01471 // fill the 1D histogram (book on demand)
01472 // ============================================================================
01473 template <class PBASE>
01474 AIDA::IHistogram1D*
01475 GaudiHistos<PBASE>::plot
01476 ( const double             value  ,
01477   const Gaudi::Histo1DDef& hdef   ,
01478   const double             weight ) const
01479 {
01480   return plot1D
01481     ( value  ,
01482       hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
01483       weight ) ;
01484 }
01485 // ============================================================================
01486 // fill the 1D histogram with forced ID assignment (book on demand)
01487 // ============================================================================
01488 template <class PBASE>
01489 AIDA::IHistogram1D*
01490 GaudiHistos<PBASE>::plot
01491 ( const double             value  ,
01492   const HistoID&           ID     ,
01493   const Gaudi::Histo1DDef& hdef   ,
01494   const double             weight ) const
01495 {
01496   return plot1D
01497     ( value  , ID ,
01498       hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
01499       weight ) ;
01500 }
01501 // ============================================================================
01502 // access the EXISTING 1D histogram by ID
01503 // ============================================================================
01504 template <class PBASE>
01505 AIDA::IHistogram1D* GaudiHistos<PBASE>::histo1D ( const HistoID& ID )  const
01506 {
01507   AIDA::IHistogram1D * h(0);
01508   if ( ID.numeric() )
01509   {
01510     Histo1DMapNumID::const_iterator found =
01511       histo1DMapNumID().find( ID.numericID() ) ;
01512     h = ( histo1DMapNumID().end() == found ? 0 : found->second );
01513   }
01514   else
01515   {
01516     Histo1DMapLitID::const_iterator found =
01517       histo1DMapLitID().find( ID.literalID() ) ;
01518     h = ( histo1DMapLitID().end() == found ? 0 : found->second );
01519   }
01520   return h;
01521 }
01522 // ============================================================================
01523 // access the EXISTING 2D histogram by ID
01524 // ============================================================================
01525 template <class PBASE>
01526 AIDA::IHistogram2D* GaudiHistos<PBASE>::histo2D ( const HistoID& ID )  const
01527 {
01528   AIDA::IHistogram2D * h(0);
01529   if ( ID.numeric() )
01530   {
01531     Histo2DMapNumID::const_iterator found =
01532       histo2DMapNumID().find( ID.numericID() ) ;
01533     h = ( histo2DMapNumID().end() == found ? 0 : found->second );
01534   }
01535   else
01536   {
01537     Histo2DMapLitID::const_iterator found =
01538       histo2DMapLitID().find( ID.literalID() ) ;
01539     h = ( histo2DMapLitID().end() == found ? 0 : found->second );
01540   }
01541   return h;
01542 }
01543 // ============================================================================
01544 // access the EXISTING 3D histogram by ID
01545 // ============================================================================
01546 template <class PBASE>
01547 AIDA::IHistogram3D* GaudiHistos<PBASE>::histo3D ( const HistoID& ID )  const
01548 {
01549   AIDA::IHistogram3D * h(0);
01550   if ( ID.numeric() )
01551   {
01552     Histo3DMapNumID::const_iterator found =
01553       histo3DMapNumID().find( ID.numericID() ) ;
01554     h = ( histo3DMapNumID().end() == found ? 0 : found->second );
01555   }
01556   else
01557   {
01558     Histo3DMapLitID::const_iterator found =
01559       histo3DMapLitID().find( ID.literalID() ) ;
01560     h = ( histo3DMapLitID().end() == found ? 0 : found->second );
01561   }
01562   return h;
01563 }
01564 // ============================================================================
01565 // access the EXISTING 1D profile histogram by ID
01566 // ============================================================================
01567 template <class PBASE>
01568 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D ( const HistoID& ID )  const
01569 {
01570   AIDA::IProfile1D * h(0);
01571   if ( ID.numeric() )
01572   {
01573     Profile1DMapNumID::const_iterator found =
01574       profile1DMapNumID().find( ID.numericID() ) ;
01575     h = ( profile1DMapNumID().end() == found ? 0 : found->second );
01576   }
01577   else
01578   {
01579     Profile1DMapLitID::const_iterator found =
01580       profile1DMapLitID().find( ID.literalID() ) ;
01581     h = ( profile1DMapLitID().end() == found ? 0 : found->second );
01582   }
01583   return h;
01584 }
01585 // ============================================================================
01586 // access the EXISTING 2D profile histogram by ID
01587 // ============================================================================
01588 template <class PBASE>
01589 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D ( const HistoID& ID )  const
01590 {
01591   AIDA::IProfile2D * h(0);
01592   if ( ID.numeric() )
01593   {
01594     Profile2DMapNumID::const_iterator found =
01595       profile2DMapNumID().find( ID.numericID() ) ;
01596     h = ( profile2DMapNumID().end() == found ? 0 : found->second );
01597   }
01598   else
01599   {
01600     Profile2DMapLitID::const_iterator found =
01601       profile2DMapLitID().find( ID.literalID() ) ;
01602     h = ( profile2DMapLitID().end() == found ? 0 : found->second );
01603   }
01604   return h;
01605 }
01606 // ============================================================================
01607 // Returns the total number of histograms (of all types) currently booked
01608 // ============================================================================
01609 template <class PBASE>
01610 unsigned int GaudiHistos<PBASE>::totalNumberOfHistos() const
01611 {
01612   const unsigned int n1D  = histo1DMapNumID().size()+histo1DMapLitID().size();
01613   const unsigned int n2D  = histo2DMapNumID().size()+histo2DMapLitID().size();
01614   const unsigned int n3D  = histo3DMapNumID().size()+histo3DMapLitID().size();
01615   const unsigned int n1DP = profile1DMapNumID().size()+profile1DMapLitID().size();
01616   const unsigned int n2DP = profile2DMapNumID().size()+profile2DMapLitID().size();
01617   return n1D+n2D+n3D+n1DP+n2DP;
01618 }
01619 // ============================================================================
01620 // Create a new histogram ID using the given title
01621 // ============================================================================
01622 template <class PBASE>
01623 void GaudiHistos<PBASE>::newHistoID( const std::string & title,
01624                                      HistoID& ID ) const
01625 {
01626   if ( useNumericAutoIDs() || title.empty() )
01627   {
01628     if ( !useNumericAutoIDs() )
01629     {
01630       this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for histogram ID",
01631                        StatusCode::SUCCESS );
01632     }
01633     // propose the histogram ID (always numeric)
01634     ID = HistoID( totalNumberOfHistos() + 1 + histoOffSet() );
01635     // adjust the proposed ID
01636     while ( histoExists( ID ) ) { ++ID; }
01637   }
01638   else
01639   {
01640     // use the title to create a unique literal ID
01641     ID = HistoID( this->convertTitleToID(title) );
01642     // Just in case ...
01643     while ( histoExists( ID ) ) { ID = HistoID(ID.idAsString()+"_"); }
01644   }
01645 }
01646 // ============================================================================
01647 // Create an ID string from a title string
01648 // ============================================================================
01649 template <class PBASE>
01650 std::string GaudiHistos<PBASE>::convertTitleToID( const std::string & title ) const
01651 {
01652   // clean up the ID string for all unwanted characters
01653   std::string tmp_id = title;
01654   for ( std::map<std::string,std::string>::const_iterator i = m_idReplaceInfo.begin();
01655         i != m_idReplaceInfo.end(); ++i )
01656   {
01657     stringSearchReplace( tmp_id, i->first, i->second );
01658   }
01659   return tmp_id;
01660 }
01661 // ============================================================================
01662 // Searches 'title' for all instancies of 'A' and replaces them with 'B'
01663 // ============================================================================
01664 template <class PBASE>
01665 void GaudiHistos<PBASE>::stringSearchReplace( std::string & title,
01666                                               const std::string & A,
01667                                               const std::string & B ) const
01668 {
01669   std::string::size_type slash = title.find_first_of ( A ) ;
01670   while ( std::string::npos != slash ) 
01671   {
01672     title = title.substr(0,slash) + B + title.substr(slash+A.size());
01673     slash = title.find_first_of( A );
01674   }
01675 }
01676 // ============================================================================
01677 // The END
01678 // ============================================================================
01679 #endif // GAUDIALG_GAUDIHISTOS_ICPP
01680 // ============================================================================

Generated at Fri Jul 18 11:59:19 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004