| 1 | #!/bin/bash
|
|---|
| 2 | #
|
|---|
| 3 |
|
|---|
| 4 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 5 | printprocesslog "INFO starting $0"
|
|---|
| 6 |
|
|---|
| 7 | # get and check variables
|
|---|
| 8 | if ! [ "$1" = "" ]
|
|---|
| 9 | then
|
|---|
| 10 | starfile=$1
|
|---|
| 11 | fi
|
|---|
| 12 |
|
|---|
| 13 | if [ "$starfile" = "" ]
|
|---|
| 14 | then
|
|---|
| 15 | echo "ERROR variable starfile empty."
|
|---|
| 16 | printprocesslog "ERROR variable starfile empty."
|
|---|
| 17 | fi
|
|---|
| 18 |
|
|---|
| 19 | # getting coordinates from raw and drive or DB
|
|---|
| 20 | date=`echo $starfile | grep -o -E '20[0-9][0-9]/[0-3][0-9]/[0-3][0-9]'`
|
|---|
| 21 | drivefile=$auxdata"/"$date"/"`basename $starfile | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
|
|---|
| 22 | rawfile=$rawdata"/"$date"/"`basename $starfile | sed -e 's/_I.root/.fits.fz/'`
|
|---|
| 23 | if [ -e $rawfile ]
|
|---|
| 24 | then
|
|---|
| 25 | printprocesslog "INFO processing "$rawfile
|
|---|
| 26 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
|---|
| 27 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
|
|---|
| 28 | tstop=${tstopi}${tstopf}
|
|---|
| 29 | else
|
|---|
| 30 | printprocesslog "WARN "$rawfile" not found."
|
|---|
| 31 | fi
|
|---|
| 32 | if [ "$tstop" == "" ]
|
|---|
| 33 | then
|
|---|
| 34 | printprocesslog "WARN tstop empty "$rawfile
|
|---|
| 35 | fi
|
|---|
| 36 | if ! ls $drivefile >/dev/null 2>&1
|
|---|
| 37 | then
|
|---|
| 38 | printprocesslog "WARN "$drivefile" missing."
|
|---|
| 39 | fi
|
|---|
| 40 | if ls $drivefile >/dev/null 2>&1 && ! [ "$tstop" == "" ]
|
|---|
| 41 | then
|
|---|
| 42 | printprocesslog "INFO getting coordinates from "$drivefile
|
|---|
| 43 | coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
|
|---|
| 44 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 45 | then
|
|---|
| 46 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 47 | echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 48 | finish
|
|---|
| 49 | fi
|
|---|
| 50 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 51 | then
|
|---|
| 52 | printprocesslog "WARN coordinates "${coordinates[@]}
|
|---|
| 53 | echo "WARN coordinates "${coordinates[@]}
|
|---|
| 54 | finish
|
|---|
| 55 | fi
|
|---|
| 56 | else
|
|---|
| 57 | night=`echo $date | sed -e 's/\///g'`
|
|---|
| 58 | runid=`basename $starfile | cut -d_ -f2`
|
|---|
| 59 | printprocesslog "INFO getting coordinates from DB."
|
|---|
| 60 | query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
|
|---|
| 61 | sourcekey=`sendquery`
|
|---|
| 62 | if [ "$sourcekey" == "" ]
|
|---|
| 63 | then
|
|---|
| 64 | printprocesslog "WARN sourcekey empty for "$night"_"$runid" - coordinates"${coordinates[@]}
|
|---|
| 65 | finish
|
|---|
| 66 | fi
|
|---|
| 67 | query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from Source WHERE fSourceKey="$sourcekey
|
|---|
| 68 | coordinates=( `sendquery` )
|
|---|
| 69 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 70 | then
|
|---|
| 71 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") for "$night"_"$runid" from DB."
|
|---|
| 72 | finish
|
|---|
| 73 | fi
|
|---|
| 74 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 75 | then
|
|---|
| 76 | printprocesslog "WARN coordinates "${coordinates[@]}" for "$night"_"$runid
|
|---|
| 77 | finish
|
|---|
| 78 | fi
|
|---|
| 79 | fi
|
|---|
| 80 | ra=${coordinates[0]}
|
|---|
| 81 | dec=${coordinates[1]}
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 | outpath=`dirname $starfile | sed -e 's/star/ganymed_run/'`
|
|---|
| 85 | makedir $outpath
|
|---|
| 86 |
|
|---|
| 87 | output=$outpath/`basename $starfile | cut -d_ -f1-2`
|
|---|
| 88 | logfile=$output"-ganymed.log"
|
|---|
| 89 | ganymedfile=$output"-analysis.root"
|
|---|
| 90 |
|
|---|
| 91 | cd $mars
|
|---|
| 92 |
|
|---|
| 93 | # run ganymed
|
|---|
| 94 | printprocesslog "INFO starting ganymed.C for starfile "$starfile
|
|---|
| 95 |
|
|---|
| 96 | printprocesslog "DEBUG root -q -b fact/analysis/ganymed.C\($ra\,$dec\,"\"$starfile\""\,"\"$output\""\) | tee $logfile | intgrep"
|
|---|
| 97 | check1=`root -q -b fact/analysis/ganymed.C\($ra\,$dec\,"\"$starfile\""\,"\"$output\""\) | tee $logfile | intgrep`
|
|---|
| 98 |
|
|---|
| 99 | case $check1 in
|
|---|
| 100 | 0) printprocesslog "INFO ganymed.C was successful for starfile "$starfile" ra "$ra" dec "$dec" (check1=$check1)"
|
|---|
| 101 |
|
|---|
| 102 | echo "run numevts.C for "$ganymedfile" for table "$resulttable1 >> $logfile 2>&1
|
|---|
| 103 | printprocesslog "INFO run numevts.C for "$ganyemdfile" for table "$resulttable1
|
|---|
| 104 | printprocesslog "DEBUG root -q -b -l fact/processing/numevents.C+\("\"$ganymedfile"\"\,"\"$starfile"\"\,"\"$resulttable1"\"\,kFALSE\)"
|
|---|
| 105 | check1=`root -q -b -l fact/processing/numevents.C+\("\"$ganymedfile"\"\,"\"$starfile"\"\,"\"$resulttable1"\"\,kFALSE\) | tee $logfile | intgrep`
|
|---|
| 106 | case $check1 in
|
|---|
| 107 | 1) printprocesslog "INFO filling numevts.C was successfully for "$ganymedfile" and table "$resulttable1" (check1=$check1)"
|
|---|
| 108 | ;;
|
|---|
| 109 | 0) printprocesslog "WARN connection to DB failed in numevts.C (check1=$check1)"
|
|---|
| 110 | ;;
|
|---|
| 111 | *) printprocesslog "ERROR numevts.C failed for "$ganymedfile" and table "$resulttable1" (check1=$check1)"
|
|---|
| 112 | ;;
|
|---|
| 113 | esac
|
|---|
| 114 | ;;
|
|---|
| 115 | *) printprocesslog "ERROR ganymed.C failed for starfile "$starfile" ra "$ra" dec "$dec" (check1=$check1)"
|
|---|
| 116 | ;;
|
|---|
| 117 | esac
|
|---|
| 118 |
|
|---|
| 119 | finish
|
|---|
| 120 |
|
|---|