From 3a343a65e564e3f7f36d165758e9ba524f6d0cf3 Mon Sep 17 00:00:00 2001
From: ahmedk <karim.ahmed@xfel.eu>
Date: Wed, 17 Jan 2024 21:12:32 +0100
Subject: [PATCH] add receiver_suffixes and corr_receiver for defining a larger
 range of names

---
 .../Characterize_Darks_Gotthard2_NBC.ipynb    | 21 ++++++++++---------
 .../Gotthard2/Correction_Gotthard2_NBC.ipynb  | 16 ++++++++------
 2 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
index fda112e5d..3908e95b3 100644
--- a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
+++ b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb
@@ -22,18 +22,19 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "in_folder = \"/gpfs/exfel/exp/FXE/202231/p900298/raw\"  # the folder to read data from, required\n",
+    "in_folder = \"/gpfs/exfel/exp/SA1/202331/p900384/raw\"  # the folder to read data from, required\n",
     "out_folder =  \"/gpfs/exfel/data/scratch/ahmedk/test/gotthard2/darks\"  # the folder to output to, required\n",
     "metadata_folder = ''  # Directory containing calibration_metadata.yml when run by xfel-calibrate\n",
-    "run_high = 7  # run number for G0 dark run, required\n",
-    "run_med = 8  # run number for G1 dark run, required\n",
-    "run_low = 9  # run number for G2 dark run, required\n",
+    "run_high = 61  # run number for G0 dark run, required\n",
+    "run_med = 62  # run number for G1 dark run, required\n",
+    "run_low = 63  # run number for G2 dark run, required\n",
     "\n",
     "# Parameters used to access raw data.\n",
-    "karabo_id = \"FXE_XAD_G2XES\"  # karabo prefix of Gotthard-II devices\n",
-    "karabo_da = [\"GH201\"]  # data aggregators\n",
-    "receiver_template = \"RECEIVER\"  # receiver template used to read INSTRUMENT keys.\n",
-    "control_template = \"CONTROL\"  # control template used to read CONTROL keys.\n",
+    "karabo_id = \"SA1_XTD9_HIREX\"  # karabo prefix of Gotthard-II devices\n",
+    "karabo_da = [\"\"]  # data aggregators\n",
+    "receiver_template = \"RECEIVER{}\"  # receiver template used to read INSTRUMENT keys.\n",
+    "receiver_suffixes = [\"\"]  # Exact receiver names. This can be used for GH2 25um when each receiver has a unique name. Leave empty to use the receiver_template instead.\n",
+    "control_template = \"GOTTHARD2_CTRL\"  # control template used to read CONTROL keys.\n",
     "ctrl_source_template = '{}/DET/{}'  # template for control source name (filled with karabo_id_control)\n",
     "karabo_id_control = \"\"  # Control karabo ID. Set to empty string to use the karabo-id\n",
     "\n",
@@ -127,8 +128,8 @@
    "source": [
     "run_dc = RunDirectory(in_folder / f\"r{run_high:04d}\")\n",
     "file_loc = f\"proposal:{run_dc.run_metadata()['proposalNumber']} runs:{run_high} {run_med} {run_low}\"  # noqa\n",
-    "\n",
-    "receivers = sorted(list(run_dc.select(f'{karabo_id}/DET/{receiver_template}*').all_sources))"
+    "receivers = [\n",
+    "    list(run_dc.select(f'*{receiver_template}{r}').all_sources)[0] for r in receiver_suffixes]"
    ]
   },
   {
diff --git a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb
index aff16f800..22f829ba8 100644
--- a/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb
+++ b/notebooks/Gotthard2/Correction_Gotthard2_NBC.ipynb
@@ -60,11 +60,13 @@
     "# Parameters used to access raw data.\n",
     "karabo_id = \"DETLAB_25UM_GH2\"  # karabo prefix of Gotthard-II devices\n",
     "karabo_da = [\"\"]  # data aggregators\n",
-    "receiver_template = \"RECEIVER\"  # receiver template used to read INSTRUMENT keys.\n",
+    "receiver_template = \"RECEIVER{}\"  # receiver template used to read INSTRUMENT keys.\n",
+    "receiver_suffixes = [\"\"]\n",
     "control_template = \"CONTROL\"  # control template used to read CONTROL keys.\n",
     "ctrl_source_template = \"{}/DET/{}\"  # template for control source name (filled with karabo_id_control)\n",
     "karabo_id_control = \"\"  # Control karabo ID. Set to empty string to use the karabo-id\n",
     "corr_data_source = \"{}/CORR/{}:daqOutput\"  # Correction data source. filled with karabo_id and correction receiver\n",
+    "corr_receiver = \"\"  # The name of the correction receiver name. Leave empty for using the same receiver name for the 50um GH2 or the first(Master) receiver for the 25um GH2.\n",
     "\n",
     "# Parameters for calibration database.\n",
     "cal_db_interface = \"tcp://max-exfl-cal001:8016#8025\"  # the database interface to use.\n",
@@ -234,11 +236,13 @@
     "print(f\"Process modules: {db_modules} for run {run}\")\n",
     "\n",
     "# Create the correction receiver name.\n",
-    "receivers = sorted(list(run_dc.select(f'{karabo_id}/DET/{receiver_template}*').all_sources))\n",
-    "if gh2_detector == \"25um\":  # For 25um use virtual karabo_das for CALCAT data mapping.\n",
-    "    corr_receiver = receivers[0].split(\"/\")[-1].split(\":\")[0][:-2]\n",
-    "else:\n",
-    "    corr_receiver = receivers[0].split(\"/\")[-1].split(\":\")[0]"
+    "receivers = [\n",
+    "    list(run_dc.select(f'*{receiver_template}{r}').all_sources)[0] for r in receiver_suffixes]\n",
+    "if not corr_receiver:\n",
+    "    if gh2_detector == \"25um\":  # For 25um use virtual karabo_das for CALCAT data mapping.\n",
+    "        corr_receiver = receivers[0].split(\"/\")[-1].split(\":\")[0][:-2]\n",
+    "    else:\n",
+    "        corr_receiver = receivers[0].split(\"/\")[-1].split(\":\")[0]"
    ]
   },
   {
-- 
GitLab