source: trunk/DataCheck/QuickLook/Step2a.sh@ 17050

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