Write/read a P0D collection to/from a XML file
Source code name: "io_data_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_data_XML_7247.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
from jhplot  import *
from java.util import Random


h1=H1D("test H1D",20,-3,3)
h1.setFill(1)
h1.setFillColor(Color.cyan)
p0=P0D("test P0D")

r=Random()
for i in range(100):
      h1.fill(2*r.nextGaussian())
      p0.add(r.nextGaussian()+10)
      

# print all statistics
print p0.getStat()

# put to a list
a=[]
a.append(h1)
a.append(p0)

# write to a XML file
IO.writeXML(a,'file.xml')
# convert to XML string
print IO.toXML(a)

# read back from XML
b=IO.readXML('file.xml')

# print collections
print b

# plot 
c1 = HPlot("Canvas",600,400)
c1.setGTitle("P0D and H1D from a serialized XML file");
c1.visible(1)
c1.setAutoRange()
c1.draw(b[0])
# convert first to H1D histogram with 100 bins
c1.draw(b[1].getH1D(100))

# convert to string
# print IO.toXML(a)


You see the box below because you did not login.