]> Creatis software - vip-workflow-odin.git/blob - bin/odin.sh
SMP folder selection
[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 OPTIONS=$5
76
77 if [ "${OPTIONS}" != "no" ] 
78 then
79         OPT=`echo ${OPTIONS} | sed s/_/\ /g`
80 else
81         OPT=""
82 fi
83
84 echo "Options are $OPT"
85
86
87 PRO=`basename $PROPATH`
88 SMP=`basename $SMPPATH`
89
90 SELMODE=`/usr/sbin/getenforce`
91 if [ "${SELMODE}" != "Disabled" ] && [ "${SELMODE}" != "Permissive" ]
92 then
93         chcon -t textrel_shlib_t v*/bin/*/*.so
94         chcon -t textrel_shlib_t v*/bin/*/*.so*
95 fi
96
97
98 #export LFC_HOST=lfc-biomed.in2p3.fr
99 #export LCG_GFAL_INFOSYS=cclcgtopbdii02.in2p3.fr:2170
100
101 #echo "whoami, Printing env"
102 #whoami
103 #env
104
105 tar -zxvf odin-release.tgz
106 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
107 OUTNAME=`echo ${SMP%.smp}`
108
109 #launching program odinfispexe
110 echo "executing ${ODINSEQ} simulate -magsi  -s $SMP  -p $PRO"
111 ./${ODINSEQ} simulate -magsi  -s $SMP  -p $PRO
112
113 CODE=$?
114 if [ ${CODE} != 0 ]
115 then
116     echo "Execution failed: exiting with code ${CODE}"
117     #exit ${CODE}
118 else
119     echo "Done"
120 fi
121
122 #launching program odinrecopexe
123 echo "executing odinrecopexe $OPT -o $OUTNAME"
124 ./odinrecoexe $OPT -o $OUTNAME
125
126 CODE=$?
127 if [ ${CODE} != 0 ]
128 then
129     echo "Execution failed: exiting with code ${CODE}"
130     #exit ${CODE}
131 else
132     echo "Done"
133 fi
134
135 JDX="${OUTNAME}.jdx"
136 test -f ${JDX}
137 CODE=$?
138 if [ ${CODE} != 0 ]
139 then
140         echo "No JDX produced, exit 6"
141         exit 6
142 else
143         LFN=${RESDIR}/$JDX
144         echo "Uploading $JDX to lfn:${LFN}"
145         lfc-ls ${LFN}
146         if [ $? = 0 ]
147         then
148                 lcg-del -a lfn:/${LFN}
149                         if [ $? != 0 ]
150                         then
151                                 echo "not able to lcg-del lfn:/${LFN}, renaming it"
152                                 d=`date -d "" +%s`
153                                 lfc-rename ${LFN} ${LFN}-garbage-${d}
154                         fi
155         fi
156 fi
157 lcg-cr -v -d ccsrm02.in2p3.fr -l lfn:${LFN} file:$PWD/$JDX
158 CODE=$?
159 if [ ${CODE} != 0 ]
160 then
161     echo "JDX upload failed"
162     exit 6
163 fi
164
165