 |
Serialize a collection of histograms to a XML file
Source code name: "io_histo_XML.py"
Programming language: Python
Topic: File IO/XML
DMelt Version 1. Last modified: 12/11/2015. License: Pro
https://datamelt.org/code/cache/io_histo_XML_3939.py
To run this script using the DMelt IDE,
copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.
from java.awt import Color,Font
from jhplot import *
from jhplot.io import *
from java.util import Random
# define dictionary
hold = {}
h1=H1D('XML Simple1',20, -2.0, 2.0)
h1.setFill(1)
h1.setFillColor(Color.blue)
h11=H1D('XML Simple2',40, -2.0, 3.0)
h11.setFill(1)
h11.setFillColor(Color.red)
# fill histograms
r=Random()
for i in range(1000):
h1.fill(r.nextGaussian())
h11.fill(r.nextGaussian()+1)
hold["describe"] = "H1D objects from serialized XML file"
hold["h1"]=h1
hold["h11"]=h11
# write to a file in the user macros directory
Serialized.writeXML(hold,'file.jxml')
# check what is written
print Serialized.toXML(h1)
# deserialize dictionary from the file
hold=Serialized.readXML('file.jxml' )
# print all keys
print hold.keys()
print "Description: "+hold["describe"]
c1 = HPlot("Canvas",600,400)
c1.setGTitle( hold["describe"] );
c1.visible(1)
c1.setAutoRange()
c1.draw(hold["h1"])
c1.draw(hold["h11"])
You see the box below because you did not login.