]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGPP/CalibMacros/MergeCalibration/alienDownloadTimeOut.sh
Moving PWG1 to PWGPP
[u/mrichter/AliRoot.git] / PWGPP / CalibMacros / MergeCalibration / alienDownloadTimeOut.sh
CommitLineData
e3e96f08 1#
2# sh script to download the data from alien to the local storage
3#
4# Arguments:
5# $1 fileList
6# $2 timeOut in seconds
7# $3 nprocess
8# $4 prefix
9#
10# Algorithm:
11# 1. Check the input parameters
12# 2. Group randomly the files into the group - generates nprocess download scripts
13# 3. Start $nprocess to download the files - with forced timeout
14# Example usage:
15# 1. Create file list
16# alien_find /alice/data/2010/LHC10h/000138795/pass0_2 root_ar | grep root > file.list
17# 2. run script with timeout 60 and n processes 10 and the sarting diectory -current directory
2bfe5463 18# $ALICE_ROOT/PWGPP/CalibMacros/MergeCalibration/alienDownloadTimeOut.sh file.list 60 30 `pwd`
e3e96f08 19#
20
21fileList=$1
22timeOut=$2
23nprocess=$3
24prefix=$4
25#
26# 1. Check the input variables
27#
28if ! [ -e $fileList ]; then
29 echo Input file does not exist
30 exit;
31fi;
32
33if [ ${#timeOut} -lt 1 ]; then
34 echo Time out not specified
35 exit;
36fi;
37
38if [ ${#nprocess} -lt 1 ]; then
39 echo N processes not specified
40 exit;
41fi;
42
43#
44# 2. Group randomly the files into the group - generates nprocess download scripts
45#
46nfiles=`wc $fileList | gawk '{print $1;}'`
47echo NFiles" "$nfiles" "$fileList" "TimeOut:$timeOut
48counterProcess=0;
49mkdirhier tmpDownload
50rm -rf tmpDownload/*.sh
51#
52# generate download scripts
53#
54for afile in `sort -r $fileList`; do
55 dname=$prefix/`dirname $afile`
56 fname=`basename $afile`
57 if ! [ -e $dname/$fname ] ; then
58 mkdirhier $dname
59 echo "echo Date `date` >> job$counterProcess.log>> job$counterProcess.log " >> tmpDownload/download$counterProcess.sh
60 echo "echo alien_cp alien:////$afile $dname 2>> job$counterProcess.log>> job$counterProcess.log " >> tmpDownload/download$counterProcess.sh
61 echo "timeout $timeOut alien_cp -t $timeOut -i alien.txt -m alien:////$afile $dname 2>> job$counterProcess.log>> job$counterProcess.log " >> tmpDownload/download$counterProcess.sh
62 echo "cat alien.txt >> job$counterProcess.log " >> tmpDownload/download$counterProcess.sh
63 let counterProcess=$counterProcess+1
64 if [ $counterProcess -gt $nprocess ]; then
65 let counterProcess=0;
66 fi;
67 fi;
68done;
69
70echo NFiles" "$nfiles" "$fileList" "TimeOut:$timeOut
71
72#
73# 3. Start $nprocess to download the files - with forced timeout
74#
75for job in `ls tmpDownload/download*.sh`; do
76 chmod u+x $job;
77 echo $job
78 command $job &
79done; > download.log