Пример #1
0
def sendSkimJob(in_files, out_files, cut, overwrite, cache, exe_name):
    python_dir = utilities.fullPath(os.path.dirname(__file__))
    run_dir = os.path.join(os.path.dirname(out_files[0]), "run")
    utilities.ensureDir(run_dir)
    run_file = os.path.join(run_dir, exe_name)

    with open(run_file, "w") as f:
        f.write('#! /usr/bin/env python\n')
        f.write('import sys\n')
        f.write('sys.path.append("' + python_dir + '")\n')
        f.write('import subprocess\n')
        f.write('import cache\n')
        for in_file, out_file in itertools.izip(in_files, out_files):
            if os.path.exists(out_file) and not overwrite:
                continue
            if cache:
                f.write('cache.cacheRun(["' + out_file + '","' + in_file +
                        '"],["' + os.path.join(python_dir, 'skim_ntuple.py') +
                        '","' + cut + '","' + out_file + '","' + in_file +
                        '"],False,10000000000,0.5,False)\n')
            else:
                f.write('subprocess.call(["' +
                        os.path.join(python_dir, 'skim_ntuple.py') + '","' +
                        cut + '","' + out_file + '","' + in_file + '"])\n')
    os.chmod(run_file, 0755)

    subprocess.call(["JobSubmit.csh", "run/wrapper.sh", run_file])
Пример #2
0
def sendSlimJob(skim, slim, overwrite, out_dir):
    mc_dir = os.path.dirname(skim)
    skim_name = os.path.basename(skim)
    slim_name = os.path.splitext(os.path.basename(slim))[0]
    if out_dir == None:
        out_dir = os.path.join(mc_dir, "merged_"+slim_name+"_"+skim_name).replace("_skim_","_")
    else:
        out_dir = os.path.join(out_dir, "merged_"+slim_name+"_"+skim_name).replace("_skim_","_")
    run_dir = os.path.join(out_dir, "run")
    utilities.ensureDir(run_dir)

    tags = utilities.findBaseSampleNames(skim)
    total_jobs = 0
    for tag in tags:
        #if "TTJets_SingleLeptFromT_" not in tag: continue
        in_files = os.path.join(skim,"*"+tag+"*.root")
        out_name = "mergedbaby_"+tag+"_"+skim_name+"_"+slim_name+"_nfiles_"+str(len(glob.glob(in_files)))
        out_file = os.path.join(out_dir,out_name+".root")
        run_file = os.path.join(run_dir,out_name+".sh")
        
        if os.path.exists(out_file) and not overwrite:
            print("Keeping pre-existing "+out_file)
            continue
        with open(run_file, "wb") as f:
            f.write("#! /bin/bash\n\n")
            #f.write("python/cache.py -c "+slim+" "+out_file+" -e python/slim_ntuple.py "+slim+" "+out_file+" "+in_files+"\n")
            f.write("python/slim_ntuple.py "+slim+" "+out_file+" "+in_files+"\n")
            os.fchmod(f.fileno(),0755)
        subprocess.call(["JobSubmit.csh","run/wrapper.sh",run_file])
        total_jobs += 1

    return total_jobs
Пример #3
0
def sendSkimJob(in_files, out_files, cut, overwrite, exe_name):
    python_dir = utilities.fullPath(os.path.dirname(__file__))
    run_dir = os.path.join(os.path.dirname(out_files[0]), "run")
    utilities.ensureDir(run_dir)
    run_file = os.path.join(run_dir, exe_name)

    with open(run_file, "w") as f:
        f.write('#! /usr/bin/env python\n')
        f.write('import sys\n')
        f.write('sys.path.append("'+python_dir+'")\n')
        f.write('import cache\n')
        for in_file, out_file in itertools.izip(in_files, out_files):
            if os.path.exists(out_file) and not overwrite:
                continue
            f.write('cache.cacheRun(["'+out_file+'","'+in_file+'"],["'
                    +os.path.join(python_dir,'skim_ntuple.py')
                    +'","'+cut+'","'+out_file+'","'+in_file
                    +'"],False,10000000000,0.5,False)\n')
    os.chmod(run_file, 0755)

    subprocess.call(["JobSubmit.csh","run/wrapper.sh",run_file])
Пример #4
0
def skimFiles(in_files, out_file, cut, keep_existing):
    in_files = [ utilities.fullPath(in_file) for in_file in in_files ]
    out_file = utilities.fullPath(out_file)

    utilities.ensureDir(os.path.dirname(out_file))

    cut = expandCut(cut)

    print("INPUT FILES:",in_files,"\n")
    print("OUTPUT FILE:",out_file,"\n")
    print("        CUT:",cut,"\n")

    if keep_existing and os.path.exists(out_file):
        print("Keeping pre-existing "+out_file+"\n")
        return

    in_tree = ROOT.TChain("tree", "tree")
    for in_file in in_files:
        in_tree.Add(in_file)

    with utilities.ROOTFile(out_file, "recreate") as out:
        out_tree = in_tree.CopyTree(cut)
        out_tree.Write()
Пример #5
0
def skimFiles(in_files, out_file, cut, keep_existing):
    in_files = [utilities.fullPath(in_file) for in_file in in_files]
    out_file = utilities.fullPath(out_file)

    utilities.ensureDir(os.path.dirname(out_file))

    cut = expandCut(cut)

    print("INPUT FILES:", in_files, "\n")
    print("OUTPUT FILE:", out_file, "\n")
    print("        CUT:", cut, "\n")

    if keep_existing and os.path.exists(out_file):
        print("Keeping pre-existing " + out_file + "\n")
        return

    in_tree = ROOT.TChain("tree", "tree")
    for in_file in in_files:
        in_tree.Add(in_file)

    with utilities.ROOTFile(out_file, "recreate") as out:
        out_tree = in_tree.CopyTree(cut)
        out_tree.Write()