3.23 Writing histograms to XML files. HBook class.

Histograms can be saved (booked) using the HBook class as shown in the examples hbook.py and hbook2D.py:

>>> from jhplot  import HBook,H1D,H2D,P1D
>>>
>>> hb = HBook("my hbook")          # create HBook instance with description 
>>> h3=H1D("test",2,0.0,1.)         # create a new H1D histogram
>>> h4=H2D("test",5,0.0,1.,4,0.,1.) # create a new H2D histogram
>>> hb.add(30,h3)           # add to HBook with ID=30
>>> hb.add(40,h3)           # add to HBook with ID=40
>>> p1=P1D('test")          # create P1D objects
>>> hb.add(10,p1)           # add to HBook with ID=10 
>>> print hb.listH1D()      # list all histograms
>>> h1 = hb.getH1D(30)      # get H1D histogram with ID=30
>>> ...
>>> hb.write("out.xml")     # write all objects to an XML file
This example illustrates that the user can add histograms (H1D or H2D) or containers (P1D) to HBook object with some ID numbers, and then one can write all such objects to an external XML file.

Also, the HBook allows to read previously created XML files using the read() method. In this case, all objects are added to the HBook container automatically. As shown in Section :autorefGetting started with jHepWork Java classes3.24, this class can be used to read histograms from external C++ or FORTRAN programs.