Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8966)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8967)
@@ -18,4 +18,21 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+
+ 2008/06/17 Daniel Hoehne
+
+   * datacenter/macros/fillcamera.C:
+     - added and changed some parameters
+
+   * datacenter/scripts/mcsequences:
+     - added database interaction. Now sequences are built by querying
+       the relevant parameters in the MC database
+
+   * datacenter/scripts/[runmccallisto, runmcstar]:
+     - added
+
+   * datacenter/scripts/sourcefile:
+     - added failed codes for runmccallisto and runmcstar
+
 
 
Index: /trunk/MagicSoft/Mars/datacenter/scripts/mcsequences
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/mcsequences	(revision 8966)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/mcsequences	(revision 8967)
@@ -19,17 +19,14 @@
 #
 #   Author(s): Daniela Dorner  12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
-#
-#   Copyright: MAGIC Software Development, 2000-2007
+#   Author(s): Daniela Dorner  06/2008 <mailto:hoehne@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2008
 #
 #
 # ========================================================================
 #
-# This script is an intermediate solution to process the montecarlo files.
-# As soon as the montecarlo database is running, this script shall be 
-# exchanged. 
-# 
-# The script is building one sequence per directory. As the files are 
-# structured by condition, the files in one directory and such in one 
-# sequence have the same observation mode, psf, zbin, ... 
+# The script is building two sequences per directory and epoch. One for
+# training and one for testing. The relevant parameters are taken from
+# the MC database.
 # 
 
@@ -46,17 +43,20 @@
 lockfile=$lockpath/lock-$program.txt
 checklock  >> $scriptlog 2>&1
-
-# find montecarlo directories, build one sequence per directory and write sequence file
-printprocesslog "INFO building one sequence per mcdirectory and epoch"
-
-user="test"
-db="TestMonteCarlo"
-pw="Ics+eaTD"
+                                              
+# find montecarlo directories, build two sequences per directory and write sequence files
+printprocesslog "INFO building two sequences per mcdirectory and epoch, one for training and one for testing"
+
+#user="test"
+#db="TestMonteCarlo"
+#pw="Ics+eaTD"
+user="operator"
+db="MyMagicMonteCarlo"
+pw="Ics+eMM!"
 
 dirs=`find $mcrawpath -type d`
 for dir in ${dirs[@]}
 do 
-   cont=`echo $dir | cut -d/ -f6`
-#   cont=`echo $dir | cut -d/ -f10`
+   cont=`echo $dir | cut -d/ -f7`
+   #cont=`echo $dir | cut -d/ -f10`
    if [ "$cont" == "" ]
    then
@@ -65,5 +65,5 @@
    echo $dir >> $scriptlog 2>&1
    
-   epochs=`ls -l $mcpath/camera | cut -c 52-70`
+   epochs=`ls -l $mcpath/camera | cut -c 52-80`
    for epoch in ${epochs[@]}
    do
@@ -81,63 +81,146 @@
       	 if [ "$datruns" != "" ]
          then
+            num=`echo $datruns | wc -w`
+            train=`expr $num / 5`
+            test=`expr $num - $train`
+            last=`expr $num \* 9`
+            train2=`expr $train \* 9`
       	    firstrun=`echo $datruns | cut -c 0-8`
+            trainruns=`echo $datruns | cut -c 0-$train2`
+            trainruns2=`echo $trainruns | sed -e 's/ /,/g'`
+            testruns=`echo $datruns | cut -c $train2-$last`
+            testruns2=`echo $testruns | sed -e 's/ /,/g'`
+      	    firstruntrain=`echo $trainruns | cut -c 0-8`
+      	    firstruntest=`echo $testruns | cut -c 0-8`
+
             date=`echo $dir | cut -c 28-37 | sed -e 's/\//-/g'`
             #date=`echo $dir | cut -c 57-66 | sed -e 's/\//-/g'`
             zbin=`echo $date | cut -c 3,4`
-   	    
-            for datrun in ${datruns[@]}
+
+
+   	    #training runs
+            for trainrun in ${trainruns[@]}
             do
-               update=" update MCRunData set fSequenceFirst=\"$firstrun\" where fRunNumber=\"$datrun\" "
-   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $update "
+               trainupdate=" update MCRunData set fSequenceFirst=\"$firstruntrain\" where fRunNumber=\"$trainrun\" "
+   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $trainupdate "
             done   
 
-            query=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY from MCRunData where fRunNumber=\"$firstrun\" "
-            values=`mysql -ss -u $user --password=$pw --host=vela $db -e " $query "`
-            spec=`echo $values | cut -d" " -f1`
-            psf=`echo $values | cut -d" " -f2`
-            amplfadc=`echo $values | cut -d" " -f3`
-            atmo=`echo $values | cut -d" " -f4`
-            obs=`echo $values | cut -d" " -f5`
-            part=`echo $values | cut -d" " -f6`
-            refl=`echo $values | cut -d" " -f7`
-            cors=`echo $values | cut -d" " -f8`
-            cam=`echo $values | cut -d" " -f9`
-            view=`echo $values | cut -d" " -f10`
-   	    query1=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstrun\" "
-   	    query2=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstrun\" "
-   	    check1=`mysql -ss -u $user --password=$pw --host=vela $db -e " $query1 "`
-   	    check2=`mysql -ss -u $user --password=$pw --host=vela $db -e " $query2 "`
-   	    insert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstrun\", fSequenceFileWritten=Now() "
-   	    insert2=" insert MCSequences set fSequenceFirst=\"$firstrun\", fRunStart=\"$date\", fZBin=\"$zbin\", fSpectrumKEY=\"$spec\", fPSFKEY=\"$psf\", fAmplFadcKEY=\"$amplfadc\", fAtmosphericModelKEY=\"$atmo\", fObservationModeKEY=\"$obs\", fMCParticleKEY=\"$part\", fReflectorVersionKEY=\"$refl\", fCorsikaVersionKEY=\"$cors\", fCameraVersionKEY=\"$cam\", fViewConeAngleOKEY=\"$view\" "
-            update2=" update MCSequences set fRunStart=\"$date\", fZBin=\"$zbin\", fSpectrumKEY=\"$spec\", fPSFKEY=\"$psf\", fAmplFadcKEY=\"$amplfadc\", fAtmosphericModelKEY=\"$atmo\", fObservationModeKEY=\"$obs\", fMCParticleKEY=\"$part\", fReflectorVersionKEY=\"$refl\", fCorsikaVersionKEY=\"$cors\", fCameraVersionKEY=\"$cam\", fViewConeAngleOKEY=\"$view\" where fSequenceFirst=\"$firstrun\" "
-            if [ "$check1" == "" ]
-            then
-               mysql -ss -u $user --password=$pw --host=vela $db -e " $insert1 "
-            fi
-            if [ "$check2" == "" ]
-            then
-   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $insert2 "
+            trainquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY from MCRunData where fRunNumber=\"$firstruntrain\" "
+            trainquery2=" select sum(fNumEvents), sum(fNumtriggers) from MCRunData where fRunNumber in ($trainruns2) "
+            trainvalues=`mysql -ss -u $user --password=$pw --host=vela $db -e " $trainquery1 "`
+            trainvalues2=`mysql -ss -u $user --password=$pw --host=vela $db -e " $trainquery2 "`
+            trainspec=`echo $trainvalues | cut -d" " -f1`
+            trainpsf=`echo $trainvalues | cut -d" " -f2`
+            trainamplfadc=`echo $trainvalues | cut -d" " -f3`
+            traintrainatmo=`echo $trainvalues | cut -d" " -f4`
+            trainobs=`echo $trainvalues | cut -d" " -f5`
+            trainpart=`echo $trainvalues | cut -d" " -f6`
+            trainrefl=`echo $trainvalues | cut -d" " -f7`
+            traincors=`echo $trainvalues | cut -d" " -f8`
+            traincam=`echo $trainvalues | cut -d" " -f9`
+            trainview=`echo $trainvalues | cut -d" " -f10`
+            trainass=`echo $trainvalues | cut -d" " -f11`
+            trainevents=`echo $trainvalues2 | cut -d" " -f1`
+            traintriggers=`echo $trainvalues2 | cut -d" " -f2`
+   	    trainquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntrain\" "
+   	    trainquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntrain\" "
+   	    traincheck3=`mysql -ss -u $user --password=$pw --host=vela $db -e " $trainquery3 "`
+   	    traincheck4=`mysql -ss -u $user --password=$pw --host=vela $db -e " $trainquery4 "`
+   	    traininsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntrain\", fSequenceFileWritten=Now() "
+   	    traininsert2=" insert MCSequences set fSequenceFirst=\"$firstruntrain\", fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$traintriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$trainspec\", fPSFKEY=\"$trainpsf\", fAddSpotSizeKEY=\"$trainass\", fAmplFadcKEY=\"$trainamplfadc\", fAtmosphericModelKEY=\"$trainatmo\", fObservationModeKEY=\"$trainobs\", fMCParticleKEY=\"$trainpart\", fReflectorVersionKEY=\"$trainrefl\", fCorsikaVersionKEY=\"$traincors\", fCameraVersionKEY=\"$traincam\", fViewConeAngleOKEY=\"$trainview\", fTestTrainKEY=2 "
+            trainupdate2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$trainevents\", fNumTriggers=\"$traintriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$trainspec\", fPSFKEY=\"$trainpsf\", fAddSpotSizeKEY=\"$trainass\", fAmplFadcKEY=\"$trainamplfadc\", fAtmosphericModelKEY=\"$trainatmo\", fObservationModeKEY=\"$trainobs\", fMCParticleKEY=\"$trainpart\", fReflectorVersionKEY=\"$trainrefl\", fCorsikaVersionKEY=\"$traincors\", fCameraVersionKEY=\"$traincam\", fViewConeAngleOKEY=\"$trainview\", fTestTrainKEY=2 where fSequenceFirst=\"$firstruntrain\" "
+            if [ "$traincheck3" == "" ]
+            then
+               mysql -ss -u $user --password=$pw --host=vela $db -e " $traininsert1 "
+            fi
+            if [ "$traincheck4" == "" ]
+            then
+   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $traininsert2 "
             else
-   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $update2 "
+   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $trainupdate2 "
             fi
             
-            no=`echo $firstrun | cut -c 0-4`
-            sequpath=$mcsequpath/$no
-            makedir $sequpath >> $scriptlog 2>&1
-            sequfile=$sequpath/sequence$firstrun.txt
-            echo "writing sequfile "$sequfile >> $scriptlog 2>&1
-            printprocesslog "INFO writing sequencefile $sequfile"
+            trainno=`echo $firstruntrain | cut -c 0-4`
+            trainsequpath=$mcsequpath/$trainno
+            makedir $trainsequpath >> $scriptlog 2>&1
+            trainsequfile=$trainsequpath/sequence$firstruntrain.txt
+            echo "writing train sequfile "$trainsequfile >> $scriptlog 2>&1
+            printprocesslog "INFO writing train sequencefile $trainsequfile"
    
-            echo "Sequence:        $firstrun" >| $sequfile
-            echo "Night:           $date" >> $sequfile
-            echo "Epoch:           $epoch" >> $sequfile
-            echo "Mode:            $mode" >> $sequfile
-            echo "" >> $sequfile
-            echo "CalRuns:         $calrun" >> $sequfile
-            echo "PedRuns:         $pedrun" >> $sequfile
-            echo "DatRuns:         $datruns" >> $sequfile
- 	    echo "" >> $sequfile
-            echo "MonteCarlo: Yes" >> $sequfile
-   	    echo "" >> $sequfile
+            echo "Sequence:        $firstruntrain" >| $trainsequfile
+            echo "Night:           $date" >> $trainsequfile
+            echo "Epoch:           $epoch" >> $trainsequfile
+            echo "Mode:            $mode" >> $trainsequfile
+            echo "" >> $trainsequfile
+            echo "CalRuns:         $calrun" >> $trainsequfile
+            echo "PedRuns:         $pedrun" >> $trainsequfile
+            echo "DatRuns:         $trainruns" >> $trainsequfile
+ 	    echo "" >> $trainsequfile
+            echo "MonteCarlo: Yes" >> $trainsequfile
+   	    echo "Training sequence" >> $trainsequfile
+   	    echo "" >> $trainsequfile
+
+
+            #test runs
+            for testrun in ${testruns[@]}
+            do
+               testupdate=" update MCRunData set fSequenceFirst=\"$firstruntest\" where fRunNumber=\"$testrun\" "
+   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $testupdate "
+            done   
+
+            testquery1=" select fSpectrumKEY, fPSFKEY, fAmplFadcKEY, fAtmosphericModelKEY, fObservationModeKEY, fMCParticleKEY, fReflectorVersionKEY, fCorsikaVersionKEY, fCameraVersionKEY, fViewConeAngleOKEY, fAddSpotSizeKEY from MCRunData where fRunNumber=\"$firstruntest\" "
+            testquery2=" select sum(fNumEvents), sum(fNumtriggers) from MCRunData where fRunNumber in ($testruns2) "
+            testvalues=`mysql -ss -u $user --password=$pw --host=vela $db -e " $testquery1 "`
+            testvalues2=`mysql -ss -u $user --password=$pw --host=vela $db -e " $testquery2 "`
+            testspec=`echo $testvalues | cut -d" " -f1`
+            testpsf=`echo $testvalues | cut -d" " -f2`
+            testamplfadc=`echo $testvalues | cut -d" " -f3`
+            testatmo=`echo $testvalues | cut -d" " -f4`
+            testobs=`echo $testvalues | cut -d" " -f5`
+            testpart=`echo $testvalues | cut -d" " -f6`
+            testrefl=`echo $testvalues | cut -d" " -f7`
+            testcors=`echo $testvalues | cut -d" " -f8`
+            testcam=`echo $testvalues | cut -d" " -f9`
+            testview=`echo $testvalues | cut -d" " -f10`
+            testass=`echo $testvalues | cut -d" " -f11`
+            testevents=`echo $testvalues2 | cut -d" " -f1`
+            testtriggers=`echo $testvalues2 | cut -d" " -f2`
+   	    testquery3=" select fSequenceFirst from MCSequenceProcessStatus where fSequenceFirst=\"$firstruntest\" "
+   	    testquery4=" select fSequenceFirst from MCSequences where fSequenceFirst=\"$firstruntest\" "
+   	    testcheck3=`mysql -ss -u $user --password=$pw --host=vela $db -e " $testquery3 "`
+   	    testcheck4=`mysql -ss -u $user --password=$pw --host=vela $db -e " $testquery4 "`
+   	    testinsert1=" insert MCSequenceProcessStatus set fSequenceFirst=\"$firstruntest\", fSequenceFileWritten=Now() "
+   	    testinsert2=" insert MCSequences set fSequenceFirst=\"$firstruntest\", fRunStart=\"$date\", fNumEvents=\"$testevents\", fNumTriggers=\"$testtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$testspec\", fPSFKEY=\"$testpsf\", fAddSpotSizeKEY=\"$testass\", fAmplFadcKEY=\"$testamplfadc\", fAtmosphericModelKEY=\"$testatmo\", fObservationModeKEY=\"$testobs\", fMCParticleKEY=\"$testpart\", fReflectorVersionKEY=\"$testrefl\", fCorsikaVersionKEY=\"$testcors\", fCameraVersionKEY=\"$testcam\", fViewConeAngleOKEY=\"$testview\", fTestTrainKEY=3 "
+            testupdate2=" update MCSequences set fRunStart=\"$date\", fNumEvents=\"$testevents\", fNumTriggers=\"$testtriggers\", fZBin=\"$zbin\", fSpectrumKEY=\"$testspec\", fPSFKEY=\"$testpsf\", fAddSpotSizeKEY=\"$testass\", fAmplFadcKEY=\"$testamplfadc\", fAtmosphericModelKEY=\"$testatmo\", fObservationModeKEY=\"$testobs\", fMCParticleKEY=\"$testpart\", fReflectorVersionKEY=\"$testrefl\", fCorsikaVersionKEY=\"$testcors\", fCameraVersionKEY=\"$testcam\", fViewConeAngleOKEY=\"$testview\", fTestTrainKEY=3 where fSequenceFirst=\"$firstruntest\" "
+            if [ "$testcheck3" == "" ]
+            then
+               mysql -ss -u $user --password=$pw --host=vela $db -e " $testinsert1 "
+            fi
+            if [ "$testcheck4" == "" ]
+            then
+   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $testinsert2 "
+            else
+   	       mysql -ss -u $user --password=$pw --host=vela $db -e " $testupdate2 "
+            fi
+            
+            testno=`echo $firstruntest | cut -c 0-4`
+            testsequpath=$mcsequpath/$testno
+            makedir $testsequpath >> $scriptlog 2>&1
+            testsequfile=$testsequpath/sequence$firstruntest.txt
+            echo "writing test sequfile "$testsequfile >> $scriptlog 2>&1
+            printprocesslog "INFO writing test sequencefile $testsequfile"
+   
+            echo "Sequence:        $firstruntest" >| $testsequfile
+            echo "Night:           $date" >> $testsequfile
+            echo "Epoch:           $epoch" >> $testsequfile
+            echo "Mode:            $mode" >> $testsequfile
+            echo "" >> $testsequfile
+            echo "CalRuns:         $calrun" >> $testsequfile
+            echo "PedRuns:         $pedrun" >> $testsequfile
+            echo "DatRuns:         $testruns" >> $testsequfile
+ 	    echo "" >> $testsequfile
+            echo "MonteCarlo: Yes" >> $testsequfile
+   	    echo "Test sequence" >> $testsequfile
+   	    echo "" >> $testsequfile
          fi
       done
Index: /trunk/MagicSoft/Mars/datacenter/scripts/runmccallisto
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/runmccallisto	(revision 8967)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/runmccallisto	(revision 8967)
@@ -0,0 +1,241 @@
+#!/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  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#   Author(s): Daniel Hoehne   06/2008 <mailto:hoehne@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2008
+#
+#
+# ========================================================================
+#
+# This script is launching the calibration of mc sequences. 
+# 
+# As callisto takes some time, only one sequence is processed at once. 
+# First the script gets a sequence number from the mc database, for which 
+# the calibration has to be done (function gettodo). After setting the 
+# status in the database (set fStartTime to know, that the sequence is 
+# already being processed), the sequence is calibrated. Afterwards 
+# the status in the mc database is updated according to the return value 
+# of the program.
+# The important INFOs, WARNings and ERRORs are written not only to the 
+# scriptlog but also to the processlog. 
+#
+# Atm the processing has to be done in a separate Mars directory because 
+# different sql.rc and steps.rc files are needed.
+# 
+# The callisto.rc files are stored in the setup directory
+#
+
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=callisto
+column=fCallisto
+
+set -C
+
+scriptlog=$runlogpath/runmc$program-$datetime.log
+date >> $scriptlog 2>&1
+
+# get sequence # 
+gettodo >> $scriptlog 2>&1
+sequence=$process
+
+# lock sequ for cal
+lockfile=$lockpath/lock-$table-$column-$sequence.txt
+checklock >> $scriptlog 2>&1
+
+cd $mars
+
+# run calibration for sequence
+echo "run $program for mc sequence $sequence..." >> $scriptlog 2>&1
+printprocesslog "INFO starting $program for mc sequence $sequence"
+no=`printf %08d $sequence | cut -c 0-4`
+no2=`printf %08d $sequence`
+outpath="$mcpath/$program/$no/$no2"
+makedir $outpath >> $scriptlog 2>&1
+sequfile="$mcsequpath/$no/sequence$no2.txt"
+
+## stage the needed files; to be removed as soon as the correct stub file size has been determined
+#echo "staging files:" >> $scriptlog 2>&1
+#day=`grep Night $sequfile | cut -c 18-27 | sed -e "s/-/\//g"`
+#runs=`grep Runs $sequfile | cut -d: -f2`
+#i=0
+#
+#for run in ${runs[@]}
+#do
+#   files[i]=19*_${run}_[PCD]_*_E.root
+#   echo ${mcpath}/rawfiles/${day}/${files[i]} >> $scriptlog 2>&1
+#   let i++
+#done
+#
+#ssh -nx phoenix "cd ${mcpath}/rawfiles/${day}; /opt/SUNWsamfs/bin/stage ${files[@]}"
+
+
+# define callisto.rc files
+callistorcnew=$setuppath/$program/callisto.rc
+callistorcmux=$setuppath/$program/callisto_mux_new.rc
+
+epoch=`grep Epoch $sequfile | cut -d: -f2 | grep Mux`
+# 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 [ "$epoch" = "" ]
+   then
+      ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
+   else
+      ln -vs $callistorcmux $outpath/callisto.rc >> $scriptlog 2>&1
+   fi
+   callistorcseq=$outpath/callisto.rc
+fi
+
+# lock sequ for zipping
+#lockfile=$lockpath/calzip$sequence.txt
+# if lockfile is already existing, 1 is returned
+#if ! checklock return 1 >> $scriptlog 2>&1
+#then
+   # reset lockfile name
+#   lockfile=$lockpath/lock-$table-$column-$sequence.txt
+#   finish >> $scriptlog 2>&1
+#fi
+
+primvar=$no2
+setstatus "start" >> $scriptlog 2>&1
+
+echo "./callisto -mc -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile  2>> $scriptlog > /dev/null" >> $scriptlog 2>&1
+./callisto -mc -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile  2>> $scriptlog > /dev/null
+check1=$?
+
+# remove lockfile for zip and reset lockfile name
+#rm -v $lockfile >> $scriptlog 2>&1
+#lockfile=$lockpath/lock-$table-$column-$sequence.txt
+
+case $check1 in
+   0)   echo " check1=$check1 -> everything ok" >> $scriptlog 2>&1
+        printprocesslog "INFO $program finished successfully for mc sequence $sequence"
+        ;;
+        # 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_* `
+#        if [ "$calfiles" = "" ]
+#        then 
+#           echo " no files found -> continue with next sequence" >> $scriptlog 2>&1
+#           printprocesslog "ERROR no calfiles found"
+#        fi
+#        echo " files to be updated: "$calfiles >> $scriptlog 2>&1
+#        
+#        merpplogpath=$outpath"/merpplogs"
+#        makedir $merpplogpath >> $scriptlog 2>&1
+#        
+#        printprocesslog "INFO doing merppupdate for sequence $sequence"
+#        # 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
+#           date=`date --date \`basename $calfile | cut -d_ -f1\` +%Y/%m/%d`
+#           ccpath=$subsystempath/cc/$date
+#           cacopath=$subsystempath/caco/$date
+#           runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
+#           ccfile=`find $ccpath -name 20[0-2][0-9][01][0-9][0-3][0-9]_*${runno}_[PDCS]_*_S.rep`
+#           source=`echo $ccfile | cut -d_ -f4`
+#           cacofile=`find /magic/subsystemdata/caco/$date -name dc_20[0-2][0-9]_[01][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
+#           if [ "$ccfile" = "" ]
+#           then
+#              echo "no ccfile found for run "$runno >> $scriptlog 2>&1
+#              printprocesslog "ERROR  ccfile $ccfile not found for $calfile"
+#              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`
+#                 cacofile=`find $cacopath -name *$newrun*`
+#                 if [ "$cacofile" = "" ]
+#                 then
+#                    if [ $i -eq 9 ]
+#                    then
+#                       echo "no cacofile found for runno $newrun in $cacopath" >> $scriptlog 2>&1
+#                       printprocesslog "ERROR cacofile $cacofile not found for $calfile"
+#                       com=$Fnocacofile
+#                       comadd=$runno
+#                       check=0
+#                       break 2
+#                    fi
+#                    continue
+#                 else
+#                    echo "cacofile: "$cacofile >> $scriptlog 2>&1
+#                    break
+#                 fi
+#              done
+#           fi
+#           echo "./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
+#           ./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
+#                   printprocesslog "INFO merppupdated $calfile sucessfully with $ccfile"
+#                   ;;
+#              *)   echo " check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
+#                   printprocesslog "ERROR merppccupdate with file $ccfile failed for $calfile"
+#                   com=$Fmerppcc
+#                   comadd=$runno
+#                   check=$check2
+#                   break ;;
+#           esac
+#           echo "./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
+#           ./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
+#                   printprocesslog "INFO merppupdated $calfile sucessfully with $cacofile"
+#                   ;;
+#              *)   echo " check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
+#                   printprocesslog "ERROR merppcacoupdate with file $cacofile failed for $calfile"
+#                   com=$Fmerppcaco
+#                   comadd=$runno
+#                   check=$check3
+#                   break ;;
+#           esac
+#        done
+#	printprocesslog "INFO finished merppupdate successfully for sequence $sequence"
+#        ;;
+   *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        printprocesslog "ERROR $program failed for mc sequence $sequence (return code $check1)"
+        com=$Fmccallisto
+        check=$check1
+        ;;
+esac
+
+setstatus "stop"  >> $scriptlog 2>&1
+
+finish >> $scriptlog 2>&1
+
Index: /trunk/MagicSoft/Mars/datacenter/scripts/runmcstar
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/runmcstar	(revision 8967)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/runmcstar	(revision 8967)
@@ -0,0 +1,117 @@
+#!/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  08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
+#   Author(s): Stefan Ruegamer 08/2007 <mailto:snruegam@astro.uni-wuerzburg.de>
+#   Author(s): Daniel Hoehne   06/2008 <mailto:hoehne@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2008
+#
+#
+# ========================================================================
+#
+# This script is launching star for mc sequences.
+# 
+# As star takes some time, only one mc sequence is processed at once. 
+# First the script gets a sequence number from the database for which 
+# star has to be done (function gettodo). After setting the status in the 
+# database (set fStartTime; to know that the sequence is already being 
+# processed), the image parameters are calculated for the sequence. 
+# Afterwards the status in the database is updated according to the return 
+# value of star. 
+# The important INFOs, WARNings and ERRORs are written not only to the 
+# scriptlog but also to the processlog.
+#
+# Atm the processing has to be done in a separate Mars directory because 
+# different sql.rc and steps.rc files are needed.
+#
+# The star.rc files are taken from the datacenter/setup/star directory
+#
+
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=star
+column=fStar
+
+set -C
+
+scriptlog=$runlogpath/runmc$program-$datetime.log
+date >> $scriptlog 2>&1
+
+# get sequence # 
+gettodo >> $scriptlog 2>&1
+sequence=$process
+
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$sequence.txt
+checklock >> $scriptlog 2>&1
+
+cd $mars
+
+echo "run $program for mc sequence $sequence..." >> $scriptlog 2>&1
+printprocesslog "INFO starting $program for mc sequence $sequence"
+no=`printf %08d $sequence | cut -c 0-4`
+no2=`printf %08d $sequence`
+outpath="$mcpath/$program/$no/$no2"
+inpath=`echo $outpath | sed -e 's/star/callisto/'`
+makedir $outpath >> $scriptlog 2>&1
+
+sequfile="$mcsequpath/$no/sequence$no2.txt"
+
+primvar=$no2
+setstatus "start" >> $scriptlog 2>&1
+
+#echo "staging files..." >> $scriptlog 2>&1
+#ssh -nx phoenix /opt/SUNWsamfs/bin/stage -V $inpath/19*_0*${run}_Y_*_E.root >> $scriptlog 2>&1
+
+
+# define star.rc files
+starrcnew=$setuppath/$program/star.rc
+starrcmux=$setuppath/$program/star_mux.rc
+
+epoch=`grep Epoch $sequfile | cut -d: -f2 | grep Mux`
+# link star.rc file
+echo "linking the star.rc file to $outpath" >> $scriptlog 2>&1
+if [ "$epoch" = "" ]
+then
+   ln -vsf $starrcnew $outpath/star.rc >> $scriptlog 2>&1
+else
+   ln -vsf $starrcmux $outpath/star.rc >> $scriptlog 2>&1
+fi
+starrcseq=$outpath/star.rc
+
+echo "./star -mc -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --ind=$inpath --out=$outpath $sequfile --config=$starrcseq 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
+./star -mc -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --ind=$inpath --out=$outpath $sequfile --config=$starrcseq 2>> $scriptlog> /dev/null
+check1=$?
+
+case $check1 in
+   0)   echo " check1=$check1 -> everything ok " >> $scriptlog 2>&1
+        printprocesslog "INFO $program finished successfully for mc sequence $sequence"
+        ;;
+   *)   echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+        printprocesslog "ERROR $program failed for mc sequence $sequence"
+        com=$Fmcstar
+        check=$check1
+        ;;
+esac
+
+setstatus "stop" >> $scriptlog 2>&1
+
+finish >> $scriptlog 2>&1
+
