From 87b684d06b7c46f76ed3e314ed0006dc57489330 Mon Sep 17 00:00:00 2001 From: Dmitry Ozerov Date: Mon, 18 May 2020 10:37:26 +0200 Subject: [PATCH] take url from request, if provided. Don't append _CA to provided in request filename. Better error handling when data_api retrieve doesn't work --- cadump/cadump.py | 20 ++++++++++++-------- conda-recipe/meta.yaml | 4 ++-- setup.py | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cadump/cadump.py b/cadump/cadump.py index b56731c..51a7a2b 100644 --- a/cadump/cadump.py +++ b/cadump/cadump.py @@ -47,7 +47,6 @@ def put_document(): def download_data(config): logger.info("Dump data to hdf5 ...") - # logger.info(config) start_pulse = config["range"]["startPulseId"] end_pulse = config["range"]["endPulseId"] @@ -57,22 +56,24 @@ def download_data(config): if "channels" in config: channels = config["channels"] - logger.info("Retrieve data for channels: ", channels) + logger.info("Retrieve data for channels: %s" % channels) + + if "retrieval_url" in config: + new_base_url = config["retrieval_url"] + else: + new_base_url = base_url logger.info("Retrieve pulse-id / data mapping for pulse ids") - # start_date, end_date = data_api.get_global_date([start_pulse, end_pulse]) start_date, end_date = get_pulse_id_date_mapping([start_pulse, end_pulse]) - # append _CA to the filename filename = config["parameters"]["output_file"] if filename != "/dev/null": - new_filename = filename[:-3]+"_CA"+filename[-3:] + new_filename = filename else: new_filename = None - logger.info("Retrieving data for interval start: " + str(start_date) + " end: " + str(end_date) + " . From " + base_url) - # data = data_api.get_data(channel_list, start=start_date, end=end_date, base_url=base_url) - data = get_data(channels, start=start_date, end=end_date, base_url=base_url) + logger.info("Retrieving data for interval start: " + str(start_date) + " end: " + str(end_date) + " . From " + new_base_url) + data = get_data(channels, start=start_date, end=end_date, base_url=new_base_url) if len(data) < 1: logger.error("No data retrieved") @@ -160,6 +161,9 @@ def get_pulse_id_date_mapping(pulse_ids): data = response.json() + if len(data[0]["data"]) == 0 or not "pulseID" in data[0]["data"][0]: + raise RuntimeError("Didn't get good responce from data_api : %s " % data) + if not pulse_id == data[0]["data"][0]["pulseId"]: logger.info("retrieval failed") if c == 0: diff --git a/conda-recipe/meta.yaml b/conda-recipe/meta.yaml index 1dcbdb0..b6675a1 100644 --- a/conda-recipe/meta.yaml +++ b/conda-recipe/meta.yaml @@ -1,6 +1,6 @@ package: name: cadump - version: 0.0.10 + version: 0.0.11 source: path: .. @@ -16,4 +16,4 @@ requirements: - data_api >=0.7.6 run: - python - - data_api >=0.7.6 \ No newline at end of file + - data_api >=0.7.6 diff --git a/setup.py b/setup.py index 48d48a1..1cd3acc 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="cadump", - version="0.0.9", + version="0.0.11", author="Paul Scherrer Institute", author_email="daq@psi.ch", description="Interface to dump data from archiver/databuffer",