From dc4e080f49de33c94e5144c838dd3083aff16a9c Mon Sep 17 00:00:00 2001
From: 29iduser <you@example.com>
Date: Mon, 17 Oct 2022 16:53:06 -0500
Subject: [PATCH] debug

---
 iexcode/instruments/ARPES.py             |  57 +++++++++---
 iexcode/instruments/IEX_BL_config.py     |   7 +-
 iexcode/instruments/Kappa.py             |   2 +-
 iexcode/instruments/Logfile.py           |   5 +-
 iexcode/instruments/Octupole.py          |  67 +++++++++-----
 iexcode/instruments/electron_analyzer.py |   7 +-
 iexcode/instruments/files_and_folders.py | 106 +++++++++++++----------
 iexcode/instruments/scanRecord.py        |  54 +++++++-----
 8 files changed, 195 insertions(+), 110 deletions(-)

diff --git a/iexcode/instruments/ARPES.py b/iexcode/instruments/ARPES.py
index 368b7f7..b62398a 100644
--- a/iexcode/instruments/ARPES.py
+++ b/iexcode/instruments/ARPES.py
@@ -10,8 +10,8 @@ from iexcode.instruments.IEX_BL_config import *
 from iexcode.instruments.IEX_cameras import _enable_endstation_cameras
 from iexcode.instruments.scanRecord import *
 
-from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv
-from iexcode.instruments.Logfile import Logfile, log_init, log_name_set
+from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv_user
+from iexcode.instruments.Logfile import log_init, log_name_set
 from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all, xrays_log_dictionary
 
@@ -55,8 +55,11 @@ def ARPES_init(*userName,**kwargs):
     kwargs.setdefault('mode','user')
     kwargs.setdefault('set_folders',False)
     kwargs.setdefault('reset',False)
+    kwargs.setdefault('debug',False)
 
-
+    if kwargs['debug']:
+        print(userName)
+    
     if len(userName) == 0:
         saveData_get_all(kwargs['scan_ioc'])
         user_name = mda_user_name()
@@ -72,8 +75,11 @@ def ARPES_init(*userName,**kwargs):
     global ARPES_Motors
     ARPES_Motors = Motors('ARPES',_ARPES_motor_dictionary(),physical_motors,pseudo_motors)
 
+    if kwargs['debug']:
+        print("Beamline_Config")
     #endstation
-    iex.BL = Beamline_Config('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['mode'],ARPES_Motors)
+    BL_kwargs={'debug':kwargs['debug']}
+    iex.BL = Beamline_Config('ARPES',kwargs['scan_ioc'],kwargs['xrays'],kwargs['mode'],ARPES_Motors,**BL_kwargs)
     BLconfig_safe_state_set(ARPES_safe_state)
     BLconfig_get_set(ARPES_get_all)
 
@@ -135,6 +141,14 @@ def _ARPES_ca_list():
     ca_list=[["c",1],["b",15],["b",4],["b",13]]
     return ca_list
 
+def _ARPES_ca_live_sequence(**kwargs):
+    """
+    """
+    kwargs.setdefault('seq_num',7)
+
+    ca_live_sequence_proc = _ca_live_sequence(mda_ioc(),kwargs['seq_num'],_ARPES_ca_list())
+    return ca_live_sequence_proc
+
 def _ARPES_detector_dictionary():
     """
     returns a dictionary of the default detectors for the scan record
@@ -154,6 +168,7 @@ def _ARPES_detector_dictionary():
     if EA.connected: 
        det_dict.update({17:EA._statsPlugin+"Total_RBV"})
 
+
     #add detectors related to beamline
     if BLconfig_xrays(): 
         det_dict.update(xrays_detector_dictionary())
@@ -232,7 +247,7 @@ def folders_ARPES(user_name,**kwargs):
 
         #Set up Scienta folders:
         if EA.connected: 
-            userPath = path_dserv(BLconfig_folder(),run,user_name)
+            userPath = path_dserv_user(BLconfig_folder(),run,user_name,mda_ioc())
             try:
                 folders_EA(userPath,filePrefix="EA")
             except:
@@ -390,13 +405,7 @@ def _ARPES_scan_before_sequence(**kwargs):
 
     return before_scan_proc
 
-def _ARPES_ca_live_sequence(**kwargs):
-    """
-    """
-    kwargs.setdefault('seq_num',7)
 
-    ca_live_sequence_proc = _ca_live_sequence(mda_ioc(),kwargs['seq_num'],_ARPES_ca_list())
-    return ca_live_sequence_proc
 
 def _ARPES_scan_after_pvs(clear=False,**kwargs):
     """
@@ -741,6 +750,32 @@ def ARPES_safe_state(**kwargs):
     if kwargs['valve_close']:
        branch_valve_close()
 
+##############################################################################################################
+##############################              ARPES_scanPause       ##############################
+##############################################################################################################
+def ARPES_pause_scan(xrays,**kwargs):
+    """
+    user calc to pause the scan in the shutter is closed
+    """
+    kwargs.setdefault('calc_num',1)
+    calc_num=kwargs['seq_num']
+
+    scan_ioc = mda_ioc()
+    
+    pv=scan_ioc+"userCalc"+str(calc_num)
+    caput(pv+".DESC","RPES_pause_scan")
+    caput(pv+".INAN",scan_ioc+"scan1.FAZE")
+    caput(pv+".INBN",".EPS:29:ID:PS2:POSITION")
+    caput(pv+".INCN","ID29:AccessSecurity.VAL")
+
+    caput(pv+".CALC$", 'A!=0 && (B!=2 || C!=0)')
+    
+    if BLconfig_xrays():
+        caput(pv+".OOPT", "Every Time")
+    else:
+        caput(pv+".OOPT", "Never")
+
+    caput(pv+".OUTN",scan_ioc+'scanPause.VAL')
 
 
 ##############################################################################################################
diff --git a/iexcode/instruments/IEX_BL_config.py b/iexcode/instruments/IEX_BL_config.py
index 24012e9..8f18c7f 100644
--- a/iexcode/instruments/IEX_BL_config.py
+++ b/iexcode/instruments/IEX_BL_config.py
@@ -119,7 +119,8 @@ class Beamline_Config:
             Note intialization does not set default detectors and logging for .mda
             
         """
-       
+        kwargs.setdefault('debug',False)
+
         self.endstation_name = None
         self.branch = None
         self.folder = None
@@ -185,3 +186,7 @@ class Beamline_Config:
         if 'endstation_get' in kwargs:
             self.endstation_get = kwargs['endstation_get']
 
+        if kwargs['debug']:
+            print('BLconfig_init')
+            print(vars(self))
+
diff --git a/iexcode/instruments/Kappa.py b/iexcode/instruments/Kappa.py
index a09950d..330809a 100644
--- a/iexcode/instruments/Kappa.py
+++ b/iexcode/instruments/Kappa.py
@@ -10,7 +10,7 @@ from iexcode.instruments.IEX_BL_config import *
 from iexcode.instruments.IEX_cameras import _enable_endstation_cameras
 from iexcode.instruments.scanRecord import *
 
-from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv
+from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv_user
 from iexcode.instruments.Logfile import log_init,log_name_set
 from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all
diff --git a/iexcode/instruments/Logfile.py b/iexcode/instruments/Logfile.py
index 38dc283..a4a0d37 100644
--- a/iexcode/instruments/Logfile.py
+++ b/iexcode/instruments/Logfile.py
@@ -46,7 +46,7 @@ def log_init(endstation_name,user_name,log_dictionary,set_file=False):
     """
     initialize the logfile
     """
-    iex.BL.mda.log=Logfile(endstation_name,user_name,log_dictionary,set_file=False)
+    iex.BL.mda.log=Logfile(endstation_name,user_name,log_dictionary,set_file=set_file)
 
 def log_header(header_list,**kwargs):
     """
@@ -70,6 +70,9 @@ class Logfile:
         self.filepath = self._fpath()
         self.log_dictionary = log_dictionary
 
+        if set_file:
+            self.name_set()
+
         print('\n log_filename = '+caget(self._name_pv(),as_string=True))
         print('\tuse log_name_set to change')
 
diff --git a/iexcode/instruments/Octupole.py b/iexcode/instruments/Octupole.py
index 54912d1..539ab95 100644
--- a/iexcode/instruments/Octupole.py
+++ b/iexcode/instruments/Octupole.py
@@ -9,8 +9,8 @@ from iexcode.instruments.IEX_BL_config import *
 from iexcode.instruments.IEX_cameras import _enable_endstation_cameras
 from iexcode.instruments.scanRecord import *
 
-from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv
-from iexcode.instruments.Logfile import Logfile, log_init,log_name_set
+from iexcode.instruments.files_and_folders import check_run,make_user_folders,folder_mda,path_dserv_user
+from iexcode.instruments.Logfile import log_init,log_name_set
 from iexcode.instruments.staff import staff_detector_dictionary
 from iexcode.instruments.xrays import xrays_detector_dictionary, _xrays_reset, xrays_get_all
 
@@ -57,6 +57,19 @@ def Octupole_init(*userName,**kwargs):
     kwargs.setdefault('mode','user')
     kwargs.setdefault('set_folders',False)
     kwargs.setdefault('reset',False)
+    kwargs.setdefault('debug',False)
+
+    if kwargs['debug']:
+        print(userName)
+    
+    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','tth']
@@ -64,21 +77,18 @@ def Octupole_init(*userName,**kwargs):
     global Octupole_Motors
     Octupole_Motors = Motors('Octupole',_Octupole_motor_dictionary(),physical_motors,pseudo_motors)
 
+    if kwargs['debug']:
+        print("Beamline_Config")
     #endstation
-    iex.BL = Beamline_Config('Octupole',kwargs['scan_ioc'],kwargs['xrays'],kwargs['mode'],Octupole_Motors)
+    BL_kwargs={'debug':kwargs['debug']}
+    iex.BL = Beamline_Config('Octupole',kwargs['scan_ioc'],kwargs['xrays'],kwargs['mode'],Octupole_Motors,**BL_kwargs)
     BLconfig_safe_state_set(Octupole_safe_state)
     BLconfig_get_set(Octupole_get_all)
 
     #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_Octupole(user_name,**kwargs)
 
     else:
@@ -86,9 +96,10 @@ def Octupole_init(*userName,**kwargs):
         print('user_name:',user_name)
 
     #logging
-    log_init('Octupole',user_name,_Octupole_log_dictionary)
     if kwargs['set_folders']:
-        log_name_set()
+        log_init('Octupole',user_name,_Octupole_log_dictionary,set_file=True)
+    else:
+        log_init('Octupole',user_name,_Octupole_log_dictionary,set_file=False)
 
 
     #global detectors
@@ -112,6 +123,8 @@ def Octupole_init(*userName,**kwargs):
     _enable_endstation_cameras()
 
     print ('\nOctupole initalized')
+    print('\tpath = "'+mda_filepath()+'"')
+    print('\tprefix = "'+mda_prefix()+'"')
     #return any detectors or other parameters that you want access to from jupyter
     return tey,tfy,pd,mesh,diag,kbh,kbv
 
@@ -133,6 +146,13 @@ def _Octupole_ca_list():
     ca_list=[]
     return ca_list
 
+def _Octupole_ca_live_sequence(**kwargs):
+    """
+    """
+    kwargs.setdefault('seq_num',7)
+
+    ca_live_sequence_proc = _ca_live_sequence(mda_ioc(),kwargs['seq_num'],_Octupole_ca_list())
+    return ca_live_sequence_proc
 
 def _Octupole_detector_dictionary(**kwargs):
     """
@@ -189,12 +209,12 @@ def _Octupole_detector_dictionary(**kwargs):
         65:"29ide:userTran3.M",
         66:"29ide:userTran3.N",
     }
-    #hkl are listed just a place holders, they are filled in by thier scanning functions
     det_dict.update(sample_temp)
     det_dict.update(m3r)
     det_dict.update(scalers)
     det_dict.update(xmcd_raw)
     det_dict.update(xmcd_norm)
+
     if kwargs['add_vortex']:
         det_dict.update(vortex)
 
@@ -273,9 +293,7 @@ def folders_Octupole(user_name,**kwargs):
         # Set up MDA folder:
         folder_mda(run,BLconfig_folder(),user_name,mda_prefix(),mda_ioc())
 
-    #resetting
-    if 'reset':
-        Octupole_reset(**kwargs)
+
 
 def Octupole_default_scan_settings(**kwargs):
     """
@@ -366,6 +384,10 @@ def _Octupole_log_dictionary():
         "mesh_current":(mesh.current_Amp,".2E"),
         "m3r_centroid":(m3r_centroid()[0],".0f") , 
     }
+
+    if BLconfig_xrays() == True:
+        d.update(xrays_log_dictionary())
+
     return d
 
 ##############################################################################################################
@@ -392,11 +414,12 @@ def _Octupole_scan_before_sequence(**kwargs):
     userStringSeq_clear(scan_ioc,seq_num)
     caput(before_scan_pv+".DESC","Before Scan")
 
-    #This is where you'd do something if need (CA -> 'Passive', etc)
-    pv=''
-    cmd=''
-    caput(before_scan_pv+".LNK" +str(1),pv)
-    caput(before_scan_pv+".STR" +str(1),cmd)
+    #sequence put CAs in passive
+    ca_list = _Octupole_ca_list()
+    for (i,ca) in enumerate(ca_list):
+        ca_pv = _Keithley_pv(ca[0], ca[1])+'read.SCAN PP NMS'
+        caput(before_scan_pv+".LNK" +str(i+1),ca_pv)
+        caput(before_scan_pv+".STR" +str(i+1),"Passive")
 
     return before_scan_proc
 
diff --git a/iexcode/instruments/electron_analyzer.py b/iexcode/instruments/electron_analyzer.py
index 9ab0204..1573d45 100644
--- a/iexcode/instruments/electron_analyzer.py
+++ b/iexcode/instruments/electron_analyzer.py
@@ -94,7 +94,7 @@ def EA_ioc_init(**kwargs):
     print("C-Shutter is closed for initialization ")
 
 
-def folders_EA(userPath,filePrefix="EA",**kwargs):
+def folders_EA(user_path,filePrefix="EA",**kwargs):
     """
     For Staff: folder='b', userName='Staff'
     For ARPES: folder ='c'
@@ -114,7 +114,7 @@ def folders_EA(userPath,filePrefix="EA",**kwargs):
     except:
         df="h5"
 
-    fpath=join(userPath,df)
+    fpath=join(user_path,df)
     print("\nFolder: " + fpath)
 
     if exists(fpath):
@@ -128,7 +128,6 @@ def folders_EA(userPath,filePrefix="EA",**kwargs):
     else:
         if kwargs['debug']==True:
             print("making")
-        mkdir(fpath)
         fileNumber=1
     try:
         if kwargs['set_folders']:
@@ -145,7 +144,7 @@ def folders_EA(userPath,filePrefix="EA",**kwargs):
         print("Next "+filePrefix+" file: "+str(fileNumber))  
     except:
         df='h5'
-        fpath=join(userPath,df)
+        fpath=join(user_path,df)
 
 def EA_filepath():
     """
diff --git a/iexcode/instruments/files_and_folders.py b/iexcode/instruments/files_and_folders.py
index 8bb38a7..c6f49ab 100644
--- a/iexcode/instruments/files_and_folders.py
+++ b/iexcode/instruments/files_and_folders.py
@@ -1,10 +1,10 @@
-from os import listdir,mkdir,chmod
-from os.path import join, isfile, exists
+import os
 import datetime
 from time import sleep
 import re
 
 from epics import caget, caput
+from iexcode.instruments.scanRecord import saveData_get_all
 
 
 ##############################################################################################################
@@ -14,16 +14,29 @@ from epics import caget, caput
 
 path_User_Folders='/home/beams/29IDUSER/Documents/User_Folders/'
 
-def path_dserv(folder,run,user_name):
+'For new endstation modify here:'
+VME_iocs = ['29idb:','29idc:','29idd:','29ide:']
+
+
+
+def path_dserv_user(folder,run,user_name,ioc=None):
     """
     Returns the path to a user folder
-            dataFolder='/net/s29data/export/data_29id'+folder+'/'+run+'/'+user_name
+            dataFolder='/net/s29data/export/data_29id'+folder+'/'+run+'/'+user_name 
 
     previously: _userDataFolder
     """
-                    
-    dataFolder='/net/s29data/export/data_29id'+folder+'/'+run+'/'+user_name
-    return dataFolder
+    if user_name.lower() == 'staff':
+        user_name = ''
+
+    if ioc in VME_iocs: 
+        user_data_folder = "//s29data/export/data_29id"+folder+"/"+run
+    else:
+        user_data_folder = "/net/s29data/export/data_29id"+folder+"/"+run 
+
+    if folder != 'b':               
+        user_data_folder = os.path.join(user_data_folder,user_name)
+    return user_data_folder
 
 
 ##############################################################################################################
@@ -90,18 +103,18 @@ def make_ftp(folder,run,user_name):
     print("\n\n")
     print(MyPath_kip)
     print(MyPath_kip+"ascii")
-    if not (exists(MyPath_kip_run)):
-        mkdir(MyPath_kip_run)
-        chmod(MyPath_kip_run, 0o775)
-    if not (exists(MyPath_kip)):
-        mkdir(MyPath_kip)
-        chmod(MyPath_kip, 0o775)
-    if not (exists(MyPath_kip+"ascii")):
-        mkdir(MyPath_kip+'ascii')
-        chmod(MyPath_kip+'ascii', 0o775)
-    if not (exists(MyPath_kip+"notebook")):
-        mkdir(MyPath_kip+"notebook")
-        chmod(MyPath_kip+"notebook", 0o775)
+    if not (os.path.exists(MyPath_kip_run)):
+        os.mkdir(MyPath_kip_run)
+        os.chmod(MyPath_kip_run, 0o775)
+    if not (os.path.exists(MyPath_kip)):
+        os.mkdir(MyPath_kip)
+        os.chmod(MyPath_kip, 0o775)
+    if not (os.path.exists(MyPath_kip+"ascii")):
+        os.mkdir(MyPath_kip+'ascii')
+        os.chmod(MyPath_kip+'ascii', 0o775)
+    if not (os.path.exists(MyPath_kip+"notebook")):
+        os.mkdir(MyPath_kip+"notebook")
+        os.chmod(MyPath_kip+"notebook", 0o775)
     
 def make_user_folders(run,folder,user_name,endstation_name,ftp=False):
     """
@@ -120,13 +133,13 @@ def make_user_folders(run,folder,user_name,endstation_name,ftp=False):
             print("\tFolder_"+str(endstation_name)+"('"+str(run)+"','"+str(user_name)+"',ftp=True)") 
 
         #create user folder for saving log files
-    path_user=join(path_User_Folders,user_name)
+    path_user=os.path.join(path_User_Folders,user_name)
     user_name = "/"+user_name
-    if not (exists(path_user)):
-        mkdir(path_user)
+    if not (os.path.exists(path_user)):
+        os.mkdir(path_user)
 
 
-def folder_mda(run,folder,user_name,file_prefix,ioc,verbose=True):
+def folder_mda(run,folder,user_name,file_prefix,ioc,**kwargs):
     """
     sets the folder, prefix and file number for the scan record
     ioc is the full ioc, e.g. '29idb', or '29idARPES'
@@ -137,40 +150,40 @@ def folder_mda(run,folder,user_name,file_prefix,ioc,verbose=True):
 
     mda_path="/net/s29data/export/data_29id"+folder+"/"+run+"/"+user_name+"mda"
     """
+    kwargs.setdefault('verbose',True)
+    kwargs.setdefault('debug',False)
     
-    if user_name == 'Staff':
-        user_name=""
-    else:
-        user_name=user_name+'/'
+    user_data_folder = path_dserv_user(folder,run,user_name,ioc)
+    mda_path=os.path.join(user_data_folder,"mda")
+    
+    if kwargs['debug']:
+        print("\nMDA folder: " + mda_path)
 
-    mda_path="/net/s29data/export/data_29id"+folder+"/"+run+"/"+user_name+"mda"
-    print("\nMDA folder: " + mda_path)
-    if not (exists(mda_path)):
-        mkdir(mda_path)
+    if not (os.path.exists(mda_path)):
+        #os.mkdir(mda_path) scanRecord does this
         FileNumber=1
     else:
         FileNumber=get_next_fileNumber(mda_path,file_prefix)
 
-    if ioc in ['29idb','29idc','29idd']: #VME iocs
-        caput(ioc+"saveData_fileSystem","//s29data/export/data_29id"+folder+"/"+run)
-        sleep(0.25)
-        caput(ioc+"saveData_subDir",user_name+"mda")
+    if folder == 'b':
+        parent_dir = user_data_folder
+        subdir = "/mda"
+    else:
+        parent_dir = os.path.dirname(user_data_folder)
+        subdir = "/"+user_name+"/mda"
 
-    else: #soft iocs
-        caput(ioc+"saveData_fileSystem","/net/s29data/export/data_29id"+folder+"/"+run)
-        sleep(0.25) #needed so that it has time to write        
-        caput(ioc+"saveData_subDir","/"+user_name+"mda")
+    caput(ioc+"saveData_fileSystem",parent_dir)
+    sleep(0.25) #needed so that it has time to write        
+    caput(ioc+"saveData_subDir",subdir)
 
     caput(ioc+"saveData_baseName",file_prefix)
     caput(ioc+"saveData_scanNumber",FileNumber)
 
-    print("\nioc set to:", ioc)
     sleep(5)
 
-    if verbose:
-        SaveStatus=caget(ioc+'saveData_status',as_string=True)
-        SaveMessage=caget(ioc+'saveData_message',as_string=True)
-        print("\nSave Status "+ioc+": "+SaveStatus+" - "+SaveMessage)
+    if kwargs['verbose']:
+        saveData = saveData_get_all(ioc)
+        print("\nSave Status "+ioc+" "+saveData['status']+" - "+saveData['message'])
        
 
 def folder_SPEC(run,folder,user_name):
@@ -184,8 +197,7 @@ def folder_SPEC(run,folder,user_name):
     print("    cd "+MyPath)
     print("    newfile FileName")
     print("To start SPEC fresh: ./bin/kappa29ID -f")
-    #if not (exists(MyPath)):
-    #    mkdir(MyPath)
+
 
 
 
@@ -207,7 +219,7 @@ def get_next_fileNumber(data_dir, file_prefix,**kwargs):
     kwargs.setdefault("debug",False)
 
     
-    onlyfiles = [f for f in listdir(data_dir) if isfile(join(data_dir, f)) and f[:len(file_prefix)] == file_prefix]
+    onlyfiles = [f for f in os.listdir(data_dir) if os.path.isfile(os.path.join(data_dir, f)) and f[:len(file_prefix)] == file_prefix]
     sortedfiles = sorted(onlyfiles, key=_filename_key)
     pattern = re.compile('(.*)_(.*)\.(.*)')
     try:
diff --git a/iexcode/instruments/scanRecord.py b/iexcode/instruments/scanRecord.py
index f889c88..1919030 100644
--- a/iexcode/instruments/scanRecord.py
+++ b/iexcode/instruments/scanRecord.py
@@ -21,7 +21,7 @@ def scan_fillin(VAL,RBV,start,stop,steps_points,**kwargs):
         print("IEX_endstations has not been initialized")
 
 def scan_fillin_2D(inner_loop_list,outer_loop_list,**kwargs):
-    iex.mda.scan_fillin_2D(inner_loop_list,outer_loop_list,**kwargs)
+    iex.BL.mda.fillin_2D(inner_loop_list,outer_loop_list,**kwargs)
 
 def scan_fillin_table(VAL,RBV,my_table,**kwargs):
     """
@@ -81,12 +81,10 @@ def scan_time(duration_min,step_min=1,**kwargs):
 
 def scan_go(**kwargs):
     """
-    Starts a scan 
-    by default: scanDIM=1  
-    Logging is automatic: use **kwargs or the optional logging arguments see scanlog() for details
-    kwargs:
-        X-ray = True (default), does shutter checks
-             = False no shutter checks
+    starts a scan
+    **kwargs:
+        scan_dim = 1 (default)
+
     """
     try:
         iex.BL.mda.go(verbose=True,**kwargs)
@@ -151,7 +149,7 @@ def mda_default_detector_dictionary(detector_dictionary=None,overwrite=False):
     returns iex.BL.detector_dictionary if None, otherwise sets to new value 
     """
     if detector_dictionary == None:
-        detector_dictionary = iex.BL.detector_dictionary
+        detector_dictionary = iex.BL.mda.detector_dictionary
     else:
         if overwrite == False:
             iex.BL.mda.detector_dictionary = detector_dictionary
@@ -213,6 +211,8 @@ def saveData_get_all(ioc_pv):
             'subDir':caget(ioc_pv+"saveData_subDir",as_string=True),
             'scanNumber':caget(ioc_pv+"saveData_scanNumber"),
             'baseName':caget(ioc_pv+"saveData_baseName",as_string=True),
+            'status':caget(ioc_pv+'saveData_status',as_string=True),
+            'message':caget(ioc_pv+'saveData_message',as_string=True),
         }
         #take care of subDir starting with '/'
         f1 = saveData_info['fileSystem']  
@@ -454,23 +454,25 @@ class ScanRecord:
         kwargs.setdefault('scan_dim',1)
 
         #positioners
-        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)
+        self.positioners_clear(**kwargs);time.sleep(.1)
+        self.positioner_settling_time_set(**kwargs)
+        self.positioner_after_scan_set(**kwargs)
+        self.positioner_absolute_mode_set(**kwargs)
            
         #detectors
-        self.detectors_clear(**kwargs);sleep(.1)
-        self.detectors_set(**kwargs);sleep(.1)
+        self.detectors_clear(**kwargs)
+        self.detectors_set(**kwargs)
         #detector settling time
-        self.detector_settling_time_set(**kwargs);sleep(.1)
+        self.detector_settling_time_set(**kwargs)
 
         #detector triggers
-        self.triggers_clear(**kwargs);sleep(.1)
-        self.triggers_set(**kwargs);sleep(.1)
+        self.triggers_clear(**kwargs)
+        self.triggers_set(**kwargs)
 
-        self.before_scan_set(**kwargs);sleep(.1)
-        self.after_scan_set(**kwargs);sleep(.1)
+        self.before_scan_set(**kwargs)
+        self.after_scan_set(**kwargs)
+        
+        time.sleep(1)
 
     def reset_all(self):
         """
@@ -1072,14 +1074,20 @@ class ScanRecord:
         kwargs.setdefault("outer_scan_dim",2)
 
         outer_scan_dim = kwargs['outer_scan_dim']
-        
+        if 'execute' in kwargs:
+            execute = kwargs['execute']
+            kwargs.pop('execute')
+
         #fillin inner loop
-        kwargs.update({'scan_dim':outer_scan_dim-1})
+        kwargs.update({'scan_dim':outer_scan_dim-1,'execute':False})
         self.fillin(inner_loop_list[0],inner_loop_list[1],inner_loop_list[2],inner_loop_list[3],inner_loop_list[4],**kwargs)
         #fillin outer loop
-        kwargs.update({'scan_dim':outer_scan_dim})
+        kwargs.update({'scan_dim':outer_scan_dim,'execute':False})
         self.fillin(outer_loop_list[0],outer_loop_list[1],outer_loop_list[2],outer_loop_list[3],outer_loop_list[4],**kwargs)
 
+        if execute:
+            kwargs.update('scan_dim'=kwargs['outer_scan_dim'])
+            self.go(**kwargs)
 
 
     def snake_pv(self,snake_dim,enable=True):
@@ -1103,7 +1111,7 @@ class ScanRecord:
         step_pv  = self.ioc+"scan"+str(snake_dim)+".P1SI"
         ### Setting up the user
         caput(snake_calc_pv+".DESC","Snake Calc")
-        caput(snake_calc_pv+".INPA",step_pv+" NPP NMS")
+        caput(snake_calc_pv+".INPA",step_pv+" PP NMS")
         caput(snake_calc_pv+".CALC$","A*-1*B")
         caput(snake_calc_pv+".OUT",step_pv+" PP NMS")
 
-- 
GitLab