Index: trunk/MagicSoft/Mars/datacenter/scripts/fillcamera
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/fillcamera	(revision 8759)
+++ trunk/MagicSoft/Mars/datacenter/scripts/fillcamera	(revision 9144)
@@ -18,7 +18,7 @@
 #
 #
-#   Author(s): Daniel Hoehne  09/2007 <mailto:hoehne@astro.uni-wuerzburg.de>
-#
-#   Copyright: MAGIC Software Development, 2000-2007
+#   Author(s): Daniel Hoehne  06/2008 <mailto:hoehne@astro.uni-wuerzburg.de>
+#
+#   Copyright: MAGIC Software Development, 2000-2008
 #
 #
@@ -44,5 +44,8 @@
 #mccampath=$mcpath/camera
 mccampath=/magic/montecarlo/camera
-cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d`
+#workaround
+cameradirs=`find /magic/montecarlo/camera -maxdepth 4 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton ! -name Spot_?.?`
+#cameradirs=`find /magic/montecarlo/camera -maxdepth 3 -mindepth 2 -type d ! -name Gamma ! -name Muon ! -name Proton`
+#cameradirs=`find $mccampath -maxdepth 1 -mindepth 1 -type d`
 echo "camera dirs: "${cameradirs[@]}  >> $scriptlog 2>&1
 echo "" >> $scriptlog 2>&1
@@ -55,10 +58,19 @@
    printprocesslog "INFO inserting information for all root camera files in $cameradir"
    cam=`basename $cameradir`
+   spot=`echo $cameradir | cut -d/ -f7` #spotsize
+   par=`echo $cameradir | cut -d/ -f6` #particle name
+   if [ $cam = "Cal_and_Ped" ]
+   then
+      par=""
+      spot=""
+   fi
+   epo=`echo $cameradir | cut -d/ -f5` #epoch
    echo "dir: "$cameradir >> $scriptlog 2>&1
    fillcamerapath=$logpath/$program
    makedir $fillcamerapath >> $scriptlog 2>&1
-   fillcameralog=$fillcamerapath/$program-$cam.log
+   fillcameralog=$fillcamerapath/$program-$epo-$par-$spot-$cam.log
    
    check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kFALSE\) | tee $fillcameralog | intgrep`
+#   check0=`root -q -b $macrospath/fillcamera.C+\("\"$cameradir\""\,kTRUE\) | tee $fillcameralog | intgrep`
    case $check0 in 
       1)   echo "check0=$check0 -> everything ok " >> $scriptlog 2>&1 
@@ -77,66 +89,86 @@
    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" ]
+   if [ $cam = "Cal_and_Ped" ];
    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 28-31,33,34,36,37`
-      
-      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
+      echo "Cal_and_Ped folder, no cal and ped files will be linked" >> $scriptlog 2>&1
+   else
+
+      epo=`echo $cameradir | cut -d/ -f5` #filename
+      #epo=`basename $cameradir` #filename
+      pedfile=`find $mccampath/$epo/Cal_and_Ped -name *_P_*.root`
+      calfile=`find $mccampath/$epo/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 or too less files in the directory $epo/Cal_and_Ped -> exit" >> $scriptlog 2>&1
+        rm -v $lockfile >> $scriptlog 2>&1
+   	exit
+      	printprocesslog "ERROR too many ped and cal files found in $epo/Cal_and_Ped"
+      	finish >> $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
+      
+      #   user="test"
+      #   db="TestMonteCarlo"
+      #   pw="Ics+eaTD"
+      user="operator"
+      db="MyMagicMonteCarlo"
+      pw="Ics+eMM!"
+      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`
+         #datacenter
+         date=`echo $file | cut -c 28-31,33,34,36,37`
+         #for tests
+         #date=`echo $file | cut -c 57-60,62,63,65,66`
+         
+         newpedfile="${dir}/${date}_${pnum}_P_MonteCarlo_E.root"
          newcalfile="${dir}/${date}_${cnum}_C_MonteCarlo_E.root"
-         ln -sv $calfile $newcalfile >> $scriptlog 2>&1
-      fi
-
-   done
+         pupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newpedfile\" where fRunNumber=\"$prun\" "
+         cupdate=" update MCRunProcessStatus set fRunLinked=Now(), fLinkName=\"$newcalfile\" where fRunNumber=\"$crun\" "
+         if ls $dir | grep MonteCarlo | grep $pnum
+         then 
+            echo "P run already there, do mysql update" >> $scriptlog 2>&1
+   #         continue
+            mysql -ss -u $user --password=$pw --host=vela $db -e " $pupdate "
+         else 
+            echo "linking P run for epoch $epo" >> $scriptlog 2>&1
+            ln -sv $pedfile $newpedfile >> $scriptlog 2>&1
+            mysql -ss -u $user --password=$pw --host=vela $db -e " $pupdate "
+         fi
+         
+         if ls $dir | grep MonteCarlo | grep $cnum
+         then 
+            echo "C run already there, do mysql update" >> $scriptlog 2>&1
+   #         continue
+            mysql -ss -u $user --password=$pw --host=vela $db -e " $cupdate "
+         else 
+            echo "linking C run for epoch $epo" >> $scriptlog 2>&1
+            ln -sv $calfile $newcalfile >> $scriptlog 2>&1
+            mysql -ss -u $user --password=$pw --host=vela $db -e " $cupdate "
+         fi
+   
+      done
+   
+   fi
 
 done
@@ -145,5 +177,5 @@
 
 # observation epochs 
-epochs=("" "After January 07 (new MUX)," "From April 06 to January 07," "Before April 06")
+epochs=("" "After January 07 (MUX FADCs)," "From April 06 to January 07 (Siegen FADCs with splitters)," "Before April 06 (Siegen FADCs)")
 
 # print information and explanation of structure into README.txt 
@@ -156,5 +188,5 @@
 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 "DD represents the additional spot size in mm" >> $readme 2>&1
 echo "" >> $readme 2>&1
 echo "explanation of the epochs" >> $readme 2>&1
@@ -180,14 +212,6 @@
 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 "<Spectrum>: 'empty' or HE, depending on the simulated MC spectrum" >> $readme 2>&1
+echo "<ObservationMode>: 'empty' (On), W1/W2 (Wobble), FW (Fake Wobble), Diff (Diffuse)" >> $readme 2>&1
 echo "" >> $readme 2>&1
 
