From e7978a40ae98b353b2b88de7466804ed02bc7011 Mon Sep 17 00:00:00 2001
From: 29iduser <you@example.com>
Date: Tue, 1 Nov 2022 11:02:10 -0500
Subject: [PATCH] debug

---
 iexcode/instruments/storage_ring.py | 11 ++++++++--
 iexcode/macros/commissioning.py     |  4 ++--
 iexcode/macros/start_of_the_week.py | 32 +++++++++++++++++------------
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/iexcode/instruments/storage_ring.py b/iexcode/instruments/storage_ring.py
index de3e7fb..f8bea60 100644
--- a/iexcode/instruments/storage_ring.py
+++ b/iexcode/instruments/storage_ring.py
@@ -15,9 +15,16 @@ def wait_for_beam(ring_current=80):
     Checks the status every 30 seconds
     """
     while True:
-        SR=caget("S:SRcurrentAI.VAL")
+        SR=ring_current_get()
         if (SR<ring_current):
             sleep(30)
         else:
             print("Beam is back -"+dateandtime())
-            break
\ No newline at end of file
+            break
+
+def ring_current_get():
+    """
+    returns the storage ring current
+    """
+    SR=caget("S:SRcurrentAI.VAL")
+    return SR
\ No newline at end of file
diff --git a/iexcode/macros/commissioning.py b/iexcode/macros/commissioning.py
index b3641a9..167a5a8 100644
--- a/iexcode/macros/commissioning.py
+++ b/iexcode/macros/commissioning.py
@@ -606,9 +606,9 @@ def M0M1_steering(h_position,v_position,verbose=False):
 
     message =  '\nSlit-2 slit: should always be centered vertically, adjust M1 roll, horizontally adjust pitch if too far off'
 
-    message +="   - vertical: "+str(current_roll)+str(v_steering)+" => FMB_mirror_move(1,'RZ',"+str(new_roll)+")"
+    message +="\n   - vertical steering adjustment = "+str(v_steering) + " => new RZ = "+str(new_roll)
     if abs(h_position) > 1:
-        message += "   - horizontal: error to large, need to steer M1 pitch => FMB_mirror_move(1,'RY',"+str(new_pitch)+")"
+        message += "\n   - horizontal: error to large, need to steer M1 pitch => FMB_mirror_move(1,'RY',"+str(new_pitch)+")"
     else:
         message +='   - horizontal: reset slit 2H center to '+str(h_position)
     
diff --git a/iexcode/macros/start_of_the_week.py b/iexcode/macros/start_of_the_week.py
index 9c5dda8..f4bc437 100644
--- a/iexcode/macros/start_of_the_week.py
+++ b/iexcode/macros/start_of_the_week.py
@@ -134,8 +134,11 @@ def interactive_fit_mda(val_name,scannum,det,FWHM_or_PolyOrder,fct,**kwargs):
             ''')
             flagfit=input('\nType ('+options+'), or press ENTER to abort script >')
             if flagfit not in options.split(","):
-                print('\ninvalid input; please try again...\n')
-                flagfit=input('\nType ('+options+') >')
+                if flagfit == '':
+                    return flagfit,None
+                else:
+                    print('\ninvalid input; please try again...\n')
+                    flagfit=input('\nType ('+options+') >')
             if flagfit == '0':  
                 print('\nresuming script...\n')
                 flagfit=0
@@ -148,8 +151,6 @@ def interactive_fit_mda(val_name,scannum,det,FWHM_or_PolyOrder,fct,**kwargs):
                 position = fit_mda(scannum,det,FWHM_or_PolyOrder,fct,xrange=(x1,x2))
                 plt.show()
                 flagfit=2 
-            if flatfit == '':
-                return
     return flagfit,position
 
 def sotw_BLinit(branch):
@@ -225,7 +226,7 @@ def sotw_setup(grt,branch,wait,**kwargs):
     ### checking ID:
     polarization(kwargs['mode'])
 
-def sotw_ID_steering(detCA4,**kwargs):
+def sotw_ID_steering_scan(**kwargs):
     """
     slit1A/ID_steering
     """
@@ -234,6 +235,9 @@ def sotw_ID_steering(detCA4,**kwargs):
     #plotting
     scanNum_h = last_mda()-1
     scanNum_v = last_mda()
+    return scanNum_h, scanNum_v
+
+def sotw_ID_steering_plot(detCA4,scanNum_h,scanNum_v):
     
     flagfit, h = interactive_fit_mda('H_center',scanNum_h,detCA4,1,'gauss',xrange=[-1,1])
     if flagfit == '' or flagfit <0:
@@ -244,7 +248,7 @@ def sotw_ID_steering(detCA4,**kwargs):
         return
     try:    
         ID_steering_message(h,v)
-        flag = interactive_fct()
+        flagfit = interactive_fct()
     except:
         print('\nUnable to calculate ID steering')
         print('steering out => move beam more positive (10 urad ~ 0.25 mm)')
@@ -328,8 +332,8 @@ def sotw_slit_vs_mono(slit_name,**kwargs):
                             print_warning_message("need to debug update_mirror_dict, do by hand")
                         except:
                             print_warning_message("couldn't update the mirror dictionary, do by hand")
-                    if flag == '':
-                        return
+                        if flag == '':
+                            return flag
                     flag == 2
                 except:
                     print('\invalid input; unable to move M1')
@@ -350,6 +354,7 @@ def sotw_slit_positions(grt,**kwargs):
     kwargs.setdefault('hv_list',[470,505])
     kwargs.setdefault('slit_list',['slit2B','slit1A'])
     kwargs.setdefault('monoVslit_quick',True)
+
     detDiode= kwargs['detDiode']
     for slit_name in kwargs['slit_list']:
         message={'slit2B': 'M1 alignment and slit center','slit1A':'slit center'}
@@ -359,7 +364,7 @@ def sotw_slit_positions(grt,**kwargs):
 
         flag,v,h =  sotw_slit_vs_mono(slit_name,**kwargs)
         if flag == '':
-            return
+            return flag
 
     if slit_name == 'slit2B':
         list_position[2] = v
@@ -450,8 +455,9 @@ def StartOfTheWeek(grt,branch,wait=False,**kwargs):
         print("\n\n================== Slit 1A scans:")
         flag=2
         while flag>1:
-            flag = sotw_ID_steering(detCA4,**kwargs)
-            if flag == '' or flag <0:
+            scanNum_h, scanNum_v = sotw_ID_steering_scan(**kwargs)
+            flag = sotw_ID_steering_plot(detCA4,scanNum_h,scanNum_v)
+            if flag == '':
                 return
         diagnostic('mesh_W','out')
             
@@ -460,7 +466,7 @@ def StartOfTheWeek(grt,branch,wait=False,**kwargs):
     if 'wire' in kwargs['scanType']:
         print("\n\n================== Slit 1A scans:")
         flag = sotw_wire(detH,detV,**kwargs)
-        if flag == ''or flag <0:
+        if flag == '':
             return
 
     ###### Mono/slit scans: 
@@ -477,7 +483,7 @@ def StartOfTheWeek(grt,branch,wait=False,**kwargs):
         print("\n\n================== Mono/slit scans:")   
 
         flag =sotw_slit_positions(grt,**kwargs)
-        if flag == '' or flag <0:
+        if flag == '':
             return
         
                   
-- 
GitLab