|
[Rivet-svn] r2163 - in trunk: . bin pyextblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Dec 10 13:32:00 GMT 2009
Author: hoeth Date: Thu Dec 10 13:32:00 2009 New Revision: 2163 Log: propagate HISTOGRAM section from .plot files through compare-histos Modified: trunk/ChangeLog trunk/bin/compare-histos trunk/pyext/lighthisto.py Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Thu Dec 10 12:11:54 2009 (r2162) +++ trunk/ChangeLog Thu Dec 10 13:32:00 2009 (r2163) @@ -1,6 +1,7 @@ 2009-12-10 Hendrik Hoeth <hendrik.hoeth at cern.ch> - * propagate SPECIAL sections from .plot files through compare-histos + * propagate SPECIAL and HISTOGRAM sections from .plot files + through compare-histos 2009-12-04 Andy Buckley <andy at insectnation.org> Modified: trunk/bin/compare-histos ============================================================================== --- trunk/bin/compare-histos Thu Dec 10 12:11:54 2009 (r2162) +++ trunk/bin/compare-histos Thu Dec 10 13:32:00 2009 (r2163) @@ -312,6 +312,7 @@ headstr += "# END SPECIAL\n" ## Write histos + histopts = plotparser.getHistogramOptions(name) histstrs = [] i = 0 for hfile in activefiles: @@ -327,6 +328,10 @@ histstr += 'LineColor=%s\n' % color histstr += 'LineStyle=%s\n' % style histstr += 'Title=%s\n' % LABELS[hfile] + for key, val in histopts.iteritems(): + if key == 'ErrorBars' and opts.MC_ERRS: + continue + histstr += "%s=%s\n" % (key, val) i += 1 for bin in HISTOS[hfile][name].getBins(): xmin, xmax = bin.getXRange() Modified: trunk/pyext/lighthisto.py ============================================================================== --- trunk/pyext/lighthisto.py Thu Dec 10 12:11:54 2009 (r2162) +++ trunk/pyext/lighthisto.py Thu Dec 10 13:32:00 2009 (r2163) @@ -410,12 +410,14 @@ raise ValueError("No plotpaths given and rivet-config call" " failed!") - def getHeaders(self, hpath): - """Get a header dict for histogram hpath. + def getSection(self, section, hpath): + """Get sections from a .plot file. hpath must have the form /AnalysisID/HistogramID """ - # parts = os.path.split(hpath) + if section not in ['PLOT', 'SPECIAL', 'HISTOGRAM']: + raise ValueError("Can't parse section \'%s\'" %section) + parts = hpath.split("/") if len(parts) != 3: raise ValueError("hpath has wrong number of parts (%i)" % @@ -429,68 +431,55 @@ if plotfile is None: raise ValueError("no plot file %s found in plotpaths %s" % (base, self.plotpaths)) - headers = {} + ret = {'PLOT': {}, 'SPECIAL': None, 'HISTOGRAM': {}} startreading = False f = open(plotfile) for line in f: m = self.pat_begin_block.match(line) if m: tag, pathpat = m.group(1,2) - if tag == 'PLOT' and re.match(pathpat, hpath) is not None: + if tag == section and re.match(pathpat, hpath) is not None: startreading=True + if section in ['SPECIAL']: + ret[section]='' continue if not startreading: continue - if self.isEndMarker(line, 'PLOT'): + if self.isEndMarker(line, section): break elif self.isComment(line): continue - vm = self.pat_property.match(line) - if vm: - prop, value = vm.group(1,2) - headers[prop] = value + if section in ['PLOT', 'HISTOGRAM']: + vm = self.pat_property.match(line) + if vm: + prop, value = vm.group(1,2) + ret[section][prop] = value + elif section in ['SPECIAL']: + ret[section] += line f.close() - return headers + return ret[section] + + + def getHeaders(self, hpath): + """Get a header dict for histogram hpath. + + hpath must have the form /AnalysisID/HistogramID + """ + return self.getSection('PLOT', hpath) def getSpecial(self, hpath): """Get a SPECIAL section for histogram hpath. hpath must have the form /AnalysisID/HistogramID """ - # parts = os.path.split(hpath) - parts = hpath.split("/") - if len(parts) != 3: - raise ValueError("hpath has wrong number of parts (%i)" % - (len(parts))) - base = parts[1] + ".plot" - plotfile = None - for pidir in self.plotpaths: - if os.access(os.path.join(pidir, base), os.R_OK): - plotfile = os.path.join(pidir, base) - break - if plotfile is None: - raise ValueError("no plot file %s found in plotpaths %s" % - (base, self.plotpaths)) - special = None - startreading = False - f = open(plotfile) - for line in f: - m = self.pat_begin_block.match(line) - if m: - tag, pathpat = m.group(1,2) - if tag == 'SPECIAL' and re.match(pathpat, hpath) is not None: - startreading=True - special = '' - continue - if not startreading: - continue - if self.isEndMarker(line, 'SPECIAL'): - break - elif self.isComment(line): - continue - special += line - f.close() - return special + return self.getSection('SPECIAL', hpath) + + def getHistogramOptions(self, hpath): + """Get a SPECIAL section for histogram hpath. + + hpath must have the form /AnalysisID/HistogramID + """ + return self.getSection('HISTOGRAM', hpath) def isEndMarker(self, line, blockname): m = self.pat_end_block.match(line)
More information about the Rivet-svn mailing list |