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]\{1,6\}\)_.*|\1|' | sort -n))
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]\{1,6\}\)_.*|\1|' | sort -n))
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|')
73 for (( i=0; i<${#RUNS[*]}; i=i+1 )); do
74 if [ ${RUNS[i]} -ge $first ]&&[ $ifirst -eq 0 ]; then ifirst=$i; fi
75 if [ ${RUNS[i]} -gt $last ]&&[ $ilast -eq ${#RUNS[*]} ]; then ilast=$i; fi
78 echo ${RUNS[$ifirst]}-${RUNS[$ilast-1]}
81 #test -d $TMPLISTDIR && rm -rf $TMPLISTDIR
84 for (( i=$ifirst; i<$ilast; i=i+1 )); do
85 if [ $count -eq $nfiles ]; then
89 if [ $count -eq 0 ]; then
90 local firstLocal=$(echo "$iter*$nfiles+$ifirst" | bc)
91 # local lastLocal=$(echo "if ($firstLocal+$nfiles-1>=$ilast-$ifirst) $ilast-1 else $firstLocal+$nfiles-1" | bc)
92 local lastLocal=$(echo "if (($iter+1)*$nfiles>=$ilast-$ifirst) $ilast-1 else $firstLocal+$nfiles-1" | bc)
93 filename=calibTreeTime_${RUNS[$firstLocal]}_${RUNS[$lastLocal]}
95 echo ${RUNS[$i]} >> $TMPLISTDIR/$filename
103 for file in $TMPLISTDIR/*; do
104 if [ "x$OUTFILE" == "x" ]; then
105 filename=$(basename $file).root
107 filename=${OUTFILE}_${count}
109 if [ $OVERWRITE -eq 0 ];then
110 test -f $OUTDIR/$filename && continue
112 if [ $BATCH -eq 0 ]; then
113 $SCRIPTDIR/makeCalibTree -l $file -f $filename -d $OUTDIR
115 $SCRIPTDIR/makeCalibTree -l $file -f $filename -d $OUTDIR -b
121 function runJobOnList {
122 if [ $OVERWRITE -eq 0 ];then
123 if [ -f $OUTDIR/$OUTFILE ]; then
124 echo "Not overwriting file '$OUTDIR/$OUTFILE' use -o to enforce it"
128 if [ $BATCH -eq 1 ]; then
129 $BATCHCOMMAND -oo $GUI_OUTDIR/logs/$OUTFILE.out.log -eo $GUI_OUTDIR/logs/$OUTFILE.err.log /$SCRIPTDIR/makeCalibTreeList $LISTFILE $OUTDIR/$OUTFILE $SCRIPTDIR
131 $SCRIPTDIR/makeCalibTreeList $LISTFILE $OUTDIR/$OUTFILE $SCRIPTDIR
135 if [ "x$SCRIPTDIR" == "x" ]; then
137 echo export SCRIPTDIR=whatever_is_you_path
141 source $SCRIPTDIR/guiEnv.sh
145 TEMP=`getopt -o r:l:f:d:aboh --long range:,list:,calibDir:,outfile:,outdir:,auto,batch,overwrite,help \
148 if [ $? != 0 ] ; then usage ; fi
159 OUTDIR=$GUI_OUTDIR_TIME
163 -r|--range) RANGE=$2; shift 2;;
164 -l|--list) LISTFILE=$2; shift 2;;
165 -f|--outfile) OUTFILE=$2; shift 2;;
166 -d|--outdir) OUTDIR=$2; shift 2;;
167 -a|--auto) AUTO=1; shift;;
168 -b|--batch) BATCH=1; shift;;
169 -o|--overwrite) OVERWRITE=1; shift;;
172 *) echo "Internal error!" ; exit 1 ;;
178 if [ $AUTO -eq 1 ]; then
179 test -d $OUTDIR || mkdir -p $OUTDIR
180 #remove last file if it does not contain $NFILES files
181 lastfile=$(ls $OUTDIR/* | tail -1)
182 if [ "x$lastfile" != "x" ]; then
183 nfiles=$(wc -l $lastfile | awk '{print $1}')
184 if [ $nfiles -ne $NFILES ]; then
190 echo "files written to '$OUTDIR'"
194 if [ "x$RANGE" != "x" ]&&[ "x$LISTFILE" == "x" ]; then
195 test -d $OUTDIR || mkdir -p $OUTDIR
201 if [ "x$RANGE" == "x" ]&&[ "x$LISTFILE" != "x" ]; then
202 test -d $OUTDIR || mkdir -p $OUTDIR
207 #we should have left already, so show usage