Exemple #1
0
def sample(name,
           version=None,
           n_events = -1,
           format = ("ICF", 2),
           path="/vols/cms02/as1604/PhysicsUtils/SampleDB2/store",
	   node = "IC_DCACHE"
	):
    store = openStore(path)
    if not store.Exists(name+"/_sample_.json"):
        print "Sample '%s' not found" % name
        sys.exit(1)
    samp = store.Get(name+"/_sample_.json")
    vers = None
    if version is not None:
        if not store.Exists("%s/%s.json" % (name, version)):
            print "No version '%s' for sample '%s'" % (version,name)
            sys.exit(1)
        vers = store.Get("%s/%s.json" % (name, version))
    else:
        if not store.Exists("%s/%s.json" % (name, samp.latest)):
            print "Oops the sample specified latest version '%s' cannot be found" % samp.latest
        vers = store.Get("%s/%s.json" % (name, sampl.latest))
    ps = PSet(Format = format)
    if samp.cross_section == -1:
        ps._quiet_set("Weight", 1.0)
    else:
        ps._quiet_set("CrossSection", samp.cross_section)
    total_events = 0
    files = []
    for b in vers.blocks:
	if b["node"] != node:
	    continue
        try:
            for f in b["files"]:
                if f["events"] == -1:
                    continue
                files.append(str(se_path_to_url(f["path"], "dcap")))
                total_events += f["events"]
                if n_events != -1 and total_events >= n_events:
                    raise BreakMeOut
        except BreakMeOut:
            break
    ps._quiet_set("File", files)
    name = samp.name[1:].replace("/", "_")
    if version is not None:
	name += "_"+vers.name
    ps._quiet_set("Name", str(name))
    ps._quiet_set("Events", total_events)
    return ps
Exemple #2
0
def evList_to_pset(fname, debug=False):
    """ Takes an input event list file and converts to a PSet suitable for use in analysis code."""
    """NOTE: made for txt file format 'Run:LS:Event' """

    import sys
    from icf.core import PSet

    with open(fname, "r") as f:

        p = PSet()

        runList = []
        lumiSList = []
        evList = []

        for line in f:
            lineTmp = line.split(":")

            #fill each list
            runList.append(int(lineTmp[0]))
            lumiSList.append(int(lineTmp[1]))
            evList.append(int(lineTmp[2]))

        #create new entry in the PSet for each list
        p._quiet_set("Run", runList)
        p._quiet_set("Lumi", lumiSList)
        p._quiet_set("Event", evList)

        return p.ps()
Exemple #3
0
    def pset(**opts):
        from icf.core import PSet
        if not "nt_format" in opts:
            raise ValueError("Must supply nt_format argument")
        nt_format = opts["nt_format"]
        if "pset_name" in opts:
            pset_name = opts["pset_name"]
            del opts["pset_name"]
        else:
            pset_name = None
        info = self.sample(**opts)

        ps = PSet()
        if pset_name is not None:
            ps._quiet_set("Name", pset_name)
        else:
            if "name" in opts:
                ps._quiet_set("Name", opts["name"].replace("/", "_").replace("*",""))
            elif "dbs" in opts:
                ps._quiet_set("Name", opts["name"].replace("/", "_"))
            else:
                raise ValueError("Cannot construct name")
        ps._quiet_set("Format", nt_format)
        ps._quiet_set("File", info["files"])
        if info["cross_section"] == -1:
            ps._quiet_set("Weight", 1.)
        else:
            ps._quiet_set("CrossSection", info["cross_section"])
        return ps