| 1 | #!/bin/bash
|
|---|
| 2 | #
|
|---|
| 3 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 4 | printprocesslog "INFO starting $0"
|
|---|
| 5 |
|
|---|
| 6 | if [ "$1" = "" ]
|
|---|
| 7 | then
|
|---|
| 8 | # get date (before 18h there is no new data to be processed)
|
|---|
| 9 | datepaths=( `date --date="-18HOUR" +%Y/%m/%d` )
|
|---|
| 10 | datepaths=( `find -L $datapath/star -mindepth 3 -type d | sort -r | sed "s/\${datapath_for_sed}\/star//g" | sed -e 's/^\///'` ) #all available dates in star-directory
|
|---|
| 11 | else
|
|---|
| 12 | datepaths=( $1 )
|
|---|
| 13 | fi
|
|---|
| 14 |
|
|---|
| 15 | echo ${datepaths[@]}
|
|---|
| 16 |
|
|---|
| 17 | for datepath in ${datepaths[@]}
|
|---|
| 18 | do
|
|---|
| 19 | printprocesslog "INFO processing "$datepath
|
|---|
| 20 | echo "INFO processing "$datepath
|
|---|
| 21 | night=`echo $datepath | sed -e 's/\///g'`
|
|---|
| 22 |
|
|---|
| 23 | numganymeds=0
|
|---|
| 24 |
|
|---|
| 25 | # getting all image files for this night
|
|---|
| 26 | printprocesslog "INFO get file list for night "$datepath
|
|---|
| 27 | files=( `find $anapath/star/$datepath -type f -name '*_I.root' 2>/dev/null | sort` )
|
|---|
| 28 | if [ ${#files[@]} -eq 0 ]
|
|---|
| 29 | then
|
|---|
| 30 | printprocesslog "INFO no image files available for night "$datepath
|
|---|
| 31 | continue
|
|---|
| 32 | fi
|
|---|
| 33 | # write data set file
|
|---|
| 34 | #dspath=$anapath/$source/datasets`printf %03d $min`min/$datepath
|
|---|
| 35 | #dspath=$anapath/$source/datasets_run/$datepath
|
|---|
| 36 | dspath=$anapath/datasets_run/$datepath
|
|---|
| 37 | makedir $dspath
|
|---|
| 38 |
|
|---|
| 39 | for (( i=1 ; i<=${#files[@]} ; i++ ))
|
|---|
| 40 | do
|
|---|
| 41 | night=`basename ${files[$i-1]} | cut -d_ -f1`
|
|---|
| 42 | run=`basename ${files[$i-1]} | cut -d_ -f2`
|
|---|
| 43 | printprocesslog "DEBUG night: "$night" run: "$run
|
|---|
| 44 | dsfile=$dspath"/dataset"$night"_"$run".txt"
|
|---|
| 45 | #echo $dsfile
|
|---|
| 46 | printprocesslog "INFO writing dataset file "$dsfile
|
|---|
| 47 | # write dataset only if merpp-log is available to make sure that star-file is complete
|
|---|
| 48 | if echo $resulttable1 | grep ISDC >/dev/null 2>&1
|
|---|
| 49 | then
|
|---|
| 50 | query="SELECT LPAD(fSequenceID, 3, 0) FROM RunInfo WHERE fNight="$night" AND fRunID="$run
|
|---|
| 51 | seq=`sendquery`
|
|---|
| 52 | merpplog=`dirname ${files[$i-1]}`"/"$night"_"$seq"-merpp.log"
|
|---|
| 53 | else
|
|---|
| 54 | merpplog=`echo ${files[$i-1]} | sed -e 's/_I.root/-merpp.log/'`
|
|---|
| 55 | fi
|
|---|
| 56 | stillrunning=`find $merpplog -mmin -1 2>/dev/null`
|
|---|
| 57 | if [ -e $merpplog ] && [ "$stillrunning" == "" ]
|
|---|
| 58 | then
|
|---|
| 59 | echo `dirname ${files[$i-1]}`" "`basename ${files[$i-1]}` > $dsfile
|
|---|
| 60 | else
|
|---|
| 61 | printprocesslog "INFO merpp still running - wait with file "${files[$i-1]}
|
|---|
| 62 | continue
|
|---|
| 63 | fi
|
|---|
| 64 | # process only if ganymedlogfiles is not yet there
|
|---|
| 65 | logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
|
|---|
| 66 | if ! ls $logfile >/dev/null 2>&1
|
|---|
| 67 | then
|
|---|
| 68 | # fixme: why is this double?
|
|---|
| 69 | night=`basename ${files[$i-1]} | cut -d_ -f1`
|
|---|
| 70 | runid=`basename ${files[$i-1]} | cut -d_ -f2 | cut -d. -f1`
|
|---|
| 71 | #echo "night: "$night
|
|---|
| 72 | #echo "runid: "$runid
|
|---|
| 73 | rawfilepath=$rawdata"/"$datepath"/"
|
|---|
| 74 | rawfilename=`basename ${files[$i-1]} | sed -e 's/_I.root/.fits/'`
|
|---|
| 75 | #echo $rawfilepath
|
|---|
| 76 | #echo $rawfilename
|
|---|
| 77 | rawfile=`find $rawfilepath -name $rawfilename*`
|
|---|
| 78 | printprocesslog "INFO processing "$rawfile
|
|---|
| 79 | drivefile=$auxdata"/"$datepath"/"`basename ${files[$i-1]} | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
|
|---|
| 80 | printprocesslog "INFO getting coordinates from "$drivefile
|
|---|
| 81 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
|---|
| 82 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
|
|---|
| 83 | tstop=${tstopi}${tstopf}
|
|---|
| 84 | #echo "tstop: "$tstop
|
|---|
| 85 | if ls $drivefile >/dev/null 2>&1
|
|---|
| 86 | then
|
|---|
| 87 | coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
|
|---|
| 88 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 89 | then
|
|---|
| 90 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 91 | #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 92 | continue
|
|---|
| 93 | fi
|
|---|
| 94 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 95 | then
|
|---|
| 96 | printprocesslog "WARN coordinates "${coordinates[@]}
|
|---|
| 97 | #echo "WARN coordinates "${coordinates[@]}
|
|---|
| 98 | continue
|
|---|
| 99 | fi
|
|---|
| 100 | else
|
|---|
| 101 | printprocesslog "DEBUG coordinates "${coordinates[@]}
|
|---|
| 102 | #echo "DEBUG coordinates "${coordinates[@]}
|
|---|
| 103 | query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
|
|---|
| 104 | sourcekey=`sendquery`
|
|---|
| 105 | if [ "$sourcekey" == "" ]
|
|---|
| 106 | then
|
|---|
| 107 | printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
|
|---|
| 108 | #echo "WARN sourcekey empty - coordinates"${coordinates[@]}" for "$rawfile
|
|---|
| 109 | continue
|
|---|
| 110 | fi
|
|---|
| 111 | query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from source WHERE fSourceKey="$sourcekey
|
|---|
| 112 | coordinates=( `sendquery` )
|
|---|
| 113 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 114 | then
|
|---|
| 115 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 116 | #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 117 | continue
|
|---|
| 118 | fi
|
|---|
| 119 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 120 | then
|
|---|
| 121 | printprocesslog "WARN coordinates "${coordinates[@]}
|
|---|
| 122 | #echo "WARN coordinates "${coordinates[@]}
|
|---|
| 123 | continue
|
|---|
| 124 | fi
|
|---|
| 125 | fi
|
|---|
| 126 |
|
|---|
| 127 | printprocesslog "DEBUG "$logfile" "${files[$i-1]}" -"${coordinates[0]}"-"${coordinates[1]}
|
|---|
| 128 | printprocesslog "DEBUG `dirname $0`/RunGanymed.sh $dsfile "${coordinates[0]}" "${coordinates[1]}
|
|---|
| 129 | if [ "$qlasge" = "yes" ]
|
|---|
| 130 | then
|
|---|
| 131 | printprocesslog "$sgepath/qsub -b y -q fact_short -v AUTOMATIONSETUP=$AUTOMATIONSETUP -v dsfile=$dsfile -v ra=${coordinates[0]} -v dec=${coordinates[1]} -e bla.txt -o bla.txt `dirname $0`/RunGanymed.sh"
|
|---|
| 132 | $sgepath/qsub -b y -q fact_short -v AUTOMATIONSETUP=$AUTOMATIONSETUP -v dsfile=$dsfile -v ra=${coordinates[0]} -v dec=${coordinates[1]} -e bla.txt -o bla.txt `dirname $0`/RunGanymed.sh
|
|---|
| 133 | else
|
|---|
| 134 | `dirname $0`/RunGanymed.sh $dsfile ${coordinates[0]} ${coordinates[1]}
|
|---|
| 135 | fi
|
|---|
| 136 | numganymeds=`echo " $numganymeds + 1 " | bc -l`
|
|---|
| 137 | fi
|
|---|
| 138 | done
|
|---|
| 139 | printprocesslog "INFO found "$numganymeds" ganymeds."
|
|---|
| 140 | done
|
|---|
| 141 |
|
|---|
| 142 | finish
|
|---|
| 143 |
|
|---|