Index: trunk/DataCheck/QuickLook/FlareAlerts.sh
===================================================================
--- trunk/DataCheck/QuickLook/FlareAlerts.sh	(revision 18772)
+++ trunk/DataCheck/QuickLook/FlareAlerts.sh	(revision 18773)
@@ -2,8 +2,18 @@
 #
 
-# missing: install cron for current night
-# change logging to processlog
-# evaluate output of all nights
+# missing: 
 # implement DB-entries for being called
+# prepare directly template for email
+# use current value for CU in triggers
+#
+# add more information: 
+#   mjd, obs-summary, weather info (clouds? dust?), CU, corrected excrates
+#
+# evaluate output of all nights (check also for crab to estimate fluctuations)
+# error emails in case no DB content / no QLA
+# calculate delay of QLA and send email if > 30 Min
+
+# run for more nights: 
+# for (( i=0; i < 70 ; i++)); do date=`date --date="-${i}days" +%Y%m%d`; /home/fact/SW.automatic.processing/DataCheck/QuickLook/FlareAlerts.sh $date; done > logfile
 
 source `dirname $0`/../Sourcefile.sh
@@ -11,5 +21,8 @@
 
 emailfrom=dorner@astro.uni-wuerzburg.de 
-emailto=dorner@astro.uni-wuerzburg.de 
+emailto=fact-online@lists.phys.ethz.ch
+
+logfile=$runlogpath"/FlareAlerts-"$datetime".log"
+date > $logfile
 
 # get date
@@ -28,5 +41,5 @@
 fi
 
-echo "Processing "$night
+echo "Processing "$night >> $logfile
 
 
@@ -171,5 +184,5 @@
       if [ "$bin" = "" ]   
       then 
-         echo "  ontime: "${results[$num+8]}" h"
+         echo "  ontime: "${results[$num+8]}" h" >> $logfile
       fi
 
@@ -209,5 +222,5 @@
       # missing: check on still available observation time
 
-      echo "    "$i" "${results[$num+2]}"-"${results[$num+3]}"["${results[$num+8]}"] "$exc" "$sig
+      echo "    "$i" "${results[$num+2]}"-"${results[$num+3]}"["${results[$num+8]}"] "$exc" "$sig >> $logfile
       
       case $triggertype in
@@ -219,7 +232,8 @@
               ;;
          3)   #echo "magic fast rise/decay"
-              trigger=`echo " $slope >= $slopelimit && $slopeprev >= $slopelimit && $slope60 >= $slopelimit && $sig >= $siglimit " | bc -l`
+              #trigger=`echo " $slope >= $slopelimit && $slopeprev >= $slopelimit && $slope60 >= $slopelimit && $sig >= $siglimit " | bc -l`
+              trigger=`echo " ( ( $slope >= $slopelimit && $slopeprev >= $slopelimit && $slope60 >= $slopelimit ) || ( - $slope >= $slopelimit && - $slopeprev >= $slopelimit && - $slope60 >= $slopelimit  ) ) && $sig >= $siglimit " | bc -l`
               ;;
-         *)   echo $triggertype" not yet implemented"
+         *)   echo $triggertype" not yet implemented" >> $logfile
               ;;
       esac
@@ -253,5 +267,5 @@
                if [ $checkstatus -eq 0 ]
                then
-                  echo "  alert already done "$donetriggerfile
+                  echo "  alert already done "$donetriggerfile >> $logfile
                   i=`echo $i +1 | bc -l`
                   continue
@@ -264,5 +278,5 @@
          fi
          #echo $night"_"$runid" "$sourcekey" -> "$triggerfile
-         echo "  writing "$triggerfile
+         echo "  writing "$triggerfile >> $logfile
          touch $triggerfile
          echo "Trigger found: " > $triggerfile
@@ -333,5 +347,9 @@
 
          # send email only of $donetriggerfile doesn't exists
-         ##cat $triggerfile | mail -s 'test flare alert ' -b $emailfrom -r $emailfrom $emailto
+         if ! [ -e $donetriggerfile ]
+         then 
+            cat $triggerfile | mail -s 'test flare alert ' -b $emailfrom -r $emailfrom $emailto
+         fi
+         
          #cat $triggerfile | mail -s "test flare alert for $sourcename " $emailto
          # that's also the cases for making a call
@@ -343,6 +361,6 @@
    done
    
-   echo "  found "$i" data point(s)."
-   echo ""
+   echo "  found "$i" data point(s)." >> $logfile
+   echo "" >> $logfile
 }
 
@@ -351,10 +369,12 @@
    query="SELECT fSourceName FROM Source WHERE fSourceKey="$sourcekey
    sourcename=`sendquery`
-   
-   if [ $sourcekey -ne 1 ]
+
+   # ignore Crab
+   if [ $sourcekey -eq 5 ]
    then
       continue
    fi
-   echo "Evaluation for $sourcename ... "
+   printprocesslog "INFO Evaluation for $sourcename ... "
+   echo "Evaluation for $sourcename ... " >> $logfile
    
    # missing: get limits from DB (structure needs to be defined)
@@ -364,5 +384,6 @@
    # limits 
    siglimit=3.0 # sigma
-   if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ]
+   #if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ]
+   if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 5 ]
    then
       exclimit=3.0 # CU 
@@ -374,6 +395,7 @@
    higher=1
    
-   echo "[General gamma-ray MoU]"
-   echo " nightly binning..."
+   printprocesslog "INFO checking for [General gamma-ray MoU]" >> $logfile
+   echo "[General gamma-ray MoU]" >> $logfile
+   echo " nightly binning..." >> $logfile
    # checking nightly binning
    bin=
@@ -384,5 +406,5 @@
    # 20 min binning
    bin=20
-   echo " "$bin" min binning..."
+   echo " "$bin" min binning..." >> $logfile
    get_query_minute_binning
    results=( `sendquery` )
@@ -396,6 +418,7 @@
       siglimit=3.0
       exclimit=2.0 # cu
-      echo "[Trigger to MAGIC 501 proposal]"
-      echo " nightly binning..."
+      printprocesslog "INFO checking for [Trigger to MAGIC 501 proposal]" >> $logfile
+      echo "[Trigger to MAGIC 501 proposal]" >> $logfile
+      echo " nightly binning..." >> $logfile
       # checking nightly binning
       bin=
@@ -405,5 +428,5 @@
       # 20 min binning
       bin=20
-      echo " "$bin" min binning..."
+      echo " "$bin" min binning..." >> $logfile
       get_query_minute_binning
       results=( `sendquery` )
@@ -413,7 +436,9 @@
    # sources: Mrk 421, Mrk 501, 2344, 1959
    triggertype=3
-   if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 3 ] || [ $sourcekey -eq 7 ]
+   #if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 3 ] || [ $sourcekey -eq 7 ]
+   if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 3 ] || [ $sourcekey -eq 7 ] || [ $sourcekey -eq 5 ]
    then 
-      echo "[Trigger to MAGIC - fast rise/decay]"
+      printprocesslog "INFO checking for [Trigger to MAGIC - fast rise/decay]" >> $logfile
+      echo "[Trigger to MAGIC - fast rise/decay]" >> $logfile
       ## keep thresholds low (or do not use in evaluation)
       #siglimit=2.0
@@ -424,5 +449,5 @@
       # binning
       bin=30
-      echo " "$bin" min binning..."
+      echo " "$bin" min binning..." >> $logfile
       get_query_minute_binning
       results=( `sendquery` )
@@ -432,6 +457,7 @@
    # Triggers to AMON
    triggertype=4
-   echo "[Trigger to AMON]"
-   echo " still to be defined"
+   printprocesslog "INFO checking for [Trigger to AMON]" >> $logfile
+   echo "[Trigger to AMON]" >> $logfile
+   echo " still to be defined" >> $logfile
    # missing: trigger limits and binning still to be defined
    # also nightly? 
@@ -443,15 +469,9 @@
    bin=20
    
-   echo ""
-   echo ""
+   echo "" >> $logfile
+   echo "" >> $logfile
  done
 
 finish 
-
-# missing information: mjd, obs-summary, weather info (clouds? dust?)
-# prepare directly template for email
-
-# missing: error emails in case no DB content / no QLA
-# calculate delay of QLA and send email if > 30 Min
 
 # for archival testing: 
