Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:02

0001 #!/bin/bash -l 
0002 grab_usage(){ cat << EOU
0003 grab.sh
0004 =============
0005 
0006 Runs rsync grabbing into local directories files from a remote geocache/CSG_GGeo/ directory 
0007 into which cxs jpg renders, json sidecars and intersect "photon" arrays are persisted.
0008 The remote directory to grab from is configurable with envvar OPTICKS_KEY_REMOTE 
0009 which is the OPTICKS_KEY from a remote node. The OPTICKS_KEY_REMOTE is converted
0010 into a remote directory by bash function opticks-key-remote-dir which uses SOpticksResourceTest 
0011 executable.
0012 
0013     OPTICKS_KEY_REMOTE     : $OPTICKS_KEY_REMOTE
0014     opticks-key-remote-dir : $(opticks-key-remote-dir)
0015 
0016 NB to update the CSGFoundry geometry on laptop for correct labelling of volumes use::
0017 
0018    ./cf_grab.sh 
0019 
0020 EOU
0021 }
0022 
0023 arg=${1:-all}
0024 shift
0025 
0026 if [ "$arg"  == "help" ]; then
0027    grab_usage
0028    exit 0
0029 fi 
0030 
0031 
0032 executable=${EXECUTABLE:-CSGOptiXSimtraceTest}
0033 
0034 opticks_key_remote_dir=$(opticks-key-remote-dir)    ## eg .opticks/geocache/DetSim0Svc_pWorld_g4live/g4ok_gltf/41c046fe05b28cb70b1fc65d0e6b7749/1
0035 xdir=$opticks_key_remote_dir/CSG_GGeo/$executable/   ## trailing slash to avoid duplicating path element 
0036 
0037 from=P:$xdir
0038 to=$HOME/$xdir
0039 
0040 LOGDIR=/tmp/$USER/opticks/CSGOptiX/$EXECUTABLE
0041 
0042 
0043 printf "arg                     %s \n" "$arg"
0044 printf "EXECUTABLE              %s \n " "$EXECUTABLE"
0045 printf "LOGDIR                  %s \n " "$LOGDIR"
0046 printf "OPTICKS_KEY_REMOTE      %s \n " "$OPTICKS_KEY_REMOTE" 
0047 printf "opticks_key_remote_dir  %s \n " "$opticks_key_remote_dir" 
0048 printf "\n"
0049 printf "xdir                    %s \n" "$xdir"
0050 printf "from                    %s \n" "$from" 
0051 printf "to                      %s \n" "$to" 
0052 
0053 mkdir -p $to
0054 
0055 
0056 find_last(){
0057     local msg="=== $FUNCNAME :"
0058     local typ=${1:-jpg}
0059     local last=$(ls -1rt `find ${to%/} -name "*.$typ" ` | tail -1 )
0060     echo $last 
0061 }
0062 
0063 relative_path(){
0064    local path=$1
0065    local pfx=${HOME}/$opticks_key_remote_dir/CSG_GGeo/CSGOptiXRenderTest/
0066    local rel=""
0067    case $path in 
0068       ${pfx}*)  rel=${path/$pfx} ;;    
0069    esac
0070    echo $rel   
0071 }
0072 
0073 pub_path(){
0074     local msg="=== $FUNCNAME :"
0075     local path=$1
0076     local typ=${2:-jpg}
0077     local rel=$(relative_path $path)
0078     rel=${rel/\.$typ}
0079 
0080     local ext=""
0081     if [ "$PUB" == "1" ]; then
0082         ext=""
0083     else
0084         ext="_${PUB}" 
0085     fi
0086 
0087     local s5p=/env/presentation/${rel}${ext}.$typ
0088     local pub=$HOME/simoncblyth.bitbucket.io$s5p    
0089 
0090     echo $msg path $path 
0091     echo $msg typ $typ 
0092     echo $msg rel $rel
0093     echo $msg s5p $s5p
0094     echo $msg pub $pub
0095     echo $msg s5p $s5p 1280px_720px 
0096 
0097     if [ -f "$pub" ]; then 
0098         echo $msg published path exists already : NOT COPYING : set PUB to an ext string to distinguish the name or more permanently arrange for a different path   
0099     else
0100         local pubdir=$(dirname $pub)
0101         if [ ! -d "$pubdir" ]; then
0102             echo $msg creating pubdir $pubdir 
0103             mkdir -p "$pubdir"
0104         fi 
0105         echo $msg copying path to pub 
0106         cp $path $pub
0107         echo $msg add s5p to s5_background_image.txt
0108     fi  
0109 }
0110 
0111 open_last(){
0112     local msg="=== $FUNCNAME :"
0113     local typ=${1:-jpg}
0114     local last=$(find_last $typ)
0115     echo $msg typ $typ last $last
0116     if [ "$(uname)" == "Darwin" ]; then
0117         open $last 
0118     fi 
0119 
0120     if [ -n "$PUB" ]; then
0121         if [ "$typ" == "jpg" -o "$typ" == "png" ]; then
0122             pub_path $last $typ
0123         fi
0124     fi
0125 
0126 }
0127 
0128 
0129 
0130 read -p "$msg Enter YES to proceed with rsync between from and to " ans
0131 if [ "$ans" == "YES" ]; then 
0132    echo $msg proceeding 
0133 else
0134    echo $msg skipping : perhaps you should be using tmp_grab.sh 
0135    exit 1 
0136 fi 
0137 
0138 
0139 
0140 if [ "$arg" == "tab" ]; then
0141 
0142     globptn="${to}cvd1/70000/cxr_overview/cam_0_tmin_0.4/cxr_overview*.jpg"
0143     refjpgpfx="/env/presentation/cxr/cxr_overview"
0144 
0145     ${IPYTHON:-ipython} -i $(which snap.py) --  --globptn "$globptn" --refjpgpfx "$refjpgpfx" $*
0146 
0147 elif [ "$arg" == "tab_water" ]; then
0148 
0149     globptn="${to}cvd1/70000/sWaterTube/cxr_view/*/cxr_view_sWaterTube.jpg"
0150     ${IPYTHON:-ipython} -i $(which snap.py) --  --globptn "$globptn"  $*
0151 
0152 elif [ "$arg" == "png" ]; then
0153 
0154     rsync -zarv --progress --include="*/" --include="*.png" --exclude="*" "$from" "$to"
0155     ls -1rt `find ${to%/} -name '*.png'`
0156     open_last png
0157 
0158 elif [ "$arg" == "jpg" ]; then
0159 
0160     rsync -zarv --progress --include="*/" --include="*.jpg" --include="*.json" --exclude="*" "$from" "$to"
0161     ls -1rt `find ${to%/} -name '*.jpg' -o -name '*.json'`
0162     open_last jpg
0163 
0164 elif [ "$arg" == "jpg_last" ]; then
0165 
0166     open_last jpg 
0167 
0168 elif [ "$arg" == "mp4" ]; then
0169 
0170     rsync -zarv --progress --include="*/" --include="*.mp4" --include="*.json" --exclude="*" "$from" "$to"
0171     ls -1rt `find ${to%/} -name '*.mp4' -o -name '*.json'`
0172     open_last mp4
0173 
0174 
0175 elif [ "$arg" == "all" ]; then
0176     rsync -zarv --progress --include="*/" --include="*.txt" --include="*.npy" --include="*.jpg" --include="*.mp4" --include "*.json" --exclude="*" "$from" "$to"
0177 
0178     ls -1rt `find ${to%/} -name '*.json' -o -name '*.txt' `
0179     ls -1rt `find ${to%/} -name '*.jpg' -o -name '*.mp4' -o -name '*.npy'  `
0180 
0181 
0182     if [ "$EXECUTABLE" == "CSGOptiXSimtraceTest" -o "$EXECUTABLE" == "CSGOptiXRenderTest" ]; then  
0183 
0184         last_npy=$(ls -1rt `find ${to%/} -name '*.npy' ` | tail -1 )
0185         last_outdir=$(dirname $last_npy)
0186         last_outbase=$(dirname $last_outdir)
0187         last_outleaf=$(basename $last_outdir)
0188 
0189         ## write source-able script ${EXECUTABLE}_OUTPUT_DIR.sh defining correponding envvar
0190         ## depending on the path of the last .npy grabbed  
0191         ## This is used from cxs.sh to transparently communicate the last OUTPUT_DIR 
0192         ## between nodes. 
0193 
0194         script=$LOGDIR/${EXECUTABLE}_OUTPUT_DIR.sh
0195         mkdir -p $(dirname $script)
0196 
0197         echo last_npy $last_npy 
0198         echo last_outdir $last_outdir 
0199         echo last_outbase $last_outbase
0200         echo last_outleaf $last_outleaf
0201 
0202         echo script $script
0203         printf "export ${EXECUTABLE}_OUTPUT_DIR=$last_outdir\n" > $script
0204         cat $script
0205    fi 
0206 
0207 fi 
0208