| 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  05/2007 <mailto:dorner@astro.uni-wuerzburg.de> | 
|---|
| 21 | # | 
|---|
| 22 | #   Copyright: MAGIC Software Development, 2000-2008 | 
|---|
| 23 | # | 
|---|
| 24 | # | 
|---|
| 25 | # ======================================================================== | 
|---|
| 26 | # | 
|---|
| 27 | # This script runs the reflector. | 
|---|
| 28 | # | 
|---|
| 29 |  | 
|---|
| 30 | source `dirname $0`/sourcefile | 
|---|
| 31 | printprocesslog "INFO starting $0" | 
|---|
| 32 | program=reflector | 
|---|
| 33 | column=fReflectorFileAvail | 
|---|
| 34 |  | 
|---|
| 35 | set -C | 
|---|
| 36 |  | 
|---|
| 37 | # printing input card to stdout | 
|---|
| 38 | function printinputcard() | 
|---|
| 39 | { | 
|---|
| 40 | echo $reflectorversion | 
|---|
| 41 | echo "verbose_level 4" | 
|---|
| 42 | echo "seeds "$seeds | 
|---|
| 43 | echo "fixed_target 0. 0. " | 
|---|
| 44 | echo "telescopes_layout 1 1" | 
|---|
| 45 | echo "telescope_position 0.0 0.0" | 
|---|
| 46 | if [ $wobble -eq 2 ] | 
|---|
| 47 | then | 
|---|
| 48 | echo "wobble_mode 1" | 
|---|
| 49 | else | 
|---|
| 50 | echo "wobble_mode 0" | 
|---|
| 51 | fi | 
|---|
| 52 | echo "ct_file $detectordir/Data/magic.def" | 
|---|
| 53 | echo "reflectivity_file $detectordir/Data/reflectivity.dat" | 
|---|
| 54 | echo "axisdev_file $detectordir/Data/axisdev.dat" | 
|---|
| 55 | echo "output_file "$outfile | 
|---|
| 56 | echo "atm_model ATM_MagicWinter" | 
|---|
| 57 | echo "cer_files " | 
|---|
| 58 | echo $infile | 
|---|
| 59 | } | 
|---|
| 60 |  | 
|---|
| 61 |  | 
|---|
| 62 | scriptlog=$runlogpath/run$program-$datetime.log | 
|---|
| 63 | date >> $scriptlog 2>&1 | 
|---|
| 64 |  | 
|---|
| 65 | # get sequence # | 
|---|
| 66 | gettodo "1">> $scriptlog 2>&1 | 
|---|
| 67 | run=${primaries[0]} | 
|---|
| 68 | # get reflector runnumber | 
|---|
| 69 | query="SELECT fReflectorRunNumber FROM MCRunData where fMCRunNumber="$run | 
|---|
| 70 | reflectorrunno=`sendquery` | 
|---|
| 71 |  | 
|---|
| 72 | # lock sequ | 
|---|
| 73 | lockfile=$lockpath/lock-$table-$column-$reflectorrunno.txt | 
|---|
| 74 | checklock >> $scriptlog 2>&1 | 
|---|
| 75 |  | 
|---|
| 76 | echo "run $program for run $run..." >> $scriptlog 2>&1 | 
|---|
| 77 | printprocesslog "INFO starting $program for run $run" | 
|---|
| 78 |  | 
|---|
| 79 | setstatus "start" >> $scriptlog 2>&1 | 
|---|
| 80 |  | 
|---|
| 81 | echo "run $program for run $run " | 
|---|
| 82 | echo "create input card... " | 
|---|
| 83 |  | 
|---|
| 84 | # get values for inputcard | 
|---|
| 85 | query="SELECT fReflectorSeed, fReflectorSeed+1 FROM MCReflectorRunData where fReflectorRunNumber="$reflectorrunno | 
|---|
| 86 | seeds=`sendquery` | 
|---|
| 87 | query="SELECT fObservationModeKEY FROM MCReflectorRunData where fReflectorRunNumber="$reflectorrunno | 
|---|
| 88 | wobble=`sendquery` | 
|---|
| 89 | query="SELECT DATE_FORMAT(fRunStart, '%Y/%m/%d') FROM MCReflectorRunData where fReflectorRunNumber="$reflectorrunno | 
|---|
| 90 | date=`sendquery` | 
|---|
| 91 | query="SELECT fParticleTypeName FROM MCCorsikaRunData " | 
|---|
| 92 | query=$query" LEFT JOIN ParticleType ON MCCorsikaRunData.fParticleTypeKEY=ParticleType.fParticleTypeKEY " | 
|---|
| 93 | query=$query" LEFT JOIN MCReflectorRunData ON MCCorsikaRunData.fCorsikaRunNumber=MCReflectorRunData.fCorsikaRunNumber " | 
|---|
| 94 | query=$query" WHERE fReflectorRunNumber="$reflectorrunno | 
|---|
| 95 | particle=`sendquery` | 
|---|
| 96 | outpath=$mcpath"/"$program"/"$date | 
|---|
| 97 | date2=`echo $date | sed -e 's/\///g'` | 
|---|
| 98 | outfile=$outpath"/"$date2"_"`printf %06d $reflectorrunno`"_"$particle".rfl" | 
|---|
| 99 | query="SELECT fCorsikaRunNumber FROM MCReflectorRunData where fReflectorRunNumber="$reflectorrunno | 
|---|
| 100 | infile=$mcpath"/corsika/"$date"/cer"`printf %06d \`sendquery\`` | 
|---|
| 101 |  | 
|---|
| 102 | echo "" >> $scriptlog 2>&1 | 
|---|
| 103 | echo "INPUTCARD:" >> $scriptlog 2>&1 | 
|---|
| 104 | echo "----------" >> $scriptlog 2>&1 | 
|---|
| 105 | echo "" >> $scriptlog 2>&1 | 
|---|
| 106 | echo "" >> $scriptlog 2>&1 | 
|---|
| 107 | printinputcard >> $scriptlog 2>&1 | 
|---|
| 108 |  | 
|---|
| 109 | makedir $outpath >> $scriptlog 2>&1 | 
|---|
| 110 | if ls $outfile >/dev/null 2>&1 | 
|---|
| 111 | then | 
|---|
| 112 | rm -v $outfile | 
|---|
| 113 | fi | 
|---|
| 114 | logfile=$outpath/$program"-"`printf %06d $reflectorrunno`".log" | 
|---|
| 115 |  | 
|---|
| 116 | cd $detectordir/ReflectorII | 
|---|
| 117 |  | 
|---|
| 118 | echo "INPUTCARD:" >| $logfile 2>&1 | 
|---|
| 119 | printinputcard >> $logfile 2>&1 | 
|---|
| 120 | echo "" >> $logfile 2>&1 | 
|---|
| 121 | echo "" >> $logfile 2>&1 | 
|---|
| 122 | printinputcard | ./reflector >> $logfile 2>&1 | 
|---|
| 123 |  | 
|---|
| 124 | check1=$? | 
|---|
| 125 |  | 
|---|
| 126 | echo "the reflector returned: "$check1 | 
|---|
| 127 |  | 
|---|
| 128 | case $check1 in | 
|---|
| 129 | 0)   echo " check1=$check1 -> everything ok " >> $scriptlog 2>&1 | 
|---|
| 130 | printprocesslog "INFO $program finished successfully for run $reflectorrunno" | 
|---|
| 131 | ;; | 
|---|
| 132 | *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1 | 
|---|
| 133 | printprocesslog "ERROR $program failed for run $reflectorrunno" | 
|---|
| 134 | com=$Freflector | 
|---|
| 135 | check=$check1 | 
|---|
| 136 | ;; | 
|---|
| 137 | esac | 
|---|
| 138 |  | 
|---|
| 139 | setstatus "stop" >> $scriptlog 2>&1 | 
|---|
| 140 |  | 
|---|
| 141 | finish >> $scriptlog 2>&1 | 
|---|
| 142 |  | 
|---|