Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7905)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7906)
@@ -40,4 +40,7 @@
    * datacenter/scripts/sourcefile: 
      - included webpath
+
+   * datacenter/scripts/jobmanager: 
+     - added
 
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/jobmanager
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 7905)
+++ trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 7906)
@@ -1,6 +1,38 @@
 #!/bin/sh
 #
+# ========================================================================
+#
+# *
+# * This file is part of MARS, the MAGIC Analysis and Reconstruction
+# * Software. It is distributed to you in the hope that it can be a useful
+# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+# * It is distributed WITHOUT ANY WARRANTY.
+# *
+# * Permission to use, copy, modify and distribute this software and its
+# * documentation for any purpose is hereby granted without fee,
+# * provided that the above copyright notice appear in all copies and
+# * that both that copyright notice and this permission notice appear
+# * in supporting documentation. It is provided "as is" without express
+# * or implied warranty.
+# *
+#
+#
+#   Author(s): Daniela Dorner  05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2006
+#
+#
+# ========================================================================
+#
+# This a resource file for the scripts, in which paths, times and number 
+# of jobs for condor are stored. 
+#
 
-source /home/operator/condor/jobsourcefile
+
+#source `dirname $0`/sourcefile (is done in jobsourcefile)
+
+user=`whoami`
+sourcefile=/home/$user/Mars.cvs/datacenter/scripts/jobsourcefile
+source $sourcefile
 
 notcount=0
@@ -9,45 +41,20 @@
    for (( i=0 ; i < ${#scripts[@]} ; i++ ))
    do 
-      date
-      echo "sleeping $sleeptime..."
+      date  #>> $scriptlog 2>&1
+      echo "sleeping $sleeptime..." #>> $scriptlog 2>&1
       sleep $sleeptime
       dayofweek=`date +%u`
       hour=`date +%k`
-      source /home/operator/condor/jobsourcefile
-      echo "script: ${scripts[$i]}"
-      echo " day: $dayofweek hour: $hour"
-#      running=`/usr/local/bin/condor_q -global | grep -c ' R '`
-      running=`/usr/local/bin/condor_q -global | grep operator | grep -c ' R '`
-      running=`setzero $running`
-      echo " found $running jobs running"
-#      queued=`/usr/local/bin/condor_q -global -format "job\n" ProcId | wc -l`
-      queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c operator`
+      source $sourcefile
+      echo "script: ${scripts[$i]}" #>> $scriptlog 2>&1
+      echo " day: $dayofweek hour: $hour" #>> $scriptlog 2>&1
+      queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c $user`
       queued=`setzero $queued`
-      echo " found $queued jobs in the queue (incl. running jobs)"
-#      runningscript=`/usr/local/bin/condor_q -global | grep ${scripts[$i]} | grep -c ' R '`
-      runningscript=`/usr/local/bin/condor_q -global | grep operator | grep ${scripts[$i]} | grep -c ' R '`
-      runningscript=`setzero $runningscript`
-      echo " found $runningscript ${scripts[$i]} running"
-#      queuedscript=`/usr/local/bin/condor_q -global | grep -c ${scripts[$i]}`
-      queuedscript=`/usr/local/bin/condor_q -global | grep operator | grep -c ${scripts[$i]}`
+      echo " found $queued jobs in the queue (incl. running jobs)" #>> $scriptlog 2>&1
+      queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
       queuedscript=`setzero $queuedscript`
-      echo " found $queuedscript ${scripts[$i]} in the queue (incl. running jobs)"
+      echo " found $queuedscript ${scripts[$i]} in the queue (incl. running jobs)" #>> $scriptlog 2>&1
 
-      #unguenstig, da es ja f versch scripte untersch sein kann
-#      if [ "$runningscriptold" == "$runningscript" ]
-#      then
-#         echo "$runningscriptold = $runningscript"
-#         sleeptime=`echo "2 * $sleeptime" | bc`
-#         echo "new sleeptime: $sleeptime"
-#      fi
-#      runningscriptold=$runningscript
       pnototal=${pnototal[$hour]}
-      echo " pnototal=$pnototal (allowed no of jobs)"
-      if [ "$pnototal" -lt "$running" ]
-      then
-         echo " pnototal=$pnototal < $running (running) => continue"
-         echo ""
-         continue 
-      fi
       #choose array according to the day of the week
       case $dayofweek in
@@ -57,54 +64,72 @@
       num=`echo "((( $i + 1 ) * 24 ) + ( $hour + 1 ) ) - 24 - 1 " | bc `
       pnoscript=${pnos[$num]}
-      echo " => num=$num => pnoscript=$pnoscript (i.e. $pnoscript ${scripts[$i]} allowed)"
+      echo " => num=$num => pnoscript=$pnoscript (i.e. $pnoscript ${scripts[$i]} allowed)" #>> $scriptlog 2>&1
       
-      echo " queued: $queued - pnototal: $pnototal"
-      if [ "$queued" -lt "$pnototal" ]
+      echo " queued: $queued - pnototal: $pnototal" #>> $scriptlog 2>&1
+      if [ "$queued" -gt "$pnototal" ]
       then
-#         echo "$queued -lt $pnototal"
-#         if [ "$queuedscript" -lt "$queued" ]
-#         then 
-#            echo "$queuedscript -lt $queued"
-#            queuedscript=$queued
-#         fi
-         echo " queued ${scripts[$i]}: $queuedscript - pno: $pnoscript"
-         if [ "$queuedscript" -lt "$pnoscript" ]
+         continue
+      else
+         echo " queued ${scripts[$i]}: $queuedscript - pno: $pnoscript" #>> $scriptlog 2>&1
+         if [ "$queuedscript" -gt "$pnoscript" ]
          then
-            pno=`echo " $pnoscript - $queuedscript " | bc`
+            continue
          fi
       fi
+      
+      echo " gettodo..."
+      echo "getting db..."
+      db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
+      col=${scriptscolname[$i]}
+      table=`grep "$col:" $steps | sed -e "s/[.]$col://" -e 's/#//' -e 's/ //g'`
+      coltab=`grep "$col:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
+      needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
+      influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
+      primary=fSequenceFirst
+      echo "db: $db - col $col - table $table - coltab $coltab"
+      echo "needs: $needs"
+      echo "influences: $influences"
+      query="select $primary from $table where "
+      for need in $needs
+      do
+         query=$query" not isnull($need) and"
+      done
+      for influence in $influences
+      do 
+         query=$query" isnull($influence) and"
+      done
+      query=$query" isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) order by $primary desc limit 0, 1 "
+      echo "QUERY: "$query
+      echo ""
+      echo " gettodofiles -> pno"
 
       if [ "$pno" == "0" ]
       then
-         echo " pno = $pno -> continue"
-         echo ""
+         echo " pno = $pno -> continue" #>> $scriptlog 2>&1
+         echo "" #>> $scriptlog 2>&1
          continue
       fi
 
-      date=`date +\%Y/\%m/\%d`
-      condordir=/magic/datacenter/autologs/condor/$date
-      if [ ! -d $condordir ]
-      then
-        mkdir -pv $condordir
-        if [ ! -d $condordir ]
-        then
-           echo "could not make dir "$condordir
-           exit
-        fi
+      y=`date +%Y`
+      m=`date +%m`
+      d=`date +%d`
+      condordir=$logpath/condor/$y/$m/$d
+      makedir  $condordir #>> $scriptlog 2>&1
+      
+      echo "  ---> starting $pno ${scripts[$i]}..." #>> $scriptlog 2>&1
+      
+      #test
+      echo ""
+      continue
+      #test
+      if ! /usr/local/bin/condor_submit -a path=$scriptspath -a prog=${scripts[$i]} -a y=$y -a m=$m -a d=$d $scriptspath/run.condor 2>$errorlog
+      then 
+         date >> $errorlog
+         nail -s 'condor problem'  $erradrs < $errorlog
+         echo "condor is not working -> sleeping $errorsleeptime" >> $scriptlog 2>&1
+         sleep $errorsleeptime
       fi
-      
-      echo "  ---> starting $pno ${scripts[$i]}..."
-      for (( j=1 ; j <= $pno ; j++ )) 
-      do 
-         echo "$i - $pno -> sleeping...."
-         sleep 2
-         if ! /usr/local/bin/condor_submit -a dir=$scriptsdir -a prog=${scripts[$i]} -a date=$date -a hour=`date +\%H` /home/operator/condor/run.condor 2>$errorfile
-         then 
-            nail -s 'condor problem'  $adrs < $errorfile
-            echo "condor is not working -> exit"
-            exit
-         fi
-      done
-      echo ""
+      echo "" >> $scriptlog 2>&1
    done
 done
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/setup
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/setup	(revision 7906)
+++ trunk/MagicSoft/Mars/datacenter/scripts/setup	(revision 7906)
@@ -0,0 +1,81 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * This file is part of MARS, the MAGIC Analysis and Reconstruction
+# * Software. It is distributed to you in the hope that it can be a useful
+# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+# * It is distributed WITHOUT ANY WARRANTY.
+# *
+# * Permission to use, copy, modify and distribute this software and its
+# * documentation for any purpose is hereby granted without fee,
+# * provided that the above copyright notice appear in all copies and
+# * that both that copyright notice and this permission notice appear
+# * in supporting documentation. It is provided "as is" without express
+# * or implied warranty.
+# *
+#
+#
+#   Author(s): Daniela Dorner  05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2006
+#
+#
+# ========================================================================
+#
+# This a resource file for the scripts, in which the standard paths and 
+# functions, which are needed more often are stored. 
+#
+
+export ROOTSYS=/opt/root_v4.04.02g
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
+export PATH=$PATH:$ROOTSYS/bin
+
+logpath=/magic/datacenter/autologs
+lockpath=/magic/datacenter/locks
+listpath=/magic/datacenter/lists
+setuppath=/magic/datacenter/setup
+
+datapath=/magic/data
+subsystempath=/magic/subsystemdata
+sequpath=/magic/sequences
+datasetpath=/magic/datasets
+
+webpath=/www/htdocs/datacenter
+
+#addresses to which the errors are sent
+erradrs="datacenter@astro.uni-wuerzburg.de" 
+#addresses to which the changes are sent
+adrs="datacenter@astro.uni-wuerzburg.de, tbretz@astro.uni-wuerzburg.de" 
+
+
+#setup for jobmanager
+sleeptime=3 #30
+errorsleeptime=10 #180
+max=16 #maximum number of processes
+#log files (can't be defined in script itself, as script can run longer 
+#than one day
+errorlog=$logpath/jobmanager/`date +%Y/%m`/error`date +%F`.log
+scriptslog=$logpath/jobmanager/`date +%Y/%m`/jobmanager`date +%F`.log
+
+scripts=( "runcallisto" "runstar" "runganymed" "dodatacheck" ) 
+scriptscolname=( "fCallisto" "fStar" "fGanymed" "fDataCheckDone" ) 
+
+#hour:            0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
+pnototal=(       16 16 16 16 16 16 16 12 12 12 10 10 10 12 12 12 12 12 12 14 16 16 16 16 )
+pnototalwe=(     16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 )
+
+pnocallisto=(     8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8 )
+pnostar=(         8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8  8 )
+pnoganymed=(      3  3  3  3  3  3  3  2  2  2  1  1  2  2  1  1  1  1  1  2  2  3  3  3 )
+pnodatacheck=(   16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 )
+
+pnocallistowe=(  10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 )
+pnostarwe=(      10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 )
+pnoganymedwe=(    3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3  3 )
+pnodatacheckwe=( 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 16 )
+
+pnosweek=( ${pnocallisto[@]} ${pnostar[@]} ${pnoganymed[@]} ${pnodatacheck[@]} )
+pnoswe=( ${pnocallistowe[@]} ${pnostarwe[@]} ${pnoganymedwe[@]} ${pnodatacheckwe[@]} )
+
