Index: trunk/MagicSoft/Mars/datacenter/scripts/cutslices
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/cutslices	(revision 9046)
+++ trunk/MagicSoft/Mars/datacenter/scripts/cutslices	(revision 9081)
@@ -20,5 +20,5 @@
 #   Author(s): Stefan Ruegamer 12/2007 <mailto:snruegam@astro.uni-wuerzburg.de>
 #
-#   Copyright: MAGIC Software Development, 2000-2007
+#   Copyright: MAGIC Software Development, 2000-2008
 #
 #
@@ -32,8 +32,4 @@
 source `dirname $0`/sourcefile
 printprocesslog "INFO starting $0"
-echo "This script has not been adapted to the new file structure (MAGIC II). "
-echo "Please adapt it before using it."
-exit
-
 program=compmux
 column=fCompmux
@@ -41,66 +37,69 @@
 set -C
 
-scriptlog=/magic/datacenter/compmux/$program-$datetime.log
+scriptlog=$runlogpath/run$program-$datetime.log
 date >> $scriptlog 2>&1
-todofile=$listpath/ToDo-$table-$column.txt
 
-if [ -e $todofile ]
-then 
-   echo "$program is already running -> exit" >> $scriptlog 2>&1
-   exit
-fi
-
-#get todo list
-getdolist >> $scriptlog 2>&1
-
-#retrieving runs from todo file
-files=(`cat $listpath/ToDo-$table-$column.txt`)
-if [ "$files" = "" ]
-then 
-   echo "nothing to do -> exit" >> $scriptlog 2>&1
-   finish >> $scriptlog 2>&1
-fi
-
-for file in ${files[@]}
+# query db 20 times for jobs
+for ((j=0 ; j < 20 ; j++))
 do
-   echo -e "\ngetting path for run $file..." >> $scriptlog 2>&1
-   fullpath=`find $datapath/rawfiles/2007/0[2-9] -name *${file}_[DCPS]_*`
+   gettodo "1" >> $scriptlog 2>&1
+   runno=${primaries[0]}
+   tempfile=/data/tmp/temp${runno}.gz
    
-   lockfile=$lockpath/lock-$program-$file.txt
+   lockfile=$lockpath/lock-$table-$column-$runno.txt
+   checklock >> $scriptlog 2>&1
    
-   #check lock file and stop for this run if already being processed
-   checklock continue >> $scriptlog 2>&1
-   
-   primvar=$file
    setstatus "start" >> $scriptlog 2>&1
    
-   cd $mars
+   # try to find the file; if impossible, continue with an error
+   echo "getting path for run $runno..." >> $scriptlog 2>&1
+   printprocesslog "INFO starting $program for run $runno"
+   fullname=`find $datapath/rawfiles/2007/0[2-9] -name 20070*${runno}_[DCPS]_*.raw.gz`
+   arraycheck=`echo $fullname | wc -w`
+   if [ "$fullname" == "" ] || ! [ $arraycheck == 1 ]
+   then
+      echo "ERROR file for run $runno not found or more than one file found... continue" >> $scriptlog 2>&1
+      printprocesslog "ERROR $program failed, file for run $runno not found or more than one file found"
+      rm -v $lockpath/lock-$table-$column-$runno.txt >> $scriptlog 2>&1
+      check=20
+      com=$FCompmux
+      setstatus "stop" >> $scriptlog 2>&1
+      echo "" >> $scriptlog 2>&1
+      continue
+   fi
    
-   #cut the slices
-   gzip -cd $fullpath | $mars/datacenter/compmux | gzip -1c > /tmp/temp${file}.gz
-   check1=$?
-   touch -r $fullpath /tmp/temp${file}.gz
+   # cut the slices
+   check1=`ssh -nx phoenix 'cd /home/operator/compmux ; nice -n 19 gzip -cd' $fullname '| nice -n 19 ./compmux | nice -n 19 gzip -1c > /data/tmp/temp'${runno}.gz ' ; echo ${PIPESTATUS[1]}'`
    
-   #check success and insert information into the database
+   # check success and insert information into the database
    case $check1 in
-      0)   echo " check1=$check1 -> everything ok -> compmux succeeded, overwriting old file for run $file" >> $scriptlog 2>&1
-           mv -f /tmp/temp${file}.gz $fullpath >> $scriptlog 2>&1
+      0)   echo " check1=$check1 -> everything ok -> compmux succeeded, overwriting old file for run $runno" >> $scriptlog 2>&1
+      	   ssh -nx phoenix nice -n 19 touch -r $fullname $tempfile
+           ssh -nx phoenix nice -n 19 mv -f $tempfile $fullname >> $scriptlog 2>&1
            check2=$?
-           chmod a=r $fullpath
            case $check2 in
-              0)   echo " check2=$check2 -> everything ok -> mv done, setting db status for run $file" >> $scriptlog 2>&1
-                   rm -v $lockfile >> $scriptlog 2>&1
+              0)   echo " check2=$check2 -> everything ok -> mv done, setting db status for run $runno" >> $scriptlog 2>&1
+      	           ssh -nx phoenix nice -n 19 chmod a=r $fullname
                    ;;
-              *)   echo " check2=$check2 -> ERROR - moving of run $file failed -> continue" >> $scriptlog 2>&1
-                   continue
+              *)   echo " check2=$check2 -> ERROR - moving of run $runno failed" >> $scriptlog 2>&1
+                   printprocesslog "ERROR $program failed, moving of run $runno failed"
+        	   check=$check2
+              	   com=$FCompmux
                    ;;
            esac
+           printprocesslog "INFO $program finished successfully for run $runno"
            ;;
-      *)   echo " check1=$check1 -> ERROR - $program failed for run $file" >> $scriptlog 2>&1
-           com=$FCompmux
+      *)   echo " check1=$check1 -> ERROR - $program failed for run $runno" >> $scriptlog 2>&1
+           printprocesslog "ERROR $program failed for run $runno"
+           rm -v $tempfile >> $scriptlog 2>&1
            check=$check1
+      	   com=$FCompmux
            ;;
    esac
    
+   rm -v $lockpath/lock-$table-$column-$runno.txt >> $scriptlog 2>&1
    setstatus "stop" >> $scriptlog 2>&1
+   echo "" >> $scriptlog 2>&1
 done
+
+finish >> $scriptlog 2>&1
