Пример #1
0
def run_lumi_dict(arg, verbose=None):
    "Return run-lumi info for given argument (dataset, block, file, run)"
    try:
        data = json.loads(arg)
    except:
        if isinstance(arg, basestring) and arg.find("{") != -1:
            data = eval(arg, {"__builtins__": None}, {})
        else:
            data = arg  # assume it is dataset/file/block/run
    url = dbs_url()
    run_lumi = {}
    if isinstance(data, dict):  # we got run-lumi dict
        for run, lumis in data.items():
            run_lumi[int(run)] = lumis
    else:
        if url.find("cmsdbsprod") != -1:  # DBS2
            run_lumi = dbs2.run_lumi(str(data), verbose)
        else:
            if pat_dataset.match(data):
                params = {"dataset": data}
                result = get_data(dbs_url("files"), params, verbose)
                for row in result:
                    params = {"logical_file_name": row["logical_file_name"]}
                    run_lumi = parse_runlumis(get_data(dbs_url("filelumis"), params, verbose))
            elif pat_block.match(data):
                params = {"block_name": data}
                run_lumi = parse_runlumis(get_data(dbs_url("filelumis"), params, verbose))
            elif pat_lfn.match(data):
                params = {"logical_file_name": data}
                run_lumi = parse_runlumis(get_data(dbs_url("filelumis"), params, verbose))
            elif pat_run.match(data):
                params = {"run_num": data}
                run_lumi = parse_runlumis(get_data(dbs_url("filelumis"), params, verbose))
    return run_lumi
Пример #2
0
def run_lumi_dict(arg, verbose=None):
    "Return run-lumi info for given argument (dataset, block, file, run)"
    try:
        data = json.loads(arg)
    except:
        if isinstance(arg, basestring) and arg.find("{") != -1:
            data = eval(arg, {"__builtins__": None}, {})
        else:
            data = arg  # assume it is dataset/file/block/run
    url = dbs_url()
    run_lumi = {}
    if isinstance(data, dict):  # we got run-lumi dict
        for run, lumis in data.items():
            run_lumi[int(run)] = lumis
    else:
        if url.find('cmsdbsprod') != -1:  # DBS2
            run_lumi = dbs2.run_lumi(str(data), verbose)
        else:
            if pat_dataset.match(data):
                params = {'dataset': data}
                result = get_data(dbs_url('files'), params, verbose)
                for row in result:
                    params = {'logical_file_name': row['logical_file_name']}
                    run_lumi = parse_runlumis(
                        get_data(dbs_url('filelumis'), params, verbose))
            elif pat_block.match(data):
                params = {'block_name': data}
                run_lumi = parse_runlumis(
                    get_data(dbs_url('filelumis'), params, verbose))
            elif pat_lfn.match(data):
                params = {'logical_file_name': data}
                run_lumi = parse_runlumis(
                    get_data(dbs_url('filelumis'), params, verbose))
            elif pat_run.match(data):
                params = {'run_num': data}
                run_lumi = parse_runlumis(
                    get_data(dbs_url('filelumis'), params, verbose))
    return run_lumi
Пример #3
0
Файл: dbs2.py Проект: dmwm/cmssh
def run_lumi(arg, verbose=None):
    if pat_block.match(arg):
        query  = 'find run,lumi where block=%s' % arg
    elif  pat_lfn.match(arg):
        query  = 'find run,lumi where file=%s' % arg
    elif  pat_dataset.match(arg):
        query  = 'find run,lumi where dataset=%s' % arg
    elif  pat_run.match(arg):
        query  = 'find run,lumi where run=%s' % arg
    params = {"api":"executeQuery", "apiversion": "DBS_2_0_9", "query":query}
    data   = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
    run_lumi = {}
    for row in qlxml_parser(data, 'run'):
        rec = row['run']
        run = rec['run']
        lumi = rec['lumi']
        if  run_lumi.has_key(run):
            run_lumi[run].append(lumi)
        else:
            run_lumi[run] = [lumi]
    for key, val in run_lumi.items():
        val.sort()
        run_lumi[key] = val
    return run_lumi
Пример #4
0
def run_lumi(arg, verbose=None):
    if pat_block.match(arg):
        query = 'find run,lumi where block=%s' % arg
    elif pat_lfn.match(arg):
        query = 'find run,lumi where file=%s' % arg
    elif pat_dataset.match(arg):
        query = 'find run,lumi where dataset=%s' % arg
    elif pat_run.match(arg):
        query = 'find run,lumi where run=%s' % arg
    params = {"api": "executeQuery", "apiversion": "DBS_2_0_9", "query": query}
    data = urllib2.urlopen(dbs_url(), urllib.urlencode(params))
    run_lumi = {}
    for row in qlxml_parser(data, 'run'):
        rec = row['run']
        run = rec['run']
        lumi = rec['lumi']
        if run_lumi.has_key(run):
            run_lumi[run].append(lumi)
        else:
            run_lumi[run] = [lumi]
    for key, val in run_lumi.items():
        val.sort()
        run_lumi[key] = val
    return run_lumi
Пример #5
0
def cms_ls(arg):
    """
    cmssh ls command lists local files/dirs/CMS storate elements or
    CMS entities (se, site, dataset, block, run, release, file).
    Examples:
        cmssh> ls # UNIX command
        cmssh> ls -l local_file
        cmssh> ls T3_US_Cornell:/store/user/valya
        cmssh> ls run=160915
    """
    arg = arg.strip()
    res = []
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    orig_arg = arg
    if orig_arg.find('|') != -1:
        arg, flt = orig_arg.split('|', 1)
        arg = arg.strip()
    else:
        flt = None
    startswith = None
    entities = \
        ['se', 'site', 'lfn', 'dataset', 'block', 'run', 'release', 'file']
    for item in entities:
        if arg.startswith(item + '='):
            startswith = item
    if os.path.isfile(orig_arg) or os.path.isdir(orig_arg):
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    elif pat_se.match(arg):
        arg = arg.replace('site=', '')
        res = list_se(arg, debug)
    elif pat_site.match(arg):
        arg = arg.replace('site=', '')
        res = site_info(arg, debug)
    elif pat_lfn.match(arg):
        arg = arg.replace('file=', '')
        arg = arg.replace('lfn=', '')
        res = file_info(arg, debug)
    elif pat_block.match(arg):
        arg = arg.replace('block=', '')
        res = block_info(arg, debug)
    elif pat_dataset.match(arg):
        arg = arg.replace('dataset=', '')
        try:
            res = dataset_info(arg, debug)
        except IndexError:
            msg = "Given pattern '%s' does not exist on local filesystem or in DBS" % arg
            print_error(msg)
    elif pat_run.match(arg):
        arg = arg.replace('run=', '')
        res = run_info(arg, debug)
    elif pat_release.match(arg):
        arg = arg.replace('release=', '')
        res = release_info(arg, debug)
    elif startswith:
        msg = 'No pattern is allowed for %s look-up' % startswith
        print_error(msg)
    else:
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    if res:
        RESMGR.assign(res)
        list_results(res, debug=True, flt=flt)
Пример #6
0
def cms_ls(arg):
    """
    cmssh ls command lists local files/dirs/CMS storate elements or
    CMS entities (se, site, dataset, block, run, release, file).
    Examples:
        cmssh> ls # UNIX command
        cmssh> ls -l local_file
        cmssh> ls T3_US_Cornell:/store/user/valya
        cmssh> ls run=160915
    """
    arg = arg.strip()
    res = []
    try:
        debug = get_ipython().debug
    except:
        debug = 0
    orig_arg = arg
    if  orig_arg.find('|') != -1:
        arg, flt = orig_arg.split('|', 1)
        arg = arg.strip()
    else:
        flt = None
    startswith = None
    entities = \
        ['se', 'site', 'lfn', 'dataset', 'block', 'run', 'release', 'file']
    for item in entities:
        if  arg.startswith(item + '='):
            startswith = item
    if  os.path.isfile(orig_arg) or os.path.isdir(orig_arg):
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    elif pat_se.match(arg):
        arg = arg.replace('site=', '')
        res = list_se(arg, debug)
    elif  pat_site.match(arg):
        arg = arg.replace('site=', '')
        res = site_info(arg, debug)
    elif pat_lfn.match(arg):
        arg = arg.replace('file=', '')
        arg = arg.replace('lfn=', '')
        res = file_info(arg, debug)
    elif pat_block.match(arg):
        arg = arg.replace('block=', '')
        res = block_info(arg, debug)
    elif pat_dataset.match(arg):
        arg = arg.replace('dataset=', '')
        try:
            res = dataset_info(arg, debug)
        except IndexError:
            msg = "Given pattern '%s' does not exist on local filesystem or in DBS" % arg
            print_error(msg)
    elif pat_run.match(arg):
        arg = arg.replace('run=', '')
        res = run_info(arg, debug)
    elif pat_release.match(arg):
        arg = arg.replace('release=', '')
        res = release_info(arg, debug)
    elif startswith:
        msg = 'No pattern is allowed for %s look-up' % startswith
        print_error(msg)
    else:
        cmd = 'ls ' + orig_arg
        run(cmd, shell=True)
    if  res:
        RESMGR.assign(res)
        list_results(res, debug=True, flt=flt)