3 # Library of some download functions
5 # --- Check AliEn token ----------------------------------------------
9 genv_file=/tmp/gclient_env_${uid}
11 if test ! -f ${genv_file} ; then
12 echo "No such file: ${genv_file}, please do alien-token-init" \
17 alien-token-info | grep -q "Token is still valid"
18 if test $? -ne 0 ; then
19 echo "Token not valid, please re-new" > /dev/stderr
24 # --- Diagnostics output ---------------------------------------------
28 if test $1 -gt $verb ; then return ; fi
33 # --- Handling of exit -----------------------------------------------
37 if test "x$lock" = "x" ; then return ; fi
42 # --- Handling of errors ---------------------------------------------
58 # --- Check the lock -------------------------------------------------
65 if test -f $lock ; then
66 echo "Another $nam process is already running:" > /dev/stderr
67 echo "Content of ${lock}:" > /dev/stderr
68 cat $lock > /dev/stderr
80 # --- Append path element --------------------------------------------
85 if test "x$tmp" != "x" ; then tmp="${tmp}/" ; fi
89 # --- Get list of files ----------------------------------------------
90 # Output is stored in .list
96 if test x$maxf = x ; then maxf=-1 ; fi
98 mess 1 "Getting list of files from AliEn - can take minutes - be patient"
99 mess 2 "alien_find ${path} ${search}"
100 files=`alien_find ${path} ${search} | grep -v "\(does not\|files found\)" 2>> ${redir}`
106 mess 1 -n "Total of $numf files ... "
107 if test $maxf -lt 0 ; then
110 mess 1 "using $maxf first of these"
113 # --- Change permissions on files ------------------------------------
116 if test ! -f $1 ; then return ; fi
120 # --- Download a single file -----------------------------------------
122 # $2: Output directory
129 local source=$1 ; shift
130 local store=$1 ; shift
134 local redir=$1 ; shift
135 local noact=$1 ; shift
139 o=${o}`basename $file .root`_`printf %04d ${r}`.root
142 local d=`printf %04d ${r}`
147 printf "%4d/%4d: %20s -> %20s ..." $cur $max $source $o
149 mess 2 -n "$source -> $o ... "
156 # mess 2 -n "copying ... "
157 if test $noact -lt 1 ; then
158 alien_cp alien:${source} file:${o} >> ${redir} 2>&1
165 if test $noact -gt 0 ; then return 0 ; fi
166 if test ! -f $o ; then return 1 ; fi
175 1|3|4|5|6) return 2 ;;
181 mess 3 "Unzipping $b in $d"
182 if ! unzip -n -qq -l $o > /dev/null 2>&1 ; then
183 mess 1 "Bad zip file: $o"
186 # (cd $d && unzip -n -qq $b)
194 # --- Submit run analysis to background ------------------------------
195 # $1: Output directory
196 # $2: Sarting off-set
198 # $4: Maximum number of files
205 local maxf=$1 ; shift
206 local noact=$1 ; shift
210 mess 5 "Submitting $maxjobs jobs from $sta/$maxf"
212 let cur=$sta+$counter
214 local b=`echo $i | sed -e "s,${path},,"`
215 local r=`echo $b | sed -e "s,/.*,,"`
218 let counter=$counter+1
220 download_file $i $out $cur $maxf $noact&
221 j=`jobs %% | sed -e 's/^[^0-9]*//' -e 's/[^0-9]*$//'`
222 joblist="$joblist $j"
226 mess 5 "will wait for jobs $joblist"
227 for i in $joblist ; do
228 mess 5 "waiting for $i of $joblist"
230 let counter=$counter+1