6 echo "makeCalibTree [options]"
9 echo " -r, --range : create tree for the given range of runs"
10 echo " e.g. 70000-80000"
11 echo " -a, --auto : create trees in chunks of \$NFILES for all the files"
12 echo " found in the OCDB entries of \$AUTOFILES"
13 echo " -l, --list : text file with a list of runs to process"
14 echo " -d, --outdir : output file directory"
15 echo " -f, --outfile : output file name"
16 echo " -b, --batch : run as batch job(s)"
17 echo " -o, --overwrite : overwrite old files"
18 echo " -h, --help : display this help"
25 # create a list of files in $RANGE which are also available in $AUTOFILES
27 function 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
33 if [ $WITHALIEN -eq 1 ]; then command=alien_ls; fi
35 RUNS=($($command $dir | sed 's|Run\([0-9]\{5\}\)_.*|\1|'))
37 local filename=calibTreeTime_${first}_${last}
39 #test -d $TMPLISTDIR && rm -rf $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
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
53 function createGuiLists {
55 if [ $WITHALIEN -eq 1 ]; then command=alien_ls; fi
57 RUNS=($($command $dir | sed 's|Run\([0-9]\{5\}\)_.*|\1|'))
63 #find first and last iterator
64 #get first and last run from range
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
78 #test -d $TMPLISTDIR && rm -rf $TMPLISTDIR
81 for (( i=$ifirst; i<$ilast; i=i+1 )); do
82 if [ $count -eq $nfiles ]; then
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]}
91 echo ${RUNS[$i]} >> $TMPLISTDIR/$filename
99 for file in $TMPLISTDIR/*; do
100 if [ "x$OUTFILE" == "x" ]; then
101 filename=$(basename $file).root
103 filename=${OUTFILE}_${count}
105 if [ $OVERWRITE -eq 0 ];then
106 test -f $OUTDIR/$filename && continue
108 if [ $BATCH -eq 0 ]; then
109 $SCRIPTDIR/makeCalibTree -l $file -f $filename -d $OUTDIR
111 $SCRIPTDIR/makeCalibTree -l $file -f $filename -d $OUTDIR -b
117 function 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"
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
127 $SCRIPTDIR/makeCalibTreeList $LISTFILE $OUTDIR/$OUTFILE $SCRIPTDIR
131 if [ "x$SCRIPTDIR" == "x" ]; then
133 echo export SCRIPTDIR=whatever_is_you_path
137 source $SCRIPTDIR/guiEnv.sh
141 TEMP=`getopt -o r:l:f:d:aboh --long range:,list:,calibDir:,outfile:,outdir:,auto,batch,overwrite,help \
144 if [ $? != 0 ] ; then usage ; fi
155 OUTDIR=$GUI_OUTDIR_TIME
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;;
168 *) echo "Internal error!" ; exit 1 ;;
174 if [ $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
186 echo "files written to '$OUTDIR'"
190 if [ "x$RANGE" != "x" ]&&[ "x$LISTFILE" == "x" ]; then
191 test -d $OUTDIR || mkdir -p $OUTDIR
197 if [ "x$RANGE" == "x" ]&&[ "x$LISTFILE" != "x" ]; then
198 test -d $OUTDIR || mkdir -p $OUTDIR
203 #we should have left already, so show usage