Visualization scripts (Jens Wiechula)
[u/mrichter/AliRoot.git] / TPC / scripts / makeCalibTree
CommitLineData
594d338f 1#!/bin/bash
2
3
4function usage {
5echo "Usage:"
6echo "makeCalibTree [options]"
7echo
8echo "options:"
9echo " -r, --range : create tree for the given range of runs"
10echo " e.g. 70000-80000"
11echo " -a, --auto : create trees in chunks of \$NFILES for all the files"
12echo " found in the OCDB entries of \$AUTOFILES"
13echo " -l, --list : text file with a list of runs to process"
14echo " -d, --outdir : output file directory"
15echo " -f, --outfile : output file name"
16echo " -b, --batch : run as batch job(s)"
17echo " -o, --overwrite : overwrite old files"
18echo " -h, --help : display this help"
19echo ""
20exit 0
21
22}
23
24#
25# create a list of files in $RANGE which are also available in $AUTOFILES
26#
27function createRangeList {
28 #get first and last run from range
29 local first=$(echo $RANGE | sed 's|\(.*\)-.*|\1|')
30 local last=$(echo $RANGE | sed 's|.*-\(.*\)|\1|')
31 #create list with all TPC runs
32 local command=ls
33 if [ $WITHALIEN -eq 1 ]; then command=alien_ls; fi
34 local dir=$AUTOFILES
35 RUNS=($($command $dir | sed 's|Run\([0-9]\{5\}\)_.*|\1|'))
36 #define filename
37 local filename=calibTreeTime_${first}_${last}
38 #remove old files
39 #test -d $TMPLISTDIR && rm -rf $TMPLISTDIR
40 test -d $TMPLISTDIR
41 mkdir -p $TMPLISTDIR
42 for (( i=0; i<${#RUNS[*]}; i=i+1 )); do
43 if [ ${RUNS[$i]} -lt $first ]||[ ${RUNS[$i]} -gt $last ]; then continue; fi
44 echo ${RUNS[$i]} >> $TMPLISTDIR/$filename
45 done
46}
47
48#
49# automatic list creation for runs in files in OCDB entry pointed to by $AUTOFILES
50# crete as many lists as needed in chunks of $NFILES files
51# respect the run range, if given
52#
53function createGuiLists {
54 local command=ls
55 if [ $WITHALIEN -eq 1 ]; then command=alien_ls; fi
56 local dir=$AUTOFILES
57 RUNS=($($command $dir | sed 's|Run\([0-9]\{5\}\)_.*|\1|'))
58 local count=0
59 local iter=0
60 local skip=0
61 local filename=
62 local nfiles=$NFILES
63 #find first and last iterator
64 #get first and last run from range
65 local first=0
66 local last=999999999
67 local ifirst=0
68 local ilast=${#RUNS[*]}
69 if [ "x$RANGE" != "x" ]; then
70 first=$(echo $RANGE | sed 's|\(.*\)-.*|\1|')
71 last=$(echo $RANGE | sed 's|.*-\(.*\)|\1|')
72 for (( i=0; i<${#RUNS[*]}; i=i+1 )); do
73 if [ ${RUNS[i]} -ge $first ]&&[ $ifirst -eq 0 ]; then ifirst=$i; fi
74 if [ ${RUNS[i]} -gt $last ]&&[ $ilast -eq ${#RUNS[*]} ]; then ilast=$i; fi
75 done
76 fi
77 #remove old files
78 #test -d $TMPLISTDIR && rm -rf $TMPLISTDIR
79 test -d $TMPLISTDIR
80 mkdir -p $TMPLISTDIR
81 for (( i=$ifirst; i<$ilast; i=i+1 )); do
82 if [ $count -eq $nfiles ]; then
83 count=0
84 let iter=$iter+1
85 fi
86 if [ $count -eq 0 ]; then
87 local firstLocal=$(echo "$iter*$nfiles+$ifirst" | bc)
88 local lastLocal=$(echo "if ($firstLocal+$nfiles-1>=$ilast-$ifirst) $ilast-1 else $firstLocal+$nfiles-1" | bc)
89 filename=calibTreeTime_${RUNS[$firstLocal]}_${RUNS[$lastLocal]}
90 fi
91 echo ${RUNS[$i]} >> $TMPLISTDIR/$filename
92 let count=$count+1
93 done
94}
95
96function runJobs {
97 local count=0;
98 local filename=
99 for file in $TMPLISTDIR/*; do
100 if [ "x$OUTFILE" == "x" ]; then
101 filename=$(basename $file).root
102 else
103 filename=${OUTFILE}_${count}
104 fi
105 if [ $OVERWRITE -eq 0 ];then
106 test -f $OUTDIR/$filename && continue
107 fi
108 if [ $BATCH -eq 0 ]; then
109 $SCRIPTDIR/makeCalibTree -l $file -f $filename -d $OUTDIR
110 else
111 $SCRIPTDIR/makeCalibTree -l $file -f $filename -d $OUTDIR -b
112 fi
113 let count=$count+1
114 done
115}
116
117function runJobOnList {
118 if [ $OVERWRITE -eq 0 ];then
119 if [ -f $OUTDIR/$OUTFILE ]; then
120 echo "Not overwriting file '$OUTDIR/$OUTFILE' use -o to enforce it"
121 exit 0;
122 fi
123 fi
124 if [ $BATCH -eq 1 ]; then
125 $BATCHCOMMAND -oo $GUI_OUTDIR/logs/$OUTFILE.out.log -eo $GUI_OUTDIR/logs/$OUTFILE.err.log /$SCRIPTDIR/makeCalibTreeList $LISTFILE $OUTDIR/$OUTFILE $SCRIPTDIR
126 else
127 $SCRIPTDIR/makeCalibTreeList $LISTFILE $OUTDIR/$OUTFILE $SCRIPTDIR
128 fi
129}
130
131if [ "x$SCRIPTDIR" == "x" ]; then
132 echo please run:
133 echo export SCRIPTDIR=whatever_is_you_path
134 echo
135 exit 1
136fi
137source $SCRIPTDIR/guiEnv.sh
138
139
140#parse options
141TEMP=`getopt -o r:l:f:d:aboh --long range:,list:,calibDir:,outfile:,outdir:,auto,batch,overwrite,help \
142-n 'run' -- "$@"`
143
144if [ $? != 0 ] ; then usage ; fi
145
146eval set -- "$TEMP"
147
148RANGE=
149OUTFILE=
150OVERWRITE=0
151LISTFILE=
152BATCH=0
153COMMAND=
154AUTO=0
155OUTDIR=$GUI_OUTDIR_TIME
156
157while true ; do
158 case "$1" in
159 -r|--range) RANGE=$2; shift 2;;
160 -l|--list) LISTFILE=$2; shift 2;;
161 -f|--outfile) OUTFILE=$2; shift 2;;
162 -d|--outdir) OUTDIR=$2; shift 2;;
163 -a|--auto) AUTO=1; shift;;
164 -b|--batch) BATCH=1; shift;;
165 -o|--overwrite) OVERWRITE=1; shift;;
166 -h|--help) usage;;
167 --) shift ; break ;;
168 *) echo "Internal error!" ; exit 1 ;;
169 esac
170done
171
172
173
174if [ $AUTO -eq 1 ]; then
175 test -d $OUTDIR || mkdir -p $OUTDIR
176 #remove last file if it does not contain $NFILES files
177 lastfile=$(ls $OUTDIR/* | tail -1)
178 if [ "x$lastfile" != "x" ]; then
179 nfiles=$(wc -l $lastfile | awk '{print $1}')
180 if [ $nfiles -ne $NFILES ]; then
181 rm $lastfile
182 fi
183 fi
184 createGuiLists
185 runJobs
186 echo "files written to '$OUTDIR'"
187 exit 0
188fi
189
190if [ "x$RANGE" != "x" ]&&[ "x$LISTFILE" == "x" ]; then
191 test -d $OUTDIR || mkdir -p $OUTDIR
192 createRangeList
193 runJobs
194 exit 0
195fi
196
197if [ "x$RANGE" == "x" ]&&[ "x$LISTFILE" != "x" ]; then
198 test -d $OUTDIR || mkdir -p $OUTDIR
199 runJobOnList
200 exit 0
201fi
202
203#we should have left already, so show usage
204usage