Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 8757)
+++ trunk/MagicSoft/Mars/Changelog	(revision 8758)
@@ -18,4 +18,26 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2007/10/15 Daniel Hoehne
+
+   * datacenter/macros/fillcamera.C:
+     - included more parameters to fill into MCDB
+     - introduced discrimination of P/C and D files
+     - included linking of camera files
+
+   * datacenter/scripts/fillcamera:
+     - added
+
+   * datacenter/scripts/mcsequences:
+     - included handling of more than two P/C runs per rawfile directory
+     - building sequences based on rawfile dirs and MC epochs
+
+   * datacenter/scripts/processmcsequences:
+     - included MC epochs for finding the right callisto.rc
+
+   * mmc/MMcCorsikaRunHeader.h:
+   - included GetViewConeAngle[Inner,Outer], GetAtmosphericModel
+
+
 
  2007/10/13 Thomas Bretz
Index: trunk/MagicSoft/Mars/datacenter/scripts/fillcamera
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/fillcamera	(revision 8758)
+++ trunk/MagicSoft/Mars/datacenter/scripts/fillcamera	(revision 8758)
@@ -0,0 +1,274 @@
+#!/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): Daniel Hoehne  09/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2007
+#
+#
+# ========================================================================
+#
+# This script launches the inserting of mc parameters into the db by 
+# starting fillcamera.C
+# 
+
+source `dirname $0`/sourcefile
+printprocesslog "INFO starting $0"
+program=fillcamera
+
+set -C
+
+scriptlog=$runlogpath/$program-$datetime.log
+date >> $scriptlog 2>&1
+
+# check if script is already running
+lockfile=$lockpath/lock-$program.txt
+checklock  >> $scriptlog 2>&1
+
+#mccampath=$mcpath/camera
+mccampath=/magic/montecarlo/camera
+cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d`
+echo "camera dirs: "${cameradirs[@]}  >> $scriptlog 2>&1
+echo "" >> $scriptlog 2>&1
+
+cd $mars
+
+# process directories
+for cameradir in ${cameradirs[@]}
+do
+   printprocesslog "INFO inserting information for all root camera files in $cameradir"
+   cam=`basename $cameradir`
+   echo "dir: "$cameradir >> $scriptlog 2>&1
+   fillcamerapath=$logpath/$program
+   makedir $fillcamerapath >> $scriptlog 2>&1
+   fillcameralog=$fillcamerapath/$program-$cam.log
+   
+   check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kFALSE\) | tee $fillcameralog | intgrep`
+   case $check0 in 
+      1)   echo "check0=$check0 -> everything ok " >> $scriptlog 2>&1 
+           printprocesslog "INFO fillcamera run successfully for dir $cameradir"
+           ;;
+      0)   echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1 
+           printprocesslog "WARN connection to DB failed"
+           check="no"
+           ;;
+      *)   echo "check0=$check0 -> ERROR " >> $scriptlog 2>&1 
+           printprocesslog "ERROR $program.C failed for dir $cameradir"
+           ;;
+   esac
+   
+   printprocesslog "INFO linking cal and ped files"
+   echo "linking cal and ped files" >> $scriptlog 2>&1
+   
+   epo=`basename $cameradir` #filename
+   pedfile=`find $cameradir/Cal_and_Ped -name *_P_*.root`
+   calfile=`find $cameradir/Cal_and_Ped -name *_C_*.root`
+   
+   echo "calfile for epoch $epo : " $calfile >> $scriptlog 2>&1
+   echo "pedfile for epoch $epo : " $pedfile >> $scriptlog 2>&1
+   
+   #check number of files
+   numfiles=`echo $pedfile $calfile | wc -w`
+   
+   if [ "$numfiles" != "2" ]
+   then
+      echo "too many files in the directory $epoch/Cal_and_Ped -> exit" >> $scriptlog 2>&1
+      rm -v $lockfile >> $scriptlog 2>&1
+      exit
+      printprocesslog "ERROR too many ped and cal files found in $epoch/Cal_and_Ped"
+      finish >> $scriptlog 2>&1
+   fi
+   
+
+   user="test"
+   db="TestMonteCarlo"
+   pw="Ics+eaTD"
+   cquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$calfile\" "
+   pquery=" select fRunNumber from MCRunProcessStatus where fFileName=\"$pedfile\" "
+
+   crun=`mysql -ss -u $user --password=$pw --host=vela $db -e " $cquery "`
+   prun=`mysql -ss -u $user --password=$pw --host=vela $db -e " $pquery "`
+   cnum=`printf %08d $crun`
+   pnum=`printf %08d $prun`
+   echo "calrun number: " $cnum >> $scriptlog 2>&1
+   echo "pedrun number: " $pnum >> $scriptlog 2>&1
+   #get all directories in the linked structure for the epoch
+#   dirs=`find $mcrawpath/ -mindepth 3 -maxdepth 3 -type d`
+   files=`find $mcrawpath/ -lname *$epo*.root`
+
+   for file in ${files[@]}
+   do 
+      dir=`dirname $file`
+      date=`echo $file | cut -c 57-60,62,63,65,66`
+      
+      if ls $dir | grep MonteCarlo | grep $pnum
+      then 
+#         echo "P run already there, do nothing" >> $scriptlog 2>&1
+         continue
+      else 
+         echo "linking P run for epoch $epo" >> $scriptlog 2>&1
+         newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root"
+         ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+      fi
+      
+      if ls $dir | grep MonteCarlo | grep $cnum
+      then 
+#         echo "C run already there, do nothing" >> $scriptlog 2>&1
+         continue
+      else 
+         echo "linking C run for epoch $epo" >> $scriptlog 2>&1
+         newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root"
+         ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+      fi
+
+   done
+
+
+#   for dir in ${dirs[@]}
+#   do
+   
+#      #continue, if directory has already linked C and P run
+#      cont=`ls $dir/*_0000000[1-9]_[CP]_MonteCarlo_E.root 2>/dev/null | wc -w`
+#      if [ "$cont" == "6" ] >> $scriptlog 2>&1
+#      then
+#      	 continue
+#      fi
+
+#      #continue, if directory is not at the lowest level of the structure
+#      cont=`echo $dir | cut -d/ -f10`
+#      if [ "$cont" == "" ]
+#      then
+#      	 continue
+#      fi
+
+      #get date for filename from directory name
+#      date=`echo $dir | cut -c 57-60,62,63,65,66`
+#      time=`echo $dir | cut -c 62,63`
+#      psf=`echo $dir | cut -c 65,66`
+#      date=`echo $dir | cut -c 28-31,33,34,36,37`
+
+
+      #create new filenames and link files depending on the epoch
+#      case "$epo" in
+#      
+#    	 "MC_up_to_April06")
+#            echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
+#            newcalfile="${dir}/${date}_00000002_C_MonteCarlo_E.root"
+#      	    ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+#      	    newpedfile="${dir}/${date}_00000001_P_MonteCarlo_E.root"
+#      	    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+#            ;;
+#    	 "MC_old")
+#            echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
+#            newcalfile="${dir}/${date}_00000002_C_MonteCarlo_E.root"
+#      	    ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+#      	    newpedfile="${dir}/${date}_00000001_P_MonteCarlo_E.root"
+#      	    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+#            ;;
+#    	 "MC_April_May06")
+#            echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
+#            newcalfile="${dir}/${date}_00000004_C_MonteCarlo_E.root"
+#      	    ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+#      	    newpedfile="${dir}/${date}_00000003_P_MonteCarlo_E.root"
+#      	    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+#            ;;
+#    	 "MC_post_June06")
+#            echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
+#            newcalfile="${dir}/${date}_00000004_C_MonteCarlo_E.root"
+#      	    ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+#      	    newpedfile="${dir}/${date}_00000003_P_MonteCarlo_E.root"
+#      	    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+#            ;;
+#    	 "MC_MuxFADCs")
+#            echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
+#            newcalfile="${dir}/${date}_00000006_C_MonteCarlo_E.root"
+#      	    ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+#      	    newpedfile="${dir}/${date}_00000005_P_MonteCarlo_E.root"
+#      	    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+#            ;;
+#    	 "MC_MuxFADCs_NEW")
+#            echo "linking P and C for epoch $epo" >> $scriptlog 2>&1
+#            newcalfile="${dir}/${date}_00000006_C_MonteCarlo_E.root"
+#      	    ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+#      	    newpedfile="${dir}/${date}_00000005_P_MonteCarlo_E.root"
+#      	    ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+#            ;;
+#         *)
+#            echo "No epoch found"
+#      	    printprocesslog "ERROR wrong epoch for linking Cal and Ped, epoch: $cameradir"
+#            finish >> $scriptlog 2>&1
+#            ;;
+#      esac
+
+#   done
+done
+
+readme=$mcrawpath/README.txt #file in which the information about the properties of the files is redirected to have always an updated explanation
+
+# observation epochs 
+epochs=("" "After January 07 (new MUX)," "From April 06 to January 07," "Before April 06")
+
+# print information and explanation of structure into README.txt 
+date >| $readme 2>&1
+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 epoch" >> $readme 2>&1
+echo "DD represents the psf in mm" >> $readme 2>&1
+echo "" >> $readme 2>&1
+echo "explanation of the epochs" >> $readme 2>&1
+echo "epochs: "${epochs[@]} >> $readme 2>&1
+echo "" >> $readme 2>&1
+for (( i=1 ; i <= 3 ; i++ )) 
+do 
+   if [ "${epochs[i]}" != "" ]
+   then 
+      numofepoch=`printf %02d $i`
+      echo "epoch (MM) = $numofepoch means ${epochs[$i]}" >> $readme 2>&1
+   fi
+done
+echo "" >> $readme 2>&1
+echo "the epoch is indicating " >> $readme 2>&1
+echo " - the time for which the MCs are produced" >> $readme 2>&1
+echo "   the epoch is determined from the AmplFADCs value filled into the MC-DB" >> $readme 2>&1
+echo "" >> $readme 2>&1
+echo "----------------" >> $readme 2>&1
+echo "" >> $readme 2>&1
+echo "The names of the files characterize their properties. Structure:" >> $readme 2>&1
+echo "/magic/montecarlo/rawfiles/YYYY/MM/DD/YYYYMMDD_<RunNumber>_<P/C/D>_<Particle><Spectrum><ObservationMode>_E.root" >> $readme 2>&1
+echo "<P/C/D> indicates the run type" >> $readme 2>&1
+echo "<Particle>: Gamma, Proton, Muon, MonteCarlo (for P,C runs)" >> $readme 2>&1
+echo "<Spectrum>: empty or HE, depending on the simulated MC spectrum" >> $readme 2>&1
+echo "<ObservationMode>: empty (On), W1/W2 (Wobble), FW1/FW2 (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
+echo "" >> $readme 2>&1
+echo "Run numbers for Cal and Ped files are linked depending on the epoch:" >> $readme 2>&1
+echo "MC_old:           P=1, C=2" >> $readme 2>&1
+echo "MC_up_to_April06: P=1, C=2" >> $readme 2>&1
+echo "MC_April_May06:   P=3, C=4" >> $readme 2>&1
+echo "MC_post_June06:   P=3, C=4" >> $readme 2>&1
+echo "MC_MuxFADCs:      P=5, C=6" >> $readme 2>&1
+echo "MC_MuxFADCs_NEW:  P=5, C=6" >> $readme 2>&1
+echo "" >> $readme 2>&1
+
+
+finish >> $scriptlog 2>&1
+
Index: trunk/MagicSoft/Mars/datacenter/scripts/mcsequences
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/mcsequences	(revision 8757)
+++ trunk/MagicSoft/Mars/datacenter/scripts/mcsequences	(revision 8758)
@@ -40,5 +40,5 @@
 set -C
 
-scriptlog=$runlogpath/$program`date +%F`.log
+scriptlog=$runlogpath/$program-$datetime.log
 date >> $scriptlog 2>&1
 
@@ -48,9 +48,10 @@
 
 # find montecarlo directories, build one sequence per directory and write sequence file
-printprocesslog "INFO building one sequence per mcdirectory"
+printprocesslog "INFO building one sequence per mcdirectory and epoch"
 dirs=`find $mcrawpath -type d`
 for dir in ${dirs[@]}
 do 
-   cont=`echo $dir | cut -d/ -f6`
+#   cont=`echo $dir | cut -d/ -f6`
+   cont=`echo $dir | cut -d/ -f10`
    if [ "$cont" == "" ]
    then
@@ -58,35 +59,45 @@
    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
-   printprocesslog "INFO writing sequencefile $sequfile"
-   
-   echo "Sequence:        $firstrun" >| $sequfile
-   echo "Night:           $date" >> $sequfile
-   echo "" >> $sequfile
-   echo "CalRuns:         $calrun" >> $sequfile
-   echo "PedRuns:         $pedrun" >> $sequfile
-   echo "DatRuns:         $datruns" >> $sequfile
-   echo "" >> $sequfile
-   echo "MonteCarlo: Yes" >> $sequfile
-   echo "" >> $sequfile
+   epochs=`ls -l $mcpath/camera | cut -c 52-70`
+   for epoch in ${epochs[@]}
+   do
+      echo $epoch >> $scriptlog 2>&1
+      calfile=`find $dir -lname *$epoch*.root | grep "_C_"`
+      pedfile=`find $dir -lname *$epoch*.root | grep "_P_"`
+#      datfiles=`find $dir -lname '*$epoch*.root' | grep "_D_"`
+      
+      calrun=`echo $calfile | cut -d_ -f2`
+      pedrun=`echo $pedfile | cut -d_ -f2`
+      datruns=`find $dir -lname *$epoch*.root | grep "_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 28-37 | sed -e 's/\//-/g'`
+      # for tests
+      date=`echo $dir | cut -c 57-66 | 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
+      printprocesslog "INFO writing sequencefile $sequfile"
+      
+      echo "Sequence:        $firstrun" >| $sequfile
+      echo "Night:           $date" >> $sequfile
+      echo "Epoch:           $epoch" >> $sequfile
+      echo "" >> $sequfile
+      echo "CalRuns:         $calrun" >> $sequfile
+      echo "PedRuns:         $pedrun" >> $sequfile
+      echo "DatRuns:         $datruns" >> $sequfile
+      echo "" >> $sequfile
+      echo "MonteCarlo: Yes" >> $sequfile
+      echo "" >> $sequfile
+   done
 done
 
Index: trunk/MagicSoft/Mars/datacenter/scripts/processmcsequences
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/processmcsequences	(revision 8757)
+++ trunk/MagicSoft/Mars/datacenter/scripts/processmcsequences	(revision 8758)
@@ -59,4 +59,31 @@
    no=`echo $sequno | cut -c 0-4`
    date=`grep Night $sequfile | cut -c 18-29 | sed -e 's/-/\//g'`
+   muxcheck=`grep Epoch $sequfile | cut -c 18-32`
+   case $muxcheck in
+      "MC_up_to_April06")
+      callistorc=$setuppath/callisto/callisto.rc
+      ;;
+      "MC_old")
+      callistorc=$setuppath/callisto/callisto.rc
+      ;;
+      "MC_April_May06")
+      callistorc=$setuppath/callisto/callisto.rc
+      ;;
+      "MC_post_June06")
+      callistorc=$setuppath/callisto/callisto.rc
+      ;;
+      "MC_MuxFADCs")
+      callistorc=$setuppath/callisto/callisto_mux.rc
+      ;;
+      "MC_MuxFADCs_NEW")
+      callistorc=$setuppath/callisto/callisto_mux.rc
+      ;;
+      *)
+      echo "No epoch found"
+      printprocesslog "ERROR no epoch found in $sequfile for setting the right callisto.rc, using standard callisto.rc, epoch: $epoch"
+      finish >> $scriptlog 2>&1
+      ;;
+   esac
+      
    caloutpath=$mccalpath/$no/$sequno
    makedir $caloutpath >> $scriptlog 2>&1
