|
[Rivet-svn] r2850 - in trunk: . bin pyextblackhole at projects.hepforge.org blackhole at projects.hepforge.orgThu Dec 16 17:06:04 GMT 2010
Author: buckley Date: Thu Dec 16 17:06:03 2010 New Revision: 2850 Log: Various small improvements to histo parsing, histo paths, plot files, etc. Modified: trunk/ChangeLog trunk/bin/compare-histos trunk/bin/make-plots trunk/bin/rivet-rescale trunk/pyext/lighthisto.py Modified: trunk/ChangeLog ============================================================================== --- trunk/ChangeLog Tue Dec 14 11:47:37 2010 (r2849) +++ trunk/ChangeLog Thu Dec 16 17:06:03 2010 (r2850) @@ -1,3 +1,11 @@ +2010-12-16 Andy Buckley <andy at insectnation.org> + + * bin/compare-histos, pyext/lighthisto.py: Take ref paths from + rivet module API rather than getting the environment by hand. + + * pyext/lighthisto.py: Only read .plot info from the first + matching file (speed-up compare-histos). + 2010-12-14 Andy Buckley <andy at insectnation.org> * Augmenting the physics vector functionality to make FourMomentum Modified: trunk/bin/compare-histos ============================================================================== --- trunk/bin/compare-histos Tue Dec 14 11:47:37 2010 (r2849) +++ trunk/bin/compare-histos Thu Dec 16 17:06:03 2010 (r2850) @@ -68,15 +68,10 @@ pass ## Get Rivet data dir - rivet_data_dirs = [] + rivet_data_dirs = None try: import rivet - if os.environ.has_key("RIVET_REF_PATH"): - env = os.environ.get("RIVET_REF_PATH").strip() - if env != ":": - rivet_data_dirs = os.environ.get("RIVET_REF_PATH").split(":") - else: - rivet_data_dirs.append(rivet.getRivetDataPath()) + rivet_data_dirs = rivet.getAnalysisRefPaths() except Exception, e: sys.stderr.write(PROGNAME + " requires the 'rivet' Python module\n"); logging.debug(str(e)) @@ -92,7 +87,8 @@ parser.add_option("--hier-out", action="store_true", dest="HIER_OUTPUT", default=False, help="write output dat files into a directory hierarchy which matches the analysis paths") parser.add_option("--plotinfodir", dest="PLOTINFODIR", action="append", - default=[rivet_data_dirs[0], "./"], help="directory which may contain plot header information") + default=["."], help="directory which may contain plot header information (in addition " + "to standard Rivet search paths)") stygroup = OptionGroup(parser, "Plot style") stygroup.add_option("--refid", dest="REF_ID", @@ -147,16 +143,11 @@ opts.SHOW_IF_REF_ONLY = True - ## Add RIVET_*_PATH to PLOTINFO path - def getpathvar(name): - rtn = [] - if os.environ.has_key(name): - rtn = [os.path.abspath(i) for i in os.environ[name].split(":") if i] - return rtn + ## Add RIVET_PLOT_PATH and ref data dirs to PLOTINFO path if os.environ.has_key("RIVET_PLOT_PATH"): - opts.PLOTINFODIR += getpathvar("RIVET_PLOT_PATH") - elif os.environ.has_key("RIVET_REF_PATH"): - opts.PLOTINFODIR += getpathvar("RIVET_REF_PATH") + opts.PLOTINFODIR += [os.path.abspath(i) for i in os.environ["RIVET_PLOT_PATH"].split(":") if i] + opts.PLOTINFODIR += rivet_data_dirs + #print opts.PLOTINFODIR for a in args: adir = os.path.abspath(os.path.split(a)[0]) if not adir in opts.PLOTINFODIR: @@ -323,7 +314,7 @@ ## Write out histos num_written = 0 - plotparser = PlotParser(filter(lambda s: len(s) > 0, opts.PLOTINFODIR)) + plotparser = PlotParser(opts.PLOTINFODIR) for name in sorted(activenames): logging.debug("Writing histos for plot '%s'" % name) Modified: trunk/bin/make-plots ============================================================================== --- trunk/bin/make-plots Tue Dec 14 11:47:37 2010 (r2849) +++ trunk/bin/make-plots Thu Dec 16 17:06:03 2010 (r2850) @@ -1772,7 +1772,7 @@ dvcmd.append("-f") logging.debug(" ".join(dvcmd)) dvproc = subprocess.Popen(dvcmd, stdout=subprocess.PIPE, cwd=tempdir) - pngcmd = ["convert", "-density", "300", "-flatten", "-", "%s.png" % filename] + pngcmd = ["convert", "-density", "200", "-flatten", "-", "%s.png" % filename] logging.debug(" ".join(pngcmd)) pngproc = subprocess.Popen(pngcmd, stdin=dvproc.stdout, stdout=subprocess.PIPE, cwd=tempdir) pngproc.wait() Modified: trunk/bin/rivet-rescale ============================================================================== --- trunk/bin/rivet-rescale Tue Dec 14 11:47:37 2010 (r2849) +++ trunk/bin/rivet-rescale Thu Dec 16 17:06:03 2010 (r2850) @@ -178,15 +178,9 @@ path = splitline[0].split(":")[0] low = "" high = "" - logging.debug("No bin-definition given for %s" % line.strip()) - if low == "": - low = None - else: - low = float(low) - if high == "": - high = None - else: - high = float(high) + logging.debug("No bin range supplied for %s" % path) + low = float(low) if low else None + high = float(high) if high else None # Try to get area to normalise to logging.debug("Trying to read area to rescale to from bindef...") @@ -208,7 +202,7 @@ parser.add_option("-O", "--obsfile", dest="OBSFILE", default=None, help="Specify a file with histograms (and bin ranges) that are to be normalised.") parser.add_option("-b", "--bins", dest="BINRANGES", action="append", default=[], - help="Specify a histogram and bin range that is to be kept. The format is `AIDAPATH:start:stop'.") + help="Specify a histogram and bin range that is to be used. The format is `AIDAPATH:start:stop'.") parser.add_option("-r", "--refdir", dest="REFDIR", default=None, help="File of folder with reference histos") parser.add_option("-a", dest="AIDA", default=True, action="store_true", Modified: trunk/pyext/lighthisto.py ============================================================================== --- trunk/pyext/lighthisto.py Tue Dec 14 11:47:37 2010 (r2849) +++ trunk/pyext/lighthisto.py Thu Dec 16 17:06:03 2010 (r2850) @@ -465,8 +465,8 @@ class PlotParser(object): - """Parser for rivet's .plot plotinfo files.""" - pat_begin_block = re.compile('^# BEGIN ([A-Z0-9_]+) ?(\S+)?') + """Parser for Rivet's .plot plot info files.""" + pat_begin_block = re.compile('^#+ BEGIN ([A-Z0-9_]+) ?(\S+)?') # temporarily allow several hashes before END for YODA pat_end_block = re.compile('^#+ END ([A-Z0-9_]+)') pat_comment = re.compile('^#|^\s*$') @@ -494,14 +494,10 @@ if len(self.plotpaths) == 0: try: - # Use old os.popen to be Python 2.3 compatible. - path = os.popen("rivet-config --datadir", "r").readline() - path = path.strip() - if not path: - raise ValueError("Path is empty!") - self.plotpaths.append(path) + import rivet + self.plotpaths = rivet.getAnalysisRefPaths() except Exception: - raise ValueError("No plotpaths given and rivet-config call failed!") + raise ValueError("No plotpaths given and the rivet module could not be loaded!") def getSection(self, section, hpath): """Get a section for a histogram from a .plot file. @@ -515,9 +511,9 @@ Todo ---- - Caching - At the moment the result of the lookup is not cache so every - call requires a file to be opened. + Caching! + At the moment the result of the lookup is not cached so every + call requires a file to be searched for and opened. """ if section not in ['PLOT', 'SPECIAL', 'HISTOGRAM']: raise ValueError("Can't parse section \'%s\'" %section) @@ -528,8 +524,9 @@ base = parts[1] + ".plot" ret = {'PLOT': {}, 'SPECIAL': None, 'HISTOGRAM': {}} for pidir in self.plotpaths: - if os.access(os.path.join(pidir, base), os.R_OK): - plotfile = os.path.join(pidir, base) + plotfile = os.path.join(pidir, base) + if os.access(plotfile, os.R_OK): + #print plotfile startreading = False f = open(plotfile) for line in f: @@ -538,14 +535,14 @@ tag, pathpat = m.group(1,2) # pathpat could be a regex if tag == section and re.match(pathpat,hpath): - startreading=True + startreading = True if section in ['SPECIAL']: ret[section] = '' continue if not startreading: continue if self.isEndMarker(line, section): - startreading=False + startreading = False continue elif self.isComment(line): continue @@ -553,10 +550,12 @@ 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() + break return ret[section] @@ -568,7 +567,7 @@ Parameters ---------- hpath : str - The histogram path, i.e. /AnaylsisID/HistogramID . + The histogram path, i.e. /AnalysisID/HistogramID . Returns -------
More information about the Rivet-svn mailing list |