Ignore:
Timestamp:
02/02/17 02:49:00 (8 years ago)
Author:
Daniela Dorner
Message:
implemented current triggers in the script
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataCheck/QuickLook/FlareAlerts.sh

    r18741 r18742  
    55printprocesslog "INFO starting $0"
    66
    7 # binning
    8 bin=20
     7emailfrom=dorner@astro.uni-wuerzburg.de
     8emailto=dorner@astro.uni-wuerzburg.de
    99
    1010# get date
    11 # add funtion
    12 night=20160102
     11if [ "$1" != "" ]
     12then
     13   checkstring=`echo $1 | grep -E -o '^20[0-9][0-9][01][0-9][0-3][0-9]$'`
     14   echo $checkstring
     15   if [ "$checkstring" = "" ]
     16   then
     17      night=`date +%Y%m%d --date="-12 HOUR"`
     18   else
     19      night=$1
     20   fi
     21else
     22   night=`date +%Y%m%d --date="-12 HOUR"`
     23fi
     24
     25echo "Processing "$night
     26
    1327
    1428# get sources for current night from DB (RunInfo)
    15 sourcekey=1
    16 
    17 # get limits from DB
    18 siglimit=3.0
    19 exclimit=20
    20 
    21 # query to get excess rate and significance from DB
    22 query="SELECT o.* FROM"
    23 query=$query" (SELECT fRunID, IF (@os+fOnTimeAfterCuts/60.>"$bin", @sig := fNumSigEvts, @sig := @sig + fNumSigEvts) AS sigevts, "
    24 query=$query" IF (@os+fOnTimeAfterCuts/60.>"$bin", @bg := fNumBgEvts, @bg := @bg + fNumBgEvts) AS bgevts,  "
    25 query=$query" IF (@os+fOnTimeAfterCuts/60.>"$bin", @exc := fNumExcEvts, @exc := @exc + fNumExcEvts) AS excevts, "
    26 query=$query" IF (@os+fOnTimeAfterCuts/60.>"$bin", @os := fOnTimeAfterCuts/60., @os := @os + fOnTimeAfterCuts/60.) AS ontime, "
    27 query=$query" @exc/@os*60 AS excrate, "
    28 query=$query" IF (@sig>0 AND @bg*5>0 AND (@sig*Log(@sig/(@sig+@bg*5)*1.2/0.2)+@bg*5*Log(@bg*5/(@sig+@bg*5)*1.2))> 0, Sqrt((@sig*Log(@sig/(@sig+@bg*5)*1.2/0.2)+@bg*5*Log(@bg*5/(@sig+@bg*5)*1.2))*2), 0) AS sig "
    29 query=$query" FROM AnalysisResultsRunLP O LEFT JOIN RunInfo USING (fNight, fRunID) "
    30 query=$query" CROSS JOIN (SELECT @os :=0, @sig :=0, @bg := 0, @exc :=0, @rate :=0) PARAMS "
    31 query=$query" WHERE fNight="$night" AND fSourceKey="$sourcekey") o HAVING ontime > "$bin"*0.9"
    32 
    33 echo $query
    34 
    35 exit
    36 
    37 results=( `sendquery` )
    38 #echo ${results[@]}
    39 
    40 i=0
    41 while [ 0 -lt 1 ]
     29query="SELECT fSourceKey FROM RunInfo WHERE fNight="$night" AND fRunTypeKey=1 AND NOT ISNULL(fSourceKey) GROUP BY fSourceKey"
     30sourcekeys=( `sendquery` )
     31
     32# some stuff for queries:
     33ontime="IF(ISNULL(fEffectiveOn), fOnTimeAfterCuts, TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart))*fEffectiveOn)"
     34threshold="IF (ISNULL(fThresholdMinSet), fThresholdMedian, fThresholdMinSet)"
     35cu="20.0"
     36corr="1"
     37# missing: corrected excessrates
     38# missing: time-dependent CU
     39
     40function get_query_nightly_binning()
     41{
     42   # query to get information from DB
     43   query="SELECT fSourceKey AS num, "
     44   query=$query"fNight AS night, MIN(fRunID) AS runmin, MAX(fRunID) AS runmax, "
     45   query=$query"MIN(fRunStart) AS start, MAX(fRunStop) AS stop, "
     46   query=$query"ROUND(SUM("$ontime")/3600.,1) AS ontime, "
     47   query=$query"SUM(fNumSigEvts) AS sig, SUM(fNumBgEvts) AS bg, "
     48   query=$query"ROUND(SUM(fNumBgEvts)/SUM("$ontime")*3600,1) AS bgrate, "
     49   query=$query"SUM(fNumExcEvts) AS exc, "
     50   query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts)), 1) AS excerr, "
     51   query=$query"ROUND(SUM(fNumExcEvts)/SUM("$ontime")*3600,1) AS excrate, "
     52   query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600, 1) AS excrateerr, "
     53   query=$query"ROUND(SUM(fNumExcEvts*"$corr")/SUM("$ontime")*3600,1) as corexcrate, " # put here correction factor
     54   query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600*SUM(fNumExcEvts)/SUM(fNumExcEvts*"$corr"), 1) AS corexcrateerr, " # correctionfactor = exc / exc_cor, put here correction factor
     55   query=$query"ROUND(LiMa(SUM(fNumSigEvts), SUM(fNumBgEvts)),1) AS signif, "
     56   query=$query"ROUND(SUM(fNumExcEvts)/SUM("$ontime")*3600/"$cu",1) AS cu, " # make value time dependent
     57   query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600/"$cu", 1) AS cuerr, " # make value time dependent
     58   query=$query"ROUND(SUM(fNumExcEvts*"$corr")/SUM("$ontime")*3600/"$cu",1) as corcu, " # make value time dependent # put here correction factor
     59   query=$query"ROUND(ExcErr(SUM(fNumSigEvts), SUM(fNumBgEvts))/SUM("$ontime")*3600*SUM(fNumExcEvts)/SUM(fNumExcEvts*"$corr")/"$cu", 1) AS corcuerr, " # correctionfactor = exc / exc_cor # make value time dependent # put here correction factor
     60   query=$query"MIN(fZenithDistanceMin) as zdmin, MAX(fZenithDistanceMax) as zdmax, "
     61   query=$query"MIN("$threshold") as thmin, MAX("$threshold") as thmax "
     62   query=$query"FROM AnalysisResultsRunLP "
     63   query=$query"LEFT JOIN RunInfo USING (fNight, fRunID) "
     64   query=$query"WHERE fSourceKey="$sourcekey" AND fNight="$night" AND NOT ISNULL(fNumExcEvts) "
     65   query=$query"GROUP BY fNight, fSourceKey "
     66#   query=$query"ORDER BY fRunStart "
     67   query=$query"HAVING ontime > 0.5 " # at least 30 minutes of observation
     68}
     69
     70function get_query_minute_binning()
     71{
     72   # set binning
     73   if [ "$1" != "" ]
     74   then
     75      bin2=$1
     76   else
     77      bin2=$bin
     78   fi
     79   # query to get information from DB
     80   query="SELECT MAX(o.b) AS num, "
     81   query=$query"MIN(o.n) AS night, MIN(o.run) AS runmin, MAX(o.run) AS runmax, "
     82   query=$query"MIN(o.start) AS start, MAX(o.stop) AS stop, "
     83   query=$query"ROUND(SUM(o.ot)/60.,1) AS ontime, "
     84   query=$query"SUM(o.sig) AS sig, SUM(o.bg) AS bg, "
     85   query=$query"ROUND(SUM(o.bg)/SUM(o.ot)*3600,1) AS bgrate, "
     86   query=$query"SUM(o.exc) AS exc, "
     87   query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg)), 1) AS excerr, "
     88   query=$query"ROUND(SUM(o.exc)/SUM(o.ot)*3600,1) AS excrate, "
     89   query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600, 1) AS excrateerr, "
     90   query=$query"ROUND(SUM(o.exccor)/SUM(o.ot)*3600,1) as corexcrate, "
     91   query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600*SUM(o.exc)/SUM(o.exccor), 1) AS corexcrateerr, " # correctionfactor = exc / exc_cor
     92   query=$query"ROUND(LiMa(SUM(o.sig), SUM(o.bg)),1) AS signif, "
     93   query=$query"ROUND(SUM(o.exc)/SUM(o.ot)*3600/o.cu,1) AS cu, "
     94   query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600/o.cu, 1) AS cuerr, "
     95   query=$query"ROUND(SUM(o.exccor)/SUM(o.ot)*3600/o.cu,1) as corcu, "
     96   query=$query"ROUND(ExcErr(SUM(o.sig), SUM(o.bg))/SUM(o.ot)*3600*SUM(o.exc)/SUM(o.exccor)/o.cu, 1) AS corcuerr, " # correctionfactor = exc / exc_cor
     97   query=$query"MIN(o.zdmin) as zdmin, MAX(o.zdmax) as zdmax, "
     98   query=$query"MIN(o.th) as thmin, MAX(o.th) as thmax "
     99   query=$query"FROM ("
     100   query=$query"SELECT "
     101   query=$query"fRunID AS run, fNight AS n, "
     102   query=$query"@ot:= "$ontime" AS ot, "
     103   query=$query"fRunStart AS start, fRunStop AS stop, "
     104   query=$query"fNumExcEvts AS exc, fNumBgEvts AS bg, fNumSigEvts AS sig, "
     105   query=$query"fNumExcEvts*"$corr" AS exccor, " # put here correction factor
     106   query=$query$cu" as cu, " # make value time dependent
     107   query=$query"fZenithDistanceMin AS zdmin, fZenithDistanceMax AS zdmax, "
     108   query=$query$threshold" AS th, "
     109   query=$query"IF (@night=fNight AND FLOOR((@os+@ot)/"$bin2"./60.)<1, @bl, @bl := @bl + 1) AS b,  "
     110   query=$query"IF (@night=fNight AND FLOOR((@os+@ot)/"$bin2"./60.)<1, @os:=@os + @ot, @os := @ot) AS os, @"
     111   query=$query"night :=fNight AS night FROM AnalysisResultsRunLP "
     112   query=$query"LEFT JOIN RunInfo USING (fNight, fRunID) "
     113   query=$query"CROSS JOIN (SELECT @night :=0, @ot :=0, @os :=0, @bl:=0) PARAMS "
     114   query=$query"WHERE fSourceKey="$sourcekey" AND fNight="$night" AND NOT ISNULL(fNumExcEvts) "
     115   if [ "$1" != "" ]
     116   then
     117      query=$query" AND fRunID <="${results[$num+3]}
     118   fi
     119   query=$query" ORDER BY fRunStart "
     120   if [ "$1" != "" ]
     121   then
     122      query=$query"DESC"
     123   fi
     124   query=$query" ) o GROUP BY b HAVING ontime > "$bin2"*0.75 ORDER BY start "
     125   if [ "$1" != "" ]
     126   then
     127      query=$query"DESC"
     128   fi
     129   #echo $query
     130}
     131
     132function evaluate_result()
     133{
     134   oldexc=0
     135   exc=0
     136   excold=0
     137   slope=0
     138   slopeprev=0
     139   i=0
     140   # be careful with start and stop (space inbetween) -> 27 columns instead of 25
     141   while [ 0 -lt 1 ]
     142   do
     143      trigger=0
     144      num=`echo "$i * 27" | bc -l`
     145      if [ "${results[$num]}" = "" ]
     146      then
     147         break
     148      fi
     149      #night=${results[$num+1]}
     150      runid=${results[$num+2]}
     151      sig=${results[$num+18]} # significance
     152      #exc=${results[$num+14]} # excrate
     153      excold=$exc
     154      exc=${results[$num+19]} # excrate in CU
     155     
     156      if [ "$onlyifhigher" = "yes" ]
     157      then
     158         higher=` echo " $exc > $oldexc " | bc `
     159         if [ $higher -eq 1 ]
     160         then
     161            # keep old value
     162            oldexc=$exc
     163         fi
     164      fi
     165     
     166      if [ "$bin" = "" ]   
     167      then
     168         echo "  ontime: "${results[$num+8]}" h"
     169      fi
     170
     171      # fast rise/decay trigger
     172      if [ $triggertype -eq 3 ]
     173      then
     174         slopeprev=$slope
     175         sigprev=$sig
     176         if [ "$excold" = "0" ]
     177         then
     178            slope=0
     179         else
     180            slope=`echo " scale=1; ( $exc - $excold ) / ( $bin / 60. ) " | bc -l `
     181         fi
     182         get_query_minute_binning 60
     183         #echo $query
     184         results2=( `sendquery` )
     185         # need to check last hour backward
     186         if [ "${results2[19]}" = "" ]
     187         then
     188            slope60=0
     189            sig60=0
     190         else
     191            sig60=${results2[18]} # significance 1h
     192            if [ "${results2[27+19]}" = "" ]
     193            then
     194               # maybe treat this case differently
     195               slope60=${results2[19]}
     196            else
     197               slope60=`echo " ${results2[19]} - ${results2[27+19]} " | bc -l` # ie /1h
     198            fi
     199         fi
     200         #echo "exc "$exc" excold "$excold
     201         #echo "slope "$slope" prev "$slopeprev" sig "$sig" prevsig "$sigprev" sig60 "$sig60" slope60 "$slope60
     202      fi
     203      # missing: probably one should check also 20 min binning (s example 20170103)
     204
     205      echo "    "$i" "${results[$num+2]}"-"${results[$num+3]}"["${results[$num+8]}"] "$exc" "$sig
     206     
     207      case $triggertype in
     208         1)   #echo "std trigger: criteria ( $exc >= $exclimit && $sig >= $siglimit && $higher )"
     209              trigger=`echo " $exc >= $exclimit && $sig >= $siglimit && $higher " | bc -l`
     210              ;;
     211         2)   #echo "magic 501: criteria ( $exc >= $exclimit && $sig >= $siglimit && $higher )"
     212              trigger=`echo " $exc >= $exclimit && $sig >= $siglimit && $higher " | bc -l`
     213              ;;
     214         3)   #echo "magic fast rise/decay"
     215              trigger=`echo " $slope >= $slopelimit && $slopeprev >= $slopelimit && $slope60 >= $slopelimit && $sig >= $siglimit " | bc -l`
     216              ;;
     217         *)   echo $triggertype" not yet implemented"
     218              ;;
     219      esac
     220
     221      if [ $trigger -eq 1 ]
     222      then
     223         # do whatever to be done to trigger
     224         #  - send email/sms / call
     225         #  - create amon file
     226         #  - prepare email for alert
     227         #  - entry in DB
     228         
     229         if [ "$bin" = "" ]
     230         then
     231            # nightly file: simply overwrite, but do not send trigger again
     232            # or check value if it's increasing?
     233            # missing: get information from previous trigger + interpret
     234            triggerfile="/home/fact/flare.alerts/"$night"-"$exclimit"_"$siglimit"-source"$sourcekey".trigger"$triggertype
     235         else
     236            # smaller binning: check if trigger is identical
     237            triggerfile="/home/fact/flare.alerts/"$night"_"`printf %03d $runid`"-"$exclimit"_"$siglimit"-source"$sourcekey".trigger"$triggertype
     238            donetriggerfile=$triggerfile".done"
     239            #ls $donetriggerfile
     240            # write new file only if old files do not agree
     241            if [ "$donetriggerfile" != "" ] && [ -e $donetriggerfile ]
     242            then
     243               diff $donetriggerfile $triggerfile >/dev/null
     244               checkstatus=`echo $?`
     245               if [ $checkstatus -eq 0 ]
     246               then
     247                  echo "  alert already done "$donetriggerfile
     248                  i=`echo $i +1 | bc -l`
     249                  continue
     250               fi
     251            fi
     252            if [ -e $triggerfile ]
     253            then
     254               mv $triggerfile $donetriggerfile
     255            fi
     256         fi
     257         #echo $night"_"$runid" "$sourcekey" -> "$triggerfile
     258         echo "  writing "$triggerfile
     259         touch $triggerfile
     260         echo "Trigger found: " > $triggerfile
     261         echo "-------------- " >> $triggerfile
     262         echo "  type: "$triggertype >> $triggerfile
     263         echo "  excess limit: "$exclimit" evts/h" >> $triggerfile
     264         echo "  significance limit: "$siglimit" sigma" >> $triggerfile
     265         if [ "$bin" = "" ]   
     266         then
     267            echo "  nightly binning " >> $triggerfile
     268         else
     269            echo "  binning: "$bin" min" >> $triggerfile
     270         fi
     271         echo "Summary of flare event: " >> $triggerfile
     272         echo "----------------------- " >> $triggerfile
     273         echo "  source:        "$sourcename >> $triggerfile
     274         echo "  night:         "${results[$num+1]} >> $triggerfile
     275         echo "  runs:          "${results[$num+2]}" - "${results[$num+3]} >> $triggerfile
     276         echo "  start:         "${results[$num+4]}" "${results[$num+5]}" UTC" >> $triggerfile
     277         echo "  stop:          "${results[$num+6]}" "${results[$num+7]}" UTC" >> $triggerfile
     278         if [ "$bin" = "" ]
     279         then
     280            echo "  ontime:        "${results[$num+8]}" h" >> $triggerfile
     281         else
     282            echo "  ontime:        "${results[$num+8]}" min" >> $triggerfile
     283         fi
     284         #echo "  ontime:        "`echo "scale=1; ${results[$num+8]} / 60. " | bc -l`" min" #scale doesn't round properly
     285         echo "  signal:        "${results[$num+9]}" evts" >> $triggerfile
     286         echo "  background:    "${results[$num+10]}" evts" >> $triggerfile
     287         echo "  bgrate:        "${results[$num+11]}" evts/h" >> $triggerfile
     288         echo "  exc:           "${results[$num+12]}" +- "${results[$num+13]}" evts" >> $triggerfile
     289         echo "  excrate:       "${results[$num+14]}" +- "${results[$num+15]}" evts/h" >> $triggerfile
     290         echo "  corr. excrate: "${results[$num+16]}" - "${results[$num+17]}" evts/h" >> $triggerfile
     291         echo "  significance:  "${results[$num+18]}" sigma" >> $triggerfile
     292         echo "  cu:            "${results[$num+19]}" +- "${results[$num+20]}" CU" >> $triggerfile
     293         echo "  corr. cu:      "${results[$num+21]}" +- "${results[$num+22]}" CU" >> $triggerfile
     294         echo "  zd:            "${results[$num+23]}" - "${results[$num+24]}" degree" >> $triggerfile
     295         echo "  th:            "${results[$num+25]}" - "${results[$num+26]}" DAC counts" >> $triggerfile
     296         # additional information fast rise/decay trigger
     297         if [ $triggertype -eq 3 ]
     298         then
     299            echo "Flux doubling/halfing times: " >> $triggerfile
     300            echo "---------------------------- " >> $triggerfile
     301            echo "  excess: "$exc >> $triggerfile
     302            echo "  excess old: "$excold >> $triggerfile
     303            echo "  significance: "$sig >> $triggerfile
     304            echo "  significance old: "$sigprev >> $triggerfile
     305            echo "  slope: "$excold >> $triggerfile
     306            echo "  slope old: "$slopeold >> $triggerfile
     307            echo "  excess 60 min: "${results2[19]}  >> $triggerfile
     308            echo "  excess 60 min old: "${results2[27+19]} >> $triggerfile
     309            echo "  slope 60 min: "$slope60 >> $triggerfile
     310            echo "  significance 60 min: "$sig60 >> $triggerfile
     311         fi
     312         
     313         if [ "$donetriggerfile" != "" ] && [ -e $donetriggerfile ]
     314         then
     315            diff $donetriggerfile $triggerfile >/dev/null
     316            checkstatus=`echo $?`
     317            if [ $checkstatus -gt 0 ]
     318            then
     319               rm $donetriggerfile
     320            fi
     321         fi
     322         # missing: get summary of whole observation
     323         
     324         # missing AMON cases - create VOEvent-File
     325
     326         # send email only of $donetriggerfile doesn't exists
     327         ##cat $triggerfile | mail -s 'test flare alert ' -b $emailfrom -r $emailfrom $emailto
     328         #cat $triggerfile | mail -s "test flare alert for $sourcename " $emailto
     329         # that's also the cases for making a call
     330         
     331      fi
     332
     333      # counter
     334      i=`echo $i +1 | bc -l`
     335   done
     336   
     337   echo "  found "$i" data point(s)."
     338   echo ""
     339}
     340
     341for sourcekey in ${sourcekeys[@]}
     342do
     343   query="SELECT fSourceName FROM Source WHERE fSourceKey="$sourcekey
     344   sourcename=`sendquery`
     345   
     346   if [ $sourcekey -ne 1 ]
     347   then
     348      continue
     349   fi
     350   echo "Evaluation for $sourcename ... "
     351   
     352   # missing: get limits from DB (structure needs to be defined)
     353   
     354   # triggers in the frame of the MoU in the gamma-ray community
     355   triggertype=1
     356   # limits
     357   siglimit=3.0 # sigma
     358   exclimit=0.5 # CU
     359   siglimit=2.0
     360   exclimit=0.5
     361   if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ]
     362   then
     363      exclimit=3.0 # CU
     364   fi
     365   # only if rate goes even higher, we have to react
     366   onlyifhigher="yes"
     367   higher=1
     368   
     369   echo "[General gamma-ray MoU]"
     370   echo " nightly binning..."
     371   bin=
     372   # checking nightly binning
     373   get_query_nightly_binning
     374   #echo $query
     375   results=( `sendquery` )
     376   #echo ${results[@]}
     377   evaluate_result
     378   #continue
     379   
     380   # binning
     381   bin=20
     382   echo " "$bin" min binning..."
     383
     384   get_query_minute_binning
     385   #echo $query
     386   results=( `sendquery` )
     387   #echo ${results[@]}
     388   evaluate_result
     389   
     390   # triggers to MAGIC
     391   # Mrk 501 proposal
     392   triggertype=2
     393   if [ $sourcekey -eq 2 ]
     394   then
     395      siglimit=3.0
     396      exclimit=2.0 # cu
     397      echo "[Trigger to MAGIC 501 proposal]"
     398      echo " nightly binning..."
     399      bin=
     400      # checking nightly binning
     401      get_query_nightly_binning
     402      #echo $query
     403      results=( `sendquery` )
     404      #echo ${results[@]}
     405      evaluate_result
     406      #continue
     407
     408      # binning
     409      bin=20
     410      echo " "$bin" min binning..."
     411
     412      get_query_minute_binning
     413      #echo $query
     414      results=( `sendquery` )
     415      #echo ${results[@]}
     416      evaluate_result
     417   fi
     418   # Mother of ToO - fast rise/decay
     419   # sources: Mrk 421, Mrk 501, 2344, 1959
     420   triggertype=3
     421   if [ $sourcekey -eq 1 ] || [ $sourcekey -eq 2 ] || [ $sourcekey -eq 3 ] || [ $sourcekey -eq 7 ]
     422   then
     423      echo "[Trigger to MAGIC - fast rise/decay]"
     424      # keep thresholds low (or do not use in evaluation)
     425      siglimit=2.0
     426      exclimit=0.5
     427      # limits in slope
     428      slopelimit=1.0 # 1CU/h
     429      siglimith=3.0 # 1 sigma in 1 hour
     430     
     431      # binning
     432      bin=30
     433      echo " "$bin" min binning..."
     434      get_query_minute_binning
     435      #echo $query
     436      results=( `sendquery` )
     437      #echo ${results[@]}
     438      evaluate_result
     439   fi
     440   
     441   # Triggers to AMON
     442   triggertype=4
     443   echo "[Trigger to AMON]"
     444   echo " still to be defined"
     445   # missing: trigger limits and binning still to be defined
     446   # also nightly?
     447   # sub-threshold-triggers?
     448   # FP-rate?
     449   siglimit=2.0
     450   exclimit=0.5
     451   onlyifhigher="no"
     452   bin=20
     453   
     454   echo ""
     455   echo ""
     456 done
     457
     458finish
     459
     460# missing information: mjd, obs-summary, weather info (clouds? dust?)
     461# prepare directly template for email
     462
     463# missing: error emails in case no DB content / no QLA
     464# calculate delay of QLA and send email if > 30 Min
     465
     466# for archival testing:
     467for (( i=0; i < 100 ; i++))
    42468do
    43    num=`echo "$i * 7" | bc -l`
    44    if [ "${results[$num]}" = "" ]
    45    then
    46       break
    47    fi
    48    runid=${results[$num]}
    49    sig=${results[$num+6]}
    50    exc=${results[$num+5]}
    51    
    52    trigger=`echo " $exc > $exclimit && $sig > $siglimit " | bc -l`
    53    
    54 #   echo $i" "$num" "$exc" "$sig
    55    if [ $trigger -eq 1 ]
    56    then
    57       # do whatever to be done to trigger
    58       #  - send email/sms / call
    59       #  - create amon file
    60       #  - prepare email for alert
    61       echo $runid" "$exc" "$sig" -> "$trigger
    62       triggerfile="/home/fact/flare.alerts/"$night"_"$runid"_"$sourcekey".trigger"
    63       touch $triggerfile
    64    fi
    65    # counter
    66    i=`echo $i +1 | bc -l`
     469   date=`date --date="-${i}days" +%Y%m%d`
     470   /home/fact/SW.automatic.processing/DataCheck/QuickLook/FlareAlerts.sh $date
    67471done
    68472
    69 finish
    70 
    71 
    72 # store limits in DB? -> Source table
    73 # run for current night
    74 # run for each source in the current night
    75 # error emails in case no DB content / no QLA
    76 # email in case of flare
    77 # add further information
    78 #  obstime (start, stop, duration), mjd, zd-range, light-condition/threshold-range, weather, (check template)
    79 # binning as command-line-option or loop for different binnings
    80 # create VO-Event file
    81 # create template-email
    82 # add logging
    83 # add certaindate
    84 # implement option for archival testing
    85 
    86 # calculate delay of QLA and send email if > 30 Min
    87 
    88 # queries:
    89 # http://stackoverflow.com/questions/32247263/mysql-select-last-n-rows-while-sum-less-then-number
    90 # http://stackoverflow.com/questions/14890486/limiting-the-rows-to-where-the-sum-a-column-equals-a-certain-value-in-mysql
    91 
    92 
    93 
     473
Note: See TracChangeset for help on using the changeset viewer.