From 52a840c29feb33771b8d6d0bc203eaeca62abb07 Mon Sep 17 00:00:00 2001
From: 29iduser <you@example.com>
Date: Tue, 11 Oct 2022 13:53:40 -0500
Subject: [PATCH] debugging sotw

---
 iexcode/instruments/ARPES.py             | 31 +++++++++++---------
 iexcode/instruments/IEX_BL_config.py     |  8 +++++
 iexcode/instruments/IEX_VPU.py           |  8 ++++-
 iexcode/instruments/electron_analyzer.py |  2 +-
 iexcode/instruments/scanRecord.py        | 37 ++++++++++++------------
 iexcode/instruments/shutters.py          |  5 ++--
 iexcode/macros/quick_plot.py             |  2 +-
 iexcode/macros/start_of_the_week.py      |  4 +--
 8 files changed, 57 insertions(+), 40 deletions(-)

diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py
index e211556..368b7f7 100644
--- a/iexcode/instruments/ARPES.py
+++ b/iexcode/instruments/ARPES.py
@@ -56,6 +56,16 @@ def ARPES_init(*userName,**kwargs):
     kwargs.setdefault('set_folders',False)
     kwargs.setdefault('reset',False)
 
+
+    if len(userName) == 0:
+        saveData_get_all(kwargs['scan_ioc'])
+        user_name = mda_user_name()
+    else:
+        user_name = userName[0]
+    if user_name == 'staff':
+        user_name = 'Staff'
+        kwargs['mode'] = 'staff'
+    
     #motors
     physical_motors = ['x','y','z','th','chi','phi']
     pseudo_motors = ['focus']
@@ -69,23 +79,16 @@ def ARPES_init(*userName,**kwargs):
 
     #setting folders
     if kwargs['set_folders']:
-        if BLconfig_mode() == 'staff':
-            user_name = 'Staff'
-        else:
-            if len(userName)==0:
-                user_name = input('user name: ')
-            else:
-                user_name = userName[0]
-        print(user_name)
+        if len(userName)==0:
+            user_name = input('user name: ')
         folders_ARPES(user_name,**kwargs)
-
-    else:
-        user_name = mda_user_name()
+    
     
     #logging
-    log_init('ARPES',user_name,_ARPES_log_dictionary,set_file=False)
     if kwargs['set_folders']:
-        log_name_set() 
+        log_init('ARPES',user_name,_ARPES_log_dictionary,set_file=True)
+    else:
+        log_init('ARPES',user_name,_ARPES_log_dictionary,set_file=False) 
 
     #EA
     if EA.connected: 
@@ -468,7 +471,7 @@ def _ARPES_detector_triggers_sequence(**kwargs):
     ca_list = _ARPES_ca_list()
     last = len(ca_list)
     for i,ca in enumerate(ca_list):
-        ca_pv = _Keithley_pv(ca[0], ca[1])+':read.PROC PP NMS'
+        ca_pv = _Keithley_pv(ca[0], ca[1])+'read.PROC PP NMS'
         caput(detector_triggers_pv+".LNK" +str(i+1),ca_pv)
         caput(detector_triggers_pv+".WAIT"+str(i+1),"After"+str(last))
 
diff --git a/iexcode/instruments/IEX_BL_config.py b/iexcode/instruments/IEX_BL_config.py
index 7a6b8b9..24012e9 100644
--- a/iexcode/instruments/IEX_BL_config.py
+++ b/iexcode/instruments/IEX_BL_config.py
@@ -166,6 +166,14 @@ class Beamline_Config:
                 #overwrite folder for staff mode
                 self.folder = 'b' 
                 self.prefix = endstation_name+"_"
+                if endstation_name == 'ARPES':
+                    self.branch = 'c'
+                elif endstation_name == 'Kappa':
+                    self.branch = 'd'
+                elif endstation_name == 'Octupole':
+                    self.branch = 'd'
+                else:
+                    print('folder and prefix not set')
         else:
             message = 'Not a valid BL_mode choice\n'
             message += 'BL_modes: '+BL_mode_list
diff --git a/iexcode/instruments/IEX_VPU.py b/iexcode/instruments/IEX_VPU.py
index 142091a..408ce16 100644
--- a/iexcode/instruments/IEX_VPU.py
+++ b/iexcode/instruments/IEX_VPU.py
@@ -246,6 +246,8 @@ def ID_start(ID_mode='RCP',QP_ratio=None, verbose=True):
     """
     #turns on if ID is off
     if ID_power_status =='Off':
+        pv_sp = ID_pvs()['energy_sp']
+        caput(pv_sp,3.8)
         ID_on()
     #set QP 
     if ID_ready():
@@ -271,6 +273,10 @@ def ID_switch_mode(ID_mode):
     """
     ID_wait_for_permission(verbose=False)
     shutter_check(verbose=False)
+    
+    if ID_power_status() == 'Off':
+        ID_start(ID_mode)
+    
     ID_state = ID_state_get()
 
     if ID_state_mode(ID_mode) != ID_state:
@@ -282,7 +288,7 @@ def ID_switch_mode(ID_mode):
         ID_on(verbose=True)
         ID_mode_set(ID_mode) 
         ID_ready()
-    
+
     if ID_mode_get() != ID_mode:
             print_warning_message("ID mode switch had an error, please try again")
     else:
diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py
index b2bf306..9ab0204 100644
--- a/iexcode/instruments/electron_analyzer.py
+++ b/iexcode/instruments/electron_analyzer.py
@@ -319,7 +319,7 @@ def _BE2KE_setupCalc(BE,DESC,CalcOutNum,OutputPV):
         caput(pvCalcOut+"Enable","D")
     else:
         caput(pvCalcOut+"Enable","E")
-    sleep(.1)
+    time.sleep(.1)
     caput(pvCalcOut+".DESC", DESC)
     caput(pvCalcOut+".A",BE)
     caput(pvCalcOut+".INPB","29idmono:ENERGY_MON PP NMS")
diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py
index 4b16879..f889c88 100644
--- a/iexcode/instruments/scanRecord.py
+++ b/iexcode/instruments/scanRecord.py
@@ -454,23 +454,23 @@ class ScanRecord:
         kwargs.setdefault('scan_dim',1)
 
         #positioners
-        self.positioners_clear(**kwargs)
-        self.positioner_settling_time_set(**kwargs)
-        self.positioner_after_scan_set(**kwargs)
-        self.positioner_absolute_mode_set(**kwargs)
+        self.positioners_clear(**kwargs);sleep(.1)
+        self.positioner_settling_time_set(**kwargs);sleep(.1)
+        self.positioner_after_scan_set(**kwargs);sleep(.1)
+        self.positioner_absolute_mode_set(**kwargs);sleep(.1)
            
         #detectors
-        self.detectors_clear(**kwargs)
-        self.detectors_set(**kwargs)
+        self.detectors_clear(**kwargs);sleep(.1)
+        self.detectors_set(**kwargs);sleep(.1)
         #detector settling time
-        self.detector_settling_time_set(**kwargs)
+        self.detector_settling_time_set(**kwargs);sleep(.1)
 
         #detector triggers
-        self.triggers_clear(**kwargs)
-        self.triggers_set(**kwargs)
+        self.triggers_clear(**kwargs);sleep(.1)
+        self.triggers_set(**kwargs);sleep(.1)
 
-        self.before_scan_set(**kwargs)
-        self.after_scan_set(**kwargs)
+        self.before_scan_set(**kwargs);sleep(.1)
+        self.after_scan_set(**kwargs);sleep(.1)
 
     def reset_all(self):
         """
@@ -661,7 +661,7 @@ class ScanRecord:
                 default => {} if scan_dim > 1 (i.e. does nothing)
         """
         kwargs.setdefault('scan_dim',1)
-        kwargs.setdefault('detector_dictionary',{})
+        kwargs.setdefault('detector_dictionary',self.detector_dictionary)
         if kwargs['scan_dim'] == 1:
             kwargs.setdefault('detector_dictionary',self.detector_dictionary)
 
@@ -984,12 +984,13 @@ class ScanRecord:
         except:
             print_warning_message('no shutter check')
 
-        try:
-            self.snake_set(kwargs['snake'])
-        except:
-            error = 'snake scanning not configured for this BL_config'
-            if verbose:
-                print(error)
+        if kwargs['snake']:
+            try:
+                self.snake_set(kwargs['snake'])
+            except:
+                error = 'snake scanning not configured for this BL_config'
+                if verbose:
+                    print(error)
 
         if self.check(scan_dim):
             filename = self.prefix()
diff --git a/iexcode/instruments/shutters.py b/iexcode/instruments/shutters.py
index 7af1dd9..0ff07df 100644
--- a/iexcode/instruments/shutters.py
+++ b/iexcode/instruments/shutters.py
@@ -84,8 +84,9 @@ def branch_shutter_status(branch=None,verbose=False):
     """
     if branch == None:
         branch = iex.BL.branch
-    pvA = "PA:29ID:S"+branch.upper()+"S_BLOCKING_BEAM.VAL"
-    pvB = "PB:29ID:S"+branch.upper()+"S_BLOCKING_BEAM.VAL"
+    branch = branch.upper()
+    pvA = "PA:29ID:S"+branch+"S_BLOCKING_BEAM.VAL"
+    pvB = "PB:29ID:S"+branch+"S_BLOCKING_BEAM.VAL"
     #"ON" = 1 => shutter blocking
     status=caget(pvA)+caget(pvB)
     if status == 0:
diff --git a/iexcode/macros/quick_plot.py b/iexcode/macros/quick_plot.py
index f48fff1..d1de5af 100755
--- a/iexcode/macros/quick_plot.py
+++ b/iexcode/macros/quick_plot.py
@@ -134,7 +134,7 @@ def mda_unpack(ScanNum,filepath=None,prefix=None):
     except:
         print('Please specify filepath and prefix, BL is not defined')
 
-    mdaFile=filepath + prefix+'{:04}.mda'.format(ScanNum)
+    mdaFile=join(filepath,prefix+'{:04}.mda'.format(ScanNum))
     data_file = readMDA(mdaFile)
     try:
         D={}
diff --git a/iexcode/macros/start_of_the_week.py b/iexcode/macros/start_of_the_week.py
index d16f4a2..ec69078 100644
--- a/iexcode/macros/start_of_the_week.py
+++ b/iexcode/macros/start_of_the_week.py
@@ -92,10 +92,8 @@ def interactive_fit_mda(val_name,scannum,det,FWHM_or_PolyOrder,fct,**kwargs):
     """
     **kwargs
         xrange
-        val_name, name for printing
     """
     kwargs.setdefault('xrange',None)
-    kwargs.setdefault('val_name','')
     fit_mda(scannum,det,FWHM_or_PolyOrder,fct,**kwargs)
 
     foo=input('\nare you happy with those values (y or n)? >')
@@ -184,7 +182,7 @@ def StartOfTheWeek(grt,branch,wait=False,**kwargs):
     if kwargs['repeat']:
         #check to see if init is defined
         if BLconfig_branch() != branch:
-            BL_init('staff',reset=True,set_folders=True,xrays=True)   
+            BL_init('staff',reset=True,set_folders=False,xrays=True)   
     else:
         BL_init('staff',reset=True,set_folders=True,xrays=True)
         switch_branch(branch)
-- 
GitLab