Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7447)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7448)
@@ -18,4 +18,17 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2005/12/06 Daniela Dorner
+
+   * datacenter/scripts/linkmc:
+     - added (script to link the mc-files into a YYYY/MM/DD structure)
+
+   * datacenter/scripts/mcsequences: 
+     - added (script to write sequencefiles for the mc)
+
+   * datacenter/scripts/processmcsequences: 
+     - added (script to run callisto and star for the mc)
+
+
+
  2005/12/06 Thomas Bretz
 
Index: /trunk/MagicSoft/Mars/datacenter/scripts/linkmc
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/linkmc	(revision 7448)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/linkmc	(revision 7448)
@@ -0,0 +1,204 @@
+#!/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  12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+user=`whoami`
+source /home/$user/Mars/datacenter/scripts/sourcefile
+
+set -C
+
+scriptlogpath=$logpath/run/linkmc/`date +%Y/%m/%d`
+makedir $scriptlogpath
+scriptlog=$scriptlogpath/linkmc`date +%F`.log
+
+date >> $scriptlog 2>&1
+
+lockfile=$lockpath/lock-mclinks.txt
+date > $lockfile >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> linkmc is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+
+mccampath=/montecarlo/camera
+mcpath=/montecarlo/rawfiles
+next=$mcpath/.next
+processed=$mcpath/.processed
+processeddir=$mcpath/.processed.dir
+readme=$mcpath/README.txt
+
+if ! ls $next >> $scriptlog 2>&1
+then
+   echo "file $next not found -> no start-runno -> exit" >> $scriptlog 2>&1
+   rm -v $lockfile >> $scriptlog 2>&1
+   exit
+fi
+
+date >| $readme 2>&1
+
+
+modes=("" "Gammawobble+" "Gammanowobble0" "GammawobbleHE+" "GammanowobbleHE0" "Gammawobble0" "GammawobbleHE0" "Proton" "DiffuseGamma" )
+
+echo "" >> $readme 2>&1
+echo "Explanation for the structure in which the mc files are linked" >> $readme 2>&1
+echo "--------------------------------------------------------------" >> $readme 2>&1
+echo "" >> $readme 2>&1
+echo "the files are linked in a YYYY/MM/DD structure like the data files" >> $readme 2>&1
+echo "YYYY represents 19zbin" >> $readme 2>&1
+echo "MM represents the mode" >> $readme 2>&1
+echo "DD represents the psf in mm" >> $readme 2>&1
+echo "" >> $readme 2>&1
+echo "explanation of the modes" >> $readme 2>&1
+echo "modes: "${modes[@]} >> $readme 2>&1
+echo "" >> $readme 2>&1
+for (( i=1 ; i <= 12 ; i++ )) 
+do 
+   if [ "${modes[i]}" != "" ]
+   then 
+      numofmode=`printf %02d $i`
+      echo "mode (MM) = $numofmode means ${modes[$i]}" >> $readme 2>&1
+   fi
+done
+echo "" >> $readme 2>&1
+echo "the mode is indicating " >> $readme 2>&1
+echo " - the particle type" >> $readme 2>&1
+echo " - wobble/nowobble" >> $readme 2>&1
+echo " - HE" >> $readme 2>&1
+echo " - w+/w0 (as +/0)" >> $readme 2>&1
+echo " a combination of w0 and wobble means 'fake wobble'" >> $readme 2>&1
+echo "  (normal mc shifted by 0.4 deg -> abberation not taken into account)" >> $readme 2>&1
+echo "" >> $readme 2>&1
+
+
+runno=`cat $next`
+
+camfiles=`find $mccampath -type f | grep -v Cal_and_Ped`
+
+for camfile in ${camfiles[@]}
+do 
+   if grep $camfile $processed >> $scriptlog 2>&1
+   then 
+      continue
+   fi
+   file=`basename $camfile`
+   no=`printf %08d $runno | cut -c 0-5`
+#   no2=`printf %08d $runno`
+# workaround due to 5digit runnumber for data with runnumber < 35487
+   no2=`printf %05d $runno`
+   zbin=`echo $file | cut -d_ -f2 | cut -c 5-6`
+   zbin=`printf %02d $zbin`
+   wobble=`echo $file | cut -d_ -f6 | cut -c 2`
+   particle=`echo $file | cut -d_ -f1`
+   psf=`echo $camfile | cut -d/ -f5 | cut -c 6,8`
+   
+   particledir=`echo $camfile | cut -d/ -f4`
+   wobbledir=`echo $camfile | cut -d/ -f6`
+   
+   testmode=$particle$wobbledir$wobble 
+#   echo "testmode:"$testmode >> $scriptlog 2>&1
+
+   case $wobble in 
+       0)   wobblemode="";;
+       +)   wobblemode="W1";;
+       -)   wobblemode="W2";;
+       *)   echo "couldn't find any indication for mode (wobble)" >> $scriptlog 2>&1
+            ;;
+   esac
+   
+   for (( i=1 ; i <= 12 ; i++ )) 
+   do 
+       if [ "${modes[$i]}" == "$testmode" ]
+       then 
+#          echo "modes[$i]=${modes[$i]}" >> $scriptlog 2>&1
+          totalmode=$i
+          break
+       fi
+   done
+
+   totalmode=`printf %02d $totalmode`
+#   echo "totalmode: "$totalmode >> $scriptlog 2>&1
+
+   project=${particle}${zbin}${wobblemode}
+   newfile="$mcpath/19$zbin/$totalmode/$psf/19${zbin}${totalmode}${psf}_${no2}_D_${project}_E.root"
+   newdir=`dirname $newfile`
+   makedir $newdir >> $scriptlog 2>&1
+
+   runno=`expr $runno + 1`
+   echo $runno >| $next 
+
+   ln -sv $camfile $newfile >> $scriptlog 2>&1
+   echo $camfile >> $processed
+
+done
+
+echo "linking cal and ped file" >> $scriptlog 2>&1
+pedfile=`find $mccampath/Cal_and_Ped -name *_P_*.root`
+calfile=`find $mccampath/Cal_and_Ped -name *_C_*.root`
+echo "calfile"$calfile >> $scriptlog 2>&1
+echo "pedfile"$pedfile >> $scriptlog 2>&1
+numfiles=`echo $pedfile $calfile | wc -w`
+if [ "$numfiles" != "2" ]
+then 
+   "too many files in the directory $mccampath/Cal_and_Ped -> exit" >> $scriptlog 2>&1
+   rm -v $lockfile >> $scriptlog 2>&1
+   exit
+fi
+
+dirs=`find $mcpath -type d`
+
+for dir in ${dirs[@]}
+do 
+   if grep $dir $processeddir >> $scriptlog 2>&1
+   then 
+      continue
+   fi
+   date=`echo $dir | cut -c 22-25,27,28,30,31`
+# workaround due to 5digit runnumber for data with runnumber < 35487
+#   newcalfile="${dir}/${date}_00000001_C_MonteCarlo_E.root"
+   newcalfile="${dir}/${date}_00001_C_MonteCarlo_E.root"
+   ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+# workaround due to 5digit runnumber for data with runnumber < 35487
+#   newpedfile="${dir}/${date}_00000002_P_MonteCarlo_E.root"
+   newpedfile="${dir}/${date}_00002_P_MonteCarlo_E.root"
+   ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+   echo $dir >> $processeddir
+done
+
+
+rm -v $lockfile >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
+
Index: /trunk/MagicSoft/Mars/datacenter/scripts/mcsequences
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/mcsequences	(revision 7448)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/mcsequences	(revision 7448)
@@ -0,0 +1,102 @@
+#!/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  12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+user=`whoami`
+source /home/$user/Mars/datacenter/scripts/sourcefile
+
+set -C
+
+scriptlogpath=$logpath/run/mcsequences/`date +%Y/%m/%d`
+makedir $scriptlogpath
+scriptlog=$scriptlogpath/mcsequences`date +%F`.log
+
+date >> $scriptlog 2>&1
+
+lockfile=$lockpath/lock-mcsequences.txt
+date > $lockfile >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> linkmc is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+
+mcpath=/montecarlo/rawfiles
+mcsequpath=/montecarlo/sequences
+
+dirs=`find $mcpath -type d`
+
+for dir in ${dirs[@]}
+do 
+   cont=`echo $dir | cut -d/ -f6`
+   if [ "$cont" == "" ]
+   then
+      continue
+   fi
+   echo $dir >> $scriptlog 2>&1
+   files=`ls $dir`
+   calfile=`find $dir -name *_C_*`
+   pedfile=`find $dir -name *_P_*`
+   calrun=`echo $calfile | cut -d_ -f2`
+   pedrun=`echo $pedfile | cut -d_ -f2`
+   datruns=`find $dir -name *_D_* | cut -d_ -f2 | tr "\n" " "`
+# workaround due to 5digit runnumber for data with runnumber < 35487
+#   firstrun=`echo $datruns | cut -c 0-8`
+   firstrun=`echo $datruns | cut -c 0-5 | sed -e 's/^0//g' -e 's/^0//g' -e 's/^0//g' -e 's/^0//g'`
+   date=`echo $dir | cut -c 22-31 | sed -e 's/\//-/g'`
+   
+# workaround due to 5digit runnumber for data with runnumber < 35487
+#   no=`echo $firstrun | cut -c 0-4`
+   no=`printf %08d $firstrun | cut -c 0-4`
+   no2=`printf %08d $firstrun`
+   sequpath=$mcsequpath/$no
+   makedir $sequpath >> $scriptlog 2>&1
+#   sequfile=$sequpath/sequence$firstrun.txt
+   sequfile=$sequpath/sequence$no2.txt
+   echo "writing sequfile "$sequfile >> $scriptlog 2>&1
+   
+   echo "Sequence:        $firstrun" > $sequfile
+   echo "Night:           $date" >> $sequfile
+   echo "" >> $sequfile
+   echo "CalRuns:         $calrun" >> $sequfile
+   echo "PedRuns:         $pedrun" >> $sequfile
+   echo "DatRuns:         $datruns" >> $sequfile
+   echo "" >> $sequfile
+done
+
+
+rm -v $lockfile >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
Index: /trunk/MagicSoft/Mars/datacenter/scripts/processmcsequences
===================================================================
--- /trunk/MagicSoft/Mars/datacenter/scripts/processmcsequences	(revision 7448)
+++ /trunk/MagicSoft/Mars/datacenter/scripts/processmcsequences	(revision 7448)
@@ -0,0 +1,126 @@
+#!/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  12/2005 <mailto:dorner@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2004
+#
+#
+# ========================================================================
+#
+#
+
+user=`whoami`
+source /home/$user/Mars/datacenter/scripts/sourcefile
+
+set -C
+
+scriptlogpath=$logpath/run/processmcsequences/`date +%Y/%m/%d`
+makedir $scriptlogpath
+scriptlog=$scriptlogpath/processmcsequences`date +%F-%H-%M-%S`.log
+
+date >> $scriptlog 2>&1
+
+lockfile=$lockpath/lock-processmcsequences.txt
+date > $lockfile >> $scriptlog 2>&1 
+checklock0=$?
+case $checklock0 in 
+    0)   echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
+    1)   echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
+         echo "-> linkmc is running -> exit" >> $scriptlog 2>&1
+         date  >> $scriptlog 2>&1
+         exit;;
+    *)   echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
+esac
+
+
+mcpath=/montecarlo/rawfiles
+mccalpath=/montecarlo/callisto
+mcimgpath=/montecarlo/star
+mcsequpath=/montecarlo/sequences
+callistorc=$setuppath/callisto/callisto.rc
+
+sequfiles=`find $mcsequpath -type f`
+
+cd $mars
+
+for sequfile in ${sequfiles[@]}
+do 
+   sequno=`echo $sequfile | cut -c 36-43`
+   no=`echo $sequno | cut -c 0-4`
+   date=`grep Night $sequfile | cut -c 18-29 | sed -e 's/-/\//g'`
+   caloutpath=$mccalpath/$no/$sequno
+   makedir $caloutpath >> $scriptlog 2>&1
+   
+   if ls $caloutpath/.done >> $scriptlog 2>&1
+   then 
+      continue
+   fi
+   
+   if ls $caloutpath/.doing >> $scriptlog 2>&1
+   then 
+      continue
+   fi
+   
+   touch $caloutpath/.doing
+   
+   echo "processing sequ $sequfile" >> $scriptlog 2>&1
+   
+   if [ -e $caloutpath/callisto.rc ]
+   then
+      echo "found callisto.rc in $caloutpath -> using this " >> $scriptlog 2>&1
+      callistorcseq=$caloutpath/callisto.rc
+   else
+      echo "no callisto.rc found in $caloutpath -> making link " >> $scriptlog 2>&1
+      ln -vs $callistorc $caloutpath/callisto.rc >> $scriptlog 2>&1
+      callistorcseq=$caloutpath/callisto.rc
+   fi
+   
+   echo "./callisto -mc -f -b -q --ind=$mcpath/$date --log=$caloutpath/callisto$sequno.log --html=$caloutpath/callisto$sequno.html --out=$caloutpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null" >> $scriptlog 2>&1
+   ./callisto -mc -f -b -q --ind=$mcpath/$date --log=$caloutpath/callisto$sequno.log --html=$caloutpath/callisto$sequno.html --out=$caloutpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
+   check1=$?
+  
+   case $check1 in
+      0)   echo "check1=$check1 -> everything ok..." >> $scriptlog 2>&1
+           touch $caloutpath/.done
+           rm $caloutpath/.doing
+           imgoutpath=$mccalpath/$no/$sequno
+           makedir $imgoutpath >> $scriptlog 2>&1
+           ./star -b -q -v4 -f -mc --log=$imgoutpath/star$sequno.log --html=$imgoutpath/star$sequno.html --ind=$caloutpath --out=$imgoutpath $sequfile  2>> $scriptlog> /dev/null
+           check2=$?
+           
+           case $check2 in 
+              0)   echo "check2=$check2 -> everything ok..." >> $scriptlog 2>&1
+                   touch $imgoutpath/.done
+                   ;;
+              *)   echo "check2=$check2 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
+                   ;;
+           esac
+    	   ;;
+      *)   echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
+   esac
+done
+
+
+rm -v $lockfile >> $scriptlog 2>&1
+
+set +C
+
+date  >> $scriptlog 2>&1
+
