| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # ========================================================================
|
|---|
| 4 | #
|
|---|
| 5 | # *
|
|---|
| 6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 7 | # * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 9 | # * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 10 | # *
|
|---|
| 11 | # * Permission to use, copy, modify and distribute this software and its
|
|---|
| 12 | # * documentation for any purpose is hereby granted without fee,
|
|---|
| 13 | # * provided that the above copyright notice appear in all copies and
|
|---|
| 14 | # * that both that copyright notice and this permission notice appear
|
|---|
| 15 | # * in supporting documentation. It is provided "as is" without express
|
|---|
| 16 | # * or implied warranty.
|
|---|
| 17 | # *
|
|---|
| 18 | #
|
|---|
| 19 | #
|
|---|
| 20 | # Author(s): Daniela Dorner 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
|---|
| 21 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2007
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | # This script is launching the calibration of sequences.
|
|---|
| 28 | #
|
|---|
| 29 | # In the case of calibration only one sequence is processed. Despite of
|
|---|
| 30 | # that the structure of the script is such, that also more sequences could
|
|---|
| 31 | # be processed. The restriction to one sequence has been made, as the
|
|---|
| 32 | # calibration takes some time. There's one todo file per sequence.
|
|---|
| 33 | # First the script searches for a todo file. Then the sequence from this
|
|---|
| 34 | # todo file is calibrated and the merpp update is done.
|
|---|
| 35 | #
|
|---|
| 36 | # the callisto.rc files are stored in the setup directory
|
|---|
| 37 | #
|
|---|
| 38 |
|
|---|
| 39 | source `dirname $0`/sourcefile
|
|---|
| 40 | printprocesslog "INFO starting $0"
|
|---|
| 41 | program=callisto
|
|---|
| 42 | column=fCallisto
|
|---|
| 43 |
|
|---|
| 44 | set -C
|
|---|
| 45 |
|
|---|
| 46 | scriptlog=$runlogpath/run$program-$datetime.log
|
|---|
| 47 | date >> $scriptlog 2>&1
|
|---|
| 48 |
|
|---|
| 49 | # get sequence #
|
|---|
| 50 | gettodo >> $scriptlog 2>&1
|
|---|
| 51 | sequence=$process
|
|---|
| 52 |
|
|---|
| 53 | # lock sequ for cal
|
|---|
| 54 | lockfile=$lockpath/lock-$table-$column-$sequence.txt
|
|---|
| 55 | checklock >> $scriptlog 2>&1
|
|---|
| 56 |
|
|---|
| 57 | cd $mars
|
|---|
| 58 |
|
|---|
| 59 | # run calibration for sequence
|
|---|
| 60 | echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
|
|---|
| 61 | printprocesslog "INFO starting $program for sequence $sequence"
|
|---|
| 62 | no=`printf %08d $sequence | cut -c 0-4`
|
|---|
| 63 | no2=`printf %08d $sequence`
|
|---|
| 64 | outpath="$datapath/$program/$no/$no2"
|
|---|
| 65 | makedir $outpath >> $scriptlog 2>&1
|
|---|
| 66 | sequfile="$sequpath/$no/sequence$no2.txt"
|
|---|
| 67 |
|
|---|
| 68 | # define callisto.rc files
|
|---|
| 69 | callistorcnew=$setuppath/$program/callisto.rc
|
|---|
| 70 | callistorcmux=$setuppath/$program/callisto_mux.rc
|
|---|
| 71 | # find callisto.rc file
|
|---|
| 72 | if [ -e $outpath/callisto.rc ]
|
|---|
| 73 | then
|
|---|
| 74 | echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
|
|---|
| 75 | callistorcseq=$outpath/callisto.rc
|
|---|
| 76 | else
|
|---|
| 77 | echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
|
|---|
| 78 | if [ $sequence -gt 200000 ]
|
|---|
| 79 | then
|
|---|
| 80 | ln -vs $callistorcmux $outpath/callisto.rc >> $scriptlog 2>&1
|
|---|
| 81 | else
|
|---|
| 82 | ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
|
|---|
| 83 | fi
|
|---|
| 84 | callistorcseq=$outpath/callisto.rc
|
|---|
| 85 | fi
|
|---|
| 86 |
|
|---|
| 87 | # lock sequ for zipping
|
|---|
| 88 | lockfile=$lockpath/calzip$sequence.txt
|
|---|
| 89 | # if lockfile is already existing, 1 is returned
|
|---|
| 90 | if ! checklock return 1 >> $scriptlog 2>&1
|
|---|
| 91 | then
|
|---|
| 92 | # reset lockfile name
|
|---|
| 93 | lockfile=$lockpath/lock-$table-$column-$sequence.txt
|
|---|
| 94 | finish >> $scriptlog 2>&1
|
|---|
| 95 | fi
|
|---|
| 96 |
|
|---|
| 97 | primvar=$no2
|
|---|
| 98 | setstatus "start" >> $scriptlog 2>&1
|
|---|
| 99 |
|
|---|
| 100 | echo "./callisto -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null" >> $scriptlog 2>&1
|
|---|
| 101 | ./callisto -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
|
|---|
| 102 | check1=$?
|
|---|
| 103 |
|
|---|
| 104 | # remove lockfile for zip and reset lockfile name
|
|---|
| 105 | rm -v $lockfile >> $scriptlog 2>&1
|
|---|
| 106 | lockfile=$lockpath/lock-$table-$column-$sequence.txt
|
|---|
| 107 |
|
|---|
| 108 | case $check1 in
|
|---|
| 109 | 0) echo " check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
|
|---|
| 110 | printprocesslog "INFO $program finished successfully for sequence $sequence"
|
|---|
| 111 | # running merpp update if calibration worked
|
|---|
| 112 | # finding files, which have to be updated
|
|---|
| 113 | echo "finding files to be updated..." >> $scriptlog 2>&1
|
|---|
| 114 | calfiles=`find $outpath -name *_Y_* `
|
|---|
| 115 | if [ "$calfiles" = "" ]
|
|---|
| 116 | then
|
|---|
| 117 | echo " no files found -> continue with next sequence" >> $scriptlog 2>&1
|
|---|
| 118 | printprocesslog "ERROR no calfiles found"
|
|---|
| 119 | fi
|
|---|
| 120 | echo " files to be updated: "$calfiles >> $scriptlog 2>&1
|
|---|
| 121 |
|
|---|
| 122 | merpplogpath=$outpath"/merpplogs"
|
|---|
| 123 | makedir $merpplogpath >> $scriptlog 2>&1
|
|---|
| 124 |
|
|---|
| 125 | printprocesslog "INFO doing merppupdate for sequence $sequence"
|
|---|
| 126 | # updated calibrated data files with the information from the cc and caco files
|
|---|
| 127 | for calfile in ${calfiles[@]}
|
|---|
| 128 | do
|
|---|
| 129 | echo "calfile: "$calfile >> $scriptlog 2>&1
|
|---|
| 130 | # find cc and caco file
|
|---|
| 131 | # if file is missing continue with next sequence
|
|---|
| 132 | date=`date --date \`basename $calfile | cut -d_ -f1\` +%Y/%m/%d`
|
|---|
| 133 | ccpath=$subsystempath/cc/$date
|
|---|
| 134 | cacopath=$subsystempath/caco/$date
|
|---|
| 135 | runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
|
|---|
| 136 | ccfile=`find $ccpath -name 20[0-2][0-9][01][0-9][0-3][0-9]_*${runno}_[PDCS]_*_S.rep`
|
|---|
| 137 | source=`echo $ccfile | cut -d_ -f4`
|
|---|
| 138 | cacofile=`find /magic/subsystemdata/caco/$date -name dc_20[0-2][0-9]_[01][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
|
|---|
| 139 | if [ "$ccfile" = "" ]
|
|---|
| 140 | then
|
|---|
| 141 | echo "no ccfile found for run "$runno >> $scriptlog 2>&1
|
|---|
| 142 | printprocesslog "ERROR ccfile $ccfile not found for $calfile"
|
|---|
| 143 | com=$Fnoccfile
|
|---|
| 144 | comadd=$runno
|
|---|
| 145 | check=0
|
|---|
| 146 | break
|
|---|
| 147 | fi
|
|---|
| 148 | if [ "$cacofile" = "" ]
|
|---|
| 149 | then
|
|---|
| 150 | echo "cacofile with no $runno not found" >> $scriptlog 2>&1
|
|---|
| 151 | echo "finding cacofile..." >> $scriptlog 2>&1
|
|---|
| 152 | for (( i = 0; i <= 10; i++ ))
|
|---|
| 153 | do
|
|---|
| 154 | newrun=`echo $runno - $i | bc`
|
|---|
| 155 | cacofile=`find $cacopath -name *$newrun*`
|
|---|
| 156 | if [ "$cacofile" = "" ]
|
|---|
| 157 | then
|
|---|
| 158 | if [ $i -eq 9 ]
|
|---|
| 159 | then
|
|---|
| 160 | echo "no cacofile found for runno $newrun in $cacopath" >> $scriptlog 2>&1
|
|---|
| 161 | printprocesslog "ERROR cacofile $cacofile not found for $calfile"
|
|---|
| 162 | com=$Fnocacofile
|
|---|
| 163 | comadd=$runno
|
|---|
| 164 | check=0
|
|---|
| 165 | break 2
|
|---|
| 166 | fi
|
|---|
| 167 | continue
|
|---|
| 168 | else
|
|---|
| 169 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
|---|
| 170 | break
|
|---|
| 171 | fi
|
|---|
| 172 | done
|
|---|
| 173 | fi
|
|---|
| 174 | echo "./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
|
|---|
| 175 | ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
|
|---|
| 176 | check2=$?
|
|---|
| 177 | case $check2 in
|
|---|
| 178 | 0) echo " check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1
|
|---|
| 179 | printprocesslog "INFO merppupdated $calfile sucessfully with $ccfile"
|
|---|
| 180 | ;;
|
|---|
| 181 | *) echo " check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
|
|---|
| 182 | printprocesslog "ERROR merppccupdate with file $ccfile failed for $calfile"
|
|---|
| 183 | com=$Fmerppcc
|
|---|
| 184 | comadd=$runno
|
|---|
| 185 | check=$check2
|
|---|
| 186 | break ;;
|
|---|
| 187 | esac
|
|---|
| 188 | echo "./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
|
|---|
| 189 | ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
|
|---|
| 190 | check3=$?
|
|---|
| 191 | case $check3 in
|
|---|
| 192 | 0) echo " check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1
|
|---|
| 193 | printprocesslog "INFO merppupdated $calfile sucessfully with $cacofile"
|
|---|
| 194 | ;;
|
|---|
| 195 | *) echo " check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
|
|---|
| 196 | printprocesslog "ERROR merppcacoupdate with file $cacofile failed for $calfile"
|
|---|
| 197 | com=$Fmerppcaco
|
|---|
| 198 | comadd=$runno
|
|---|
| 199 | check=$check3
|
|---|
| 200 | break ;;
|
|---|
| 201 | esac
|
|---|
| 202 | done
|
|---|
| 203 | printprocesslog "INFO finished merppupdate successfully for sequence $sequence"
|
|---|
| 204 | ;;
|
|---|
| 205 | *) echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
|
|---|
| 206 | printprocesslog "ERROR $program failed for sequence $sequence (return code $check1)"
|
|---|
| 207 | com=$Fcallisto
|
|---|
| 208 | check=$check1
|
|---|
| 209 | ;;
|
|---|
| 210 | esac
|
|---|
| 211 |
|
|---|
| 212 | setstatus "stop" >> $scriptlog 2>&1
|
|---|
| 213 |
|
|---|
| 214 | finish >> $scriptlog 2>&1
|
|---|
| 215 |
|
|---|