Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 9503)
+++ trunk/MagicSoft/Mars/Changelog	(revision 9504)
@@ -23,4 +23,22 @@
    * datacenter/scripts/setup:
      - removed 
+
+   * datacenter/scripts/sourcefile:
+     - small fix in function makedir()
+
+   * datacenter/scripts/fillmcdb:
+     - added (script to add run in mc db (cta))
+
+   * datacenter/scripts/runsimtel:
+     - added (script to run corsika and simtelarray for cta)
+
+   * datacenter/scripts/runchimp:
+     - added (script to run coverter from simtel to mars format for cta)
+
+   * datacenter/scripts/runctastar:
+     - added (script to run star (macro) for cta)
+
+   * datacenter/scripts/runstereo:
+     - added (script to macro to calculate stereo parameters for cta)
 
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/fillmcdb
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/fillmcdb	(revision 9504)
+++ trunk/MagicSoft/Mars/datacenter/scripts/fillmcdb	(revision 9504)
@@ -0,0 +1,89 @@
+#!/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  04/2009 <mailto:daniela.dorner@unige.ch>
+#
+#   Copyright: MAGIC Software Development, 2000-2009
+#
+#
+# ========================================================================
+#
+# script to insert new runs into mc database
+#
+
+
+#
+# to be given by user
+#
+
+# number of runs to be inserted
+numruns=2700
+# number of events per run
+numevts=200000
+# particle type: 
+#   1 = gamma
+#  14 = proton
+#   6 = muon
+particlekey=1
+particlekey=14
+
+
+#
+# infos concerning DB:
+# table names: MCRunData, MCRunProcessStatus
+#     primary: fMCRunNumber
+#
+# currently working for CTA_MC
+#
+
+
+
+# begin of script
+
+source `dirname $0 `/sourcefile
+
+query="SELECT Max(fMCRunNumber)+1, Max(fMCRunNumber)+"$numruns" FROM MCRunData"
+echo $query
+# get next runnumber from db
+runs=( `sendquery "$query"` )
+if [ "${runs[0]}" == "NULL" ]
+then
+   runs[0]=1
+   runs[1]=$numruns
+fi
+
+
+echo "Inserting "$numruns" runs with "$numevts" events each and particle number "$particlekey"."
+echo "Next runs in DB from run number "${runs[0]}" to run number "${runs[1]}"."
+if [ "$1" == "-n" ]
+then 
+   echo "Dummy-Mode => exit"
+   exit
+fi
+
+for i in `seq ${runs[0]} ${runs[1]}` 
+do 
+   query="INSERT MCRunData SET fNumEvents=$numevts, fParticleTypeKEY=$particlekey, fMCRunNumber=$i"
+   echo $query
+   sendquery "$query"
+   query="INSERT MCRunProcessStatus SET fMCRunNumber=$i, fPriority=$i"
+   echo $query
+   sendquery "$query"
+done
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runchimp
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runchimp	(revision 9504)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runchimp	(revision 9504)
@@ -0,0 +1,97 @@
+#!/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  04/2009 <mailto:daniela.dorner@unige.ch>
+#
+#   Copyright: MAGIC Software Development, 2000-2009
+#
+#
+# ========================================================================
+#
+
+rootsys=/opt/root5.20.x86_64
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=chimp
+column=fChimp
+chimpdir=/home/dorner/Chimp
+export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$chimpdir/hessioxxx/lib:.
+
+set -C
+
+node=`echo $HOSTNAME | sed -e 's/compute-0-//' -e 's/[.]local//'`
+#printprocesslog "INFO $program is running on node $node"
+# get run # 
+gettodo "1" $node
+run=${primaries[0]}
+
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$run.txt
+checklock 
+
+printprocesslog "INFO starting $program for run $run"
+
+#get particle for file name
+particles[1]="gamma"
+particles[14]="proton"
+particles[6]="muon"
+particles[3]="electron"
+query="select fParticleTypeKEY from MCRunData where fMCRunNumber=$run"
+key=( `mysql -P 3306 -u operator --password=Ics+eMM! --host=mysql.isdc.unige.ch CTA_MC -s -e "$query"` )
+particle=${particles[$key]}
+infile=$mcpath/simtel/cta-ultra3/0.0deg/Data/${particle}_20deg_90deg_run`printf '%06d' ${run}`___cta-ultra3_desert.simtel.gz
+outfile=$mcpath/chimp/cta-ultra3/0.0deg/Data/${particle}_20deg_90deg_run`printf '%06d' ${run}`___cta-ultra3_desert.root
+outpath=$mcpath/chimp/cta-ultra3/0.0deg/Data
+logfile=$outpath/chimp_run`printf '%06d' ${run}`.log
+makedir $outpath
+chimppath=/home/dorner/data/chimp
+clusterchimppath=/state/cta/chimp
+makedir $chimppath
+
+
+setstatus "start" 
+
+cd $chimpdir
+
+printprocesslog "INFO ./chimp $infile >| $logfile 2>&1 "
+./chimp $infile >| $logfile 2>&1 
+check1=$?
+
+case $check1 in
+   0)   printprocesslog "INFO $program finished successfully for run $run (check1=$check1)"
+#        if ! cp $outfile $chimppath
+        if ! scp $outfile $clusterchimppath
+        then
+           printprocesslog "ERROR copying $outfile to $chimppath failed"
+           com=$Fchimpcp
+           check=2
+        else
+           printprocesslog "INFO copied $outfile successfully to $chimppath"
+        fi
+        ;;
+   *)   printprocesslog "ERROR $program failed for run $run (check1=$check1)"
+        com=$Fchimp
+        check=$check1
+        ;;
+esac
+
+setstatus "stop"
+
+finish
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runctastar
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runctastar	(revision 9504)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runctastar	(revision 9504)
@@ -0,0 +1,92 @@
+#!/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  04/2009 <mailto:daniela.dorner@unige.ch>
+#
+#   Copyright: MAGIC Software Development, 2000-2009
+#
+#
+# ========================================================================
+#
+
+rootsys=/opt/root5.12.i386
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=ctastar
+column=fCTAStar
+bcnmars=/home/dorner/Mars.BCN.2009.03.27.cvs
+
+set -C
+
+node=`echo $HOSTNAME | sed -e 's/compute-0-//' -e 's/[.]local//'`
+printprocesslog "INFO $program is running on node $node"
+# get run # 
+gettodo "1" $node
+run=${primaries[0]}
+
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$run.txt
+checklock 
+
+printprocesslog "INFO starting $program for run $run"
+
+#get particle for file name
+particles[1]="gamma"
+particles[14]="proton"
+particles[6]="muon"
+particles[3]="electron"
+query="select fParticleTypeKEY from MCRunData where fMCRunNumber=$run"
+key=( `mysql -P 3306 -u operator --password=Ics+eMM! --host=mysql.isdc.unige.ch CTA_MC -s -e "$query"` )
+particle=${particles[$key]}
+infile=$mcpath/chimp/cta-ultra3/0.0deg/Data/${particle}_20deg_90deg_run`printf '%06d' ${run}`___cta-ultra3_desert.root
+outpath=$mcpath/star
+outfile=$outpath/${particle}_20deg_90deg_run`printf '%06d' ${run}`___cta-ultra3_desert_I.root
+starpath=/home/dorner/data/star
+makedir $starpath
+logfile=$outpath/CTAstar_run`printf '%06d' ${run}`.log
+makedir $outpath
+
+setstatus "start" 
+
+cd $bcnmars
+
+printprocesslog "INFO starting: root -q -b macros/CTAstar.C\("\"$infile\""\,"\"$outpath\""\) | tee $logfile | intgrep" 
+check1=`root -q -b macros/CTAstar.C\(\""$infile\""\,\""$outpath\""\) | tee $logfile | intgrep`
+
+case $check1 in
+   1)   printprocesslog "INFO $program finished successfully for run $run (check1=$check1)"
+        if ! cp $outfile $starpath
+        then
+           printprocesslog "ERROR copying $outfile to $starpath failed"
+           com=$Fctastarcp
+           check=2
+        else
+           printprocesslog "INFO copied $outfile successfully to $starpath"
+        fi
+        ;;
+   *)   printprocesslog "ERROR $program failed for run $run (check1=$check1)"
+        com=$Fctastar
+        check=$check1
+        ;;
+esac
+
+setstatus "stop"
+
+finish
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runsimtel
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runsimtel	(revision 9504)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runsimtel	(revision 9504)
@@ -0,0 +1,155 @@
+#!/bin/sh
+#
+# ========================================================================
+#
+# *
+# * This file is part of CheObs, the Modular 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 appears 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  01/2009 <mailto:daniela.dorner@unige.ch>
+#
+#   Copyright: CheObs Software Development, 2000-2009
+#
+#
+# ========================================================================
+#
+# This script runs corsika and simtelarray.
+# 
+
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=corsikasimtel
+column=fCorsikaSimTelarray
+
+# todo:
+# evtl trennung v corsika u simtel
+
+set -C
+
+simdir=/home/dorner/cta_mc
+
+export CORSIKA_PATH=$simdir/corsika-6735/run/
+export SIM_TELARRAY_PATH=$simdir/sim_telarray
+export MCDATA_PATH=$mcpath
+export CORSIKA_DATA="${MCDATA_PATH}/corsika"
+export SIM_TELARRAY_DATA="${MCDATA_PATH}/simtel"
+
+# printing input card to stdout
+function printinputcard()
+{
+   # Run number
+   echo "RUNNR "$run
+   # Number of simulated events
+   echo "NSHOW "$numevts
+   # Seed values for simulation
+   echo "SEED "$run" 0 0 "
+   echo "SEED "$run" 0 0 "
+   echo "SEED "$run" 0 0 "
+   echo "SEED "$run" 0 0 "
+   # output directory
+   echo "DIRECT "$outpath"/ "
+   inputcardpart=$setuppath/INPUTS_CTA_ULTRA3_${primparticle}_part
+   cat $inputcardpart
+}
+
+
+# get hostname
+prodhost=`echo $HOSTNAME | sed -e 's/compute-0-//' -e 's/[.]local//'`
+
+diskusage=( `df /state/partition2/ | grep '/state/partition2'` )
+# continue only if more than 90 GB are left on /state/cta
+if [ ${diskusage[3]} -lt 90000000 ]
+then
+   printprocesslog "WARN less than 90 GB left on /state/cta on node $prodhost "
+   finish
+else
+   printprocesslog "INFO still ${diskusage[3]} left on /state/cta on node $prodhost "
+fi
+
+
+# get sequence # 
+gettodo "1" 
+run=${primaries[0]}
+
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$run.txt
+checklock 
+
+printprocesslog "INFO starting $program for run $run"
+
+# get values for inputcard
+query="SELECT fParticleTypeName FROM MCRunData LEFT JOIN ParticleType using (fParticleTypeKEY) where fMCRunNumber="$run
+primparticle=`sendquery`
+query="SELECT fNumEvents FROM MCRunData where fMCRunNumber="$run
+numevts=`sendquery`
+
+# path and logs
+outpath=$mcpath"/corsika/"`printf %06d $run`
+logfile=$outpath/$program"-"`printf %06d $run`".log"
+inputcard=$outpath/$program"-"`printf %06d $run`".card"
+makedir $outpath 
+
+# insert host into db
+query="UPDATE MCRunProcessStatus set fProductionHostKEY=$prodhost where fMCRunNumber="$run
+if ! sendquery $query
+then
+   printprocesslog "inserting host failed"
+   finish
+fi
+
+setstatus "start" 
+
+cd $CORSIKA_PATH
+
+printprocesslog "INFO create inputcar for run $run"
+
+#
+# starting corsika with pipe to simtelarray
+#  in the inputcard the path to the script is defined:
+#     ${SIM_TELARRAY_PATH}/run_sim_cta-ultra3 (i.e. run_sim_hessarray_generic)
+#  in this script a setup file is chosen:
+#     multicfg="multi/multi_${cfg}.cfg"
+#  in multi/multi_cta-ultra3.cfg one can choose whether to store 
+#     the corsika files:
+#     gzip > ${CORSIKA_DATA}/run${CORSIKA_RUN}.corsika.gz
+#  and multi/multi_cta-ultra3.cfg starts the script
+#     ${SIM_TELARRAY_PATH}/cta-ultra2_run.sh (i.e. generic_run.sh)
+#     in which e.g. path and file name are set
+#
+printinputcard >| $inputcard
+#./corsika < $inputcard >| $logfile 2>&1
+./corsika6735Linux_QGSJET_urqmd < $inputcard >| $logfile 2>&1
+check1=$?
+
+case $check1 in
+   0)   printprocesslog "INFO finished corsika and simtelarray without error (check1=$check1) "
+        if ! grep 'END OF RUN' $logfile
+        then
+           printprocesslog "ERROR could not find 'END OF RUN' in $logfile => unknown error for run $run"
+           com=$Fcorsikasimtel
+           check=2
+        else
+           printprocesslog "INFO $program finished successfully for mc run number $run"
+        fi
+        ;;
+   *)   printprocesslog "ERROR $program failed for mc run number $run (check1=$check1)"
+        com=$Fcorsikasimtel
+        check=$check1
+        ;;
+esac
+
+setstatus "stop"
+
+finish
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/runstereo
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/runstereo	(revision 9504)
+++ trunk/MagicSoft/Mars/datacenter/scripts/runstereo	(revision 9504)
@@ -0,0 +1,111 @@
+#!/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  04/2009 <mailto:daniela.dorner@unige.ch>
+#
+#   Copyright: MAGIC Software Development, 2000-2009
+#
+#
+# ========================================================================
+#
+
+rootsys=/opt/root5.12.i386
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=ctastereo
+case $1 in 
+   2) column=fStereoB
+      Fctastereo=$FctastereoB
+      outpath=$mcpath/stereoB
+      stereopath=/home/dorner/data/stereoB
+      ;;
+   3) column=fStereoC
+      Fctastereo=$FctastereoC
+      outpath=$mcpath/stereoC
+      stereopath=/home/dorner/data/stereoC
+      ;;
+   7) column=fStereoG
+      Fctastereo=$FctastereoG
+      outpath=$mcpath/stereoG
+      stereopath=/home/dorner/data/stereoG
+      ;;
+   *) printprocesslog "ERROR Unknown commandline option $1"
+      finish
+      ;;
+esac
+bcnmars=/home/dorner/Mars.BCN.2009.03.27.cvs
+
+set -C
+
+node=`echo $HOSTNAME | sed -e 's/compute-0-//' -e 's/[.]local//'`
+printprocesslog "INFO $program (for column $column) is running on node $node"
+# get run # 
+gettodo "1" $node
+run=${primaries[0]}
+
+# lock sequ
+lockfile=$lockpath/lock-$table-$column-$run.txt
+checklock 
+
+printprocesslog "INFO starting $program for run $run"
+
+#get particle for file name
+particles[1]="gamma"
+particles[14]="proton"
+particles[6]="muon"
+particles[3]="electron"
+query="select fParticleTypeKEY from MCRunData where fMCRunNumber=$run"
+key=( `mysql -P 3306 -u operator --password=Ics+eMM! --host=mysql.isdc.unige.ch CTA_MC -s -e "$query"` )
+particle=${particles[$key]}
+infile=$mcpath/chimp/cta-ultra3/0.0deg/Data/${particle}_20deg_90deg_run${run}___cta-ultra3_desert_I.root
+inpath=$mcpath/star
+infile=$inpath/${particle}_20deg_90deg_run${run}___cta-ultra3_desert_I.root
+outfile=$outpath/${particle}_20deg_90deg_run${run}___cta-ultra3_desert_S.root
+makedir $stereopath
+logfile=$outpath/CTAstereo_run${run}.log
+makedir $outpath
+
+setstatus "start" 
+
+cd $bcnmars
+
+printprocesslog "INFO starting: root -q -b macros/CTAstereoSub.C\("\"$infile\""\,"\"$outpath"\"\,"$1"\) | tee $logfile | intgrep" 
+check1=`root -q -b macros/CTAstereoSub.C\(\""$infile\""\,\""$outpath\""\,$1\) 2>&1 | tee $logfile | intgrep`
+
+case $check1 in
+   1)   printprocesslog "INFO $program finished successfully for run $run (check1=$check1)"
+        if ! cp $outfile $stereopath
+        then
+           printprocesslog "ERROR copying $outfile to $starpath failed"
+           com=$Fctastereocp
+           check=2
+        else
+           printprocesslog "INFO copied $outfile successfully to $starpath"
+        fi
+        ;;
+   *)   printprocesslog "ERROR $program failed for run $run (check1=$check1)"
+        com=$Fctastereo
+        check=$check1
+        ;;
+esac
+
+setstatus "stop"
+
+finish
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9503)
+++ trunk/MagicSoft/Mars/datacenter/scripts/sourcefile	(revision 9504)
@@ -57,8 +57,9 @@
       if [ ! -d $@ ]
       then 
-         echo "could not make dir "$@
          if ! [ "$processlog" = "" ]
          then
             echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] could not make dir "$@ >> $processlog
+         else
+            echo "could not make dir "$@
          fi
          if ls $lockfile >/dev/null 2>&1
