[Rivet-svn] r3177 - trunk/bin

blackhole at projects.hepforge.org blackhole at projects.hepforge.org
Tue Jul 12 00:38:53 BST 2011


Author: buckley
Date: Tue Jul 12 00:38:53 2011
New Revision: 3177

Log:
bin/make-plots: Protect property reading against unstripped \r characters from DOS newlines.

Modified:
   trunk/bin/make-plots

Modified: trunk/bin/make-plots
==============================================================================
--- trunk/bin/make-plots	Wed Jul  6 12:16:15 2011	(r3176)
+++ trunk/bin/make-plots	Tue Jul 12 00:38:53 2011	(r3177)
@@ -4,7 +4,6 @@
 Usage: %prog [options] file.dat [file2.dat ...]
 
 TODO
- * use std method (from compphys marking) to kill the subprocess
  * Optimise output for e.g. lots of same-height bins in a row
  * Tidy LaTeX-writing code
  * Handle boolean values flexibly (yes, no, true, false, etc. as well as 1, 0)
@@ -30,7 +29,8 @@
 import string
 from math import *
 
-## regex patterns ##
+
+## Regex patterns
 pat_begin_block = re.compile(r'^#+\s*BEGIN ([A-Z0-9_]+) ?(\S+)?')
 pat_end_block =   re.compile('^#+\s*END ([A-Z0-9_]+)')
 pat_comment = re.compile('^#|^\s*$')
@@ -165,7 +165,8 @@
                 prop, value = m.group(1,2)
                 if prop in self.description:
                     logging.debug("Overwriting property %s = %s -> %s" % (prop, self.description[prop], value))
-                self.description[prop] = value
+                ## Use strip here to deal with DOS newlines containing \r
+                self.description[prop.strip()] = value.strip()
 
 
     def read_path_based_input(self, line):
@@ -179,14 +180,16 @@
         for obj_dict in [self.special, self.histos, self.functions]:
             for path, obj in obj_dict.iteritems():
                 for regex, prop, value in self.pathdescriptions:
-                    if re.match(regex,path):
-                        obj.description.update({prop : value})
+                    if re.match(regex, path):
+                        ## Use strip here to deal with DOS newlines containing \r
+                        obj.description.update({prop.strip() : value.strip()})
 
     def get_path_settings(self, path):
         dictionary = {}
         for regex, prop, value in self.pathdescriptions:
-            if re.match(regex,path):
-                dictionary.update({prop : value})
+            if re.match(regex, path):
+                ## Use strip here to deal with DOS newlines containing \r
+                dictionary.update({prop.strip() : value.strip()})
         return dictionary
 
 
@@ -1836,7 +1839,7 @@
         if label=='':
             label=self.get_ticklabel(value,self.description['LogY'])
         if self.description.has_key('RatioPlotMode') and self.description['RatioPlotMode']=='deviation' \
-                and self.description.has_key('RatioPlotStage') and self.description['RatioPlotStage']==True:
+                and self.description.has_key('RatioPlotStage') and self.description['RatioPlotStage']:
             return ('\\uput[180]{0}(0, '+self.coors.strphys2frameY(value)+'){\\strut{}'+label+'\\,$\\sigma$}\n')
         else:
             return ('\\uput[180]{0}(0, '+self.coors.strphys2frameY(value)+'){\\strut{}'+label+'}\n')
@@ -1875,7 +1878,7 @@
         if label=='':
             label=self.get_ticklabel(value,self.description['LogZ'])
         if self.description.has_key('RatioPlotMode') and self.description['RatioPlotMode']=='deviation' \
-                and self.description.has_key('RatioPlotStage') and self.description['RatioPlotStage']==True:
+                and self.description.has_key('RatioPlotStage') and self.description['RatioPlotStage']:
             return ('\\uput[0]{0}(1, '+self.coors.strphys2frameZ(value)+'){\\strut{}'+label+'\\,$\\sigma$}\n')
         else:
             return ('\\uput[0]{0}(1, '+self.coors.strphys2frameZ(value)+'){\\strut{}'+label+'}\n')


More information about the Rivet-svn mailing list