Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ]   [ 15.*.* ] 

001 // $Id: GaudiHistos.icpp,v 1.17 2008/10/10 12:39:04 marcocle Exp $
002 // ============================================================================
003 #ifndef GAUDIALG_GAUDIHISTOS_ICPP
004 #define GAUDIALG_GAUDIHISTOS_ICPP 1
005 // ============================================================================
006 /* @file
007  *
008  *  Implementation file for class : GaudiHistos
009  *
010  *  @author Chris Jones   Christopher.Rob.Jones@cern.ch
011  *  @author Vanya BELYAEV Ivan.Belyaev@itep.ru
012  *  @date   2005-08-08
013  */
014 // ============================================================================
015 // STD & STL
016 // ============================================================================
017 #include <algorithm>
018 #include <string>
019 #include <vector>
020 #include <set>
021 // ============================================================================
022 // GaudiKernel
023 // ============================================================================
024 #include "GaudiKernel/MsgStream.h"
025 #include "GaudiKernel/IHistogramSvc.h"
026 // ============================================================================
027 // GaudiUtils
028 // ============================================================================
029 #include "GaudiUtils/HistoTableFormat.h"
030 // ============================================================================
031 // GaudiAlg
032 // ============================================================================
033 #include "GaudiAlg/GaudiHistos.h"
034 #include "GaudiAlg/CheckForNaN.h"
035 #include "GaudiAlg/Print.h"
036 #include "GaudiAlg/Fill.h"
037 // ============================================================================
038 // forward declarations from AIDA
039 // ============================================================================
040 namespace AIDA
041 {
042   class IBaseHistogram ;
043   class IHistogram     ;
044   class IHistogram1D   ;
045   class IHistogram2D   ;
046   class IHistogram3D   ;
047   class IProfile       ;
048   class IProfile1D     ;
049   class IProfile2D     ;
050 }
051 // ============================================================================
052 // Destructor
053 // ============================================================================
054 template <class PBASE>
055 GaudiHistos<PBASE>::~GaudiHistos() {}
056 // =============================================================================
057 // Constructor initialisation and job options
058 // =============================================================================
059 template <class PBASE>
060 void GaudiHistos<PBASE>::initGaudiHistosConstructor()
061 {
062   // SWITCH ON/OFF the histograms
063   this->declareProperty
064     ( "HistoProduce"          ,
065       m_produceHistos = true  ,
066       "Swith on/off the production of histograms "   ) ;
067   // print the histograms at finalization
068   this->declareProperty
069     ( "HistoPrint"            ,
070       m_histosPrint   = false ,
071       "Switch on/off the printout of histograms at finalization"    ) ;
072   // check for NaN/Finite
073   this->declareProperty
074     ( "HistoCheckForNaN"      ,
075       m_checkForNaN   = true  ,
076       "Swicth on/off the checks for NaN and Infinity for histogram fill" ) ;
077   // for HBOOK persistency, 'true' can be useful
078   this->declareProperty
079     ( "HistoSplitDir"         ,
080       m_splitHistoDir = false ,
081       "Split long directory names into short pieces (suitable for HBOOK)" );
082   // general OffSet for histogram ID
083   this->declareProperty
084     ( "HistoOffSet"           ,
085       m_histoOffSet   =   0   ,
086       "OffSet for automatically assigned histogram numerical identifiers " ) ;
087   // top level histogram directory
088   this->declareProperty
089     ( "HistoTopDir"           ,
090       m_histoTopDir   =   ""  ,
091       "Top level histogram directory (take care that it ends with '/')" ) ;
092   // histogram directory
093   this->declareProperty
094     ( "HistoDir"             ,
095       m_histoDir      = this->name() ,
096       "Histogram Directory" ) ;
097   // control output level of histograms
098   this->declareProperty ( "FullDetail"            , m_fullDetail    = false ) ;
099   // monitor histograms
100   this->declareProperty ( "MonitorHistograms"     , m_declareMoniHists = true ) ;
101   // format for 1D-histograms printout
102   this->declareProperty
103     ( "FormatFor1DHistoTable" ,
104       m_histo1DTableFormat   = Gaudi::Utils::Histos::Formats::format () ,
105       "Format string for printout of 1D histograms"      ) ;
106   // "short" format for 1D-histograms printout
107   this->declareProperty
108     ( "ShortFormatFor1DHistoTable" ,
109       m_histo1DTableFormatShort   = " | %1$-25.25s %2%"  ,
110       "Format string for printout of 1D histograms"      ) ;
111   // the header for 1D-histogram tabkle
112   this->declareProperty
113     ( "HeaderFor1DHistoTable" ,
114       m_histo1DTableHeader   = Gaudi::Utils::Histos::Formats::header () ,
115       "The table header for printout of 1D histograms "  ) ;
116   this->declareProperty
117     ( "UseSequencialNumericAutoIDs", m_useNumericAutoIDs = false,
118       "Flag to allow users to switch back to the old style of creating numerical automatic IDs" );
119   m_idReplaceInfo.clear();
120   m_idReplaceInfo["/"] = "=SLASH=";
121   this->declareProperty
122     ( "AutoStringIDPurgeMap", m_idReplaceInfo,
123       "Map of strings to search and replace when using the title as the basis of automatically generated literal IDs" );
124 }
125 // ============================================================================
126 // Initialise Histogramming
127 // ============================================================================
128 template <class PBASE>
129 StatusCode GaudiHistos<PBASE>::initialize()
130 {
131   // initialize base class
132   const StatusCode sc = PBASE::initialize();
133   if ( sc.isFailure() ) return sc;
134 
135   // produce histograms?
136   if ( !produceHistos() )
137   {
138     this->debug() << "Histogram production is switched OFF" << endreq;
139     return sc;
140   }
141 
142   // check the validity of histogram service
143   if ( 0 == this->histoSvc() )
144   { return this->Error("initialize():: IHistogramSvc* is invalid"); }
145 
146   // Warn if the user has decided to use numerical automatic IDs
147   if ( useNumericAutoIDs() )
148   {
149     this ->
150       Warning( "Using numerical automatic IDs. These are not guaranteed to be totally deterministic. Use with care...",
151                StatusCode::SUCCESS );
152   }
153 
154   // Finally, print the location histogram will be written to
155   Print
156     ( "The histogram path is set to be '" + histoPath() + "'",
157       StatusCode( StatusCode::SUCCESS, true )  , MSG::DEBUG );
158 
159   return sc;
160 }
161 // ============================================================================
162 // Finalise Histogramming
163 // ============================================================================
164 template <class PBASE>
165 StatusCode GaudiHistos<PBASE>::finalize()
166 {
167 
168   if ( produceHistos() )
169   {
170 
171     // Count how many histos of each type
172     if ( !noHistos() )
173     {
174       const unsigned int n1D  = histo1DMapNumID().size()+histo1DMapLitID().size();
175       const unsigned int n2D  = histo2DMapNumID().size()+histo2DMapLitID().size();
176       const unsigned int n3D  = histo3DMapNumID().size()+histo3DMapLitID().size();
177       const unsigned int n1DP = profile1DMapNumID().size()+profile1DMapLitID().size();
178       const unsigned int n2DP = profile2DMapNumID().size()+profile2DMapLitID().size();
179       const unsigned int total = n1D+n2D+n3D+n1DP+n2DP;
180       if ( total>0 )
181       {
182         this->always() << "Booked " << total << " Histogram(s) : ";
183         if ( n1D>0  ) this->always() << "1D=" << n1D << " ";
184         if ( n2D>0  ) this->always() << "2D=" << n2D << " ";
185         if ( n3D>0  ) this->always() << "3D=" << n3D << " ";
186         if ( n1DP>0 ) this->always() << "1DProf=" << n1DP << " ";
187         if ( n2DP>0 ) this->always() << "2DProf=" << n2DP << " ";
188         this->always() << endreq;
189       }
190     }
191 
192     // detailed printing
193     if ( histosPrint() ) { printHistos() ; }
194 
195   }
196 
197   // clear all maps
198   m_histo1DMapTitle   .clear() ;
199   m_histo2DMapTitle   .clear() ;
200   m_histo3DMapTitle   .clear() ;
201   m_histo1DMapNumID   .clear() ;
202   m_histo1DMapLitID   .clear() ;
203   m_histo2DMapNumID   .clear() ;
204   m_histo2DMapLitID   .clear() ;
205   m_histo3DMapNumID   .clear() ;
206   m_histo3DMapLitID   .clear() ;
207   m_profile1DMapTitle .clear() ;
208   m_profile2DMapTitle .clear() ;
209   m_profile1DMapNumID .clear() ;
210   m_profile1DMapLitID .clear() ;
211   m_profile2DMapNumID .clear() ;
212   m_profile2DMapLitID .clear() ;
213 
214   // finalize base class
215   return PBASE::finalize();
216 }
217 // ============================================================================
218 // perform the actual detailed printout of histograms
219 // ============================================================================
220 template <class PBASE>
221 int GaudiHistos<PBASE>::printHistos ( const MSG::Level level ) const
222 {
223   // temporary storage
224   std::set<const AIDA::IBaseHistogram*> histos   ;
225   std::set<const AIDA::IBaseHistogram*> profiles ;
226 
227   using namespace Gaudi::Utils::Histos ;
228 
229   if ( noHistos() )
230   { if (this->msgLevel(MSG::DEBUG)) this->msgStream(level) << "No histograms are booked" << endreq ; }
231   else
232   {
233     MsgStream & msg = this->msgStream(level);
234 
235     // Printout all histograms
236     // Note, each must appear in either the numeric or literal map
237 
238     Gaudi::Utils::Histos::Table table
239       ( m_histo1DTableFormat ,
240         m_histo1DTableHeader ) ;
241 
242     if ( !histo1DMapNumID().empty() || !histo1DMapLitID().empty() )
243     {
244       msg << "List of booked 1D histograms in directory         "
245           << "\"" << histoPath() << "\" :-"  ;
246 
247       if ( !table.header().empty() )
248       {
249         msg << std::endl << Gaudi::Utils::Histos::format
250           ( "ID" , table.header() , m_histo1DTableFormatShort ) ;
251       }
252       {
253         for ( Histo1DMapNumID::const_iterator entry = histo1DMapNumID().begin() ;
254               histo1DMapNumID().end() != entry ; ++entry )
255         {
256           AIDA::IHistogram1D* aida = entry->second ;
257           if ( 0 == aida )
258           { this->error() << "IHistogram1D points to NULL" << endreq ; continue ; }
259           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
260           histos.insert ( toBase ( aida  ) ) ;
261           // format and print the row
262           msg << std::endl << table.toString
263             ( aida                      ,
264               HistoID ( entry->first )  ,
265               m_histo1DTableFormatShort ) ;
266         }
267       }
268       {
269         for ( Histo1DMapLitID::const_iterator entry = histo1DMapLitID().begin() ;
270               histo1DMapLitID().end() != entry ; ++entry )
271         {
272           AIDA::IHistogram1D* aida = entry->second ;
273           if ( 0 == aida )
274           { this->error() << "IHistogram1D points to NULL" << endreq ; continue ; }
275           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
276           histos.insert ( toBase ( aida  ) ) ;
277           // format and print the row
278           msg << std::endl << table.toString
279             ( aida                      ,
280               entry->first              ,
281               m_histo1DTableFormatShort ) ;
282         }
283       }
284       msg << endreq ;
285     }
286     if ( !histo2DMapNumID().empty() || !histo2DMapLitID().empty() )
287     {
288       msg << "List of booked 2D histograms in directory         "
289           << "\"" << histoPath() << "\" :-" ;
290       {
291         for ( Histo2DMapNumID::const_iterator entry = histo2DMapNumID().begin() ;
292               histo2DMapNumID().end() != entry ; ++entry )
293         {
294           AIDA::IHistogram2D* aida = entry->second ;
295           if ( 0 == aida )
296           { this->error() << "IHistogram2D points to NULL" << endreq ; continue ; }
297           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
298           histos.insert ( toBase ( aida  ) ) ;
299           msg << std::endl
300               << GaudiAlg::Print2D::toString ( aida , entry->first );
301         }
302       }
303       {
304         for ( Histo2DMapLitID::const_iterator entry = histo2DMapLitID().begin() ;
305               histo2DMapLitID().end() != entry ; ++entry )
306         {
307           AIDA::IHistogram2D* aida = entry->second ;
308           if ( 0 == aida )
309           { this->error() << "IHistogram2D points to NULL" << endreq ; continue ; }
310           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
311           histos.insert ( toBase ( aida  ) ) ;
312           msg << std::endl
313               << GaudiAlg::Print2D::toString ( aida , entry->first );
314         }
315       }
316       msg << endreq ;
317     }
318 
319     if ( !histo3DMapNumID().empty() || !histo3DMapLitID().empty() )
320     {
321       msg << "List of booked 3D histograms in directory         "
322           << "\"" << histoPath() << "\" :-" ;
323       {
324         for ( Histo3DMapNumID::const_iterator entry = histo3DMapNumID().begin() ;
325               histo3DMapNumID().end() != entry ; ++entry )
326         {
327           AIDA::IHistogram3D* aida = entry->second ;
328           if ( 0 == aida )
329           { this->error() << "IHistogram3D points to NULL" << endreq ; continue ; }
330           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
331           histos.insert ( toBase ( aida  ) ) ;
332           msg << std::endl << GaudiAlg::Print3D::toString ( aida , entry->first );
333         }
334       }
335       {
336         for ( Histo3DMapLitID::const_iterator entry = histo3DMapLitID().begin() ;
337               histo3DMapLitID().end() != entry ; ++entry )
338         {
339           AIDA::IHistogram3D* aida = entry->second ;
340           if ( 0 == aida )
341           { this->error() << "IHistogram3D points to NULL" << endreq ; continue ; }
342           if ( histos.end() != histos.find( toBase ( aida ) ) ) { continue ; }
343           histos.insert ( toBase ( aida  ) ) ;
344           msg << std::endl << GaudiAlg::Print3D::toString ( aida , entry->first ) ;
345         }
346       }
347       msg << endreq ;
348     }
349     if ( !profile1DMapNumID().empty() || !profile1DMapLitID().empty() )
350     {
351       msg << "List of booked 1D profile histograms in directory "
352           << "\"" << histoPath() << "\" :-" ;
353       {
354         for ( Profile1DMapNumID::const_iterator entry = profile1DMapNumID().begin() ;
355               profile1DMapNumID().end() != entry ; ++entry )
356         {
357           AIDA::IProfile1D*   aida = entry->second ;
358           if ( 0 == aida )
359           { this->error() << "IProfile1D points to NULL" << endreq ; continue ; }
360           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
361           profiles.insert ( toBase ( aida  ) ) ;
362           msg << std::endl << GaudiAlg::Print1DProf::toString  ( aida , entry->first );
363         }
364       }
365       {
366         for ( Profile1DMapLitID::const_iterator entry = profile1DMapLitID().begin() ;
367               profile1DMapLitID().end() != entry ; ++entry )
368         {
369           AIDA::IProfile1D*   aida = entry->second ;
370           if ( 0 == aida )
371           { this->error() << "IProfile1D points to NULL" << endreq ; continue ; }
372           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
373           profiles.insert ( toBase ( aida  ) ) ;
374           msg << std::endl << GaudiAlg::Print1DProf::toString ( aida , entry->first );
375         }
376       }
377       msg << endreq ;
378     }
379     if ( !profile2DMapNumID().empty() || !profile2DMapLitID().empty() )
380     {
381       msg << "List of booked 2D profile histograms in directory "
382           << "\"" << histoPath() << "\" :-" ;
383       {
384         for ( Profile2DMapNumID::const_iterator entry = profile2DMapNumID().begin() ;
385               profile2DMapNumID().end() != entry ; ++entry )
386         {
387           AIDA::IProfile2D*   aida = entry->second ;
388           if ( 0 == aida )
389           { this->error() << "IProfile2D points to NULL" << endreq ; continue ; }
390           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
391           profiles.insert ( toBase ( aida  ) ) ;
392           msg << std::endl << GaudiAlg::Print2DProf::toString ( aida , entry->first );
393         }
394       }
395       {
396         for ( Profile2DMapLitID::const_iterator entry = profile2DMapLitID().begin() ;
397               profile2DMapLitID().end() != entry ; ++entry )
398         {
399           AIDA::IProfile2D*   aida = entry->second ;
400           if ( 0 == aida )
401           { this->error() << "IProfile2D points to NULL" << endreq ; continue ; }
402           if ( profiles.end() != profiles.find( toBase ( aida ) ) ) { continue ; }
403           profiles.insert ( toBase ( aida  ) ) ;
404           msg << std::endl << GaudiAlg::Print2DProf::toString ( aida , entry->first );
405         }
406       }
407       msg << endreq ;
408     }
409 
410   }
411   return histos.size() + profiles.size() ;
412 }
413 // ============================================================================
414 // Check if all histogram maps are empty
415 // ============================================================================
416 template <class PBASE>
417 bool GaudiHistos<PBASE>::noHistos() const
418 {
419   return ( histo1DMapTitle()   .empty() &&
420            histo2DMapTitle()   .empty() &&
421            histo3DMapTitle()   .empty() &&
422            profile1DMapTitle() .empty() &&
423            profile2DMapTitle() .empty() &&
424            histo1DMapNumID()   .empty() &&
425            histo1DMapLitID()   .empty() &&
426            histo2DMapNumID()   .empty() &&
427            histo2DMapLitID()   .empty() &&
428            histo3DMapNumID()   .empty() &&
429            histo3DMapLitID()   .empty() &&
430            profile1DMapNumID() .empty() &&
431            profile1DMapLitID() .empty() &&
432            profile2DMapNumID() .empty() &&
433            profile2DMapLitID() .empty() );
434 }
435 // ============================================================================
436 
437 // ============================================================================
438 // Declare a histogram to the monitor service
439 // ============================================================================
440 template <class PBASE>
441 void GaudiHistos<PBASE>::monitorHisto
442 ( const AIDA::IBaseHistogram* hist,
443   const HistoID& ID ) const
444 {
445   if ( hist && m_declareMoniHists )
446   {
447     if ( this->msgLevel(MSG::DEBUG) )
448     {
449       this->debug() << "Monitoring histogram '"
450                     << ID.idAsString() << "' desc = '"
451                     << Gaudi::Utils::Histos::htitle  ( hist ) << endreq;
452     }
453     this->declareInfo ( histoPath()+"/"+ID.idAsString() ,
454                         hist            ,
455                         Gaudi::Utils::Histos::htitle ( hist ) ) ;
456   }
457 }
458 // ============================================================================
459 // ==================================== 1D ====================================
460 // ============================================================================
461 // book the 1D histogram (book on demand)
462 // ============================================================================
463 template <class PBASE>
464 AIDA::IHistogram1D*  GaudiHistos<PBASE>::book1D
465 ( const std::string&  title        ,
466   const double        low          ,
467   const double        high         ,
468   const unsigned long bins         ) const
469 {
470   // exist?
471   AIDA::IHistogram1D* hist = histo1D ( title ) ;
472   // histogram is already booked
473   if( 0 != hist      )                           { return hist ; } // RETURN !!
474 
475   // propose the histogram ID
476   HistoID ID;
477   newHistoID( title, ID );
478 
479   // Create a new histogram and return
480   return this -> book1D ( ID, title, low, high, bins );
481 }
482 // ============================================================================
483 // book the 1D histogram with forced ID (book on demand)
484 // ============================================================================
485 template <class PBASE>
486 AIDA::IHistogram1D*  GaudiHistos<PBASE>::book1D
487 ( const HistoID&                ID     ,
488   const std::string&            title  ,
489   const double                  low    ,
490   const double                  high   ,
491   const unsigned long           bins   ) const
492 {
493   // Check ID
494   if (ID.undefined())
495   {
496     this->Error("Undefined Histogram ID : Title='"+title+"'");
497     return NULL;
498   }
499 
500   // exist?
501   AIDA::IHistogram1D* hist = histo1D ( ID ) ;
502   // histogram is already booked
503   if ( 0 != hist       )                         { return hist ; } // RETURN !!
504 
505   // Histogram title
506   const std::string & htitle =
507     ( title.empty() ? "Unnamed 1D Histogram ID="+ID.idAsString() : title ) ;
508 
509   // book the histogram
510   if ( ID.numeric() )
511   {
512     hist = this->histoSvc() -> book ( histoPath()  ,
513                                       ID.numericID() ,
514                                       htitle       ,
515                                       bins         ,
516                                       low          ,
517                                       high         ) ;
518   }
519   else if ( ID.literal() )
520   {
521     hist = this->histoSvc() -> book ( histoPath()+"/"+
522                                       ID.literalID() ,
523                                       htitle         ,
524                                       bins           ,
525                                       low            ,
526                                       high         ) ;
527   }
528 
529   // check OK
530   if( 0 == hist )
531   { this->Error( "IHistogram1D* points to NULL! ID='" + ID.idAsString() +
532                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
533 
534   // add histogram into histogram storages
535   if      ( ID.numeric() )
536   { m_histo1DMapNumID [ ID.numericID() ] = hist ; }
537   else if ( ID.literal() )
538   { m_histo1DMapLitID [ ID.literalID() ] = hist ; }
539   m_histo1DMapTitle [ title ] = hist ;
540 
541   // Declare to monitoring service
542   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
543 
544   // Printout and return
545   if ( this->msgLevel(MSG::DEBUG) )
546   { this->debug() << "Booked 1D Histogram : ID='" << ID
547                   << "' Path=" << histoPath()
548                   << " Title='"
549                   << Gaudi::Utils::Histos::htitle ( hist )
550                   << "'" << endreq; }
551   return hist ;
552 }
553 // ============================================================================
554 // fill the 1D histogram with the value and weight
555 // ============================================================================
556 template <class PBASE>
557 AIDA::IHistogram1D* GaudiHistos<PBASE>::fill
558 ( AIDA::IHistogram1D*  histo  ,
559   const double         value  ,
560   const double         weight ,
561   const std::string&   title  ) const
562 {
563   if ( 0 != histo && produceHistos() )
564   {
565     if ( !checkForNaN() )
566     { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
567     else if  ( lfin ( value ) && lfin ( weight ) )
568     { Gaudi::Utils::Histos::fill ( histo , value , weight ) ; }
569     else if  ( lnan ( value ) || lnan ( weight ) )
570     {
571       this -> Warning
572         ("fill():: 'NaN'      value is skipped from the histogram '"
573          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
574     }
575     else
576     {
577       this -> Warning
578         ("fill():: 'Infinite' value is skipped from the histogram '"
579          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
580     }
581   }
582   // return
583   return histo ;
584 }
585 // ============================================================================
586 // ==================================== 2D ====================================
587 // ============================================================================
588 // book the 2D histogram (book on demand)
589 // ============================================================================
590 template <class PBASE>
591 AIDA::IHistogram2D*  GaudiHistos<PBASE>::book2D
592 ( const std::string&  title   ,
593   const double        lowX    ,
594   const double        highX   ,
595   const unsigned long binsX   ,
596   const double        lowY    ,
597   const double        highY   ,
598   const unsigned long binsY   ) const
599 {
600   // exist?
601   AIDA::IHistogram2D* hist = histo2D ( title ) ;
602   // histogram is already booked
603   if( 0 != hist      )                                { return hist ; } // RETURN !!
604 
605   // propose the histogram ID
606   HistoID ID;
607   newHistoID( title, ID );
608 
609   // Create a new histogram and return
610   return this -> book2D ( ID, title, lowX, highX, binsX, lowY, highY, binsY );
611 }
612 // ============================================================================
613 // book the 2D histogram with forced ID (book on demand)
614 // ============================================================================
615 template <class PBASE>
616 AIDA::IHistogram2D*  GaudiHistos<PBASE>::book2D
617 ( const HistoID&      ID           ,
618   const std::string&  title   ,
619   const double        lowX    ,
620   const double        highX   ,
621   const unsigned long binsX   ,
622   const double        lowY    ,
623   const double        highY   ,
624   const unsigned long binsY   ) const
625 {
626   // Check ID
627   if (ID.undefined())
628   {
629     this->Error("Undefined Histogram ID : Title='"+title+"'");
630     return NULL;
631   }
632 
633   // exist?
634   AIDA::IHistogram2D* hist = histo2D( ID ) ;
635   // histogram is already booked
636   if( 0 != hist       )                         { return hist ; } // RETURN !!
637 
638   // Histogram title
639   const std::string & htitle =
640     ( title.empty() ? "Unnamed 2D Histogram ID="+ID.idAsString() : title ) ;
641 
642   // book the histogram
643   if ( ID.numeric() )
644   {
645     hist = this->histoSvc() -> book ( histoPath()  ,
646                                       ID.numericID() ,
647                                       htitle       ,
648                                       binsX        ,
649                                       lowX         ,
650                                       highX        ,
651                                       binsY        ,
652                                       lowY         ,
653                                       highY        ) ;
654   }
655   else if ( ID.literal() )
656   {
657     hist = this->histoSvc() -> book ( histoPath()+"/"+
658                                       ID.literalID() ,
659                                       htitle       ,
660                                       binsX        ,
661                                       lowX         ,
662                                       highX        ,
663                                       binsY        ,
664                                       lowY         ,
665                                       highY        ) ;
666   }
667 
668   // Check OK
669   if( 0 == hist )
670   { this->Error( "IHistogram2D* points to NULL! ID='" + ID.idAsString() +
671                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
672 
673   // add histogram into histogram storages
674   if      ( ID.numeric() )
675   { m_histo2DMapNumID [ ID.numericID() ] = hist ; }
676   else if ( ID.literal() )
677   { m_histo2DMapLitID [ ID.literalID() ] = hist ; }
678   m_histo2DMapTitle [ title ] = hist ;
679 
680   // Declare to monitoring service
681   monitorHisto( Gaudi::Utils::Histos::toBase ( hist) , ID );
682 
683   // Printout and return
684   if ( this->msgLevel(MSG::DEBUG) )
685   { this->debug() << "Booked 2D Histogram : ID='"
686                   << ID << "' Path=" << histoPath()
687                   << " Title='"
688                   << Gaudi::Utils::Histos::htitle ( hist )
689                   << "'" << endreq; }
690   // return
691   return hist ;
692 }
693 // ============================================================================
694 // fill the 2D histogram with the values and weight
695 // ============================================================================
696 template <class PBASE>
697 AIDA::IHistogram2D* GaudiHistos<PBASE>::fill
698 ( AIDA::IHistogram2D* histo  ,
699   const double        valueX ,
700   const double        valueY ,
701   const double        weight ,
702   const std::string&  title  ) const
703 {
704   if ( 0 != histo && produceHistos() )
705   {
706     if ( !checkForNaN() )
707     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ) ; }
708     else if  ( lfin ( valueX ) && lfin ( valueY ) && lfin ( weight ) )
709     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ) ; }
710     else if  ( lnan ( valueX ) || lnan ( valueY ) || lnan ( weight ) )
711     {
712       this -> Warning
713         ("fill():: 'NaN'      value is skipped from the histogram '"
714          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
715     }
716     else
717     {
718       this -> Warning
719         ("fill():: 'Infinite' value is skipped from the histogram '"
720          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
721     }
722   }
723   // return
724   return histo ;
725 }
726 // ============================================================================
727 // ==================================== 3D ====================================
728 // ============================================================================
729 // book the 3D histogram (book on demand)
730 // ============================================================================
731 template <class PBASE>
732 AIDA::IHistogram3D*  GaudiHistos<PBASE>::book3D
733 ( const std::string&  title   ,
734   const double        lowX    ,
735   const double        highX   ,
736   const unsigned long binsX   ,
737   const double        lowY    ,
738   const double        highY   ,
739   const unsigned long binsY   ,
740   const double        lowZ    ,
741   const double        highZ   ,
742   const unsigned long binsZ   ) const
743 {
744   // exist?
745   AIDA::IHistogram3D* hist = histo3D ( title ) ;
746   // histogram is already booked
747   if( 0 != hist      )                           { return hist ; } // RETURN !!
748 
749   // propose the histogram ID
750   HistoID ID;
751   newHistoID( title, ID );
752 
753   // Create a new histogram and return
754   return this -> book3D ( ID, title,
755                           lowX, highX, binsX,
756                           lowY, highY, binsY,
757                           lowZ, highZ, binsZ );
758 }
759 // ============================================================================
760 // book the 3D histogram with forced ID (book on demand)
761 // ============================================================================
762 template <class PBASE>
763 AIDA::IHistogram3D*  GaudiHistos<PBASE>::book3D
764 ( const HistoID&      ID           ,
765   const std::string&  title   ,
766   const double        lowX    ,
767   const double        highX   ,
768   const unsigned long binsX   ,
769   const double        lowY    ,
770   const double        highY   ,
771   const unsigned long binsY   ,
772   const double        lowZ    ,
773   const double        highZ   ,
774   const unsigned long binsZ   ) const
775 {
776   // Check ID
777   if (ID.undefined())
778   {
779     this->Error("Undefined Histogram ID : Title='"+title+"'");
780     return NULL;
781   }
782 
783   // exist?
784   AIDA::IHistogram3D* hist = histo3D( ID ) ;
785   // histogram is already booked
786   if( 0 != hist       )                        { return hist ; } // RETURN !!
787 
788   // Histogram title
789   const std::string & htitle =
790     ( title.empty() ? "Unnamed 3D Histogram ID="+ID.idAsString() : title ) ;
791 
792   // book the histogram
793   if ( ID.numeric() )
794   {
795     hist = this->histoSvc() -> book ( histoPath()  ,
796                                       ID.numericID() ,
797                                       htitle       ,
798                                       binsX        ,
799                                       lowX         ,
800                                       highX        ,
801                                       binsY        ,
802                                       lowY         ,
803                                       highY        ,
804                                       binsZ        ,
805                                       lowZ         ,
806                                       highZ        ) ;
807   }
808   else if ( ID.literal() )
809   {
810     hist = this->histoSvc() -> book ( histoPath()+"/"+
811                                       ID.literalID() ,
812                                       htitle       ,
813                                       binsX        ,
814                                       lowX         ,
815                                       highX        ,
816                                       binsY        ,
817                                       lowY         ,
818                                       highY        ,
819                                       binsZ        ,
820                                       lowZ         ,
821                                       highZ        ) ;
822   }
823 
824   // Check OK
825   if( 0 == hist )
826   { this->Error( "IHistogram3D* points to NULL! ID='" + ID.idAsString() +
827                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
828 
829   // add histogram into histogram storages
830   if      ( ID.numeric() )
831   { m_histo3DMapNumID [ ID.numericID() ] = hist ; }
832   else if ( ID.literal() )
833   { m_histo3DMapLitID [ ID.literalID() ] = hist ; }
834   m_histo3DMapTitle [ title ] = hist ;
835 
836   // Declare to monitoring service
837   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
838 
839   // Printout and return
840   if ( this->msgLevel(MSG::DEBUG) )
841   { this->debug() << "Booked 3D Histogram : ID='"
842                   << ID << "' Path=" << histoPath()
843                   << " Title='"
844                   << Gaudi::Utils::Histos::htitle ( hist )
845                   << "'" << endreq; }
846   return hist ;
847 }
848 // ============================================================================
849 // fill the 3D histogram with the values and weight
850 // ============================================================================
851 template <class PBASE>
852 AIDA::IHistogram3D* GaudiHistos<PBASE>::fill
853 ( AIDA::IHistogram3D* histo  ,
854   const double        valueX ,
855   const double        valueY ,
856   const double        valueZ ,
857   const double        weight ,
858   const std::string&  title  ) const
859 {
860   if ( 0 != histo && produceHistos() )
861   {
862     if ( !checkForNaN() )
863     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ) ; }
864     else if  ( lfin ( valueX ) && lfin ( valueY ) &&
865                lfin ( valueZ ) && lfin ( weight ) )
866     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ) ; }
867     else if  ( lnan ( valueX ) || lnan ( valueY ) ||
868                lnan ( valueZ ) || lnan ( weight ) )
869     {
870       this -> Warning
871         ("fill():: 'NaN'      value is skipped from the histogram '"
872          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
873     }
874     else
875     {
876       this -> Warning
877         ("fill():: 'Infinite' value is skipped from the histogram '"
878          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
879     }
880   }
881   // return
882   return histo ;
883 }
884 // ============================================================================
885 // =========================== Profile Histograms =============================
886 // ============================================================================
887 // book the 1D profile histogram (book on demand)
888 // ============================================================================
889 template <class PBASE>
890 AIDA::IProfile1D*  GaudiHistos<PBASE>::bookProfile1D
891 ( const std::string&  title        ,
892   const double        low          ,
893   const double        high         ,
894   const unsigned long bins         ,
895   const std::string&  opt          ,
896   const double        lowY         ,
897   const double        highY        ) const
898 {
899   // exist?
900   AIDA::IProfile1D* hist = profile1D ( title ) ;
901   // histogram is already booked
902   if( 0 != hist      )                              { return hist ; } // RETURN !!
903 
904   // propose the histogram ID
905   HistoID ID;
906   newHistoID( title, ID );
907 
908   // Book the histo and return
909   return this -> bookProfile1D ( ID, title, low, high, bins , opt , lowY , highY );
910 }
911 // ============================================================================
912 // book the 1D profile histogram with forced ID (book on demand)
913 // ============================================================================
914 template <class PBASE>
915 AIDA::IProfile1D*  GaudiHistos<PBASE>::bookProfile1D
916 ( const HistoID&      ID           ,
917   const std::string&  title        ,
918   const double        low          ,
919   const double        high         ,
920   const unsigned long bins         ,
921   const std::string&  opt          ,
922   const double        lowY         ,
923   const double        highY        ) const
924 {
925   // Check ID
926   if (ID.undefined())
927   {
928     this->Error("Undefined Histogram ID : Title='"+title+"'");
929     return NULL;
930   }
931 
932   // exist?
933   AIDA::IProfile1D* hist = profile1D ( ID ) ;
934   // histogram is already booked
935   if( 0 != hist       )                         { return hist ; } // RETURN !!
936 
937   // Histogram title
938   const std::string & htitle =
939     ( title.empty() ?
940       "Unnamed 1D Profile Histogram ID="+ID.idAsString() : title ) ;
941 
942   // book the histogram
943   if ( ID.numeric() )
944   {
945     hist = this->histoSvc() -> bookProf ( histoPath()  ,
946                                           ID.numericID() ,
947                                           htitle       ,
948                                           bins         ,
949                                           low          ,
950                                           high         ,
951                                           lowY         ,
952                                           highY        ,
953                                           opt          ) ;
954   }
955   else if ( ID.literal() )
956   {
957     hist = this->histoSvc() -> bookProf ( histoPath()+"/"+
958                                           ID.literalID() ,
959                                           htitle       ,
960                                           bins         ,
961                                           low          ,
962                                           high         ,
963                                           lowY         ,
964                                           highY        ,
965                                           opt          ) ;
966   }
967 
968   // test ok
969   if( 0 == hist )
970   { this->Error( "IProfile1D* points to NULL! ID='" + ID.idAsString() +
971                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
972 
973   // add histogram into histogram storages
974   if      ( ID.numeric() )
975   { m_profile1DMapNumID [ ID.numericID() ] = hist ; }
976   else if ( ID.literal() )
977   { m_profile1DMapLitID [ ID.literalID() ] = hist ; }
978   m_profile1DMapTitle [ title ] = hist ;
979 
980   // Declare to monitoring service
981   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
982 
983   // printout and return
984   if ( this->msgLevel(MSG::DEBUG) )
985   { this->debug() << "Booked 1D Profile Histogram : ID='"
986                   << ID << "' Path=" << histoPath()
987                   << " Title='"
988                   << Gaudi::Utils::Histos::htitle ( hist )
989                   << "'" << endreq; }
990   return hist ;
991 }
992 // ============================================================================
993 // fill the 1D profile histogram with the value and weight
994 // ============================================================================
995 template <class PBASE>
996 AIDA::IProfile1D* GaudiHistos<PBASE>::fill
997 ( AIDA::IProfile1D*    histo  ,
998   const double         valueX ,
999   const double         valueY ,
1000   const double         weight ,
1001   const std::string&   title  ) const
1002 {
1003   if ( 0 != histo && produceHistos() )
1004   {
1005     if ( !checkForNaN() )
1006     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ); }
1007     else if  ( lfin ( valueX ) && lfin ( valueY ) && lfin ( weight ) )
1008     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , weight ); }
1009     else if  ( lnan ( valueX ) || lnan ( valueY ) || lnan ( weight ) )
1010     {
1011       this -> Warning
1012         ("fill():: 'NaN'      value is skipped from the histogram '"
1013          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
1014     }
1015     else
1016     {
1017       this -> Warning
1018         ("fill():: 'Infinite' value is skipped from the histogram '"
1019          + Gaudi::Utils::Histos::htitle ( histo , title  ) + "'" ) ;
1020     }
1021   }
1022   // return
1023   return histo ;
1024 }
1025 // ============================================================================
1026 // book the 2D profile histogram (book on demand)
1027 // ============================================================================
1028 template <class PBASE>
1029 AIDA::IProfile2D*  GaudiHistos<PBASE>::bookProfile2D
1030 ( const std::string&  title        ,
1031   const double        lowX         ,
1032   const double        highX        ,
1033   const unsigned long binsX        ,
1034   const double        lowY         ,
1035   const double        highY        ,
1036   const unsigned long binsY         ) const
1037 {
1038   // exist?
1039   AIDA::IProfile2D* hist = profile2D ( title ) ;
1040   // histogram is already booked
1041   if( 0 != hist      )                          { return hist ; } // RETURN !!
1042 
1043   // propose the histogram ID
1044   HistoID ID;
1045   newHistoID( title, ID );
1046 
1047   // book histogram and return
1048   return this -> bookProfile2D ( ID, title, lowX, highX, binsX, lowY, highY, binsY );
1049 }
1050 // ============================================================================
1051 // book the 2D profile histogram with forced ID (book on demand)
1052 // ============================================================================
1053 template <class PBASE>
1054 AIDA::IProfile2D*  GaudiHistos<PBASE>::bookProfile2D
1055 ( const HistoID&      ID           ,
1056   const std::string&  title        ,
1057   const double        lowX         ,
1058   const double        highX        ,
1059   const unsigned long binsX        ,
1060   const double        lowY         ,
1061   const double        highY        ,
1062   const unsigned long binsY         ) const
1063 {
1064   // Check ID
1065   if (ID.undefined())
1066   {
1067     this->Error("Undefined Histogram ID : Title='"+title+"'");
1068     return NULL;
1069   }
1070 
1071   // exist?
1072   AIDA::IProfile2D* hist = profile2D ( ID ) ;
1073   // histogram is already booked
1074   if( 0 != hist )                               { return hist ; } // RETURN !!
1075 
1076   // Histogram title
1077   const std::string & htitle =
1078     ( title.empty() ?
1079       "Unnamed 2D Profile Histogram ID="+ID.idAsString() : title ) ;
1080 
1081   // book the histogram
1082   if ( ID.numeric() )
1083   {
1084     hist = this->histoSvc() -> bookProf ( histoPath() ,
1085                                           ID.numericID() ,
1086                                           htitle      ,
1087                                           binsX       ,
1088                                           lowX        ,
1089                                           highX       ,
1090                                           binsY       ,
1091                                           lowY        ,
1092                                           highY        ) ;
1093   }
1094   else if ( ID.literal() )
1095   {
1096     hist = this->histoSvc() -> bookProf ( histoPath()+"/"+
1097                                           ID.literalID() ,
1098                                           htitle      ,
1099                                           binsX       ,
1100                                           lowX        ,
1101                                           highX       ,
1102                                           binsY       ,
1103                                           lowY        ,
1104                                           highY        ) ;
1105   }
1106 
1107   // test OK
1108   if( 0 == hist )
1109   { this->Error( "IProfile2D* points to NULL! ID='" + ID.idAsString() +
1110                  "' title='"+htitle+"'" ) ; return 0; } // RETURN !!
1111 
1112   // add histogram into histogram storages
1113   if      ( ID.numeric() )
1114   { m_profile2DMapNumID [ ID.numericID() ] = hist ; }
1115   else if ( ID.literal() )
1116   { m_profile2DMapLitID [ ID.literalID() ] = hist ; }
1117   m_profile2DMapTitle [ title ] = hist ;
1118 
1119   // Declare to monitoring service
1120   monitorHisto( Gaudi::Utils::Histos::toBase ( hist ) , ID );
1121 
1122   // printout and return
1123   if ( this->msgLevel(MSG::DEBUG) )
1124   {  this->debug() << "Booked 2D Profile Histogram : ID='" << ID
1125                    << "' Path=" << histoPath()
1126                    << " Title='"
1127                    << Gaudi::Utils::Histos::htitle ( hist )
1128                    << "'" << endreq; }
1129   return hist ;
1130 }
1131 // ============================================================================
1132 // fill the 2D profile histogram with the value and weight
1133 // ============================================================================
1134 template <class PBASE>
1135 AIDA::IProfile2D* GaudiHistos<PBASE>::fill
1136 ( AIDA::IProfile2D*    histo  ,
1137   const double         valueX ,
1138   const double         valueY ,
1139   const double         valueZ ,
1140   const double         weight ,
1141   const std::string&   title  ) const
1142 {
1143   if ( 0 != histo && produceHistos() )
1144   {
1145     if ( !checkForNaN() )
1146     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ); }
1147     else if  ( lfin ( valueX ) && lfin ( valueY ) &&
1148                lfin ( valueZ ) && lfin ( weight ) )
1149     { Gaudi::Utils::Histos::fill ( histo , valueX , valueY , valueZ , weight ); }
1150     else if  ( lnan ( valueX ) || lnan ( valueY ) ||
1151                lnan ( valueZ ) || lnan ( weight ) )
1152     {
1153       this -> Warning
1154         ("fill():: 'NaN'      value is skipped from the histogram '"
1155          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
1156     }
1157     else
1158     {
1159       this -> Warning
1160         ("fill():: 'Infinite' value is skipped from the histogram '"
1161          + Gaudi::Utils::Histos::htitle ( histo , title ) + "'" ) ;
1162     }
1163   }
1164   // return
1165   return histo ;
1166 }
1167 // ============================================================================
1168 // fill the 1D histogram (book on demand)
1169 // ============================================================================
1170 template <class PBASE>
1171 AIDA::IHistogram1D*
1172 GaudiHistos<PBASE>::plot1D
1173 ( const double        value  ,
1174   const std::string&  title  ,
1175   const double        low    ,
1176   const double        high   ,
1177   const unsigned long bins   ,
1178   const double        weight ) const
1179 {
1180   AIDA::IHistogram1D * h(0);
1181   if ( produceHistos() )
1182   {
1183     // retrieve or book the histogram
1184     h = histo1D ( title ) ;
1185     if ( 0 == h )     { h = book1D  ( title , low , high , bins ) ; }
1186     // fill the histogram
1187     h = fill ( h , value , weight , title );
1188   }
1189   return h;
1190 }
1191 // ============================================================================
1192 // fill the 1D histogram with forced ID assignment (book on demand)
1193 // ============================================================================
1194 template <class PBASE>
1195 AIDA::IHistogram1D*
1196 GaudiHistos<PBASE>::plot1D
1197 ( const double        value  ,
1198   const HistoID&      ID     ,
1199   const std::string&  title  ,
1200   const double        low    ,
1201   const double        high   ,
1202   const unsigned long bins   ,
1203   const double        weight ) const
1204 {
1205   AIDA::IHistogram1D* h(0);
1206   if ( produceHistos() )
1207   {
1208     // retrieve or book the histogram
1209     h = histo1D ( ID ) ;
1210     if ( 0 == h ) {  h = book1D ( ID , title , low , high , bins ) ; }
1211     // fill
1212     h = fill ( h , value , weight , title ) ;
1213   }
1214   return h;
1215 }
1216 // ============================================================================
1217 // fill the 2D histogram (book on demand)
1218 // ============================================================================
1219 template <class PBASE>
1220 AIDA::IHistogram2D* GaudiHistos<PBASE>::plot2D
1221 ( const double        valueX       ,
1222   const double        valueY       ,
1223   const std::string&  title        ,
1224   const double        lowX         ,
1225   const double        highX        ,
1226   const double        lowY         ,
1227   const double        highY        ,
1228   const unsigned long binsX        ,
1229   const unsigned long binsY        ,
1230   const double        weight       ) const
1231 {
1232   AIDA::IHistogram2D * h(0);
1233   if ( produceHistos() )
1234   {
1235     // retrieve or book the histogram
1236     h = histo2D ( title ) ;
1237     if ( 0 == h )
1238     { h = book2D ( title , lowX , highX , binsX , lowY , highY , binsY ) ; }
1239     // fill the histogram
1240     h = fill ( h , valueX , valueY , weight , title ) ;
1241   }
1242   return h;
1243 }
1244 // ============================================================================
1245 // fill the 2D histogram with forced ID assignment (book on demand)
1246 // ============================================================================
1247 template <class PBASE>
1248 AIDA::IHistogram2D*  GaudiHistos<PBASE>::plot2D
1249 ( const double        valueX       ,
1250   const double        valueY       ,
1251   const HistoID&      ID           ,
1252   const std::string&  title        ,
1253   const double        lowX         ,
1254   const double        highX        ,
1255   const double        lowY         ,
1256   const double        highY        ,
1257   const unsigned long binsX        ,
1258   const unsigned long binsY        ,
1259   const double        weight       ) const
1260 {
1261   AIDA::IHistogram2D * h(0);
1262   // produce histograms ?
1263   if ( produceHistos() )
1264   {
1265     // retrieve or book the histogram
1266     h = histo2D ( ID ) ;
1267     if ( 0 == h ) { h = book2D ( ID   , title ,
1268                                  lowX , highX , binsX ,
1269                                  lowY , highY , binsY ) ; }
1270     // fill the histogram
1271     h = fill ( h , valueX , valueY , weight , title ) ;
1272   }
1273   return h;
1274 }
1275 // ============================================================================
1276 // fill the 3D histogram (book on demand)
1277 // ============================================================================
1278 template <class PBASE>
1279 AIDA::IHistogram3D*  GaudiHistos<PBASE>::plot3D
1280 ( const double        valueX       ,
1281   const double        valueY       ,
1282   const double        valueZ       ,
1283   const std::string&  title        ,
1284   const double        lowX         ,
1285   const double        highX        ,
1286   const double        lowY         ,
1287   const double        highY        ,
1288   const double        lowZ         ,
1289   const double        highZ        ,
1290   const unsigned long binsX        ,
1291   const unsigned long binsY        ,
1292   const unsigned long binsZ        ,
1293   const double        weight       ) const
1294 {
1295   AIDA::IHistogram3D * h(0);
1296   if ( produceHistos() )
1297   {
1298     // retrieve or book the histogram
1299     h = histo3D ( title ) ;
1300     if ( 0 == h ) { h = book3D ( title ,
1301                                  lowX , highX , binsX ,
1302                                  lowY , highY , binsY ,
1303                                  lowZ , highZ , binsZ ) ; }
1304     // fill the histogram
1305     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
1306   }
1307   return h;
1308 }
1309 // ============================================================================
1310 // fill the 3D histogram with forced ID assignment (book on demand)
1311 // ============================================================================
1312 template <class PBASE>
1313 AIDA::IHistogram3D* GaudiHistos<PBASE>::plot3D
1314 ( const double        valueX       ,
1315   const double        valueY       ,
1316   const double        valueZ       ,
1317   const HistoID&      ID           ,
1318   const std::string&  title        ,
1319   const double        lowX         ,
1320   const double        highX        ,
1321   const double        lowY         ,
1322   const double        highY        ,
1323   const double        lowZ         ,
1324   const double        highZ        ,
1325   const unsigned long binsX        ,
1326   const unsigned long binsY        ,
1327   const unsigned long binsZ        ,
1328   const double        weight       ) const
1329 {
1330   AIDA::IHistogram3D * h(0);
1331   if ( produceHistos() )
1332   {
1333     // retrieve or book the histogram
1334     h = histo3D ( ID ) ;
1335     if ( 0 == h ) { h = book3D ( ID , title ,
1336                                  lowX , highX , binsX ,
1337                                  lowY , highY , binsY ,
1338                                  lowZ , highZ , binsZ ) ; }
1339     // fill the histogram
1340     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
1341   }
1342   return h;
1343 }
1344 // ============================================================================
1345 // fill the 1D profile histogram (book on demand)
1346 // ============================================================================
1347 template <class PBASE>
1348 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D
1349 ( const double        valueX       ,
1350   const double        valueY       ,
1351   const std::string&  title        ,
1352   const double        lowX         ,
1353   const double        highX        ,
1354   const unsigned long binsX        ,
1355   const std::string&  opt          ,
1356   const double        lowY         ,
1357   const double        highY        ,
1358   const double        weight       ) const
1359 {
1360   AIDA::IProfile1D * h(0);
1361   if ( produceHistos() )
1362   {
1363     // retrieve or book the histogram
1364     h = profile1D ( title ) ;
1365     if ( 0 == h )
1366     { h = bookProfile1D ( title , lowX , highX , binsX , opt , lowY , highY ) ; }
1367     // fill the histogram
1368     h = fill ( h , valueX , valueY , weight , title ) ;
1369   }
1370   return h;
1371 }
1372 // ============================================================================
1373 // fill the 1D profile histogram with forced ID assignment (book on demand)
1374 // ============================================================================
1375 template <class PBASE>
1376 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D
1377 ( const double        valueX       ,
1378   const double        valueY       ,
1379   const HistoID&      ID           ,
1380   const std::string&  title        ,
1381   const double        lowX         ,
1382   const double        highX        ,
1383   const unsigned long binsX        ,
1384   const std::string&  opt          ,
1385   const double        lowY         ,
1386   const double        highY        ,
1387   const double        weight       ) const
1388 {
1389   AIDA::IProfile1D * h(0);
1390   if ( produceHistos() )
1391   {
1392     // retrieve or book the histogram
1393     h = profile1D ( ID ) ;
1394     if ( 0 == h )
1395     { h = bookProfile1D ( ID , title , lowX , highX , binsX , opt , lowY , highY ) ; }
1396     // fill the histogram
1397     h = fill ( h , valueX , valueY , weight , title ) ;
1398   }
1399   return h;
1400 }
1401 // ============================================================================
1402 // fill the 2D profile histogram (book on demand)
1403 // ============================================================================
1404 template <class PBASE>
1405 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D
1406 ( const double        valueX       ,
1407   const double        valueY       ,
1408   const double        valueZ       ,
1409   const std::string&  title        ,
1410   const double        lowX         ,
1411   const double        highX        ,
1412   const double        lowY         ,
1413   const double        highY        ,
1414   const unsigned long binsX        ,
1415   const unsigned long binsY        ,
1416   const double        weight       ) const
1417 {
1418   AIDA::IProfile2D * h(0);
1419   if ( produceHistos() )
1420   {
1421     // retrieve or book the histogram
1422     h = profile2D ( title ) ;
1423     if ( 0 == h ) { h = bookProfile2D ( title ,
1424                                         lowX , highX , binsX ,
1425                                         lowY , highY , binsY ) ; }
1426     // fill the histogram
1427     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
1428   }
1429   return h;
1430 }
1431 // ============================================================================
1432 // fill the 2D profile histogram with forced ID assignment (book on demand)
1433 // ============================================================================
1434 template <class PBASE>
1435 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D
1436 ( const double        valueX       ,
1437   const double        valueY       ,
1438   const double        valueZ       ,
1439   const HistoID&      ID           ,
1440   const std::string&  title        ,
1441   const double        lowX         ,
1442   const double        highX        ,
1443   const double        lowY         ,
1444   const double        highY        ,
1445   const unsigned long binsX        ,
1446   const unsigned long binsY        ,
1447   const double        weight       ) const
1448 {
1449   AIDA::IProfile2D * h(0);
1450   if ( produceHistos() )
1451   {
1452     // retrieve or book the histogram
1453     h = profile2D ( ID ) ;
1454     if ( 0 == h ) { h = bookProfile2D ( ID , title ,
1455                                         lowX , highX , binsX ,
1456                                         lowY , highY , binsY ) ; }
1457     // fill the histogram
1458     h = fill ( h , valueX , valueY , valueZ , weight , title ) ;
1459   }
1460   return h;
1461 }
1462 // ============================================================================
1463 // book the 1D histogram
1464 // ============================================================================
1465 template <class PBASE>
1466 AIDA::IHistogram1D*
1467 GaudiHistos<PBASE>::book
1468 ( const Gaudi::Histo1DDef& hdef ) const
1469 {
1470   return book1D ( hdef.title    () ,
1471                   hdef.lowEdge  () ,
1472                   hdef.highEdge () ,
1473                   hdef.bins     () ) ;
1474 }
1475 // ============================================================================
1476 // book the 1D histogram with forced ID
1477 // ============================================================================
1478 template <class PBASE>
1479 AIDA::IHistogram1D*
1480 GaudiHistos<PBASE>::book
1481 ( const HistoID&           ID   ,
1482   const Gaudi::Histo1DDef& hdef ) const
1483 {
1484   return book1D ( ID               ,
1485                   hdef.title    () ,
1486                   hdef.lowEdge  () ,
1487                   hdef.highEdge () ,
1488                   hdef.bins     () ) ;
1489 }
1490 // ============================================================================
1491 // fill the 1D histogram (book on demand)
1492 // ============================================================================
1493 template <class PBASE>
1494 AIDA::IHistogram1D*
1495 GaudiHistos<PBASE>::plot
1496 ( const double             value  ,
1497   const Gaudi::Histo1DDef& hdef   ,
1498   const double             weight ) const
1499 {
1500   return plot1D
1501     ( value  ,
1502       hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
1503       weight ) ;
1504 }
1505 // ============================================================================
1506 // fill the 1D histogram with forced ID assignment (book on demand)
1507 // ============================================================================
1508 template <class PBASE>
1509 AIDA::IHistogram1D*
1510 GaudiHistos<PBASE>::plot
1511 ( const double             value  ,
1512   const HistoID&           ID     ,
1513   const Gaudi::Histo1DDef& hdef   ,
1514   const double             weight ) const
1515 {
1516   return plot1D
1517     ( value  , ID ,
1518       hdef.title() , hdef.lowEdge() , hdef.highEdge() , hdef.bins() ,
1519       weight ) ;
1520 }
1521 // ============================================================================
1522 // access the EXISTING 1D histogram by ID
1523 // ============================================================================
1524 template <class PBASE>
1525 AIDA::IHistogram1D* GaudiHistos<PBASE>::histo1D ( const HistoID& ID )  const
1526 {
1527   AIDA::IHistogram1D * h(0);
1528   if ( ID.numeric() )
1529   {
1530     Histo1DMapNumID::const_iterator found =
1531       histo1DMapNumID().find( ID.numericID() ) ;
1532     h = ( histo1DMapNumID().end() == found ? 0 : found->second );
1533   }
1534   else
1535   {
1536     Histo1DMapLitID::const_iterator found =
1537       histo1DMapLitID().find( ID.literalID() ) ;
1538     h = ( histo1DMapLitID().end() == found ? 0 : found->second );
1539   }
1540   return h;
1541 }
1542 // ============================================================================
1543 // access the EXISTING 2D histogram by ID
1544 // ============================================================================
1545 template <class PBASE>
1546 AIDA::IHistogram2D* GaudiHistos<PBASE>::histo2D ( const HistoID& ID )  const
1547 {
1548   AIDA::IHistogram2D * h(0);
1549   if ( ID.numeric() )
1550   {
1551     Histo2DMapNumID::const_iterator found =
1552       histo2DMapNumID().find( ID.numericID() ) ;
1553     h = ( histo2DMapNumID().end() == found ? 0 : found->second );
1554   }
1555   else
1556   {
1557     Histo2DMapLitID::const_iterator found =
1558       histo2DMapLitID().find( ID.literalID() ) ;
1559     h = ( histo2DMapLitID().end() == found ? 0 : found->second );
1560   }
1561   return h;
1562 }
1563 // ============================================================================
1564 // access the EXISTING 3D histogram by ID
1565 // ============================================================================
1566 template <class PBASE>
1567 AIDA::IHistogram3D* GaudiHistos<PBASE>::histo3D ( const HistoID& ID )  const
1568 {
1569   AIDA::IHistogram3D * h(0);
1570   if ( ID.numeric() )
1571   {
1572     Histo3DMapNumID::const_iterator found =
1573       histo3DMapNumID().find( ID.numericID() ) ;
1574     h = ( histo3DMapNumID().end() == found ? 0 : found->second );
1575   }
1576   else
1577   {
1578     Histo3DMapLitID::const_iterator found =
1579       histo3DMapLitID().find( ID.literalID() ) ;
1580     h = ( histo3DMapLitID().end() == found ? 0 : found->second );
1581   }
1582   return h;
1583 }
1584 // ============================================================================
1585 // access the EXISTING 1D profile histogram by ID
1586 // ============================================================================
1587 template <class PBASE>
1588 AIDA::IProfile1D* GaudiHistos<PBASE>::profile1D ( const HistoID& ID )  const
1589 {
1590   AIDA::IProfile1D * h(0);
1591   if ( ID.numeric() )
1592   {
1593     Profile1DMapNumID::const_iterator found =
1594       profile1DMapNumID().find( ID.numericID() ) ;
1595     h = ( profile1DMapNumID().end() == found ? 0 : found->second );
1596   }
1597   else
1598   {
1599     Profile1DMapLitID::const_iterator found =
1600       profile1DMapLitID().find( ID.literalID() ) ;
1601     h = ( profile1DMapLitID().end() == found ? 0 : found->second );
1602   }
1603   return h;
1604 }
1605 // ============================================================================
1606 // access the EXISTING 2D profile histogram by ID
1607 // ============================================================================
1608 template <class PBASE>
1609 AIDA::IProfile2D* GaudiHistos<PBASE>::profile2D ( const HistoID& ID )  const
1610 {
1611   AIDA::IProfile2D * h(0);
1612   if ( ID.numeric() )
1613   {
1614     Profile2DMapNumID::const_iterator found =
1615       profile2DMapNumID().find( ID.numericID() ) ;
1616     h = ( profile2DMapNumID().end() == found ? 0 : found->second );
1617   }
1618   else
1619   {
1620     Profile2DMapLitID::const_iterator found =
1621       profile2DMapLitID().find( ID.literalID() ) ;
1622     h = ( profile2DMapLitID().end() == found ? 0 : found->second );
1623   }
1624   return h;
1625 }
1626 // ============================================================================
1627 // Returns the total number of histograms (of all types) currently booked
1628 // ============================================================================
1629 template <class PBASE>
1630 unsigned int GaudiHistos<PBASE>::totalNumberOfHistos() const
1631 {
1632   const unsigned int n1D  = histo1DMapNumID().size()+histo1DMapLitID().size();
1633   const unsigned int n2D  = histo2DMapNumID().size()+histo2DMapLitID().size();
1634   const unsigned int n3D  = histo3DMapNumID().size()+histo3DMapLitID().size();
1635   const unsigned int n1DP = profile1DMapNumID().size()+profile1DMapLitID().size();
1636   const unsigned int n2DP = profile2DMapNumID().size()+profile2DMapLitID().size();
1637   return n1D+n2D+n3D+n1DP+n2DP;
1638 }
1639 // ============================================================================
1640 // Create a new histogram ID using the given title
1641 // ============================================================================
1642 template <class PBASE>
1643 void GaudiHistos<PBASE>::newHistoID( const std::string & title,
1644                                      HistoID& ID ) const
1645 {
1646   if ( useNumericAutoIDs() || title.empty() )
1647   {
1648     if ( !useNumericAutoIDs() )
1649     {
1650       this -> Warning( "Cannot generate automatic literal ID from an empty title ! Using numeric ID instead for histogram ID",
1651                        StatusCode::SUCCESS );
1652     }
1653     // propose the histogram ID (always numeric)
1654     ID = HistoID( totalNumberOfHistos() + 1 + histoOffSet() );
1655     // adjust the proposed ID
1656     while ( histoExists( ID ) ) { ++ID; }
1657   }
1658   else
1659   {
1660     // use the title to create a unique literal ID
1661     ID = HistoID( this->convertTitleToID(title) );
1662     // Just in case ...
1663     while ( histoExists( ID ) ) { ID = HistoID(ID.idAsString()+"_"); }
1664   }
1665 }
1666 // ============================================================================
1667 // Create an ID string from a title string
1668 // ============================================================================
1669 template <class PBASE>
1670 std::string GaudiHistos<PBASE>::convertTitleToID( const std::string & title ) const
1671 {
1672   // clean up the ID string for all unwanted characters
1673   std::string tmp_id = title;
1674   for ( std::map<std::string,std::string>::const_iterator i = m_idReplaceInfo.begin();
1675         i != m_idReplaceInfo.end(); ++i )
1676   {
1677     stringSearchReplace( tmp_id, i->first, i->second );
1678   }
1679   return tmp_id;
1680 }
1681 // ============================================================================
1682 // Searches 'title' for all instancies of 'A' and replaces them with 'B'
1683 // ============================================================================
1684 template <class PBASE>
1685 void GaudiHistos<PBASE>::stringSearchReplace( std::string & title,
1686                                               const std::string & A,
1687                                               const std::string & B ) const
1688 {
1689   std::string::size_type slash = title.find_first_of ( A ) ;
1690   while ( std::string::npos != slash )
1691   {
1692     title = title.substr(0,slash) + B + title.substr(slash+A.size());
1693     slash = title.find_first_of( A );
1694   }
1695 }
1696 // ============================================================================
1697 // The END
1698 // ============================================================================
1699 #endif // GAUDIALG_GAUDIHISTOS_ICPP
1700 // ============================================================================

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!