From a77525ccbff09a0381f335d53aebe8c1262fa44b Mon Sep 17 00:00:00 2001
From: mwyman <mwyman@anl.gov>
Date: Fri, 16 Aug 2024 06:23:48 -0500
Subject: [PATCH] Moved env files; consolidating startup for CRL

---
 100idPyApp/Db/pyDevCRLsingle.db                  |  5 +++--
 100idPyApp/python/pyTransfocator_single.py       | 16 ++++++++++------
 .../ioc100idPy/100idPyFilter_startup_env         |  0
 iocBoot/ioc100idPy/softioc/100idPy.pl            |  2 +-
 .../ioc100idPyCRL/100idPyCRL_startup_env         |  0
 iocBoot/ioc100idPyCRL/cmds/pydeviceCRL.cmd       |  2 +-
 iocBoot/ioc100idPyCRL/softioc/100idPyCRL.pl      |  2 +-
 .../ioc100idPyFilter/100idPyFilter_startup_env   |  6 ++++++
 .../ioc100idPyFilter/softioc/100idPyFilter.pl    |  2 +-
 .../ioc100idPySBL/100idPySBL_startup_env         |  0
 iocBoot/ioc100idPySBL/softioc/100idPySBL.pl      |  2 +-
 11 files changed, 24 insertions(+), 13 deletions(-)
 rename 100idPyFilter_startup_env => iocBoot/ioc100idPy/100idPyFilter_startup_env (100%)
 rename 100idPyCRL_startup_env => iocBoot/ioc100idPyCRL/100idPyCRL_startup_env (100%)
 create mode 100644 iocBoot/ioc100idPyFilter/100idPyFilter_startup_env
 rename 100idPySBL_startup_env => iocBoot/ioc100idPySBL/100idPySBL_startup_env (100%)

diff --git a/100idPyApp/Db/pyDevCRLsingle.db b/100idPyApp/Db/pyDevCRLsingle.db
index 6a37ec3..2be2418 100644
--- a/100idPyApp/Db/pyDevCRLsingle.db
+++ b/100idPyApp/Db/pyDevCRLsingle.db
@@ -4,6 +4,7 @@ record(ao, "$(P)CRL$(N):energy"){
     field(OMSL, "closed_loop")
 	field(DTYP, "pydev")
 	field(OUT, "@$(OBJ).updateE('VAL')")
+	field(FLNK, "$(P)CRL$(N):recalc_table.PROC CA")
 }
 
 record(ai, "$(P)CRL$(N):energy_RBV"){
@@ -110,8 +111,8 @@ record(transform, "$(P)CRL$(N):lens_decode"){
 	field(CLCI, "(A >> 7) % 2")
 	field(CLCJ, "(A >> 8) % 2")
 	field(CLCK, "(A >> 9) % 2")
-	field(CLCL, "(A >> 10) % 2")
-	field(CLCM, "(A >> 11) % 2")
+#	field(CLCL, "(A >> 10) % 2")
+#	field(CLCM, "(A >> 11) % 2")
 }
 
 record(calcout, "$(P)CRL$(N):lens_encode"){
diff --git a/100idPyApp/python/pyTransfocator_single.py b/100idPyApp/python/pyTransfocator_single.py
index ecf0388..2faa46e 100644
--- a/100idPyApp/python/pyTransfocator_single.py
+++ b/100idPyApp/python/pyTransfocator_single.py
@@ -171,17 +171,17 @@ class singleTF():
         '''
         pass 
                 
-    def setupLookupTable(self, subs_file, n_lenses, energy = 8.0):
+    def setupLookupTable(self, subs_file, n_lenses):
         '''
-        lookup table created after IOC startup (after transfocator materials and 
-        thicknesses are set
+        lookup table created after IOC startup
+        energy and slit size are updated before this is called
         '''
         print(80*'#')
         print('Setting up lens control...')
         
         self.num_stacks = n_lenses
         
-        self.energy = energy
+#       self.energy = energy
         
         #read in substitutions file
         try:
@@ -270,6 +270,8 @@ class singleTF():
                                              self.crl, self.slit1_H, self.slit1_V,
                                              self.lens_thickerr, flag_HE = self.thickerr_flag)
         self.cull_lookup_table()
+        self.updateEnergyRBV()
+        self.updateSlitSizeRBV()
 
     def cull_lookup_table(self):
         '''
@@ -393,7 +395,7 @@ class singleTF():
         self.setSlitSize(self, size, slit)
         
         # Testing calling the lookup table reconstruction in EPICS instead of python
-        # self.construct_lookup_table()
+        #! self.construct_lookup_table()
 
     def setEnergy(self, energy):
         '''
@@ -411,7 +413,9 @@ class singleTF():
         # Energy variable sent from IOC as a string
         self.setEnergy(energy)
 
-        self.construct_lookup_table()
+        # Testing calling the lookup table reconstruction in EPICS instead of python
+        #! self.construct_lookup_table()
+
         # Do I need to find what the current config would produce as far as focal size and location?
         # self.focalSizeRBV = 
 
diff --git a/100idPyFilter_startup_env b/iocBoot/ioc100idPy/100idPyFilter_startup_env
similarity index 100%
rename from 100idPyFilter_startup_env
rename to iocBoot/ioc100idPy/100idPyFilter_startup_env
diff --git a/iocBoot/ioc100idPy/softioc/100idPy.pl b/iocBoot/ioc100idPy/softioc/100idPy.pl
index a300761..57ad657 100644
--- a/iocBoot/ioc100idPy/softioc/100idPy.pl
+++ b/iocBoot/ioc100idPy/softioc/100idPy.pl
@@ -86,7 +86,7 @@ BEGIN
 	##########################
 	
 	#If PyDevice is to be used, source script needs to be set here
-	$ENV{PYDEV_STARTUP}="/net/s100dserv/xorApps/epics/synApps_6_3/ioc/100idPy/100idPyFilter_startup_env";
+	$ENV{PYDEV_STARTUP}="$ENV{IOC_STARTUP_DIR}/100idPyFilter_startup_env";
 	$ENV{PYDEV_IOC_CMD}="source $ENV{PYDEV_STARTUP}; $ENV{IOC_CMD}";
 }
 
diff --git a/100idPyCRL_startup_env b/iocBoot/ioc100idPyCRL/100idPyCRL_startup_env
similarity index 100%
rename from 100idPyCRL_startup_env
rename to iocBoot/ioc100idPyCRL/100idPyCRL_startup_env
diff --git a/iocBoot/ioc100idPyCRL/cmds/pydeviceCRL.cmd b/iocBoot/ioc100idPyCRL/cmds/pydeviceCRL.cmd
index 5b7f837..93554f4 100644
--- a/iocBoot/ioc100idPyCRL/cmds/pydeviceCRL.cmd
+++ b/iocBoot/ioc100idPyCRL/cmds/pydeviceCRL.cmd
@@ -32,4 +32,4 @@ dbLoadRecords(""${TOP}/db/pyDevCRLsingle.db","P=$(PREFIX), N=1, OBJ=CRL1, KEV=$(
 doAfterIocInit() # PROC energy read and update CRL1 object
 doAfterIocInit() # PROC slit size read and update CRL1 object
 # TODO get STACKS from TOML file?
-doAfterIocInit("pydev('CRL1.setupLookupTable(stack_subFile, $(_STACKS), energy = $(_ENERGY))')") #TODO get energy from beamline...
+doAfterIocInit("pydev('CRL1.setupLookupTable(stack_subFile, $(_STACKS)')") #TODO get energy from beamline...
diff --git a/iocBoot/ioc100idPyCRL/softioc/100idPyCRL.pl b/iocBoot/ioc100idPyCRL/softioc/100idPyCRL.pl
index e4f95aa..0d50471 100644
--- a/iocBoot/ioc100idPyCRL/softioc/100idPyCRL.pl
+++ b/iocBoot/ioc100idPyCRL/softioc/100idPyCRL.pl
@@ -87,7 +87,7 @@ BEGIN
 	##########################
 	
 	#If PyDevice is to be used, source script needs to be set here
-	$ENV{PYDEV_STARTUP}="/net/s100dserv/xorApps/epics/synApps_6_3/ioc/100idPy/100idPyCRL_startup_env";
+	$ENV{PYDEV_STARTUP}="$ENV{IOC_STARTUP_DIR}/100idPyCRL_startup_env";
 	$ENV{PYDEV_IOC_CMD}="source $ENV{PYDEV_STARTUP}; $ENV{IOC_CMD}";
 }
 
diff --git a/iocBoot/ioc100idPyFilter/100idPyFilter_startup_env b/iocBoot/ioc100idPyFilter/100idPyFilter_startup_env
new file mode 100644
index 0000000..8971318
--- /dev/null
+++ b/iocBoot/ioc100idPyFilter/100idPyFilter_startup_env
@@ -0,0 +1,6 @@
+# Activate python environment containing modules used by IOC
+eval "$(conda shell.bash hook)"
+conda activate /net/s100dserv/xorApps/epics/synApps_6_3/support/PyDevice-env/filters
+
+# Put python library in path
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/net/s100dserv/xorApps/epics/synApps_6_3/support/PyDevice-env/filters/lib/
diff --git a/iocBoot/ioc100idPyFilter/softioc/100idPyFilter.pl b/iocBoot/ioc100idPyFilter/softioc/100idPyFilter.pl
index b6da908..625a12f 100755
--- a/iocBoot/ioc100idPyFilter/softioc/100idPyFilter.pl
+++ b/iocBoot/ioc100idPyFilter/softioc/100idPyFilter.pl
@@ -84,7 +84,7 @@ BEGIN
 	##########################
 	
 	#If PyDevice is to be used, source script needs to be set here
-	$ENV{PYDEV_STARTUP}="/net/s100dserv/xorApps/epics/synApps_6_3/ioc/100idPy/100idPyFilter_startup_env";
+	$ENV{PYDEV_STARTUP}="$ENV{IOC_STARTUP_DIR}/100idPyFilter_startup_env";
 	$ENV{PYDEV_IOC_CMD}="source $ENV{PYDEV_STARTUP}; $ENV{IOC_CMD}";
 }
 
diff --git a/100idPySBL_startup_env b/iocBoot/ioc100idPySBL/100idPySBL_startup_env
similarity index 100%
rename from 100idPySBL_startup_env
rename to iocBoot/ioc100idPySBL/100idPySBL_startup_env
diff --git a/iocBoot/ioc100idPySBL/softioc/100idPySBL.pl b/iocBoot/ioc100idPySBL/softioc/100idPySBL.pl
index 7a1e4a3..93090de 100755
--- a/iocBoot/ioc100idPySBL/softioc/100idPySBL.pl
+++ b/iocBoot/ioc100idPySBL/softioc/100idPySBL.pl
@@ -86,7 +86,7 @@ BEGIN
 	##########################
 	
 	#If PyDevice is to be used, source script needs to be set here
-	$ENV{PYDEV_STARTUP}="/net/s100dserv/xorApps/epics/synApps_6_3/ioc/100idPy/100idPySBL_startup_env";
+	$ENV{PYDEV_STARTUP}="$ENV{IOC_STARTUP_DIR}/100idPySBL_startup_env";
 	$ENV{PYDEV_IOC_CMD}="source $ENV{PYDEV_STARTUP}; $ENV{IOC_CMD}";
 }
 
-- 
GitLab