Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7926)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7927)
@@ -18,4 +18,29 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2006/08/24 Daniela Dorner
+
+   * datacenter/scripts/sourcefile: 
+     - implemented new functions to get information from the database
+     - fixed bug in naming of variable
+
+   * datacenter/scripts/jobmanager: 
+     - implemented usage of getstatus
+     - fixed bug in naming of variable
+
+   * datacenter/scripts/runcallisto, datacenter/scripts/runstar, 
+     datacenter/scripts/runganymed, datacenter/scripts/dodatacheck: 
+     - implemented usage of gettodo
+     - removed for-loop to process several primaries
+
+   * datacenter/scripts/buildsequenceentries, 
+     datacenter/scripts/checkfilesforsequenceavail, 
+     datacenter/scripts/checkstardone, datacenter/scripts/correcttime, 
+     datacenter/scripts/doexclusions, datacenter/scripts/fillcallisto, 
+     datacenter/scripts/fillganymed, datacenter/scripts/fillstar, 
+     datacenter/scripts/writesequencefiles: 
+     - implemented usage of new getdolist function
+
+
+
  2006/08/23 Thomas Bretz
 
Index: /trunk/MagicSoft/Mars/datacenter/scripts/dodatacheck
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/dodatacheck	(revision 7926)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/dodatacheck	(revision 7927)
@@ -51,159 +51,127 @@
 date >> $scriptlog 2>&1
 
-# get todo file
-possibletodofiles=`ls -r $listpath/ToDo-*-$column-*.txt`  >> $scriptlog 2>&1
-if [ "$possibletodofiles" = "" ]
-then 
-   echo "ERROR: in $program no todofiles found => something went wrong in jobmanager"
-   finish >> $scriptlog 2>&1
-else
-   singleprocess="yes"
-   echo "todofiles: "${possibletodofiles[@]} >> $scriptlog 2>&1
-   for possibletodofile in ${possibletodofiles[@]}
-   do 
-      if ! ls $possibletodofile >> $scriptlog 2>&1
-      then 
-         echo "file is not on disk -> continue" >> $scriptlog 2>&1
-         continue
-      fi
-      lockfile=`echo $possibletodofile | sed -e 's/lists/locks/' -e 's/ToDo/lock/'`
-      checklock >> $scriptlog 2>&1
-      todofile=$possibletodofile
-   done
-fi
-if [ "$todofile" = "" ]
-then 
-   echo "no todofile found -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
+# get run # 
+gettodo >> $scriptlog 2>&1
+run=$process
 
-# get run(s) from todo file
-runs=(`cat $todofile`)
-if [ "$runs" = "" ]
-then 
-   echo "nothing to do -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
-echo "runs: "${runs[@]} >> $scriptlog 2>&1
-rm -v $todofile >> $scriptlog 2>&1
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$run.txt
+checklock >> $scriptlog 2>&1
 
 cd $mars
 
-# processing run(s)
-for run in ${runs[@]}
+echo "do $program for run "$run >> $scriptlog 2>&1
+no=`printf %08d $run | cut -c 0-2`
+no2=`printf %08d $run`
+var1=$date
+var2=$no2
+rawfile=`find /magic/data/rawfiles/ -name *${run}_[D,P,C,S]_*_E.raw -o -name *${run}_[D,P,C,S]_*_E.raw.gz`
+echo "rawfile: "$rawfile >> $scriptlog 2>&1
+date=`echo $rawfile | cut -c 22-31`
+# for sinope the date is needed in the format YYYY-MM-DD
+date2=`echo $date | sed -e 's/\//-/g'`
+
+setstatus "start" >> $scriptlog 2>&1
+
+# running filldotraw
+echo "doing filldotraw..." >> $scriptlog 2>&1
+filldotrawpath=$logpath/filldotraw/$date
+makedir $filldotrawpath >> $scriptlog 2>&1
+filldotrawlogfile=$filldotrawpath/filldotraw-$no2.log
+
+check1=`root -q -b $macrospath/filldotraw.C+\("\"$rawfile\""\,kFALSE\) | tee $filldotrawlogfile | grep int | sed -e 's/.*(int)//'`
+
+case $check1 in 
+   1)   echo " check1=$check1 -> everything ok -> go on with $program..." >> $scriptlog 2>&1
+        ;;
+   0)   echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1 
+        check="no"
+        setstatus "stop" >> $scriptlog 2>&1
+        continue ;;
+   *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        com=$Ffillraw
+        check=$check1
+        setstatus "stop" >> $scriptlog 2>&1
+        continue ;;
+esac
+
+# running sinope 
+sinopepath=$datapath/sinope/$date
+makedir $sinopepath >> $scriptlog 2>&1
+
+sins=( "-dat"  "-cal")
+for sin in ${sins[@]}
 do 
-   echo "do $program for run "$run >> $scriptlog 2>&1
-   no=`printf %08d $run | cut -c 0-2`
-   no2=`printf %08d $run`
-   var1=$date
-   var2=$no2
-   rawfile=`find /magic/data/rawfiles/ -name *${run}_[D,P,C,S]_*_E.raw -o -name *${run}_[D,P,C,S]_*_E.raw.gz`
-   echo "rawfile: "$rawfile >> $scriptlog 2>&1
-   date=`echo $rawfile | cut -c 22-31`
-   # for sinope the date is needed in the format YYYY-MM-DD
-   date2=`echo $date | sed -e 's/\//-/g'`
+   sinopefile=sinope$sin$no2
+   
+   echo "running sinope $sin..." >> $scriptlog 2>&1
+   ./sinope -b -q -v4 -f $sin --outf=$sinopefile --out=$sinopepath --log=$sinopepath/$sinopefile.log --html=$sinopepath/$sinopefile.html --run=$run --date=$date2  2>> $scriptlog > /dev/null
+   check2=$?
+   
+   case $check2 in 
+       0)   echo " check2=$check2 -> everything ok -> go on with $program..." >> $scriptlog 2>&1
+            ;;
+       *)   echo " check2=$check2 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+            com=$Fsinope
+#            comadd=
+            check=$check2
+            setstatus "stop" >> $scriptlog 2>&1
+            continue 2;;
+   esac
+   check2=1
+done
 
-   setstatus "start" >> $scriptlog 2>&1
+# running fillsinope
+fillsinopepath=$logpath/fillsinope/$date
+makedir $fillsinopepath >> $scriptlog 2>&1
+fillsinopelogfile=$fillsinopepath/fillsinope-$no2.log
 
-   # running filldotraw
-   echo "doing filldotraw..." >> $scriptlog 2>&1
-   filldotrawpath=$logpath/filldotraw/$date
-   makedir $filldotrawpath >> $scriptlog 2>&1
-   filldotrawlogfile=$filldotrawpath/filldotraw-$no2.log
+echo "doing fillsinope..." >> $scriptlog 2>&1
+check3=`root -q -b $macrospath/fillsinope.C+\($run\,"\"$datapath\""\,kFALSE\) | tee $fillsinopelogfile | grep int | sed -e 's/.*(int)//'`
 
-   check1=`root -q -b $macrospath/filldotraw.C+\("\"$rawfile\""\,kFALSE\) | tee $filldotrawlogfile | grep int | sed -e 's/.*(int)//'`
+case $check3 in 
+   1)   echo " check3=$check3 -> everything ok -> set status..." >> $scriptlog 2>&1
+        ;;
+   0)   echo " check3=$check3 -> no connection to db -> continue..." >> $scriptlog 2>&1 
+        check="no"
+        setstatus "stop" >> $scriptlog 2>&1
+        continue ;;
+   *)   echo " check3=$check3 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        com=$Ffillsinope
+        check=$check3
+        setstatus "stop" >> $scriptlog 2>&1
+        continue ;;
+esac
 
-   case $check1 in 
-      1)   echo " check1=$check1 -> everything ok -> go on with $program..." >> $scriptlog 2>&1
-           ;;
-      0)   echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1 
-           check="no"
-           setstatus "stop" >> $scriptlog 2>&1
-           continue ;;
-      *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
-           com=$Ffillraw
-           check=$check1
-           setstatus "stop" >> $scriptlog 2>&1
-           continue ;;
-   esac
-   
-   # running sinope 
-   sinopepath=$datapath/sinope/$date
-   makedir $sinopepath >> $scriptlog 2>&1
-   
-   sins=( "-dat"  "-cal")
-   for sin in ${sins[@]}
-   do 
-      sinopefile=sinope$sin$no2
-      
-      echo "running sinope $sin..." >> $scriptlog 2>&1
-      ./sinope -b -q -v4 -f $sin --outf=$sinopefile --out=$sinopepath --log=$sinopepath/$sinopefile.log --html=$sinopepath/$sinopefile.html --run=$run --date=$date2  2>> $scriptlog > /dev/null
-      check2=$?
-      
-      case $check2 in 
-          0)   echo " check2=$check2 -> everything ok -> go on with $program..." >> $scriptlog 2>&1
-               ;;
-          *)   echo " check2=$check2 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
-               com=$Fsinope
-#               comadd=
-               check=$check2
-               setstatus "stop" >> $scriptlog 2>&1
-               continue 2;;
-      esac
-      check2=1
-   done
-   
-   # running fillsinope
-   fillsinopepath=$logpath/fillsinope/$date
-   makedir $fillsinopepath >> $scriptlog 2>&1
-   fillsinopelogfile=$fillsinopepath/fillsinope-$no2.log
+# resetting the status for exclusions
+echo "resetting the status for fExclusionsDone for date $date2" >> $scriptlog 2>&1
+resetlogpath=$logpath/resetexclusions/$date
+makedir $resetlogpath >> $scriptlog 2>&1
+resetlog=$resetlogpath/reset-exclusions-$no2-$date2.log
 
-   echo "doing fillsinope..." >> $scriptlog 2>&1
-   check3=`root -q -b $macrospath/fillsinope.C+\($run\,"\"$datapath\""\,kFALSE\) | tee $fillsinopelogfile | grep int | sed -e 's/.*(int)//'`
+check5=`root -q -b $macrospath/resetcolumn.C+\("\"fExclusionsDone\""\,"\"SequenceBuildStatus\""\,"\"$date2\""\,"\"$date2\""\,kFALSE\) | tee $resetlog | grep int | sed -e 's/(int)//'`
+case $check5 in
+   1)   echo " check5=$check5 -> everything ok, fExclusions have been reset " >> $scriptlog 2>&1
+        ;;
+   0)   echo " check5=$check5 -> no connection to db -> continue..." >> $scriptlog 2>&1 
+        check="no"
+        setstatus "stop" >> $scriptlog 2>&1
+        continue ;;
+   *)   echo " check5=$check5 -> ERROR -> step could not be resetted -> repeat step " >> $scriptlog 2>&1
+        com=$Fresetexcl
+        comadd=`echo $date2 | sed -e 's/-//g'`
+        check=$check5
+        setstatus "stop" >> $scriptlog 2>&1
+        continue ;;
+esac
 
-   case $check3 in 
-      1)   echo " check3=$check3 -> everything ok -> set status..." >> $scriptlog 2>&1
-           ;;
-      0)   echo " check3=$check3 -> no connection to db -> continue..." >> $scriptlog 2>&1 
-           check="no"
-           setstatus "stop" >> $scriptlog 2>&1
-           continue ;;
-      *)   echo " check3=$check3 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
-           com=$Ffillsinope
-           check=$check3
-           setstatus "stop" >> $scriptlog 2>&1
-           continue ;;
-   esac
-
-   # resetting the status for exclusions
-   echo "resetting the status for fExclusionsDone for date $date2" >> $scriptlog 2>&1
-   resetlogpath=$logpath/resetexclusions/$date
-   makedir $resetlogpath >> $scriptlog 2>&1
-   resetlog=$resetlogpath/reset-exclusions-$no2-$date2.log
-
-   check5=`root -q -b $macrospath/resetcolumn.C+\("\"fExclusionsDone\""\,"\"SequenceBuildStatus\""\,"\"$date2\""\,"\"$date2\""\,kFALSE\) | tee $resetlog | grep int | sed -e 's/(int)//'`
-   case $check5 in
-      1)   echo " check5=$check5 -> everything ok, fExclusions have been reset " >> $scriptlog 2>&1
-           ;;
-      0)   echo " check5=$check5 -> no connection to db -> continue..." >> $scriptlog 2>&1 
-           check="no"
-           setstatus "stop" >> $scriptlog 2>&1
-           continue ;;
-      *)   echo " check5=$check5 -> ERROR -> step could not be resetted -> repeat step " >> $scriptlog 2>&1
-           com=$Fresetexcl
-           comadd=`echo $date2 | sed -e 's/-//g'`
-           check=$check5
-           setstatus "stop" >> $scriptlog 2>&1
-           continue ;;
-   esac
-
-   # set status
-   statustime="Now()"
-   failed="NULL"
-   starttime="NULL"
-   failedtime="NULL"
-   var1=$date
-   var2=$no2
-   setstatus "stop" >> $scriptlog 2>&1
+# set status
+statustime="Now()"
+failed="NULL"
+starttime="NULL"
+failedtime="NULL"
+var1=$date
+var2=$no2
+setstatus "stop" >> $scriptlog 2>&1
 done
 
Index: /trunk/MagicSoft/Mars/datacenter/scripts/jobmanager
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 7926)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/jobmanager	(revision 7927)
@@ -18,5 +18,5 @@
 #
 #
-#   Author(s): Daniela Dorner  05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+#   Author(s): Daniela Dorner  05/2006 <mailto:dorner@astro.uni-wuerzburg.de>
 #
 #   Copyright: MAGIC Software Development, 2000-2006
@@ -56,10 +56,9 @@
       queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
       queuedscript=`setzero $queuedscript`
+      runningscript=`/usr/local/bin/condor_q -global | grep $user | grep ' R ' | grep -c ${scripts[$i]}`
+      runningscript=`setzero $runningscript`
+      stillinqueue=`echo $queuedscript - $runningscript | bc `
 
-      echo "date: "`date`" --- date +%k"`date +%k` >> $jmscriptlog 2>&1
-      echo "--- hour: $hour --- pnototal(hour): ${pnototal[$hour]} --- totalpno: $totalpno ---" >> $jmscriptlog 2>&1
       totalpno=${pnototal[$hour]}
-      echo "--- hour: $hour --- pnototal(hour): ${pnototal[$hour]} --- totalpno: $totalpno ---" >> $jmscriptlog 2>&1
-      echo "date: "`date`" --- date +%k"`date +%k` >> $jmscriptlog 2>&1
       
       #choose array according to the day of the week
@@ -76,18 +75,27 @@
       if [ "$queued" -gt "$totalpno" ]
       then
-         contex >> $jmscriptlog 2>&1
+         cont >> $jmscriptlog 2>&1
       else
          if [ "$queuedscript" -gt "$pnoscript" ]
          then
-            contex >> $jmscriptlog 2>&1
+            cont >> $jmscriptlog 2>&1
          fi
       fi
 
-      # get todofile
-      lockfile=$lockpath/lock-getting-${scripts[$i]}-list.txt
-      checklock  >> $jmscriptlog 2>&1
-      singleprocess="yes"
-      gettodo  >> $jmscriptlog 2>&1
-      rm -v $lockfile >> $jmscriptlog 2>&1
+      # check if there's something to do
+      getstatus
+      if [ "$numproc" = "" ]
+      then 
+         cont >> $jmscriptlog 2>&1
+      fi
+      if ! [ $numproc -gt 0 ]
+      then
+         cont >> $jmscriptlog 2>&1
+      fi
+      if [ $numproc -lt $stillinqueue ]
+      then 
+         echo "numproc($numproc) -lt stillinqueue($stillinqueue)" >> $jmscriptlog 2>&1
+         cont >> $jmscriptlog 2>&1
+      fi
 
       date=`date +%Y/%m/%d`
Index: /trunk/MagicSoft/Mars/datacenter/scripts/runcallisto
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/runcallisto	(revision 7926)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/runcallisto	(revision 7927)
@@ -49,6 +49,4 @@
 #pno=500 # number of processes, i.e. number of todo-files
 
-lockfile=$lockpath/lock-getting-$program-list.txt
-
 scriptlogpath=$logpath/run/$program/`date +%Y/%m/%d`
 makedir $scriptlogpath
@@ -57,170 +55,138 @@
 date >> $scriptlog 2>&1
 
-# get todo file
-possibletodofiles=`ls -r $listpath/ToDo-*-$column-*.txt`  >> $scriptlog 2>&1
-if [ "$possibletodofiles" = "" ]
-then 
-   echo "ERROR: in $program no todofiles found => something went wrong in jobmanager"
-   finish >> $scriptlog 2>&1
-else
-   singleprocess="yes"
-   echo "todofiles: "${possibletodofiles[@]} >> $scriptlog 2>&1
-   for possibletodofile in ${possibletodofiles[@]}
-   do 
-      if ! ls $possibletodofile >> $scriptlog 2>&1
-      then 
-         echo "file is not on disk -> continue" >> $scriptlog 2>&1
-         continue
-      fi
-      lockfile=`echo $possibletodofile | sed -e 's/lists/locks/' -e 's/ToDo/lock/'`
-      checklock >> $scriptlog 2>&1
-      todofile=$possibletodofile
-   done
-fi
-if [ "$todofile" = "" ]
-then 
-   echo "no todofile found -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
+# get sequence # 
+gettodo >> $scriptlog 2>&1
+sequence=$process
 
-# get sequence(s) from todo file
-sequences=(`cat $todofile`)
-if [ "$sequences" = "" ]
-then 
-   echo "nothing to do -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
-echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
-rm -v $todofile >> $scriptlog 2>&1
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$sequence.txt
+checklock >> $scriptlog 2>&1
 
 cd $mars
 
-# run calibration for sequence(s)
-for sequence in ${sequences[@]}
-do 
-  echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
-  no=`printf %08d $sequence | cut -c 0-4`
-  no2=`printf %08d $sequence`
-  var1=$no
-  var2=$no2
-  outpath="$datapath/$program/$no/$no2"
-  makedir $outpath >> $scriptlog 2>&1
+# run calibration for sequence
+echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
+no=`printf %08d $sequence | cut -c 0-4`
+no2=`printf %08d $sequence`
+var1=$no
+var2=$no2
+outpath="$datapath/$program/$no/$no2"
+makedir $outpath >> $scriptlog 2>&1
 
-  sequfile="$sequpath/$no/sequence$no2.txt"
-  
-  # find callisto.rc file
-  if [ -e $outpath/callisto.rc ]
-  then
-     echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
-     callistorcseq=$outpath/callisto.rc
-  else
-     echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
-     if [ 49735 -lt $sequence ] && [ $sequence -lt 53516 ]
-     then 
-        ln -vs $callistorcmarapr05 $outpath/callisto.rc >> $scriptlog 2>&1
-     else
-        ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
-     fi
-     callistorcseq=$outpath/callisto.rc
-  fi
+sequfile="$sequpath/$no/sequence$no2.txt"
 
-  setstatus "start" >> $scriptlog 2>&1
+# find callisto.rc file
+if [ -e $outpath/callisto.rc ]
+then
+   echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
+   callistorcseq=$outpath/callisto.rc
+else
+   echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
+   if [ 49735 -lt $sequence ] && [ $sequence -lt 53516 ]
+   then 
+      ln -vs $callistorcmarapr05 $outpath/callisto.rc >> $scriptlog 2>&1
+   else
+      ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
+   fi
+   callistorcseq=$outpath/callisto.rc
+fi
 
-  ./callisto -b -q -v4 -f -raw --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile  2>> $scriptlog > /dev/null
-  check1=$?
+setstatus "start" >> $scriptlog 2>&1
 
-  case $check1 in
-     0)   echo " check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
-          # running merpp update if calibration worked
-          # finding files, which have to be updated
-          echo "finding files to be updated..." >> $scriptlog 2>&1
-          calfiles=`find $outpath -name *_Y_* `
-          echo " files to be updated: "$calfiles >> $scriptlog 2>&1
-          if [ "$calfiles" = "" ]
-          then 
-             echo " no files found -> continue with next sequence" >> $scriptlog 2>&1
-             continue
-          fi
-          
-          merpplogpath=$outpath"/merpplogs"
-          makedir $merpplogpath >> $scriptlog 2>&1
-          
-          # updated calibrated data files with the information from the cc and caco files
-          for calfile in ${calfiles[@]}
-          do 
-             echo "calfile: "$calfile >> $scriptlog 2>&1
-             # find cc and caco file
-             # if file is missing continue with next sequence
-             runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
-             ccfile=`find /magic/subsystemdata/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep`
-             source=`echo $ccfile | cut -d_ -f4`
-             cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
-#             cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
-             if [ "$ccfile" = "" ]
-             then
-                echo "no ccfile found for run "$runno >> $scriptlog 2>&1
-                com=$Fnoccfile
-                comadd=$runno
-                check=0
-                break
-             fi
-             if [ "$cacofile" = "" ]
-             then 
-                echo "cacofile with no $runno not found" >> $scriptlog 2>&1
-                echo "finding cacofile..." >> $scriptlog 2>&1
-                for (( i = 0; i <= 10; i++ ))
-                do 
-                   newrun=`echo $runno - $i | bc`
-            #      echo "$missingcacorun + $i = $newrun"
-                   path=`dirname $ccfile`
-                   path=`echo $path | sed -e 's/cc/caco/'`
-                   echo "path: "$path >> $scriptlog 2>&1
-                   cacofile=`find $path -name *$newrun*`
-                   if [ "$cacofile" = "" ]
-                   then
-                      if [ $i -eq 9 ]
-                      then
-                         echo "no cacofile found" >> $scriptlog 2>&1
-                         com=$Fnocacofile
-                         comadd=$runno
-                         check=0
-                      fi   
-                      continue
-                   else
-                      echo "cacofile: "$cacofile >> $scriptlog 2>&1
-                      break
-                   fi
-                done
-             fi
-             ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
-             check2=$?
-             case $check2 in
-                     0)   echo " check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
-         	     *)   echo " check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
-                          com=$Fmerppcc
-                          comadd=$runno
-                          check=$check2
-                          break ;;
-             esac
-             ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
-             check3=$?
-             case $check3 in
-                     0)   echo " check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
-         	     *)   echo " check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
-                          com=$Fmerppcaco
-                          comadd=$runno
-                          check=$check3
-                          break ;;
-             esac
-          done
-  	  ;;
-     *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
-          com=$Fcallisto
-          check=$check1
-          ;;
-  esac
-  
-  setstatus "stop"  >> $scriptlog 2>&1
-done
+./callisto -b -q -v4 -f -raw --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile  2>> $scriptlog > /dev/null
+check1=$?
+
+case $check1 in
+   0)   echo " check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
+        # running merpp update if calibration worked
+        # finding files, which have to be updated
+        echo "finding files to be updated..." >> $scriptlog 2>&1
+        calfiles=`find $outpath -name *_Y_* `
+        echo " files to be updated: "$calfiles >> $scriptlog 2>&1
+        if [ "$calfiles" = "" ]
+        then 
+           echo " no files found -> continue with next sequence" >> $scriptlog 2>&1
+           continue
+        fi
+        
+        merpplogpath=$outpath"/merpplogs"
+        makedir $merpplogpath >> $scriptlog 2>&1
+        
+        # updated calibrated data files with the information from the cc and caco files
+        for calfile in ${calfiles[@]}
+        do 
+           echo "calfile: "$calfile >> $scriptlog 2>&1
+           # find cc and caco file
+           # if file is missing continue with next sequence
+           runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
+           ccfile=`find /magic/subsystemdata/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep`
+           source=`echo $ccfile | cut -d_ -f4`
+           cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
+#            cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
+           if [ "$ccfile" = "" ]
+           then
+              echo "no ccfile found for run "$runno >> $scriptlog 2>&1
+              com=$Fnoccfile
+              comadd=$runno
+              check=0
+              break
+           fi
+           if [ "$cacofile" = "" ]
+           then 
+              echo "cacofile with no $runno not found" >> $scriptlog 2>&1
+              echo "finding cacofile..." >> $scriptlog 2>&1
+              for (( i = 0; i <= 10; i++ ))
+              do 
+                 newrun=`echo $runno - $i | bc`
+          #      echo "$missingcacorun + $i = $newrun"
+                 path=`dirname $ccfile`
+                 path=`echo $path | sed -e 's/cc/caco/'`
+                 echo "path: "$path >> $scriptlog 2>&1
+                 cacofile=`find $path -name *$newrun*`
+                 if [ "$cacofile" = "" ]
+                 then
+                    if [ $i -eq 9 ]
+                    then
+                       echo "no cacofile found" >> $scriptlog 2>&1
+                       com=$Fnocacofile
+                       comadd=$runno
+                       check=0
+                    fi   
+                    continue
+                 else
+                    echo "cacofile: "$cacofile >> $scriptlog 2>&1
+                    break
+                 fi
+              done
+           fi
+           ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
+           check2=$?
+           case $check2 in
+                   0)   echo " check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
+       	     *)   echo " check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
+                        com=$Fmerppcc
+                        comadd=$runno
+                        check=$check2
+                        break ;;
+           esac
+           ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
+           check3=$?
+           case $check3 in
+                   0)   echo " check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
+       	     *)   echo " check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
+                        com=$Fmerppcaco
+                        comadd=$runno
+                        check=$check3
+                        break ;;
+           esac
+        done
+	  ;;
+   *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        com=$Fcallisto
+        check=$check1
+        ;;
+esac
+
+setstatus "stop"  >> $scriptlog 2>&1
 
 finish >> $scriptlog 2>&1
Index: /trunk/MagicSoft/Mars/datacenter/scripts/runganymed
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/runganymed	(revision 7926)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/runganymed	(revision 7927)
@@ -43,7 +43,4 @@
 
 column=fGanymed
-#pno=24 # number of processes, i.e. number of todo-files
-
-lockfile=$lockpath/lock-getting-$program-list.txt
 
 scriptlogpath=$logpath/run/$program/`date +%Y/%m/%d`
@@ -53,79 +50,48 @@
 date >> $scriptlog 2>&1
 
-# get todo file
-possibletodofiles=`ls -r $listpath/ToDo-*-$column-*.txt`  >> $scriptlog 2>&1
-if [ "$possibletodofiles" = "" ]
+# get dataset # 
+gettodo >> $scriptlog 2>&1
+dataset=$process
+
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$dataset.txt
+checklock >> $scriptlog 2>&1
+
+cd $mars
+
+echo "run $program for dataset $dataset..." >> $scriptlog 2>&1
+no=`printf %08d $dataset | cut -c 0-5`
+no2=`printf %08d $dataset`
+var1=$no
+var2=$no2
+outpath="$datapath/$program/$no/$no2"
+makedir $outpath >> $scriptlog 2>&1
+
+datasetfile="$datasetpath/$no/dataset$no2.txt"
+# get observation mode to choose ganymed.rc file
+wobble=`grep 'WobbleMode:' $datasetfile` >> $scriptlog 2>&1 
+wobble2=`echo $wobble | grep ^\#` >> $scriptlog 2>&1 
+if [ "$wobble2" = "" ]
 then 
-   echo "ERROR: in $program no todofiles found => something went wrong in jobmanager"
-   finish >> $scriptlog 2>&1
+   mode="wobble" >> $scriptlog 2>&1 
 else
-   singleprocess="yes"
-   echo "todofiles: "${possibletodofiles[@]} >> $scriptlog 2>&1
-   for possibletodofile in ${possibletodofiles[@]}
-   do 
-      if ! ls $possibletodofile >> $scriptlog 2>&1
-      then 
-         echo "file is not on disk -> continue" >> $scriptlog 2>&1
-         continue
-      fi
-      lockfile=`echo $possibletodofile | sed -e 's/lists/locks/' -e 's/ToDo/lock/'`
-      checklock >> $scriptlog 2>&1
-      todofile=$possibletodofile
-   done
+   mode="onoff" >> $scriptlog 2>&1 
 fi
-if [ "$todofile" = "" ]
-then 
-   echo "no todofile found -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
+ganymedrc=$setuppath/ganymed/ganymed_$mode.rc
 
-# retrieve dataset from todo file
-datasets=(`cat $todofile`)
-if [ "$datasets" = "" ]
-then 
-   echo "nothing to do -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
-echo "datasets: "${datasets[@]} >> $scriptlog 2>&1
-rm -v $todofile >> $scriptlog 2>&1
+setstatus "start" >> $scriptlog 2>&1
 
-# run ganymed for dataset
-for dataset in ${datasets[@]}
-do 
-  echo "run $program for dataset $dataset..." >> $scriptlog 2>&1
-  no=`printf %08d $dataset | cut -c 0-5`
-  no2=`printf %08d $dataset`
-  var1=$no
-  var2=$no2
-  outpath="$datapath/$program/$no/$no2"
-  makedir $outpath >> $scriptlog 2>&1
+./ganymed -b -q -v4 -f --ind=$datapath/star --config=$ganymedrc --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath $datasetfile  2>> $scriptlog> /dev/null
+check1=$?
 
-  datasetfile="$datasetpath/$no/dataset$no2.txt"
-  # get observation mode to choose ganymed.rc file
-  wobble=`grep 'WobbleMode:' $datasetfile` >> $scriptlog 2>&1 
-  wobble2=`echo $wobble | grep ^\#` >> $scriptlog 2>&1 
-  if [ "$wobble2" = "" ]
-  then 
-     mode="wobble" >> $scriptlog 2>&1 
-  else
-     mode="onoff" >> $scriptlog 2>&1 
-  fi
-  ganymedrc=$setuppath/ganymed/ganymed_$mode.rc
-  
-  setstatus "start" >> $scriptlog 2>&1
+case $check1 in
+   0)   echo " check1=$check1 -> everything ok " >> $scriptlog 2>&1 ;;
+   *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        com=$Fganymed
+        check=$check1
+        ;;
+esac
 
-  ./ganymed -b -q -v4 -f --ind=$datapath/star --config=$ganymedrc --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath $datasetfile  2>> $scriptlog> /dev/null
-  check1=$?
-
-  case $check1 in
-     0)   echo " check1=$check1 -> everything ok " >> $scriptlog 2>&1 ;;
-     *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
-          com=$Fganymed
-          check=$check1
-          ;;
-  esac
-  
-  setstatus "stop" >> $scriptlog 2>&1
-done
+setstatus "stop" >> $scriptlog 2>&1
 
 finish >> $scriptlog 2>&1
Index: /trunk/MagicSoft/Mars/datacenter/scripts/runstar
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/runstar	(revision 7926)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/runstar	(revision 7927)
@@ -43,7 +43,4 @@
 
 column=fStar
-#pno=500 # number of processes, i.e. number of todo-files
-
-lockfile=$lockpath/lock-getting-$program-list.txt
 
 scriptlogpath=$logpath/run/$program/`date +%Y/%m/%d`
@@ -53,72 +50,39 @@
 date >> $scriptlog 2>&1
 
-# get todo file
-possibletodofiles=`ls -r $listpath/ToDo-*-$column-*.txt`  >> $scriptlog 2>&1
-if [ "$possibletodofiles" = "" ]
-then 
-   echo "ERROR: in $program no todofiles found => something went wrong in jobmanager"
-   finish >> $scriptlog 2>&1
-else
-   singleprocess="yes"
-   echo "todofiles: "${possibletodofiles[@]} >> $scriptlog 2>&1
-   for possibletodofile in ${possibletodofiles[@]}
-   do 
-      if ! ls $possibletodofile >> $scriptlog 2>&1
-      then 
-         echo "file is not on disk -> continue" >> $scriptlog 2>&1
-         continue
-      fi
-      lockfile=`echo $possibletodofile | sed -e 's/lists/locks/' -e 's/ToDo/lock/'`
-      checklock >> $scriptlog 2>&1
-      todofile=$possibletodofile
-   done
-fi
-if [ "$todofile" = "" ]
-then 
-   echo "no todofile found -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
+# get sequence # 
+gettodo >> $scriptlog 2>&1
+sequence=$process
 
-# retrieve sequence from todo file
-sequences=(`cat $todofile`)
-if [ "$sequences" = "" ]
-then 
-   echo "nothing to do -> exit"  >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
-echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
-rm -v $todofile >> $scriptlog 2>&1
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$sequence.txt
+checklock >> $scriptlog 2>&1
 
 cd $mars
 
-# run star for sequence
-for sequence in ${sequences[@]}
-do 
-  echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
-  no=`printf %08d $sequence | cut -c 0-4`
-  no2=`printf %08d $sequence`
-  var1=$no
-  var2=$no2
-  outpath="$datapath/$program/$no/$no2"
-  inpath=`echo $outpath | sed -e 's/star/callisto/'`
-  makedir $outpath >> $scriptlog 2>&1
+echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
+no=`printf %08d $sequence | cut -c 0-4`
+no2=`printf %08d $sequence`
+var1=$no
+var2=$no2
+outpath="$datapath/$program/$no/$no2"
+inpath=`echo $outpath | sed -e 's/star/callisto/'`
+makedir $outpath >> $scriptlog 2>&1
 
-  sequfile="$sequpath/$no/sequence$no2.txt"
-  
-  setstatus "start" >> $scriptlog 2>&1
+sequfile="$sequpath/$no/sequence$no2.txt"
 
-  ./star -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --ind=$inpath --out=$outpath $sequfile  2>> $scriptlog> /dev/null
-  check1=$?
+setstatus "start" >> $scriptlog 2>&1
 
-  case $check1 in
-     0)   echo " check1=$check1 -> everything ok " >> $scriptlog 2>&1;;
-     *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
-          com=$Fstar
-          check=$check1
-          ;;
-  esac
-  
-  setstatus "stop" >> $scriptlog 2>&1
-done
+./star -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --ind=$inpath --out=$outpath $sequfile  2>> $scriptlog> /dev/null
+check1=$?
+
+case $check1 in
+   0)   echo " check1=$check1 -> everything ok " >> $scriptlog 2>&1;;
+   *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        com=$Fstar
+        check=$check1
+        ;;
+esac
+
+setstatus "stop" >> $scriptlog 2>&1
 
 finish >> $scriptlog 2>&1
Index: /trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 7926)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 7927)
@@ -70,7 +70,9 @@
 Ffillganymed=21
 
+#
 # setup for jobmanager
+#
 steps=$mars/steps.rc
-
+# resetting values
 pno=0
 totalpno=0
@@ -79,5 +81,5 @@
 runningscript=0
 queuedscript=0
-
+stillinqueue=0
 
 function setzero()
@@ -100,5 +102,4 @@
 
 
-
 # in the following the function, which are needed by several scripts, are 
 # defined
@@ -113,14 +114,10 @@
 }
 
-# function to do continue in a loop or exit the program depending on what is needed
-function contex()
-{
+# function to do continue in a loop and produce according logging
+function cont()
+{
+   date
    echo ""
-   if [ "$singleprocess" = "yes" ]
-   then 
-      continue
-   else
-      finish
-   fi
+   continue
 }
 
@@ -148,5 +145,5 @@
        1)   echo " checklock0=$checklock0 -> file $lockfile exists -> exit"
             date 
-            contex;;
+            exit;;
        *)   echo " checklock0=$checklock0 -> something went completely wrong" ;;
    esac
@@ -154,5 +151,5 @@
 
 # function calling the macro, which is producing the todo-list
-function getdolist()
+function getdolistroot()
 {
    datetime=`date +%F-%H-%M-%S`
@@ -278,12 +275,8 @@
 
 # function to get todolist
-function gettodo()
-{
-   echo "getting todo..."
+function getdolist()
+{
+   echo "getting todolist..."
    getdbsetup 
-   if [ "$singleprocess" = "yes" ]
-   then 
-      column=${scriptscolname[$i]}
-   fi
    getstepinfo
    # get query
@@ -296,24 +289,12 @@
       done
    fi
-   if ! echo $influences | grep '#' > /dev/null 
-   then 
-      for influence in $influences
-      do 
-         query=$query" isnull($influence) and"
-      done
-   fi
    query=$query" isnull($column) "
    query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
    query=$query" order by $primary desc "
-   if [ "$singleprocess" = "yes" ]
-   then 
-      query=$query" limit 0, 1 "
-   fi
 #   echo " QUERY: "$query
    if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
    then
-      echo "ERROR could not query process from db -> contex"
-      rm -v $lockfile
-      contex
+      echo "ERROR could not query process from db -> exit"
+      finish
    fi
 
@@ -321,24 +302,77 @@
    then
       echo "  => nothing to do" 
-      rm -v $lockfile
-      contex 
+      finish
    else 
-      if [ "$singleprocess" = "yes" ]
-      then 
-         todofile=$listpath/ToDo-$table-$column-$process.txt
-         echo "  => found $process"
-      else
-         todofile=$listpath/ToDo-$table-$column.txt
-         echo "found processes"
-      fi
-#      echo " list: "$todofile
+      todofile=$listpath/ToDo-$table-$column.txt
       
       if ls $todofile > /dev/null 2>&1
       then
          echo "$todofile exists already"
-         rm -v $lockfile
-         contex 
+         finish
       fi
+      echo "found processes, writing todofile..."
       echo $process > $todofile
+   fi
+}
+
+# function to get todo (process)
+function gettodo()
+{
+   process=
+   echo "getting todo..."
+   getdbsetup 
+   getstepinfo
+   # get query
+   query=" select $primary from $table where "
+   if ! echo $needs | grep '#' > /dev/null 
+   then 
+      for need in $needs
+      do
+         query=$query" not isnull($need) and"
+      done
+   fi
+   query=$query" isnull($column) "
+   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
+   query=$query" order by $primary desc "
+   query=$query" limit 0, 1 "
+#   echo " QUERY: "$query
+   if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
+   then
+      echo "ERROR could not query process from db -> exit"
+      finish
+   fi
+
+   if [ "$process" = "" ]
+   then
+      echo "  => nothing to do -> exit" 
+      finish
+   fi
+}
+
+# function to get the number of processes which still have to be done
+function getstatus()
+{
+   numproc=
+   echo "getting status..."
+   getdbsetup 
+   column=${scriptscolname[$i]}
+   getstepinfo
+   # get query
+   query=" select count(*) from $table where "
+   if ! echo $needs | grep '#' > /dev/null 
+   then 
+      for need in $needs
+      do
+         query=$query" not isnull($need) and"
+      done
+   fi
+   query=$query" isnull($column) "
+   query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
+   query=$query" group by $column "
+#   echo " QUERY: "$query
+   if ! numproc=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
+   then
+      echo "ERROR could not query number of todo proceses from db -> continue"
+      cont
    fi
 }
@@ -349,11 +383,8 @@
    resetstatusvalues
    evalstatus $@
-
-   echo "setting todo..."
    getdbsetup 
    getstepinfo
    # get query
    reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'`
-   echo -$reset-
    if [ "$reset" = "no" ]
    then
