]> Creatis software - vip-workflow-odin.git/blob - bin/odin.sh
odin fisp and epi workflow v0.1
[vip-workflow-odin.git] / bin / odin.sh
1 #!/bin/sh -l
2
3 function unziptar {
4         zipname=`echo $1 | grep '\.zip'`
5         echo $zipname
6         tarname=`echo $1 | grep '\.tar'`
7         echo $tarname
8         tgzname=`echo $1 | grep '\.tgz'`
9         echo $tgzname
10         if [ "x$zipname" != "x" ]
11                 then
12                 echo "ZIP File"
13                 unzip -j $1 -d data
14         else
15                 if [ "x$tarname" != "x" ]
16                         then
17                         echo "TAR File"
18                         COMP=`tar -tvf $1 | awk 'END{print}' |   awk -F' ' '{print $NF}' | awk -F'/' '{print NF-1}'`
19                         tar -xvf $1 --strip-components=${COMP} -C data
20                 else
21                         if [ "x$tgzname" != "x" ]
22                                 then
23                                 echo "TGZ File"
24                                 COMP=`tar -tvf $1 | awk 'END{print}' |   awk -F' ' '{print $NF}' | awk -F'/' '{print NF-1}'`
25                                 tar -zxvf $1 --strip-components=${COMP} -C data
26                         else
27                                 echo "Unknown File Type"
28                                 exit 6
29                         fi
30                 fi
31         fi
32
33         if [ $? != 0 ]
34                 then
35                 echo "A problem occurred while untargzing the input: giving up!"
36                 exit 2
37         fi
38 }
39
40 function checkdir {
41         lfc-ls $1 > /dev/null
42         if [ $? != 0 ]
43         then
44                 echo "Directory $1 not found, creating it!"
45                 lfc-mkdir -p $1
46                 #exit 6
47         fi
48 }
49
50
51 function downloadDir {
52         checkdir $1
53         LOCALDIR=`basename $1`
54         mkdir -p ${LOCALDIR}
55         for i in `lfc-ls $1 | grep -v garbage`
56         do
57                 lcg-cp -v lfn:$1/$i file:$PWD/${LOCALDIR}/$i
58                 if [ $? != 0 ]
59                 then
60                         echo "lcg-cp failed: trying once more"
61                         lcg-cp -v lfn:$1/$i file:$PWD/${LOCALDIR}/$i
62                         if [ $? != 0 ]
63                         then
64                                 echo "Unable to download file lfn:$1/$i: giving up."
65                                 exit 1
66                         fi
67                 fi
68         done
69 }
70
71 PROPATH=$1
72 SMPPATH=$2
73 RESDIR=$3
74 ODINSEQ=$4
75
76 PRO=`basename $PROPATH`
77 SMP=`basename $SMPPATH`
78
79 SELMODE=`/usr/sbin/getenforce`
80 if [ "${SELMODE}" != "Disabled" ] && [ "${SELMODE}" != "Permissive" ]
81 then
82         chcon -t textrel_shlib_t v*/bin/*/*.so
83         chcon -t textrel_shlib_t v*/bin/*/*.so*
84 fi
85
86
87 #export LFC_HOST=lfc-biomed.in2p3.fr
88 #export LCG_GFAL_INFOSYS=cclcgtopbdii02.in2p3.fr:2170
89
90 #echo "whoami, Printing env"
91 #whoami
92 #env
93
94 tar -zxvf odin-release.tgz
95 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
96 OUTNAME=`echo ${SMP%.smp}`
97
98 #launching program odinfispexe
99 echo "executing ${ODINSEQ} simulate -magsi  -s $SMP  -p $PRO"
100 ./${ODINSEQ} simulate -magsi  -s $SMP  -p $PRO
101
102 CODE=$?
103 if [ ${CODE} != 0 ]
104 then
105     echo "Execution failed: exiting with code ${CODE}"
106     #exit ${CODE}
107 else
108     echo "Done"
109 fi
110
111 #launching program odinrecopexe
112 echo "executing odinrecopexe -o $OUTNAME"
113 ./odinrecoexe -o $OUTNAME
114
115 CODE=$?
116 if [ ${CODE} != 0 ]
117 then
118     echo "Execution failed: exiting with code ${CODE}"
119     #exit ${CODE}
120 else
121     echo "Done"
122 fi
123
124 JDX="${OUTNAME}.jdx"
125 test -f ${JDX}
126 CODE=$?
127 if [ ${CODE} != 0 ]
128 then
129         echo "No JDX produced, exit 6"
130         exit 6
131 else
132         LFN=${RESDIR}/$JDX
133         echo "Uploading $JDX to lfn:${LFN}"
134         lfc-ls ${LFN}
135         if [ $? = 0 ]
136         then
137                 lcg-del -a lfn:/${LFN}
138                         if [ $? != 0 ]
139                         then
140                                 echo "not able to lcg-del lfn:/${LFN}, renaming it"
141                                 d=`date -d "" +%s`
142                                 lfc-rename ${LFN} ${LFN}-garbage-${d}
143                         fi
144         fi
145 fi
146 lcg-cr -v -d ccsrm02.in2p3.fr -l lfn:${LFN} file:$PWD/$JDX
147 CODE=$?
148 if [ ${CODE} != 0 ]
149 then
150     echo "JDX upload failed"
151     exit 6
152 fi
153
154