]> Creatis software - vip-workflow-creaphase.git/blob - bin/1D_CreaPhase.sh
Fixed LFN issues
[vip-workflow-creaphase.git] / bin / 1D_CreaPhase.sh
1 #!/bin/bash
2
3 #     Functions     #
4
5 function info {
6   local D=`date`
7   echo [ INFO - $D ] $*
8 }
9
10 function warning {
11   local D=`date`
12   echo [ WARN - $D ] $*
13 }
14
15 function error {
16   local D=`date`
17   echo [ ERROR - $D ] $* >&2
18 }
19
20 function downloadLFN {
21
22   local LFN=$1
23   local LOCAL=${PWD}/`basename ${LFN}`
24
25   info "getting file size and computing sendReceiveTimeout"
26   size=`lfc-ls -l ${LFN} | awk -F' ' '{print $5}'`
27   sendReceiveTimeout=`echo $[${size}/150/1024]`
28   if [ "$sendReceiveTimeout" = "" ] || [ $sendReceiveTimeout -le 900 ]; then echo "sendReceiveTimeout empty or too small, setting it to 900s"; sendReceiveTimeout=900; else echo "sendReceiveTimeout is $sendReceiveTimeout"; fi;
29   info "Removing file ${LOCAL} in case it is already here"
30   \rm -f ${LOCAL}
31
32   info "Checking if the file is on local SE ${VO_BIOMED_DEFAULT_SE}"
33   local closeSURL=`lcg-lr lfn:${LFN} | grep ${VO_BIOMED_DEFAULT_SE}`
34   if [ "${closeSURL}" != "" ]
35   then
36     info "It is. Trying to download the file from there"
37     LINE="lcg-cp -v --connect-timeout 10 --sendreceive-timeout $sendReceiveTimeout --bdii-timeout 10 --srm-timeout 30 ${closeSURL} file:${LOCAL}"
38     info ${LINE}
39     ${LINE} &> lcg-log
40     if [ $? = 0 ]
41     then
42       info "lcg-cp worked fine"
43       lcg_source=`cat lcg-log | awk -F"://" '/Trying SURL srm/ {print $2}' | awk -F"/" '{print $1}'|awk -F":" '{print $1}'`;
44       lcg_destination=`hostname`;
45       lcg_time=`cat lcg-log | awk '/Transfer took/ {print $3$4}'`;
46       info "DownloadCommand=lcg-cp Source=$lcg_source Destination=$lcg_destination Size=$size Time=$lcg_time";
47       return 0
48     else
49       error "It failed, falling back on regular lcg-cp"
50     fi
51   else
52     info "It's not, falling back on regular lcg-cp"
53   fi
54
55 info "Downloading file ${LFN}..."
56 LINE="lcg-cp -v --connect-timeout 10 --sendreceive-timeout $sendReceiveTimeout --bdii-timeout 10 --srm-timeout 30 lfn:${LFN} file:${LOCAL}"
57 info ${LINE}
58 ${LINE} &> lcg-log
59 if [ $? = 0 ]
60 then
61   info "lcg-cp worked fine"
62   lcg_source=`cat lcg-log | awk -F"://" '/Trying SURL srm/ {print $2}' | awk -F"/" '{print $1}'|awk -F":" '{print $1}'`;
63   lcg_destination=`hostname`;
64   lcg_time=`cat lcg-log | awk '/Transfer took/ {print $3$4}'`;
65   info "DownloadCommand=lcg-cp Source=$lcg_source Destination=$lcg_destination Size=$size Time=$lcg_time";
66 else
67   error "lcg-cp failed"
68   error "`cat lcg-log`"
69   return 1
70 fi
71 \rm lcg-log 
72 }
73
74 # Arguments parsing #
75 RES=$1
76 COMM_LINE=`echo "${@:2:$(($#-4))}"`
77 MU=`echo "${@:$(($#-2)):1}"`
78 DELTA=`echo "${@:$(($#-1)):1}"`
79 # Command-line construction #
80
81 #echo "COMM line is $COMM_LINE"
82 #remove flags starting with --
83 #BOUTIQUES_ARGS="$(echo ${COMM_LINE} | sed 's/[--][[:alpha:]]*/,/g')"
84 BOUTIQUES_ARGS="$(echo ${COMM_LINE} | sed 's/ , /, /g')"
85 #remove leading ,,
86 #BOUTIQUES_ARGS="$(echo ${BOUTIQUES_ARGS} | sed 's/^,, //g')"
87 BOUTIQUES_COMMAND_LINE="octave --silent --eval \"SimuPBI_unknown_1D_func(${BOUTIQUES_ARGS})\""
88 echo "Boutiques COMM line is $BOUTIQUES_COMMAND_LINE"
89
90
91 #WARNING Cheating here : we know that outputs are written in dirOut
92 DIROUT="dirOut"
93 # Command-line execution #
94
95 cat << DOCKERJOB > .dockerjob.sh
96 #!/bin/bash -l
97 cd /CreaPhase
98 cp /gasw-dir/$MU ./
99 cp /gasw-dir/$DELTA ./
100 ${BOUTIQUES_COMMAND_LINE}
101 DOCKERJOB
102
103 mkdir $DIROUT
104 chmod 755 .dockerjob.sh
105 #.dockerjob.sh script needs to be found in the workdir, ten we need to cd to /CreaPhase to be able to execute SimuPBI_circle_func
106 docker run --rm -v $PWD:/gasw-dir -v $PWD/$DIROUT:/CreaPhase/$DIROUT -v $PWD/../cache:$PWD/../cache -w /gasw-dir -u `id -u`:`id -g` camarasu/creaphase ./.dockerjob.sh
107
108 if [ $? != 0 ]
109 then
110     echo "CreaPhase execution failed!"
111     exit 1
112 fi
113
114 tar -czvf result.tgz $DIROUT
115
116
117 echo "Execution of CreaPhase completed."
118