Skip to content

Commit

Permalink
Merge pull request #50 from nikitinvv/master
Browse files Browse the repository at this point in the history
merging latest from 7-BM and 2-BM
  • Loading branch information
nikitinvv committed Dec 23, 2021
2 parents c21f17f + 131da6f commit f4a2f49
Show file tree
Hide file tree
Showing 24 changed files with 1,866 additions and 421 deletions.
6 changes: 6 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
TOP = ../..
include $(TOP)/configure/CONFIG
#ARCH = windows-x64-static
ARCH = linux-x86_64
TARGETS = envPaths dllPath.bat
include $(TOP)/configure/RULES.ioc
2 changes: 2 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/auto_settings.req
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
file "tomoStream.req", P=$(P), R=$(R)
file "tomoStream_settings.req", P=$(P), R=$(R)
36 changes: 36 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/save_restore.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
### save_restore setup
#
# The rest this file does not require modification for standard use, but...
# If you want save_restore to manage its own NFS mount, specify the name and
# IP address of the file server to which save files should be written.
# This currently is supported only on vxWorks.
#save_restoreSet_NFSHost("oxygen", "164.54.52.4")

# Debug-output level
save_restoreSet_Debug(0)

# Ok to save/restore save sets with missing values (no CA connection to PV)?
save_restoreSet_IncompleteSetsOk(1)
# Save dated backup files?
save_restoreSet_DatedBackupFiles(1)

# Number of sequenced backup files to write
save_restoreSet_NumSeqFiles(3)
# Time interval between sequenced backups
save_restoreSet_SeqPeriodInSeconds(300)

# specify where save files should be
set_savefile_path(".", "autosave")

# specify what save files should be restored. Note these files must be
# in the directory specified in set_savefile_path(), or, if that function
# has not been called, from the directory current when iocInit is invoked
set_pass0_restoreFile("auto_settings.sav")
set_pass1_restoreFile("auto_settings.sav")

# specify directories in which to to search for included request files
# Note cdCommands defines 'startup', but envPaths does not
set_requestfile_path(".", "")
set_requestfile_path(".", "autosave")
set_requestfile_path($(AUTOSAVE), "db")
set_requestfile_path($(TOP), "db")
25 changes: 25 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/st.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
< envPaths

epicsEnvSet("P", "7bmtomo:")
epicsEnvSet("R", "EncoderStream:")

## Register all support components

# Use these lines to run the locally built tomoStreamApp
dbLoadDatabase "../../dbd/tomoStreamApp.dbd"
tomoStreamApp_registerRecordDeviceDriver pdbbase

# Use these lines to run the xxx application on APSshare.
#dbLoadDatabase "/APSshare/epics/synApps_6_1/support/xxx-R6-1/dbd/iocxxxLinux.dbd"
#iocxxxLinux_registerRecordDeviceDriver pdbbase


dbLoadTemplate("tomoStream.substitutions")

< save_restore.cmd
save_restoreSet_status_prefix($(P))
dbLoadRecords("$(AUTOSAVE)/asApp/Db/save_restoreStatus.db", "P=$(P)")

iocInit

create_monitor_set("auto_settings.req", 30, "P=$(P),R=$(R)")
6 changes: 6 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/start_IOC
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Use this line to run the locally built tomoStreamApp
../../bin/linux-x86_64/tomoStreamApp st.cmd

# Use this line to run the xxx application on /APSshare
#/APSshare/epics/synApps_6_1/support/xxx-R6-1/bin/linux-x86_64/xxx st.cmd

1 change: 1 addition & 0 deletions iocBoot/iocTomoStream3D_7BM/start_medm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
medm -x -macro "P=7bmtomo:,R=EncoderStream:" ../../tomoStreamApp/op/adl/tomoStream.adl &
68 changes: 68 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/start_tomostream3d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This script creates an object of type TomoStream for doing tomography streaming reconstruction
# To run this script type the following:
# python -i start_tomostream.py
# The -i is needed to keep Python running, otherwise it will create the object and exit

import sys
sys.path.append('/home/beams/7BMB/solder_beamtime/solder_imaging')

from tomostream3d import EncoderStream
ts = EncoderStream(["../../db/tomoStream_settings.req","../../db/tomoStream_settings.req"], {"$(P)":"7bmtomo:", "$(R)":"EncoderStream:"})




# import vedo
# import matplotlib.pyplot as plt
# from vedo.applications import IsosurfaceBrowser

# clip_val = 0.3
# from pdb import set_trace
# from time import sleep


# def run_vis(vol_vis):

# vol_vis = vol_vis < clip_val
# vol = vedo.Volume(vol_vis)
# plt = IsosurfaceBrowser(vol, c='gold') # Plotter instance
# plt.show(axes = 7, bg2 = 'lb').close()
# return


# import threading, queue

# q = queue.Queue(maxsize = 2)

# def worker():
# while True:
# if q.qsize() > 2:
# continue
# vol_vis = ts.slv.rec_vol[::2,::2,::2].get()
# q.put(vol_vis)
# q.task_done()
# sleep(2.0)



# sleep(30.0)

# # turn-on the worker thread
# threading.Thread(target=worker, daemon=True).start()



# while True:
# vol_vis = q.get()
# run_vis(vol_vis)
# sleep(5.0)

# # block until all tasks are done
# q.join()
# print('All work completed')






6 changes: 6 additions & 0 deletions iocBoot/iocTomoStream3D_7BM/tomoStream.substitutions
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
file "$(TOP)/db/tomoStream.template"
{
pattern
{ P, R, TOMO_SCAN, IMAGE_P, DARK_PVA, FLAT_PVA, RECON_PVA, THETA_PVA}
{7bmtomo:, EncoderStream:, 7bmtomo:TomoScanStream:, 7bmtomo:TSS:PvaPluginPVPrefix, 7bmtomo:TSS:StreamDarkFields, 7bmtomo:TSS:StreamFlatFields, 7bmtomo:EncoderStream:StreamRecon, 7bmtomo:TSS:StreamTheta}
}
3 changes: 0 additions & 3 deletions iocBoot/iocTomoStream_2BM/autosave/README

This file was deleted.

2 changes: 1 addition & 1 deletion iocBoot/iocTomoStream_2BM/tomoStream.substitutions
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ file "$(TOP)/db/tomoStream.template"
{
pattern
{ P, R, TOMO_SCAN, IMAGE_P, DARK_PVA, FLAT_PVA, RECON_PVA, THETA_PVA}
{2bmb:, TomoStream:, 2bmb:TomoScanStream:, 2bmb:TomoScanStream:PvaPluginPVPrefix, 2bmb:TomoScanStream:StreamDarkFields, 2bmb:TomoScanStream:StreamFlatFields, 2bmb:TomoStream:StreamRecon, 2bmb:TomoStream:StreamTheta}
{2bmb:, TomoStream:, 2bmb:TomoScanStream:, 2bmb:TomoScanStream:PvaPluginPVPrefix, 2bmb:TomoScanStream:StreamDarkFields, 2bmb:TomoScanStream:StreamFlatFields, 2bmb:TomoStream:StreamRecon, 2bmb:TomoScanStream:StreamTheta}
}
229 changes: 229 additions & 0 deletions iocBoot/iocTomoStream_7BM/auto_python.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
#!/bin/sh
#
# description: start/stop/restart an EPICS IOC in a screen session
#

# Manually set IOC_STARTUP_DIR if 7bm_dau3.sh will reside somewhere other than softioc
IOC_STARTUP_DIR=/home/beams/7BMB/epics/synApps/support/tomostream/iocBoot/iocTomoStream_7BM
IOC_BINARY="python -i"
IOC_NAME=TomoStream_python
# The name of the IOC binary isn't necessarily the same as the name of the IOC
# Change YES to NO in the following line to disable screen-PID lookup
GET_SCREEN_PID=YES

# Commands needed by this script
ECHO=echo
ID=id
PGREP=pgrep
SCREEN=screen
KILL=kill
BASENAME=basename
DIRNAME=dirname
READLINK=readlink
PS=ps
#####################################################################

SNAME=${BASH_SOURCE:-$0}
SELECTION=$1

IOC_STARTUP_FILE="start_tomostream_7bm.py"

if [ -z "$IOC_STARTUP_DIR" ] ; then
# If no startup dir is specified, use the script's directory
IOC_STARTUP_DIR=`dirname ${SNAME}`
IOC_CMD="${IOC_BINARY} ${IOC_STARTUP_FILE}"
else
IOC_CMD="${IOC_BINARY} ${IOC_STARTUP_DIR}/${IOC_STARTUP_FILE}"
fi

#####################################################################

screenpid() {
if [ -z ${SCREEN_PID} ] ; then
${ECHO}
else
${ECHO} " in a screen session (pid=${SCREEN_PID})"
fi
}

checkpid() {
MY_UID=`${ID} -u`
# The '\$' is needed in the pgrep pattern to select 7bmLinux, but not 7bmLinux.sh
IOC_PID=`${PGREP} ${IOC_BINARY}\$ -u ${MY_UID}`
#!${ECHO} "IOC_PID=${IOC_PID}"

if [ "${IOC_PID}" != "" ] ; then
# Assume the IOC is down until proven otherwise
IOC_DOWN=1

# At least one instance of the IOC binary is running;
# Find the binary that is associated with this script/IOC
for pid in ${IOC_PID}; do
BIN_CWD=`${READLINK} /proc/${pid}/cwd`
IOC_CWD=`${READLINK} -f ${IOC_STARTUP_DIR}`

if [ "$BIN_CWD" = "$IOC_CWD" ] ; then
# The IOC is running; the binary with PID=$pid is the IOC that was run from $IOC_STARTUP_DIR
IOC_PID=${pid}
IOC_DOWN=0

SCREEN_PID=""

if [ "${GET_SCREEN_PID}" = "YES" ] ; then
# Get the PID of the parent of the IOC (shell or screen)
P_PID=`${PS} -p ${IOC_PID} -o ppid=`

# Get the PID of the grandparent of the IOC (sshd, screen, or ???)
GP_PID=`${PS} -p ${P_PID} -o ppid=`

#!${ECHO} "P_PID=${P_PID}, GP_PID=${GP_PID}"

# Get the screen PIDs
S_PIDS=`${PGREP} screen`

for s_pid in ${S_PIDS} ; do
#!${ECHO} ${s_pid}

if [[ ${s_pid} -eq ${P_PID} ]] ; then
SCREEN_PID=${s_pid}
break
fi

if [[ ${s_pid} -eq ${GP_PID} ]] ; then
SCREEN_PID=${s_pid}
break
fi

done
fi

break
#else
# ${ECHO} "PATHS are different"
# ${ECHO} ${BIN_CWD}
# ${ECHO} ${IOC_CWD}
fi
done
else
# IOC is not running
IOC_DOWN=1
fi

return ${IOC_DOWN}
}

start() {
if checkpid; then
${ECHO} -n "${IOC_NAME} is already running (pid=${IOC_PID})"
screenpid
else
${ECHO} "Starting ${IOC_NAME}"
cd ${IOC_STARTUP_DIR}
# Run 7bmLinux inside a screen session
${SCREEN} -dm -S ${IOC_NAME} -h 5000 ${IOC_CMD}
fi
}

stop() {
if checkpid; then
${ECHO} "Stopping ${IOC_NAME} (pid=${IOC_PID})"
${KILL} ${IOC_PID}
else
${ECHO} "${IOC_NAME} is not running"
fi
}

restart() {
stop
start
}

status() {
if checkpid; then
${ECHO} -n "${IOC_NAME} is running (pid=${IOC_PID})"
screenpid
else
${ECHO} "${IOC_NAME} is not running"
fi
}

console() {
if checkpid; then
${ECHO} "Connecting to ${IOC_NAME}'s screen session"
# The -r flag will only connect if no one is attached to the session
#!${SCREEN} -r ${IOC_NAME}
# The -x flag will connect even if someone is attached to the session
${SCREEN} -x ${IOC_NAME}
else
${ECHO} "${IOC_NAME} is not running"
fi
}

run() {
if checkpid; then
${ECHO} -n "${IOC_NAME} is already running (pid=${IOC_PID})"
screenpid
else
${ECHO} "Starting ${IOC_NAME}"
cd ${IOC_STARTUP_DIR}
# Run 7bmLinux outside of a screen session, which is helpful for debugging
${IOC_CMD}
fi
}

start_medm() {
${IOC_STARTUP_DIR}/../../start_MEDM_7bmLinux
}

start_caqtdm() {
${IOC_STARTUP_DIR}/../../start_caQtDM_7bmLinux
}

usage() {
${ECHO} "Usage: $(${BASENAME} ${SNAME}) {start|stop|restart|status|console|run|medm|caqtdm}"
}

#####################################################################

if [ ! -d ${IOC_STARTUP_DIR} ] ; then
${ECHO} "Error: ${IOC_STARTUP_DIR} doesn't exist."
${ECHO} "IOC_STARTUP_DIR in ${SNAME} needs to be corrected."
else
case ${SELECTION} in
start)
start
;;

stop | kill)
stop
;;

restart)
restart
;;

status)
status
;;

console)
console
;;

run)
run
;;

medm)
start_medm
;;

caqtdm)
start_caqtdm
;;

*)
usage
;;
esac
fi

0 comments on commit f4a2f49

Please sign in to comment.