Index: trunk/DataCheck/QuickLook/Step2a.sh
===================================================================
--- trunk/DataCheck/QuickLook/Step2a.sh	(revision 16676)
+++ trunk/DataCheck/QuickLook/Step2a.sh	(revision 16677)
@@ -7,183 +7,137 @@
 then 
    # get date (before 18h there is no new data to be processed)
-   datepath=`date --date="-18HOUR" +%Y/%m/%d`
+   datepaths=( `date --date="-18HOUR" +%Y/%m/%d` )
+   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
 else
-   datepath=$1
+   datepaths=( $1 )
 fi
-printprocesslog "INFO processing "$datepath
-#echo "INFO processing "$datepath
-night=`echo $datepath | sed -e 's/\///g'`
 
-numganymeds=0
+echo ${datepaths[@]}
 
-# getting all image files for this night
-printprocesslog "INFO get file list for night "$datepath
-files=( `find /loc_data/analysis/star/$datepath -type f -name '*_I.root' 2>/dev/null | sort` )
-if [ ${#files[@]} -eq 0 ]
-then
-   printprocesslog "INFO no image files available for night "$datepath
-   finish
-fi
-# write data set file
-#dspath=$anapath/$source/datasets`printf %03d $min`min/$datepath
-#dspath=$anapath/$source/datasets_run/$datepath
-dspath=$anapath/datasets_run/$datepath
-makedir $dspath
-
-for (( i=1 ; i<=${#files[@]} ; i++ ))
+for datepath in ${datepaths[@]}
 do 
-   night=`basename ${files[$i-1]} | cut -d_ -f1`
-   run=`basename ${files[$i-1]} | cut -d_ -f2`
-   printprocesslog "DEBUG night: "$night" run: "$run
-   dsfile=$dspath"/dataset"$night"_"$run".txt"
-   #echo $dsfile
-   printprocesslog "INFO writing dataset file "$dsfile
-   # write dataset only if merpp-log is available to make sure that star-file is complete
-   merpplog=`echo ${files[$i-1]} | sed -e 's/_I.root/-merpp.log/'`
-   stillrunning=`find $merpplog -mmin -1 2>/dev/null`
-   if [ -e $merpplog ] && [ "$stillrunning" == "" ]
-   then 
-      echo `dirname ${files[$i-1]}`" "`basename ${files[$i-1]}` > $dsfile
-   else
-      printprocesslog "INFO merpp still running - wait with file "${files[$i-1]}
+   printprocesslog "INFO processing "$datepath
+   echo "INFO processing "$datepath
+   night=`echo $datepath | sed -e 's/\///g'`
+   
+   numganymeds=0
+   
+   # getting all image files for this night
+   printprocesslog "INFO get file list for night "$datepath
+   files=( `find $anapath/star/$datepath -type f -name '*_I.root' 2>/dev/null | sort` )
+   if [ ${#files[@]} -eq 0 ]
+   then
+      printprocesslog "INFO no image files available for night "$datepath
       continue
    fi
-   # process only if ganymedlogfiles is not yet there
-   logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
-   if ! ls $logfile >/dev/null 2>&1
-   then
-      # fixme: why is this double? 
+   # write data set file
+   #dspath=$anapath/$source/datasets`printf %03d $min`min/$datepath
+   #dspath=$anapath/$source/datasets_run/$datepath
+   dspath=$anapath/datasets_run/$datepath
+   makedir $dspath
+
+   for (( i=1 ; i<=${#files[@]} ; i++ ))
+   do
       night=`basename ${files[$i-1]} | cut -d_ -f1`
-      runid=`basename ${files[$i-1]} | cut -d_ -f2 | cut -d. -f1`
-      #echo "night: "$night
-      #echo "runid: "$runid
-      rawfilepath=$rawdata"/"$datepath"/"
-      rawfilename=`basename ${files[$i-1]} | sed -e 's/_I.root/.fits/'`
-      #echo $rawfilepath
-      #echo $rawfilename
-      rawfile=`find $rawfilepath -name $rawfilename*`
-      printprocesslog "INFO processing "$rawfile
-      drivefile=$auxdata"/"$datepath"/"`basename ${files[$i-1]} | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
-      printprocesslog "INFO getting coordinates from "$drivefile
-      tstopi=`$factpath/fitsdump -h $rawfile  2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
-      tstopf=`$factpath/fitsdump -h $rawfile  2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
-      tstop=${tstopi}${tstopf}
-      #echo "tstop: "$tstop
-      if ls $drivefile >/dev/null 2>&1
+      run=`basename ${files[$i-1]} | cut -d_ -f2`
+      printprocesslog "DEBUG night: "$night" run: "$run
+      dsfile=$dspath"/dataset"$night"_"$run".txt"
+      #echo $dsfile
+      printprocesslog "INFO writing dataset file "$dsfile
+      # write dataset only if merpp-log is available to make sure that star-file is complete
+      if echo $resulttable1 | grep ISDC >/dev/null 2>&1
+      then 
+         query="SELECT LPAD(fSequenceID, 3, 0) FROM RunInfo WHERE fNight="$night" AND fRunID="$run
+         seq=`sendquery`
+         merpplog=`dirname ${files[$i-1]}`"/"$night"_"$seq"-merpp.log"
+      else 
+         merpplog=`echo ${files[$i-1]} | sed -e 's/_I.root/-merpp.log/'`
+      fi
+      stillrunning=`find $merpplog -mmin -1 2>/dev/null`
+      if [ -e $merpplog ] && [ "$stillrunning" == "" ]
+      then
+         echo `dirname ${files[$i-1]}`" "`basename ${files[$i-1]}` > $dsfile
+      else
+         printprocesslog "INFO merpp still running - wait with file "${files[$i-1]}
+         continue
+      fi
+      # process only if ganymedlogfiles is not yet there
+      logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
+      if ! ls $logfile >/dev/null 2>&1
+      then
+         # fixme: why is this double?
+         night=`basename ${files[$i-1]} | cut -d_ -f1`
+         runid=`basename ${files[$i-1]} | cut -d_ -f2 | cut -d. -f1`
+         #echo "night: "$night
+         #echo "runid: "$runid
+         rawfilepath=$rawdata"/"$datepath"/"
+         rawfilename=`basename ${files[$i-1]} | sed -e 's/_I.root/.fits/'`
+         #echo $rawfilepath
+         #echo $rawfilename
+         rawfile=`find $rawfilepath -name $rawfilename*`
+         printprocesslog "INFO processing "$rawfile
+         drivefile=$auxdata"/"$datepath"/"`basename ${files[$i-1]} | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
+         printprocesslog "INFO getting coordinates from "$drivefile
+         tstopi=`$factpath/fitsdump -h $rawfile  2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
+         tstopf=`$factpath/fitsdump -h $rawfile  2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
+         tstop=${tstopi}${tstopf}
+         #echo "tstop: "$tstop
+         if ls $drivefile >/dev/null 2>&1
+            then
+            coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop}  2>/dev/null | tail -1 2>&1` )
+            if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
+            then
+               printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+               #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+               continue
+            fi
+            if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
+            then
+               printprocesslog "WARN coordinates "${coordinates[@]}
+               #echo "WARN coordinates "${coordinates[@]}
+               continue
+            fi
+         else
+            printprocesslog "DEBUG coordinates "${coordinates[@]}
+            #echo "DEBUG coordinates "${coordinates[@]}
+            query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
+            sourcekey=`sendquery`
+            if [ "$sourcekey" == "" ]
+            then
+               printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
+               #echo "WARN sourcekey empty - coordinates"${coordinates[@]}" for "$rawfile
+               continue
+            fi
+            query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from source WHERE fSourceKey="$sourcekey
+            coordinates=( `sendquery` )
+            if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
+            then
+               printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+               #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
+               continue
+            fi
+            if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
+            then
+               printprocesslog "WARN coordinates "${coordinates[@]}
+               #echo "WARN coordinates "${coordinates[@]}
+               continue
+            fi
+         fi
+
+         printprocesslog "DEBUG "$logfile" "${files[$i-1]}" -"${coordinates[0]}"-"${coordinates[1]}
+         printprocesslog "DEBUG `dirname $0`/RunGanymed.sh $dsfile "${coordinates[0]}" "${coordinates[1]}
+         if [ "$qlasge" = "yes" ]
          then
-         coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop}  2>/dev/null | tail -1 2>&1` )
-         if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
-         then
-            printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
-            #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
-            continue
+            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"
+            $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
+         else
+            `dirname $0`/RunGanymed.sh $dsfile ${coordinates[0]} ${coordinates[1]}
          fi
-         if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
-         then
-            printprocesslog "WARN coordinates "${coordinates[@]}
-            #echo "WARN coordinates "${coordinates[@]}
-            continue
-         fi
-      else
-         printprocesslog "DEBUG coordinates "${coordinates[@]}
-         #echo "DEBUG coordinates "${coordinates[@]}
-         query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
-         sourcekey=`sendquery`
-         if [ "$sourcekey" == "" ]
-         then
-            printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
-            #echo "WARN sourcekey empty - coordinates"${coordinates[@]}" for "$rawfile
-            continue
-         fi
-         query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from source WHERE fSourceKey="$sourcekey
-         coordinates=( `sendquery` )
-         if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
-         then
-            printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
-            #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
-            continue
-         fi
-         if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
-         then
-            printprocesslog "WARN coordinates "${coordinates[@]}
-            #echo "WARN coordinates "${coordinates[@]}
-            continue
-         fi
+         numganymeds=`echo " $numganymeds + 1 " | bc -l`
       fi
-
-      printprocesslog "DEBUG "$logfile" "${files[$i-1]}" -"${coordinates[0]}"-"${coordinates[1]}
-      printprocesslog "DEBUG `dirname $0`/RunGanymed.sh $dsfile "${coordinates[0]}" "${coordinates[1]}
-      `dirname $0`/RunGanymed.sh $dsfile ${coordinates[0]} ${coordinates[1]}
-      numganymeds=`echo " $numganymeds + 1 " | bc -l`
-   fi
-done 
-printprocesslog "INFO found "$numganymeds" ganymeds."
-   
-#   # get list of 5min-dataset-files as starting point
-#   printprocesslog "INFO get list of dataset files for "$min"min"
-#   files=( `find $dspath -type f -name 'dataset*.txt' | sort` )
-#   minold=5
-#   # loop over data set files
-#   # copy always 2 in one new file for double observation time
-#   while [ ${#files[@]} -gt 1 ]
-#   do
-#      # get double observation time and path for datasets
-#      min=`echo " $minold + $minold " | bc -l `
-#      dspathold=$dspath
-#      dspath=$anapath"/"$source"/datasets"`printf %03d $min`"min/"$datepath
-#      makedir $dspath
-#      # loop over already existing data set files
-#      for (( i=0 ; i<=${#files[@]} ; i++ ))
-#      do
-#         # number of 1st and 2nd old dataset file
-#         num1=`echo " $i + $i + 1" | bc -l `
-#         num2=`echo " $i + $i + 2 " | bc -l `
-#         # number of new dataset file
-#         dsnum=`echo " $i + 1 " | bc -l `
-#         # continue only if 2 dataset files are left
-#         if ! [ ${files[$num1]} ]
-#         then
-#            break
-#         fi
-#         ds1=$dspathold"/dataset"$num1".txt"
-#         ds2=$dspathold"/dataset"$num2".txt"
-#         dsfile=$dspath"/dataset"$dsnum".txt"
-#         if ! [ -e $ds1 ] || ! [ -e $ds2 ]
-#         then
-#            echo $ds1" or "$ds2" is still missing -> continue."
-#            continue
-#         fi
-#         # copy two old into one new dataset file
-#         printprocesslog "INFO writing dataset "$dsfile
-#         cat $ds1 > $dsfile
-#         cat $ds2 >> $dsfile
-#         # process only if ganymedlogfiles is not yet there
-#         logfile=`echo $dsfile | sed -e 's/datasets/ganymed/' -e 's/dataset//' -e 's/[.]txt/-ganymed[.]log/'`
-#         if ! ls $logfile  >/dev/null 2>&1
-#         then
-#            echo $logfile
-#            `dirname $0`/RunGanymed.sh $source $dsfile
-#             numganymeds=`echo " $numganymeds + 1 " | bc -l`
-#         fi
-#      done
-#      # get list of new dataset files
-#      printprocesslog "INFO get list of dataset files for "$min"min"
-#      files=( `find $dspath -type f -name 'dataset*.txt' | sort` )
-#      minold=$min
-#   done
-
-#   if [ $numganymeds -gt 0 ]
-#   then 
-#       if ! ps aux | grep Step2b | grep -v grep >/dev/null 2>&1
-#       then 
-#         `dirname $0`/Step2b.sh &
-#       fi
-#       if ! ps aux | grep Step3 | grep -v grep >/dev/null 2>&1
-#       then 
-#         `dirname $0`/Step3.sh min &
-#       fi
-#      numganymeds=0
-#   fi
-#done
+   done
+   printprocesslog "INFO found "$numganymeds" ganymeds."
+done
 
 finish
+
