| 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-2008 | 
|---|
| 23 | # | 
|---|
| 24 | # | 
|---|
| 25 | # ======================================================================== | 
|---|
| 26 | # | 
|---|
| 27 | # This script is launching the calibration of sequences. | 
|---|
| 28 | # | 
|---|
| 29 | # As callisto takes some time, only one sequence is processed at once. | 
|---|
| 30 | # First the script gets a sequence number from the database, for which | 
|---|
| 31 | # the calibration has to be done (function gettodo). After setting the | 
|---|
| 32 | # status in the database (set fStartTime to know, that the sequence is | 
|---|
| 33 | # already being processed), the sequence is calibrated and the merpp | 
|---|
| 34 | # update is done. Afterwards the status in the database is updated | 
|---|
| 35 | # according to the return value of the program. In case one of the merpp | 
|---|
| 36 | # update failes, also the corresponding runnumber is inserted into the | 
|---|
| 37 | # database. | 
|---|
| 38 | # The important INFOs, WARNings and ERRORs are written not only to the | 
|---|
| 39 | # scriptlog but also to the processlog. | 
|---|
| 40 | # | 
|---|
| 41 | # The callisto.rc files are stored in the setup directory | 
|---|
| 42 | # | 
|---|
| 43 |  | 
|---|
| 44 | source `dirname $0`/sourcefile | 
|---|
| 45 | printprocesslog "INFO starting $0" | 
|---|
| 46 | program=callisto | 
|---|
| 47 | column=fCallisto | 
|---|
| 48 |  | 
|---|
| 49 | set -C | 
|---|
| 50 |  | 
|---|
| 51 | scriptlog=$runlogpath/run$program-$datetime.log | 
|---|
| 52 | date >> $scriptlog 2>&1 | 
|---|
| 53 |  | 
|---|
| 54 | # get sequence # | 
|---|
| 55 | gettodo "1" >> $scriptlog 2>&1 | 
|---|
| 56 | sequence=${primaries[0]} | 
|---|
| 57 | telnum=${primaries[1]} | 
|---|
| 58 |  | 
|---|
| 59 | # lock sequ for cal | 
|---|
| 60 | lockfile=$lockpath/lock-$table-$column-$sequence.txt | 
|---|
| 61 | checklock >> $scriptlog 2>&1 | 
|---|
| 62 |  | 
|---|
| 63 | cd $mars | 
|---|
| 64 |  | 
|---|
| 65 | # run calibration for sequence | 
|---|
| 66 | echo "run $program for sequence $sequence..." >> $scriptlog 2>&1 | 
|---|
| 67 | printprocesslog "INFO starting $program for sequence $sequence" | 
|---|
| 68 | no=`printf %08d $sequence | cut -c 0-4` | 
|---|
| 69 | no2=`printf %08d $sequence` | 
|---|
| 70 | sequfile="$sequpath/$no/sequence$no2.txt" | 
|---|
| 71 |  | 
|---|
| 72 | outpath="$datapath/$program/$no/$no2" | 
|---|
| 73 | makedir $outpath >> $scriptlog 2>&1 | 
|---|
| 74 |  | 
|---|
| 75 | # define callisto.rc files | 
|---|
| 76 | callistorcnew=$setuppath/$program/callisto.rc | 
|---|
| 77 | callistorcmux=$setuppath/$program/callisto_mux.rc | 
|---|
| 78 |  | 
|---|
| 79 | # find callisto.rc file | 
|---|
| 80 | if [ -e $outpath/callisto.rc ] | 
|---|
| 81 | then | 
|---|
| 82 | echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1 | 
|---|
| 83 | callistorcseq=$outpath/callisto.rc | 
|---|
| 84 | else | 
|---|
| 85 | echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1 | 
|---|
| 86 | if [ $sequence -gt 200000 ] | 
|---|
| 87 | then | 
|---|
| 88 | ln -vs $callistorcmux $outpath/callisto.rc >> $scriptlog 2>&1 | 
|---|
| 89 | else | 
|---|
| 90 | ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1 | 
|---|
| 91 | fi | 
|---|
| 92 | callistorcseq=$outpath/callisto.rc | 
|---|
| 93 | fi | 
|---|
| 94 |  | 
|---|
| 95 | # lock sequ for zipping | 
|---|
| 96 | lockfile=$lockpath/calzip${sequence}-${telnum}.txt | 
|---|
| 97 | # if lockfile is already existing, 1 is returned | 
|---|
| 98 | if ! checklock return 1 >> $scriptlog 2>&1 | 
|---|
| 99 | then | 
|---|
| 100 | # reset lockfile name | 
|---|
| 101 | lockfile=$lockpath/lock-$table-$column-$sequence.txt | 
|---|
| 102 | finish >> $scriptlog 2>&1 | 
|---|
| 103 | fi | 
|---|
| 104 |  | 
|---|
| 105 | setstatus "start" >> $scriptlog 2>&1 | 
|---|
| 106 |  | 
|---|
| 107 | # stage the needed files; to be removed as soon as the correct stub file size has been determined | 
|---|
| 108 | echo "staging files:" >> $scriptlog 2>&1 | 
|---|
| 109 |  | 
|---|
| 110 | echo 'root -q -b $macrospath/stage.C\("\"$sequfile\""\) | tee -a $scriptlog | intgrep' >> $scriptlog 2>&1 | 
|---|
| 111 | check0=`root -q -b $macrospath/stage.C\("\"$sequfile\""\) | tee -a $scriptlog | intgrep` | 
|---|
| 112 |  | 
|---|
| 113 | case $check0 in | 
|---|
| 114 | 0)   echo " check0=$check0 -> everything ok -> files staging..." >> $scriptlog 2>&1 | 
|---|
| 115 | printprocesslog "INFO staging files started for $sequence" | 
|---|
| 116 | ;; | 
|---|
| 117 | *)   echo " check0=$check0 -> an error occured..." >> $scriptlog 2>&1 | 
|---|
| 118 | printprocesslog "ERROR getting sequence $sequence" | 
|---|
| 119 | check="no" | 
|---|
| 120 | ;; | 
|---|
| 121 | esac | 
|---|
| 122 |  | 
|---|
| 123 |  | 
|---|
| 124 | 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 | 
|---|
| 125 | ./callisto -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile  2>> $scriptlog > /dev/null | 
|---|
| 126 | check1=$? | 
|---|
| 127 |  | 
|---|
| 128 | # remove lockfile for zip and reset lockfile name | 
|---|
| 129 | rm -v $lockfile >> $scriptlog 2>&1 | 
|---|
| 130 | lockfile=$lockpath/lock-$table-$column-$sequence.txt | 
|---|
| 131 |  | 
|---|
| 132 | case $check1 in | 
|---|
| 133 | 0)   echo " check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1 | 
|---|
| 134 | printprocesslog "INFO $program finished successfully for sequence $sequence" | 
|---|
| 135 |  | 
|---|
| 136 | printprocesslog "INFO starting merpp/ccupdate for sequence $sequence" | 
|---|
| 137 |  | 
|---|
| 138 | # updated calibrated data files with the information from the cc and caco files | 
|---|
| 139 | echo "./merpp -v3 --log=$outpath/merpp$no2.log --html=$outpath/merpp$no2.html --auto-time-stop $sequfile $outpath 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1 | 
|---|
| 140 | ./merpp -v3 --log=$outpath/merpp$no2.log --html=$outpath/merpp$no2.html --auto-time-stop $sequfile $outpath 2>> $scriptlog > /dev/null | 
|---|
| 141 | check2=$? | 
|---|
| 142 |  | 
|---|
| 143 | case $check2 in | 
|---|
| 144 | 0)   echo " check2=$check2 -> everything ok, merpp/ccupdate worked -> continue" >> $scriptlog 2>&1 | 
|---|
| 145 | printprocesslog "INFO merpp/ccupdate of sequence $sequence sucessfull" | 
|---|
| 146 | ;; | 
|---|
| 147 | *)   echo " check2=$check2 -> ERROR -> merpp/ccupdate $sequence failed" >> $scriptlog 2>&1 | 
|---|
| 148 | printprocesslog "ERROR merpp/ccupdate of sequence $sequence failed" | 
|---|
| 149 | com=$Fmerppcc | 
|---|
| 150 | check=$check2 | 
|---|
| 151 | #                comadd=$runno | 
|---|
| 152 | ;; | 
|---|
| 153 | esac | 
|---|
| 154 | ;; | 
|---|
| 155 | *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1 | 
|---|
| 156 | printprocesslog "ERROR $program failed for sequence $sequence (return code $check1)" | 
|---|
| 157 | com=$Fcallisto | 
|---|
| 158 | check=$check1 | 
|---|
| 159 | ;; | 
|---|
| 160 | esac | 
|---|
| 161 |  | 
|---|
| 162 | setstatus "stop"  >> $scriptlog 2>&1 | 
|---|
| 163 |  | 
|---|
| 164 | finish >> $scriptlog 2>&1 | 
|---|
| 165 |  | 
|---|