6. Histogram Factories and Naming Trees

Table of Contents

Histogram factories
Naming histograms
Retrieving named histograms

This section describes a number of techniques for handling the naming and location of persistent histograms in the database. As such, this section only applies to persistent HTL histograms as they

Histogram factories

The Object Database Management Group (ODMG) standard for Object Databases specifies that persistent objects are created using a new() operator with a clustering hint argument. This parameter provides a mechanism whereby the user or application code can specify where each individual object is physically stored. This is demonstrated by the the following code fragment, where the histo1 object is created in the database referred to by the database handle db_.

HepRef(PHisto1D) histo1 = 
  new (db_) PHisto1D("A 1D histogram",20,0.,40.);

Not only is this syntax somewhat unusual to novice users, but also it poses problems when attempting to use tools such as the SWIG interface generator for scripting languages.[2]

The HFactory class overcomes this problem by letting the user specify by name the database or container in which histograms should be created and provides a factory method for the actual creation of the histograms.

The following code fragment demonstrates the usage of a Histogram Factory. It first initialises the factory, specifying the target database and container by name. Histograms are then created and filled and are automatically stored in the appropriate container.

#include "HTL/H_Factory.h" 
... 
  HFactory myFactory; 
  // Create histograms in DataBase "gepo", Container "sbaffini" 
  if (myFactory.init(this,"gepo","sbaffini")) { 
    // Create a histogram using the factory 
    HepRef(PHisto1D) h1 = myFactory.Histo1D("Histo-1",noBins,0.0,20.0); 
   ... 
   h1->fill(x, 1.); 

The HFactory class provides a method to generate all useful types of histograms. The factory methods are named according to the histogram type and take parameters according to the corresponding constructor.

int init (HepDbApplication *sess, char *dbname,  char *contname = 0); 
HepRef(PHisto1D) Histo1D (const char *a_title, Size n, double x1, 
              double x2, End_Point_Convention epc = RIGHT_OPEN);
HepRef(PHisto1DVar) Histo1DVar(const char *,P_Points_Vector &,
              End_Point_Convention epc = RIGHT_OPEN );  
HepRef(PProfileHisto) ProfileHisto1D (const char *a_title, Size n,
              double x1, double x2, End_Point_Convention  epc =
              RIGHT_OPEN ); 
HepRef(PProfileHistoVar) ProfileHisto1DVar(const char *,
              P_Points_Vector &, End_Point_Convention epc = RIGHT_OPEN );  
HepRef(PHisto2D) Histo2D (const char *, Size , double  , double ,
              Size , double  , double , End_Point_Convention  epc1 =
              RIGHT_OPEN , End_Point_Convention  epc2 = RIGHT_OPEN );  
HepRef(PHisto2DVar) Histo2DVar( const char *, P_Points_Vector &,
              P_Points_Vector &, End_Point_Convention  epc1 =
              RIGHT_OPEN, End_Point_Convention   epc2 = RIGHT_OPEN );  

The SWIG interface generator provides a generic mechanism for integrating a wide variety of scripting languages, including Tcl, Perl, Python and even Java.