From 967262ddfb66e5face2257a6536c4c36c3d25dcd Mon Sep 17 00:00:00 2001 From: Karim Ahmed <karim.ahmed@xfel.eu> Date: Wed, 29 Jan 2020 12:20:10 +0100 Subject: [PATCH] add doraise bool and show msg when retrieval fails --- cal_tools/cal_tools/tools.py | 18 ++++++++++++------ notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb | 5 ++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cal_tools/cal_tools/tools.py b/cal_tools/cal_tools/tools.py index 435c998ca..b2ad615d4 100644 --- a/cal_tools/cal_tools/tools.py +++ b/cal_tools/cal_tools/tools.py @@ -238,7 +238,7 @@ already_printed = {} def get_from_db(device, constant, condition, empty_constant, cal_db_interface, creation_time=None, verbosity=1, timeout=30000, ntries=7, meta_only=True, - version_info=False): + version_info=False, doraise=False): """ Return calibration constants and metadata requested from CalDB @@ -253,8 +253,10 @@ def get_from_db(device, constant, condition, empty_constant, ntries is set to 7 so that if the timeout started at 30s last timeout will be ~ 1h. :param ntries: number of tries to contact the database - :param meta_only: Retrieve only metadata via ZMQ. Constants are taken - directly from the h5 file on maxwell. + :param meta_only: (bool) Retrieve only metadata via ZMQ. Constants are + taken directly from the h5 file on maxwell. + :param version_info: (bool) to show the info for the retrieved Constant + :param doraise: (bool) if True raise errors during communication with DB. :return: Calibration constant, metadata """ from iCalibrationDB import ConstantMetaData, Versions @@ -292,6 +294,8 @@ def get_from_db(device, constant, condition, empty_constant, ntries -= 1 timeout *= 2 sleep(np.random.randint(30)) + if ntries == 0 and doraise: + raise except Exception as e: if verbosity > 0: print(e) @@ -299,7 +303,9 @@ def get_from_db(device, constant, condition, empty_constant, ntries -= 1 else: ntries = 0 - break + if ntries == 0 and doraise: + raise RuntimeError(f'{e}') + if ntries > 0: if verbosity > 0: @@ -332,7 +338,7 @@ def send_to_db(device, constant, condition, file_loc, :param ntries: number of tries to contact the database, ntries is set to 7 so that if the timeout started at 30s last timeout will be ~ 1h. - :param doraise: if True raise errors during communication with DB + :param doraise: (bool) if True raise errors during communication with DB """ from iCalibrationDB import ConstantMetaData, Versions import zmq @@ -371,7 +377,7 @@ def send_to_db(device, constant, condition, file_loc, else: ntries = 0 if ntries == 0 and doraise: - raise + raise RuntimeError(f'{e}') if ntries > 0: if verbosity > 0: diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb index 3d34b7934..7b4e19887 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb @@ -640,7 +640,10 @@ " else:\n", " for key, item in when.items():\n", " if hasattr(item, 'strftime'):\n", - " item = item.strftime('%y-%m-%d %H:%M')\n", + " if item == creation_time:\n", + " item = \"Constant was not retrieved\"\n", + " else:\n", + " item = item.strftime('%y-%m-%d %H:%M')\n", " # If constant retrieval is crashed\n", " else:\n", " item = 'None'\n", -- GitLab