7. Using interfaces

Table of Contents

Interfaces in HTL
Example using Interface classes

Interfaces are a powerful OO concept which allows designers to decouple what an object does from its actual implementation. This reduces the impact on "external" software using such object(s) and makes software reuse more realistic.

In the C++ world, interfaces are usually implemented by abstract classes with virtual methods. In this context the only drawback of interfaces might be a performance penalty due to the extra indirection required by virtual functions, but we should not neglect the usefulness of interfaces just because of that.

Interfaces in HTL

HTL defines and implements abstract interfaces for most of its functionalities. The only method which is not available on purpose at the interface level is the fill() method, which must be implemented as an non-virtual inline method to provide the highest performance (see Appendix Appendix C. for details).

HTL interfaces are used by other packages such as fitting (HEPFitting) and visualisation (HEPInventor) that are thus independent from the actual HTL implementation of histograms. Interfaces are what allows external packages to deal with transient and persistent HTL histograms at the same time. Using such interfaces we might even implement an HTL-like package based on other technologies, for instance an HTL interface to HBOOK, although this is not envisaged at present.

The I_Histo interface

I_Histo is the high-level interface to histograms. The following is a list of supported methods.

virtual const char* name()

Title attached to current histogram.

virtual I_Bin& i_bin( I_Bin_Location &a_location )

In-range bin associated with location a_location.

virtual I_Bin& i_extra_bin( I_Extra_Bin_Location &a_location )

Extra bin associated with extra location a_location.

virtual Size bin_count()

Number of in-range bins.

virtual Size extra_bin_count()

Number of extra bins.

virtual Size dim()

Dimension of the histo, i.e., of the problem space.

virtual I_Partition& i_partition( Index p = 0 )

Partition interface associated with this histo. For the first partition one has a_dim_index = 0.

virtual I_Bin& i_bin( Index i )

Any bin (in-range or extra) with index "i" (note that this is a linear access).

The I_Histo interface can retrieve the number of bins that are in-range or out-range, for instance, overflow or underflow, as well as the number of partitions (i.e. the dimensionality of the histogram). It also allows you to access other interfaces such as I_Partition and I_Bin.

On the other hand, the I_Histo interface does not try to provide all information in a single interface: details about binning and bin content are delegated, respectively, to the I_Partition and I_Bin interfaces, as explained later.

The I_Partition interface

The I_partition interface deals with binning details, such as, which interval of the problem space a bin is mapped to, that is where does it start and end, and what are the limits of the range spanned by the partition. The following is a list of supported methods.

End_Point_Convention end_point_convention()

End point convention for all bins; can be either RIGHT_OPEN or LEFT_OPEN.

virtual double i_bin_width( Index i )

Width of in-range bin "i".

virtual double i_lower_point()

Leftmost point of the partition.

virtual double i_lower_point( Index i )

Leftmost point of bin indexed by "i".

virtual double i_upper_point()

Rightmost point of the partition.

virtual double i_upper_point( Index i )

R`ightmost point of bin indexed by "i".

The I_Bin interface

The I_Bin interface allows you to set or get the content of a bin, its count information, and its error. The available methods are listed below.

virtual double value( Index i = 0)

Value associated with this bin.

virtual double error( Index i = 0)

Error associated with this bin.

virtual Size count()

Count associated with this bin. = Number of entries.

virtual void set_value( double other, Index i = 0 )

Set the value associated with this bin to "other".

virtual void set_error( double other, Index i = 0 )

Change/set the error of the bin to "other".

virtual void set_count( Size other )

Change/set the count of the bin to "other".

virtual double center( Index i = 0)

Absolute or relative center of this bin on axis "i".

virtual int offset( Index i = 0)

Relative or absolute position for the center of the bin.