def test_convert2ranges(self): "Test sort_rows function" url = 'http://a.b.com/api?arg1=1&arg2=foo' expect = {'arg1':'1', 'arg2': 'foo'} result = url_args(url) self.assertEqual(result, expect) expect = {'arg1':1, 'arg2': 'foo'} result = url_args(url, convert_types=True) self.assertEqual(result, expect)
def block_run_lumis(url, blocks, runs=None, verbose=0): """ Find block, run, lumi tuple for given set of files and (optional) runs. """ headers = {'Accept': 'application/json;text/json'} urls = [] params = {} for blk in blocks: if not blk: continue dbs_url = '%s/filelumis/?block_name=%s' % (url, urllib.quote(blk)) if runs and isinstance(runs, list): params.update({'run_num': urllib.quote(str(runs))}) urls.append(dbs_url) if not urls: return if verbose > 1: print("\nDEBUG: block_run_lumis") print(urls) gen = urlfetch_getdata(urls, CKEY, CERT, headers) odict = {} # output dict for rec in gen: blk = urllib.unquote(url_args(rec['url'])['block_name']) if 'error' in rec: error = rec.get('error') reason = rec.get('reason', '') yield {'error':error, 'reason':reason} else: for row in json.loads(rec['data']): run = row['run_num'] lumilist = row['lumi_section_num'] eventlist = row.get('event_count', []) key = (blk, run) for idx, lumi in enumerate(lumilist): if len(eventlist) > 0: evts = eventlist[idx] else: evts = None odict.setdefault(key, []).append((lumi, evts)) for key, values in odict.items(): blk, run = key lumis = [] evts = [] for lumi, evt in values: lumis.append(lumi) evts.append(evt) yield blk, run, lumis, evts
def block_run_lumis(url, blocks, runs=None, verbose=0): """ Find block, run, lumi tuple for given set of files and (optional) runs. """ headers = {"Accept": "application/json;text/json"} urls = [] params = {} for blk in blocks: if not blk: continue dbs_url = "%s/filelumis/?block_name=%s" % (url, urllib.quote(blk)) if runs and isinstance(runs, list): params.update({"run_num": runrange(runs[0], runs[-1], False)}) urls.append(dbs_url) if not urls: return if verbose > 1: print "\nDEBUG: block_run_lumis" print urls gen = urlfetch_getdata(urls, CKEY, CERT, headers) odict = {} # output dict for rec in gen: blk = urllib.unquote(url_args(rec["url"])["block_name"]) if "error" in rec: error = rec.get("error") reason = rec.get("reason", "") yield {"error": error, "reason": reason} else: for row in json.loads(rec["data"]): run = row["run_num"] lumilist = row["lumi_section_num"] key = (blk, run) for lumi in lumilist: odict.setdefault(key, []).append(lumi) for key, lumis in odict.iteritems(): blk, run = key yield blk, run, lumis