Example #1
0
def status(self, params):
    inputs = custom_sort(params.files)

    from ROOT import TFile
    files = [TFile.Open(f) for f in inputs]
    
    def depickle_rootstring(s):
        return loads(s.GetString().Data())
    
    def get_info(f):
        try:
            return [
                f.exception_count.GetVal(),
                f.cputime.GetVal(),
                f.skimtime.GetVal() if f.Get("skimtime") else "N/A",
                f.walltime.GetVal(),
                f.processed_trees.GetVal(),
                f.jobs_files.GetVal(),
                len(depickle_rootstring(f.file_processed_list)),
            ]
        except AttributeError:
            return [None]*6
       
    labels = ["exceptions", "cputime", "skimtime", "walltime", "ntrees", "njf", "nfiles"]
    numbers = [[f.GetName()] + get_info(f) for f in files]
    table = [["file"] + list(labels)] + numbers
    pprint_table(table) 
Example #2
0
def print_tables(firstpart, cuts, tables, options):
    _linkify = if_htmlify(linkify, options)
    
    aliased_cuts = [aliases.get(cut, cut) for cut in cuts]
    header = [firstpart, "all"] + aliased_cuts
    
    headings, _tables = zip(*tables)
    _tables += ([header],)
    col_paddings = compute_col_paddings(reduce(list.__add__, _tables, []))
    
    header = [firstpart, "all"] + map(_linkify, aliased_cuts)
    
    for heading, table in tables:
        print_heading(heading, options)
        table = linkify_first_column(table, options)
        pprint_table([header] + table, col_paddings=col_paddings)    
Example #3
0
def dump(self, params):
    
    inputs = custom_sort(params.files)

    #inputs = [i for i in inputs if "PUNK" not in i and "periodP." not in i]
    
    from ROOT import TFile
    files = [TFile.Open(f) for f in inputs]
    good_files = []
    for f in files:
        if not f.Get(params.name):
            print "Warning, ignoring", f.GetName()
        else:
            good_files.append(f)
    files = good_files
    cutflows = [f.Get(params.name)  for f in files]
    axes = [c.GetXaxis() for c in cutflows]
    labels = set(tuple(a.GetBinLabel(i) for i in xrange(1, a.GetNbins()+1))
                 for a in axes)
    
    assert len(labels) == 1, labels
    (labels,) = labels
    
    lumi = lambda f, h: []
    
    if params.dataset:
        _, data_info = load_all(open(params.dataset))
        by_period, by_run = {}, {}
        for d in data_info["datasets"]:
            by_period.setdefault(d.period, []).append(d)
            by_period.setdefault(d.period[0], []).append(d)
            by_run.setdefault(d.run, []).append(d)
            
        def extra(f, h):
            bad, events = "-", "N/A"
            
            period, run = get_run_period(f)
            
            if period == "all":
                ds = [ds for name, ds in by_period.iteritems() if len(name) == 1]
                events = sum(d.totalevents for dd in ds for d in dd if d.period != "UNK")
                
            elif run is None:
                # A period or period list
                if isinstance(period, list):
                    periods = period
                    events = 0
                    for period in (p for p in periods if p in by_period):
                        events += sum(d.totalevents for d in by_period[period])
                    
                elif period in by_period:
                    events = sum(d.totalevents for d in by_period[period])
                else:
                    raise RuntimeError("Unknown period {0}".format(period))

            elif run:
                events = sum(d.totalevents for d in by_run[run])
            
            if isinstance(events, int):
                bad = "!" if events != h[1] else " "
            return [bad, events]
        extra_labels = ["?", "AMI events"]
        
        lumi = lambda f, h: []
        if exists("lumi.yaml"):
            extra_labels[:0] = ["lumi[1/pb]", "yield[per 1/pb]"]
            
            lumi_info = LumiInfo.from_file("lumi.yaml")
            lumi_by_run = lumi_info.total_per_run
            def lumi(f, h):                
                period, run = get_run_period(f)
                
                lumi = None
                if period == "all":
                    ds = [ds for name, ds in by_period.iteritems() if len(name) == 1]
                    lumi = sum(lumi_by_run[d.run] for dd in ds for d in dd 
                               if d.period != "UNK" and d.run in lumi_by_run)
                    
                elif run is None:
                    def get_period_lumi(period):
                        if period not in by_period:
                            return 0
                        return sum(lumi_by_run[d.run] for d in by_period[period] 
                                   if d.run in lumi_by_run)
                    
                    # Period
                    if isinstance(period, list):
                        periods = period
                        lumi = sum(get_period_lumi(p) for p in periods)
                    elif period in by_period:
                        lumi = get_period_lumi(period)
                    
                else:
                    lumi = lumi_by_run.get(int(run), 0)
                               
                def u_to_p(x): return x / 1e6
                
                if lumi:
                    lumi = u_to_p(lumi)
                    final_count = h[h.GetNbinsX()]
                    from uncertainties import ufloat
                    from math import sqrt
                    final_count = ufloat((final_count, sqrt(final_count))) / lumi
                    args = final_count.nominal_value, final_count.std_dev()
                    final_count = "{0:6.2f}+-{1:6.2f}".format(*args)
                    
                    lumi = "{0:.2f}".format(lumi)
                else:
                    final_count = "0"
                return [lumi, final_count]
                
    else:
        def extra(f, h): return []
        extra_labels = []
    
    def pretty_file(f):
        if "mc" in f:
            return f[3:-len(".root")]
    
        if "all" in f:
            return "Total"
        f, _, ext = f.rpartition(".")
        if f.startswith("period"):
            return "period " + f[len("period"):]
        if "data" in f:
            p, r = f.split("_")[-1].split("-")
            return "{0}:{1}".format(p, r.lstrip("R"))
        x = get_mc_name(f.split("-")[-1].lstrip("R"))
        return x
    
    #formatter = lambda s: "{0:.2f}".format(s)
    
    header = [["what"] + extra_labels + list(labels)]
    numbers = [[pretty_file(f)] + lumi(f, h) + extra(f, h) + map(int, get_bin_values(h)) 
               for f, h in zip([f.GetName() for f in files], cutflows)]
    table = header + numbers
    pprint_table(table)