Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9604)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9605)
@@ -19,4 +19,32 @@
                                                  -*-*- END OF LINE -*-*-
 
+ 2010/07/02 Daniela Dorner
+
+   * datacenter/scripts/runcorsika:
+     - removed $com
+     - updated logging
+
+   * datacenter/scripts/runceres:
+     - fixed path
+     - added error handling
+
+   * resources/steps_fact.rc:
+     - update joins to new scheme to include further steps in the chain
+
+   * datacenter/scripts/sourcefile:
+     - adapted queries to new scheme of joins
+
+   * datacenter/scripts/runstar_mc:
+     - added (script to run star for mc) 
+
+
+
+ 2010/07/02 Daniela Dorner, Christian Farnier
+
+   * datacenter/scripts/runcallisto_mc:
+     - added (script to callibrate mc) 
+
+
+
  2010/06/30 Daniela Dorner
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/runcallisto_mc
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runcallisto_mc	(revision 9605)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runcallisto_mc	(revision 9605)
@@ -0,0 +1,78 @@
+#!/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  07/2010 <mailto:daniela.dorner@unige.ch>
+#              Christian Farnier 07/2010 <mailto:christian.farnier@unige.ch>
+#
+#   Copyright: MAGIC Software Development, 2000-2010
+#
+#
+# ========================================================================
+#
+# This script is launching the calibration of mc sequences. 
+# 
+
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=callisto
+step=Callisto
+
+set -C
+
+# get sequence # 
+gettodo "1" 
+sequence=${primaries[0]}
+cereskey=${primaries[1]}
+
+# lock sequ for cal
+lockfile=$lockpath/lock-$step-$sequence-$cereskey.txt
+checklock 
+
+cd $mars
+
+# run calibration for sequence
+printprocesslog "INFO starting $program for sequence $sequence cereskey $cereskey"
+
+# define files and paths
+sequfile="$mcsequpath/`printf %08d $sequence | cut -c 1-4`/sequence`printf %08d $sequence`.txt"
+outpath=$mcpath/$program/`printf %03d $cereskey`/`printf %08d $sequence | cut -c 1-4`/`printf %08d $sequence | cut -c 5-8`
+makedir $outpath
+log=$outpath/$program`printf %08d $sequence`
+callistorc=$setuppath/$program/callisto.rc
+inpath=$mcpath/ceres/`printf %03d $cereskey`/`printf %08d $sequence | cut -c 1-4`/`printf %08d $sequence | cut -c 5-8`
+
+setstatus "start"
+
+command="./callisto -b -q -v4 -f --out=$outpath --log=$log.log --html=$log.html --config=$callistorc $sequfile"
+printprocesslog "INFO executing "$command
+$command
+check1=$?
+
+case $check1 in
+   0)  printprocesslog "INFO $program finished successfully for sequence $sequence cereskey $cereskey (return code $check1)"
+       ;;
+   *)  printprocesslog "ERROR $program failed for sequence $sequence cereskey $cereskey (return code $check1)"
+       check=$check1
+       ;;
+esac
+
+setstatus "stop"
+
+finish
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runceres
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runceres	(revision 9604)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runceres	(revision 9605)
@@ -57,5 +57,5 @@
 makedir $outpath
 log=$outpath/ceres`printf %08d $run `"."`printf %06d $file | cut -c 4-6`
-setupfile=$setuppath/`printf %03d $cereskey`/ceres.rc
+setupfile=$setuppath/$program/`printf %03d $cereskey`/ceres.rc
 
 query="SELECT fRunTypeKEY FROM CeresInfo WHERE fRunNumber="$run" AND fFileNumber="$file" AND fCeresSetupKEY="$cereskey
@@ -87,4 +87,11 @@
 esac
 
+case $check1 in
+   0)   printprocesslog "INFO $program finished successfully for run $run file $file cereskey $cereskey runtype $runkey (check1=$check1)"
+        ;;
+   *)   printprocesslog "ERROR $program failed for run $run file $file cereskey $cereskey runtype $runkey (check1=$check1)"
+        check=$check1
+        ;;
+esac
 
 setstatus "stop"
Index: trunk/MagicSoft/Mars/datacenter/scripts/runcorsika
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runcorsika	(revision 9604)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runcorsika	(revision 9605)
@@ -206,8 +206,7 @@
 check1=$?
 case $check1 in
-   0)   printprocesslog "INFO $program finished successfully for run $run file $file (check1=$check1)"
+   0)   printprocesslog "INFO $program finished successfully for run $run file $file (return code $check1)"
         ;;
-   *)   printprocesslog "ERROR $program failed for run $run file $file (check1=$check1)"
-        com=$Fcorsika
+   *)   printprocesslog "ERROR $program failed for run $run file $file (return code $check1)"
         check=$check1
         ;;
Index: trunk/MagicSoft/Mars/datacenter/scripts/runstar_mc
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runstar_mc	(revision 9605)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runstar_mc	(revision 9605)
@@ -0,0 +1,75 @@
+#!/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  07/2010 <mailto:daniela.dorner@unige.ch>
+#
+#   Copyright: MAGIC Software Development, 2000-2010
+#
+#
+# ========================================================================
+#
+# This script is launching star for mc sequences. 
+# 
+
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=star
+step=Star
+
+set -C
+
+# get sequence # 
+gettodo "1" 
+sequence=${primaries[0]}
+cereskey=${primaries[1]}
+
+# lock sequ for cal
+lockfile=$lockpath/lock-$step-$sequence-$cereskey.txt
+checklock 
+
+cd $mars
+
+# run calibration for sequence
+printprocesslog "INFO starting $program for sequence $sequence cereskey $cereskey"
+
+# define files and paths
+sequfile="$mcsequpath/`printf %08d $sequence | cut -c 1-4`/sequence`printf %08d $sequence`.txt"
+outpath=$mcpath/$program/`printf %03d $cereskey`/`printf %08d $sequence | cut -c 1-4`/`printf %08d $sequence | cut -c 5-8`
+makedir $outpath
+log=$outpath/$program`printf %08d $sequence`
+
+setstatus "start"
+
+command="./star -b -q -v4 -f --out=$outpath --log=$log.log --html=$log.html sequfile"
+printprocesslog "INFO executing "$command
+$command
+check1=$?
+
+case $check1 in
+   0)  printprocesslog "INFO $program finished successfully for sequence $sequence cereskey $cereskey (return code $check1)"
+       ;;
+   *)  printprocesslog "ERROR $program failed for sequence $sequence cereskey $cereskey (return code $check1)"
+       check=$check1
+       ;;
+esac
+
+setstatus "stop"
+
+finish
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9604)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9605)
@@ -254,19 +254,11 @@
 
 # function to get the join of a step 
-#  (normal join but using different primaries)
 #  from the dependencies-file steps.rc
+# $1 gives the step
+# $2 gives the type of join
 function getjoin()
 {
    getdbsetup
-   grep $@"[.]Join:" $steps | grep -v '#' | sed -e "s/$@[.]Join://"
-}
-
-# function to get the special join of a step 
-#  (i.e. join with a different table) 
-#  from the dependencies-file steps.rc
-function getspecialjoin()
-{
-   getdbsetup
-   grep $@"[.]SpecialJoin:" $steps | grep -v '#' | sed -e "s/$@[.]SpecialJoin://"
+   grep $1"[.]"$2"Join:" $steps | grep -v '#' | sed -e "s/$1[.]$2Join://"
 }
 
@@ -276,4 +268,17 @@
    getdbsetup
    grep $@"[.]Needs:" $steps | sed -e "s/$@[.]Needs://"
+}
+
+# subquery which is needed to check the 
+#   status of the steps with different primaries
+function subquerypart()
+{
+   query=$query" SELECT COUNT(*) FROM "$need"Status "
+   query=$query" "`getjoin $need "SpecialInfluence"`" "
+   query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
+   for (( j=1 ; j < ${#prims[@]} ; j++ ))
+   do
+      query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`
+   done
 }
 
@@ -289,19 +294,12 @@
       needprims=( `getprimary $need` )
       # make sure that the correct joins are used
-      # in case the primaries of the step and the need are 
-      #   the same, the tables are join with these primaries
-      # otherwise it is checked whether there has to be a 
-      #   join with different primaries (indicated as 'Join'
-      #   in the steps.rc
-      # 'SpecialJoins' do not have to be taken into account here
-      if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ]
-      then 
-         query=$query" LEFT JOIN "$need"Status USING (${prims[@]}) "
-      else 
-         stdjoin=`getjoin $need`
-         if ! [ "$stdjoin" = "" ]
-         then
-            query=$query" "$stdjoin" "
-         fi
+      specialneedjoin=`getjoin $need "SpecialNeed"`
+      if [ "$specialneedjoin" = "" ]
+      then
+         query=$query" LEFT JOIN "$need"Status USING (${needprims[@]}) "
+      else
+         query=$query" "$specialneedjoin" "
+         query=$query" LEFT JOIN "$need"Status USING (${needprims[@]}) "
+         break
       fi
    done
@@ -310,4 +308,5 @@
    # add condition for the status of the peceding steps
    counter=0
+   specialneedjoin=
    for need in $needs
    do
@@ -316,31 +315,23 @@
          query=$query" AND "
       fi
-      needprims=( `getprimary $need` )
-      # in case the primaries of the tables agree
-      #   or there is just a normal 'Join' needed
-      #   only the condition is added to the query
-      # for tables which need a join with a different
-      #   table, a special query is added using the
-      #   'SpecialJoin' from the steps.rc
-      if [ "`echo ${needprims[@]}`" == "`echo ${prims[@]}`" ] || ! [ "$stdjoin" = "" ]
+      specialneedjoin=$specialneedjoin" "`getjoin $need "SpecialNeed"`
+      if [ "$specialneedjoin" = " " ]
       then 
+         # condition for step with same primaries
          query=$query" NOT ISNULL("$need"Status.fStartTime) AND "
          query=$query" NOT ISNULL("$need"Status.fStopTime) AND "
          query=$query" ISNULL("$need"Status.fReturnCode) "
+         specialneedjoin=
       else 
-         query=$query" (SELECT COUNT(*) FROM "$need"Status "
-         query=$query" "`getspecialjoin $need`" "
-         query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
-         for (( j=1 ; j < ${#prims[@]} ; j++ ))
-         do
-            query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`
-         done
-         query=$query") = (SELECT COUNT(*) FROM "$need"Status "
-         query=$query" "`getspecialjoin $need`" "
-         query=$query" WHERE "$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[0]} | sed -e 's/,//g'`
-         for (( j=1 ; j < ${#prims[@]} ; j++ ))
-         do
-            query=$query" AND "$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`"="$step"Status."`echo ${prims[$j]} | sed -e 's/,//g'`
-         done
+         # special query to check steps which 
+         #   do not have the same primaries
+         # comparison of 
+         #     number of rows
+         #   with
+         #     number of rows which are done
+         query=$query" ( "
+         subquerypart
+         query=$query" ) = ( "
+         subquerypart
          query=$query" AND NOT ISNULL(fStartTime) "
          query=$query" AND NOT ISNULL(fStopTime) "
@@ -500,38 +491,18 @@
    query=" UPDATE "$step"Status "
    # add joins to the influenced tables
-   stepspecialjoin=""
+   specialinfljoin=`getjoin $step "SpecialInfluence"`
+   if ! [ "$specialinfljoin" = "" ]
+   then
+      query=$query" "$specialinfljoin
+   fi
    for influence in $influences
    do
-      inflprims=( `getprimary $influence` )
-      # make sure that the correct joins are used
-      # in case the primaries of the step and the influence are 
-      #   the same, the tables are join with these primaries
-      # otherwise they are joined with the primaries of the influence
-      if [ "`echo ${inflprims[@]}`" == "`echo ${prims[@]}`" ]
-      then 
-         query=$query" LEFT JOIN "$influence"Status USING (${prims[@]}) "
+      infljoin=`getjoin $influence "Influence"`
+      if [ "$infljoin" = "" ]
+      then
+         inflprims=( `getprimary $influence` )
+         query=$query" LEFT JOIN "$influence"Status USING (${inflprims[@]}) "
       else 
-         prims2=`getprimary $step | sed -e "s/\ //g"`
-         primstest=`echo ${inflprims[@]} | sed -e "s/\ //g" | sed -e "s/$prims2//g"`
-         if [ "$primstest" == "`echo ${inflprims[@]} | sed -e "s/\ //g"`" ]
-         then
-            if [ "$stepspecialjoin" == "" ]
-            then
-               stepspecialjoin=`getspecialjoin $step`
-               query=$query" "$stepspecialjoin" "
-            fi
-            query=$query" LEFT JOIN "$influence"Status USING (${inflprims[@]}) "
-         else
-            infljoin=`getjoin $influence`
-            if [ "$infljoin" = "" ]
-            then
-               query=$query" LEFT JOIN "$influence"Status USING (${prims[@]}) "
-            else
-               query=$query" "$infljoin
-               # warning: this is a workaround
-               #  it has to be checked whether it works for all steps
-               stepspecialjoin="not empty"
-            fi
-         fi
+         query=$query" "$infljoin
       fi
    done
Index: trunk/MagicSoft/Mars/resources/steps_fact.rc
===================================================================
--- trunk/MagicSoft/Mars/resources/steps_fact.rc	(revision 9604)
+++ trunk/MagicSoft/Mars/resources/steps_fact.rc	(revision 9605)
@@ -1,21 +1,17 @@
 
 Corsika.Primaries: fRunNumber, fFileNumber
-Corsika.SpecialJoin: LEFT JOIN CeresInfo USING(fRunNumber, fFileNumber)
-Corsika.Join: LEFT JOIN CorsikaStatus USING(fRunNumber, fFileNumber)
 
 Ceres.Primaries: fRunNumber, fFileNumber, fCeresSetupKEY
-Ceres.SpecialJoin: LEFT JOIN CeresInfo USING(fRunNumber, fFileNumber, fCeresSetupKEY)
-Ceres.Join: LEFT JOIN CeresStatus USING(fRunNumber, fFileNumber) LEFT JOIN CeresInfo USING(fRunNumber, fFileNumber, fCeresSetupKEY)
-Ceres.Needs: Corsika
+Ceres.SpecialNeedJoin: LEFT JOIN CeresInfo USING(fSequenceNumber, fCeresSetupKEY)
+Ceres.SpecialInfluenceJoin: LEFT JOIN CeresInfo USING(fRunNumber, fFileNumber, fCeresSetupKEY)
+Ceres.NeedJoin: fSequenceNumber, fCeresSetupKEY
+Ceres.InfluenceJoin: fRunNumber, fFileNumber
 
 SequenceFile.Primaries: fSequenceNumber
-SequenceFile.Join: LEFT JOIN SequenceFileStatus USING(fSequenceNumber)
 
 Callisto.Primaries: fSequenceNumber, fCeresSetupKEY
-Callisto.Needs: Corsika Ceres SequenceFile 
+Callisto.Needs: SequenceFile Ceres Corsika 
 
 Star.Primaries: fSequenceNumber, fCeresSetupKEY
-Star.Needs: Corsika Ceres SequenceFile Callisto
+Star.Needs: Callisto SequenceFile Ceres Corsika 
 
-
-
