[Rivet-svn] r3552 - in trunk: bin pyext

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Thu Feb 9 18:46:54 GMT 2012


Author: dgrell
Date: Thu Feb  9 18:46:54 2012
New Revision: 3552

Log:
rivet-mkhtml -c option now has semantics of .plot file. The contents are appended to the dat output by compare-histos.

Modified:
   trunk/bin/compare-histos
   trunk/bin/rivet-mkhtml
   trunk/pyext/lighthisto.py

Modified: trunk/bin/compare-histos
==============================================================================
--- trunk/bin/compare-histos	Fri Jan 27 15:01:31 2012	(r3551)
+++ trunk/bin/compare-histos	Thu Feb  9 18:46:54 2012	(r3552)
@@ -93,7 +93,7 @@
         h.expt = dpsname.split("_")[0][1:]
         ## Hard-coded cosmetic handling for the D0 experiment name!
         if h.expt == "D0":
-            h.expt = "D\O\ "
+            h.expt = "D\O{}"
         histos[dpsname] = h
     return histos, titles, xlabels, ylabels
 
@@ -134,6 +134,8 @@
                         "(useful when the plot description should only be given in a caption)")
     stygroup.add_option("--style", dest="STYLE", default="default",
                         help="change plotting style: default|bw|talk")
+    stygroup.add_option("-c", "--config", dest="CONFIGFILES", action="append", default=["~/.make-plots"],
+                        help="additional plot config file(s). Settings will be included in the output configuration.")
     parser.add_option_group(stygroup)
 
     selgroup = OptionGroup(parser, "Selective plotting")
@@ -385,7 +387,7 @@
 
     ## Write out histos
     num_written = 0
-    plotparser = PlotParser(opts.PLOTINFODIR)
+    plotparser = PlotParser(opts.PLOTINFODIR, opts.CONFIGFILES)
     for name in sorted(activenames):
         logging.debug("Writing histos for plot '%s'" % name)
 

Modified: trunk/bin/rivet-mkhtml
==============================================================================
--- trunk/bin/rivet-mkhtml	Fri Jan 27 15:01:31 2012	(r3551)
+++ trunk/bin/rivet-mkhtml	Thu Feb  9 18:46:54 2012	(r3552)
@@ -38,7 +38,7 @@
 parser.add_option("-t", "--title", dest="TITLE",
                   default="Plots from Rivet analyses", help="title to be displayed on the main web page")
 parser.add_option("-c", "--config", dest="CONFIGFILES", action="append", default=["~/.make-plots"],
-                  help="plot config file(s) to be used with make-plots.")
+                  help="plot config file(s) to be used with compare-histos.")
 parser.add_option("-s", "--single", dest="SINGLE", action="store_true",
                   default=False, help="display plots on single webpage.")
 parser.add_option("--no-ratio", dest="SHOW_RATIO", action="store_false",
@@ -182,7 +182,13 @@
             newarg += ":%s" % opt
     # print newarg
     ch_cmd.append(newarg)
+for configfile in opts.CONFIGFILES:
+    configfile = os.path.abspath(os.path.expanduser(configfile))
+    if os.access(configfile, os.R_OK):
+        ch_cmd.append("-c")
+        ch_cmd.append(configfile)
 # TODO: Pass rivet-mkhtml -m and -M args to compare-histos
+
 if opts.VERBOSE:
     ch_cmd.append("--verbose")
     print "Calling compare-histos with the following command:"
@@ -313,10 +319,6 @@
 elif opts.OUTPUT_FONT == "minion":
     mp_cmd.append("--minion")
 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))
 datfiles = []
 for analysis in analyses:
     anapath = os.path.join(opts.OUTPUTDIR, analysis)

Modified: trunk/pyext/lighthisto.py
==============================================================================
--- trunk/pyext/lighthisto.py	Fri Jan 27 15:01:31 2012	(r3551)
+++ trunk/pyext/lighthisto.py	Thu Feb  9 18:46:54 2012	(r3552)
@@ -554,7 +554,7 @@
     pat_property = re.compile('^(\w+?)=(.*)$')
     pat_path_property  = re.compile('^(\S+?)::(\w+?)=(.*)$')
 
-    def __init__(self, plotpaths=None):
+    def __init__(self, plotpaths=None, addfiles=[]):
         """
         Parameters
         ----------
@@ -573,6 +573,8 @@
             plotpaths = []
         self.plotpaths = plotpaths
 
+        self.addfiles = addfiles
+
         if len(self.plotpaths) == 0:
             try:
                 import rivet
@@ -615,39 +617,43 @@
         ret = {'PLOT': {}, 'SPECIAL': None, 'HISTOGRAM': {}}
         for pidir in self.plotpaths:
             plotfile = os.path.join(pidir, base)
-            if os.access(plotfile, os.R_OK):
-                #print plotfile
-                startreading = False
-                f = open(plotfile)
-                for line in f:
-                    m = self.pat_begin_block.match(line)
-                    if m:
-                        tag, pathpat = m.group(1,2)
-                        # pathpat could be a regex
-                        if tag == section and re.match(pathpat,hpath):
-                            startreading = True
-                            if section in ['SPECIAL']:
-                                ret[section] = ''
-                            continue
-                    if not startreading:
-                        continue
-                    if self.isEndMarker(line, section):
-                        startreading = False
-                        continue
-                    elif self.isComment(line):
-                        continue
-                    if section in ['PLOT', 'HISTOGRAM']:
-                        vm = self.pat_property.match(line)
-                        if vm:
-                            prop, value = vm.group(1,2)
-                            #print prop, value
-                            ret[section][prop] = value
-                    elif section in ['SPECIAL']:
-                        ret[section] += line
-                f.close()
-                # no break, as we can collect settings from multiple .plot files
+            self.readHeadersFromFile(plotfile, ret, section, hpath)
+            # no break, as we can collect settings from multiple .plot files
+        for extrafile in self.addfiles:
+            self.readHeadersFromFile(extrafile, ret, section, hpath)
         return ret[section]
 
+    def readHeadersFromFile(self, plotfile, ret, section, hpath):
+        """Get a section for a histogram from a .plot file."""
+        if os.access(plotfile, os.R_OK):
+            startreading = False
+            f = open(plotfile)
+            for line in f:
+                m = self.pat_begin_block.match(line)
+                if m:
+                    tag, pathpat = m.group(1,2)
+                    # pathpat could be a regex
+                    if tag == section and re.match(pathpat,hpath):
+                        startreading = True
+                        if section in ['SPECIAL']:
+                            ret[section] = ''
+                        continue
+                if not startreading:
+                    continue
+                if self.isEndMarker(line, section):
+                    startreading = False
+                    continue
+                elif self.isComment(line):
+                    continue
+                if section in ['PLOT', 'HISTOGRAM']:
+                    vm = self.pat_property.match(line)
+                    if vm:
+                        prop, value = vm.group(1,2)
+                        #print prop, value
+                        ret[section][prop] = value
+                elif section in ['SPECIAL']:
+                    ret[section] += line
+            f.close()
 
     def getHeaders(self, hpath):
         """Get the plot headers for histogram hpath.


More information about the Rivet-svn mailing list