+#!/bin/sh -l
+
+function unziptar {
+ 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
+}
+
+PROPATH=$1
+SMPPATH=$2
+RESDIR=$3
+ODINSEQ=$4
+
+PRO=`basename $PROPATH`
+SMP=`basename $SMPPATH`
+
+SELMODE=`/usr/sbin/getenforce`
+if [ "${SELMODE}" != "Disabled" ] && [ "${SELMODE}" != "Permissive" ]
+then
+ chcon -t textrel_shlib_t v*/bin/*/*.so
+ chcon -t textrel_shlib_t v*/bin/*/*.so*
+fi
+
+
+#export LFC_HOST=lfc-biomed.in2p3.fr
+#export LCG_GFAL_INFOSYS=cclcgtopbdii02.in2p3.fr:2170
+
+#echo "whoami, Printing env"
+#whoami
+#env
+
+tar -zxvf odin-release.tgz
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
+OUTNAME=`echo ${SMP%.smp}`
+
+#launching program odinfispexe
+echo "executing ${ODINSEQ} simulate -magsi -s $SMP -p $PRO"
+./${ODINSEQ} simulate -magsi -s $SMP -p $PRO
+
+CODE=$?
+if [ ${CODE} != 0 ]
+then
+ echo "Execution failed: exiting with code ${CODE}"
+ #exit ${CODE}
+else
+ echo "Done"
+fi
+
+#launching program odinrecopexe
+echo "executing odinrecopexe -o $OUTNAME"
+./odinrecoexe -o $OUTNAME
+
+CODE=$?
+if [ ${CODE} != 0 ]
+then
+ echo "Execution failed: exiting with code ${CODE}"
+ #exit ${CODE}
+else
+ echo "Done"
+fi
+
+JDX="${OUTNAME}.jdx"
+test -f ${JDX}
+CODE=$?
+if [ ${CODE} != 0 ]
+then
+ echo "No JDX produced, exit 6"
+ exit 6
+else
+ LFN=${RESDIR}/$JDX
+ echo "Uploading $JDX to lfn:${LFN}"
+ lfc-ls ${LFN}
+ if [ $? = 0 ]
+ then
+ 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
+fi
+lcg-cr -v -d ccsrm02.in2p3.fr -l lfn:${LFN} file:$PWD/$JDX
+CODE=$?
+if [ ${CODE} != 0 ]
+then
+ echo "JDX upload failed"
+ exit 6
+fi
+
+