|
[Rivet-svn] r3178 - trunk/binblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Jul 12 00:40:48 BST 2011
Author: buckley Date: Tue Jul 12 00:40:48 2011 New Revision: 3178 Log: Adding -m/-M flags to compare-histos in favour of the -l histogram list file. Was anyone using that feature? Let me know and I'll put it back, but it's so cumbersome that I think that just using the same lists of match/antimatch regexes as we use on the other scripts is fine. Modified: trunk/bin/compare-histos Modified: trunk/bin/compare-histos ============================================================================== --- trunk/bin/compare-histos Tue Jul 12 00:38:53 2011 (r3177) +++ trunk/bin/compare-histos Tue Jul 12 00:40:48 2011 (r3178) @@ -148,9 +148,15 @@ selgroup.add_option("--show-mc-only", "--all", action="store_true", dest="SHOW_IF_MC_ONLY", default=False, help="make a plot file even if there is only one dataset to be plotted and " "it is an MC one. Deprecated and will be removed: use --show-single instead, which overrides this.") - selgroup.add_option("-l", "--histogram-list", dest="HISTOGRAMLIST", - default=None, help="specify a file containing a list of histograms to plot, in the format " - "/ANALYSIS_ID/histoname, one per line, e.g. '/DELPHI_1996_S3430090/d01-x01-y01'.") + # selgroup.add_option("-l", "--histogram-list", dest="HISTOGRAMLIST", + # default=None, help="specify a file containing a list of histograms to plot, in the format " + # "/ANALYSIS_ID/histoname, one per line, e.g. '/DELPHI_1996_S3430090/d01-x01-y01'.") + selgroup.add_option("-m", "--match", action="append", + help="Only write out histograms whose $path/$name string matches these regexes", + dest="PATHPATTERNS") + selgroup.add_option("-M", "--unmatch", action="append", + help="Exclude histograms whose $path/$name string matches these regexes", + dest="PATHUNPATTERNS") parser.add_option_group(selgroup) verbgrp = OptionGroup(parser, "Verbosity control") @@ -199,6 +205,16 @@ opts, args = parser.parse_args() + ## Initialise regex list variables + import re + if opts.PATHPATTERNS is None: + opts.PATHPATTERNS = [] + opts.PATHPATTERNS = [re.compile(r) for r in opts.PATHPATTERNS] + if opts.PATHUNPATTERNS is None: + opts.PATHUNPATTERNS = [] + opts.PATHUNPATTERNS = [re.compile(r) for r in opts.PATHUNPATTERNS] + + ## Work out the implications of the SHOW_SINGLE option opts.SHOW_IF_MC_ONLY = False opts.SHOW_IF_REF_ONLY = False @@ -315,23 +331,44 @@ YLABELS[n] = t - ## Choose histos - use all histos with MC data, or restrict with a list read from file - if opts.HISTOGRAMLIST is not None: - newnames = [] - try: - f = open(opts.HISTOGRAMLIST, 'r') - except: - logging.error("Cannot open histo list file %s" % opts.HISTOGRAMLIST) - exit(2) - hnames = set() - for line in f: - stripped = line.strip() - if len(stripped) == 0 or stripped.startswith("#"): - continue - hnames.add(stripped.split()[0]) - f.close() - NAMES = NAMES.intersection(hnames) - MCNAMES = MCNAMES.intersection(hnames) + # ## Choose histos - use all histos with MC data, or restrict with a list read from file + # if opts.HISTOGRAMLIST is not None: + # newnames = [] + # try: + # f = open(opts.HISTOGRAMLIST, 'r') + # except: + # logging.error("Cannot open histo list file %s" % opts.HISTOGRAMLIST) + # exit(2) + # hnames = set() + # for line in f: + # stripped = line.strip() + # if len(stripped) == 0 or stripped.startswith("#"): + # continue + # hnames.add(stripped.split()[0]) + # f.close() + # NAMES = NAMES.intersection(hnames) + # MCNAMES = MCNAMES.intersection(hnames) + + + ## Use regex matching to reduce the number of histos + acceptednames = set() + for path in NAMES.union(MCNAMES): + useThis = True + if opts.PATHPATTERNS: + useThis = False + for regex in opts.PATHPATTERNS: + if regex.search(path): + useThis = True + break + if useThis and opts.PATHUNPATTERNS: + for regex in opts.PATHUNPATTERNS: + if regex.search(path): + useThis = False + break + if useThis: + acceptednames.add(path) + NAMES = NAMES.intersection(acceptednames) + MCNAMES = MCNAMES.intersection(acceptednames) ## Pre-emptively reduce number of files to iterate through
More information about the Rivet-svn mailing list |