19 Writing histograms to external 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 *
>>> 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=P1('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 you can add histograms (H1D or H2D) or containers (P1D) to HBook object with some ID numbers, and then you can write all such objects to an external XML file.

Also, the HBook allows to read such XML file using the "read" method (in this case all objects are added to the HBook container automatically). As shown in Section :autorefsection20, this class can be used to read histograms from external C++ or FORTRAN programs.