[Rivet-svn] r1905 - trunk/bin

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Wed Oct 14 13:32:24 BST 2009


Author: fsiegert
Date: Wed Oct 14 13:32:23 2009
New Revision: 1905

Log:
Add script "make-html" for easy creation of web pages to compare all
given Monte-Carlo aida files.

Added:
   trunk/bin/make-html   (contents, props changed)
Modified:
   trunk/bin/Makefile.am

Modified: trunk/bin/Makefile.am
==============================================================================
--- trunk/bin/Makefile.am	Wed Oct 14 12:38:52 2009	(r1904)
+++ trunk/bin/Makefile.am	Wed Oct 14 13:32:23 2009	(r1905)
@@ -1,5 +1,5 @@
 bin_SCRIPTS = rivet-config 
-dist_bin_SCRIPTS = aida2flat aida2root compare-histos make-plots rivet-mkanalysis 
+dist_bin_SCRIPTS = aida2flat aida2root compare-histos make-html make-plots rivet-mkanalysis 
 EXTRA_DIST = flat2aida
 
 if ENABLE_PYEXT

Added: trunk/bin/make-html
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ trunk/bin/make-html	Wed Oct 14 13:32:23 2009	(r1905)
@@ -0,0 +1,114 @@
+#! /usr/bin/env python
+
+from optparse import OptionParser, OptionGroup
+import sys, os, glob, shutil
+from subprocess import Popen, PIPE
+
+## Try to load faster but non-standard cElementTree module
+try:
+    import xml.etree.cElementTree as ET
+except ImportError:
+    try:
+        import cElementTree as ET
+    except ImportError:
+        try:
+            import xml.etree.ElementTree as ET
+        except:
+            sys.stderr.write("Can't load the ElementTree XML parser: please install it!\n")
+            sys.exit(1)
+
+
+usage = """Webpages from histogram files written out by Rivet.
+You can specify multiple Monte-Carlo aida files to be compared. Reference data
+should be found automatically.
+
+Examples:
+  source /path/to/rivetenv.sh
+  %prog [options] <aidafile1> [<aidafile2> <aidafile3>...]
+"""
+
+
+parser = OptionParser(usage=usage)
+parser.add_option("-o", "--outputdir", dest="OUTPUTDIR",
+                  default="./plots", help="directory for webpage output.")
+parser.add_option("-c", "--config", dest="CONFIGFILES", action="append", default=["~/.make-plots"],
+                  help="Plot config file(s) to be used with make-plots.")
+
+
+opts, aidafiles = parser.parse_args()
+
+try:
+    datadir = Popen(["rivet-config", "--datadir"], stdout=PIPE).communicate()[0].split()[0]
+except:
+    print "Error: Didn't find rivet-config. Have you sourced rivetenv.sh?"
+    exit(1)
+
+try:
+    os.makedirs(opts.OUTPUTDIR)
+except:
+    print "Error: Directory '%s' already exists. Set -o to something else." % opts.OUTPUTDIR
+    exit(1)
+
+## get set of analyses/reffiles involved in the runs
+analyses = set()
+reffiles = list()
+for aidafile in aidafiles:
+    aidafilepath = os.path.abspath(aidafile)
+    if not os.access(aidafilepath, os.R_OK):
+        print "Error: cannot read from %s" % aidafile
+        exit(2)
+    tree = ET.parse(aidafilepath)
+    for dps in tree.findall("dataPointSet"):
+        analysis = dps.get("path")[1:]
+        analyses.add(analysis)
+        if os.access(os.path.join(datadir, analysis+".aida"), os.R_OK):
+            reffiles.append("%s/%s.aida" % (datadir, analysis))
+
+
+## run compare-histos to get plain .dat files from .aida
+ch_cmd = ["compare-histos"]
+ch_cmd.append("--mc-errs")
+ch_cmd.append("--plot-info-dir=../")
+if len(aidafiles)+len(reffiles)<2:
+    ch_cmd.append("--show-ref-only")
+    ch_cmd.append("--no-ratio")
+for file in aidafiles+reffiles:
+    ch_cmd.append("%s" % os.path.abspath(file))
+Popen(ch_cmd, cwd=opts.OUTPUTDIR).wait()
+
+
+index = open(os.path.join(opts.OUTPUTDIR, "index.html"), "w")
+for analysis in sorted(analyses):
+    anapath = os.path.join(opts.OUTPUTDIR, analysis)
+    os.mkdir(anapath)
+    anaindex = open(os.path.join(anapath, "index.html"), 'w')
+    anaindex.write("<html>\n")
+    
+    datfiles = glob.glob("%s/%s_*.dat" % (opts.OUTPUTDIR, analysis))
+    for fulldatfile in sorted(datfiles):
+        shutil.move(fulldatfile, anapath)
+        datfile = os.path.basename(fulldatfile)
+
+        ## make-plots run for each .dat file
+        mp_cmd = ["make-plots"]
+        mp_cmd.append("--full-range")
+        for configfile in opts.CONFIGFILES:
+            if os.access(os.path.expanduser(configfile), os.R_OK):
+                mp_cmd.append("-c")
+                mp_cmd.append(os.path.expanduser(configfile))
+        mp_cmd.append(datfile)
+        Popen(mp_cmd, cwd=anapath).wait()
+
+        psfile = datfile.replace(".dat", ".ps")
+        if os.access(os.path.join(anapath, psfile), os.R_OK):
+            # convert to png and add to webpage
+            pngfile = datfile.replace(".dat", ".png")
+            Popen(["convert", "-density", "100", psfile, pngfile], cwd=anapath)
+            anaindex.write('<div style="float:left;">')
+            anaindex.write('<a href="%s" style="font-size:small;text-decoration:none;font-weight:bold;">' % psfile)
+            anaindex.write('%s:<br><img border="0" src="%s"></a></div>\n' % (psfile, pngfile))
+
+    anaindex.write("</html>\n")
+    index.write('<h1><a href="%s/index.html" style="text-decoration:none;">%s</a></h1>\n' %(analysis, analysis))
+    description = Popen(["rivet", "--show-analysis", analysis], stdout=PIPE).communicate()[0]
+    index.write('<pre>%s</pre>\n' % description)


More information about the Rivet-svn mailing list