From 45a6440916669e2643c72fd1b6f884b7230599b9 Mon Sep 17 00:00:00 2001 From: Sorina Pop Date: Mon, 20 Jun 2016 18:08:21 +0200 Subject: [PATCH 1/1] hrquest workflow v0.1 --- bin/hrquest.sh | 215 +++++++++++++++++++++++++++++++++++++++ gasw/hrquest.xml | 23 +++++ workflow/hrquest.gwendia | 53 ++++++++++ 3 files changed, 291 insertions(+) create mode 100755 bin/hrquest.sh create mode 100644 gasw/hrquest.xml create mode 100644 workflow/hrquest.gwendia diff --git a/bin/hrquest.sh b/bin/hrquest.sh new file mode 100755 index 0000000..61b07c4 --- /dev/null +++ b/bin/hrquest.sh @@ -0,0 +1,215 @@ +#!/bin/sh -l + +function unziptar { + echo "unziptar $1" + zipname=`echo $1 | grep '\.zip'` + echo $zipname + tarname=`echo $1 | grep '\.tar'` + echo $tarname + tgzname=`echo $1 | grep '\.tgz'` + echo $tgzname + if [ "x$zipname" != "x" ] + then + echo "ZIP File" + unzip -j $1 -d data + else + if [ "x$tarname" != "x" ] + then + echo "TAR File" + COMP=`tar -tvf $1 | awk 'END{print}' | awk -F' ' '{print $NF}' | awk -F'/' '{print NF-1}'` + tar -xvf $1 --strip-components=${COMP} -C data + else + if [ "x$tgzname" != "x" ] + then + echo "TGZ File" + COMP=`tar -tvf $1 | awk 'END{print}' | awk -F' ' '{print $NF}' | awk -F'/' '{print NF-1}'` + tar -zxvf $1 --strip-components=${COMP} -C data + else + echo "Unknown File Type" + exit 6 + fi + fi + fi + + if [ $? != 0 ] + then + echo "A problem occurred while untargzing the input: giving up!" + exit 2 + fi +} + +function checkdir { + lfc-ls $1 > /dev/null + if [ $? != 0 ] + then + echo "Directory $1 not found, creating it!" + lfc-mkdir -p $1 + #exit 6 + fi +} + + +function downloadDir { + checkdir $1 + LOCALDIR=`basename $1` + mkdir -p ${LOCALDIR} + for i in `lfc-ls $1 | grep -v garbage` + do + lcg-cp -v lfn:$1/$i file:$PWD/${LOCALDIR}/$i + if [ $? != 0 ] + then + echo "lcg-cp failed: trying once more" + lcg-cp -v lfn:$1/$i file:$PWD/${LOCALDIR}/$i + if [ $? != 0 ] + then + echo "Unable to download file lfn:$1/$i: giving up." + exit 1 + fi + fi + done +} + +function downloadFile { + local fname=`basename $1` + test -f $fname + CODE=$? + if [ ${CODE} != 0 ] + then + + lcg-cp -v lfn:$1 file:$PWD/$fname + if [ $? != 0 ] + then + echo "lcg-cp failed: trying once more" + lcg-cp -v lfn:$1 file:$PWD/$fname + if [ $? != 0 ] + then + echo "Unable to download file lfn:$1: giving up." + exit 1 + fi + fi + else + echo "File $fname already exists locally" + fi +} + +in=$@ +suffix=" ] " +echo $in | grep '\[' +CODE=$? +if [ ${CODE} != 0 ] +#simple arguments, no arrays +then + SIGFILE=$1 + PARAMFILE=$2 + INFOLDER=$3 + RESDIR=$4 +else +#split inputs based on [] and retrieve contents + SIGFILE=`echo $in | awk -F'\\\[' '{print $2}' | awk -F'\\\]' '{print $1}'` + mySigArray=( $SIGFILE ) + PARAMFILE=`echo $in | awk -F'\\\]' '{print $2}' | awk -F' ' '{print $1}'` + INFOLDER=`echo $in | awk -F'\\\]' '{print $2}' | awk -F' ' '{print $2}'` + RESDIR=`echo $in | awk -F'\\\] ' '{print $2}' | awk -F' ' '{print $3}'` + + echo "Resdir is $RESDIR" + +fi + + +DATADIR=`dirname ${INFOLDER}` + +echo "Downloading inputs" + +downloadFile $PARAMFILE + +((n_elements=${#mySigArray[@]}, max_index=n_elements - 1)) +for ((i = 0; i <= max_index; i++)); do + downloadFile ${mySigArray[i]} +done + + +#COMPDATA=$4 +#RESDIR=$5 +#preparing input data +#export LD_LIBRARY_PATH=/usr/local/matlab/MCR/v84/runtime/glnxa64:/usr/local/matlab/MCR/v84/bin/glnxa64:/usr/local/matlab/MCR/v84/sys/os/glnxa64:$LD_LIBRARY_PATH +#export XAPPLRESDIR=/usr/local/matlab/MCR/v84/X11/app-defaults + +hname=`hostname` +if [ "${hname}" != "moteur1.grid.creatis.insa-lyon.fr" ] && [ "${hname}" != "moteur2.grid.creatis.insa-lyon.fr" ] +then + echo "hrquest not yest supported on grid resources" + +else + export PATH=/usr/local/hrquest:$PATH + export LD_LIBRARY_PATH=/usr/local/hrquest/lib:$LD_LIBRARY_PATH + echo "LD_LIBRARY_PATH is $LD_LIBRARY_PATH" +fi + + +#export LFC_HOST=lfc-biomed.in2p3.fr +#export LCG_GFAL_INFOSYS=cclcgtopbdii02.in2p3.fr:2170 + +#echo "whoami, Printing env" +#whoami +#env + +echo "result dir is $RESDIR" +checkdir $RESDIR + +#preparing comparison data +#mkdir ${DATADIR} +#cd ${DATADIR} +downloadDir ${INFOLDER} +#cd .. + +echo "pwd is `pwd`, creating outputs folder" +mkdir outputs +#launching program +echo "launching the program" +((n_elements=${#mySigArray[@]}, max_index=n_elements - 1)) +PF=`basename ${PARAMFILE}` +for ((i = 0; i <= max_index; i++)); do + echo "launching the program for i = $i" + SIG=`basename ${mySigArray[i]}` + echo "hrquestCml -f $PF $SIG" + hrquestCml -f $PF ${SIG} + CODE=$? + if [ ${CODE} != 0 ] + then + echo "Execution failed with code ${CODE}" + exit ${CODE} + fi + #echo "mySigarray is ${SIG}" + basefilename=`basename ${SIG%.*}` + mv ${basefilename}_* outputs/ +done + + +RESULT=results.tgz +LFN=${RESDIR}/${RESULT} +lfc-ls ${LFN} + if [ $? = 0 ] + then + echo "deleting previous ${LFN}" + lcg-del -a lfn:/${LFN} + if [ $? != 0 ] + then + echo "not able to lcg-del lfn:/${LFN}, renaming it" + d=`date -d "" +%s` + lfc-rename ${LFN} ${LFN}-garbage-${d} + fi + fi + + + +tar -czvf $RESULT outputs +test -f ${RESULT} +CODE=$? +if [ ${CODE} != 0 ] +then + echo "Execution failed: exiting with code ${CODE} since ${RESULT} does not exist" + exit ${CODE} +else + echo "Execution done, ${RESULT} created." +fi + diff --git a/gasw/hrquest.xml b/gasw/hrquest.xml new file mode 100644 index 0000000..7b4a512 --- /dev/null +++ b/gasw/hrquest.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + +