def main(): args = parse_arguments() if args.runs: resource_name = "runs" method = oms.get_runs arguments = args.runs elif args.fills: resource_name = "fills" method = oms.get_fills arguments = args.fills elif args.lumisections: resource_name = "lumisections" method = oms.get_lumisections arguments = args.lumisections elif args.hltrates: resource_name = "hltrates" method = oms.get_hltpathrates arguments = args.hltrates elif args.all_hltrates: resource_name = "hltrates" method = oms.get_all_hltpathrates arguments = args.all_hltrates else: raise NotImplementedError kwargs = {} if not check_oms_connectivity(): kwargs["inside_cern_gpn"] = False kwargs["cookies"] = get_oms_cookie() #extra_arguments = {} if args.split_filling_scheme and args.fills: kwargs['split_filling_scheme'] = True response = method(*arguments, **kwargs) #print("Value of HTTP Response ", response) content = json.dumps(response, indent=2) filename = "oms_{}.json".format(resource_name) save_to_disk(filename, content=content) print("Stored {} {} in '{}'".format(len(response), resource_name, filename))
def get_resources(table, parameters, page_size=PAGE_SIZE, silent=False, **kwargs): if "inside_cern_gpn" not in kwargs: kwargs['inside_cern_gpn'] = check_oms_connectivity() if not silent: print("Getting initial response...", end="\r") response = _get_resources_page(table, parameters, page=1, page_size=page_size, **kwargs) print("Inside get_resources") resource_count = response["meta"]["totalResourceCount"] page_count = calc_page_count(resource_count, page_size) if not silent: print(" " * 100, end="\r") print("Total number of {}: {}".format(table, resource_count)) print() resources = [flatten_resource(resource) for resource in response["data"]] for page in range(2, page_count + 1): if not silent: print_progress(page, page_count, text="Page {}/{}".format(page, page_count)) response = _get_resources_page(table, parameters, page, page_size, **kwargs) resources.extend( [flatten_resource(resource) for resource in response["data"]]) if not silent: print() print() assert len(resources ) == resource_count, "Oops, not enough resources were returned" return resources
def get_lumisection_count(run_number, **kwargs): """ :return: Number of lumisections where CMS was active """ parameters = { "filter[run_number][EQ]": run_number, "filter[cms_active][EQ]": 'true', "sort": "lumisection_number" } if "inside_cern_gpn" not in kwargs: kwargs['inside_cern_gpn'] = check_oms_connectivity() response = _get_resources_page("lumisections", parameters, page_size=1, page=1, **kwargs) resource_count = response["meta"]["totalResourceCount"] return resource_count
def _get_single_resource(table, parameters, **kwargs): if "inside_cern_gpn" not in kwargs: kwargs['inside_cern_gpn'] = check_oms_connectivity() data = get_oms_resource(table, parameters, **kwargs)["data"] assert len(data) == 1, "More than 1 {} were returned".format(table) return data[0]