From 2176dfacf8a40dacf16ce0ee15fc8b2448b6a40e Mon Sep 17 00:00:00 2001
From: Andrey Samartsev <andrey.samatrtsev@xfel.eu>
Date: Thu, 25 Feb 2021 10:24:23 +0100
Subject: [PATCH] changes after Karim's revision

---
 cal_tools/cal_tools/dssclib.py | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/cal_tools/cal_tools/dssclib.py b/cal_tools/cal_tools/dssclib.py
index 18a339e77..ca3d254b2 100644
--- a/cal_tools/cal_tools/dssclib.py
+++ b/cal_tools/cal_tools/dssclib.py
@@ -69,10 +69,10 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
             ctrlDataFiles[quadrant + 1] = f
 
     if len(ctrlDataFiles) == 0:
-        print("No Control Slow Data found!")
+        print("ERROR: no Control Slow Data found!")
         return targetGainAll, encodedGainAll, operatingFreqAll
 
-    daq_format = ''
+    daq_format = None
 
     ctrlloc = None
     filename = next(iter(ctrlDataFiles.values()))
@@ -93,11 +93,18 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
     tGain = {}
     encodedGain = {}
     operatingFreqs = {}
-    for quadrant, file in ctrlDataFiles.items():
-        if len(file):
-            with h5py.File(file) as h5file:
+    for quadrant in slow_data_aggregators.keys():
+        if quadrant in ctrlDataFiles.keys():
+            file = ctrlDataFiles[quadrant]
+            with h5py.File(file) as h5file:                
+                iramp_path = f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/irampFineTrm/value                
                 if not daq_format:
                     tGain[quadrant] = 0.0  # 0.0 is default value for TG
+                    
+                    if iramp_path in h5file:
+                        irampSettings = h5file[iramp_path][0]
+                    else:
+                        irampSettings = "Various                    
                 else:
                     epcConfig = h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/epcRegisterFilePath/value'][0]\
                         .decode("utf-8")
@@ -106,21 +113,14 @@ def get_dssc_ctrl_data(in_folder, slow_data_pattern,
                     print(f"EPC configuration: {epcConfig}")
                     targGain = _extr_gainparam_conffilename(epcConfig)
                     tGain[quadrant] = float(
-                        targGain) if targGain is not None else 0.0
+                        targGain) if targGain is not None else 0.0                    
+                    irampSettings = h5file[iramp_path][0].decode("utf-8")
 
                 gainSettingsMap = {}
                 for coarseParam in ['fcfEnCap', 'csaFbCap', 'csaResistor']:
                     gainSettingsMap[coarseParam] = int(
                         h5file[f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/{coarseParam}/value'][0])
 
-                iramp_path = f'/RUN/{ctrlloc}/FPGA/PPT_Q{quadrant}/gain/irampFineTrm/value'
-                if daq_format != '':
-                    irampSettings = h5file[iramp_path][0].decode("utf-8")
-                elif iramp_path in h5file:
-                    irampSettings = h5file[iramp_path][0]
-                else:
-                    irampSettings = "Various"
-
                 gainSettingsMap['trimmed'] = np.int64(
                     1) if irampSettings == "Various" else np.int64(0)
 
-- 
GitLab