Index: trunk/MagicSoft/Mars/datacenter/scripts/zipscript
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/zipscript	(revision 8331)
+++ trunk/MagicSoft/Mars/datacenter/scripts/zipscript	(revision 8482)
@@ -20,5 +20,5 @@
 #   Author(s): Daniela Dorner  09/2006 <mailto:dorner@astro.uni-wuerzburg.de>
 #
-#   Copyright: MAGIC Software Development, 2000-2006
+#   Copyright: MAGIC Software Development, 2000-2007
 #
 #
@@ -30,5 +30,7 @@
 source `dirname $0`/sourcefile
 printprocesslog "INFO starting $0"
-program=zipscript
+# to give the possibility to run several zipscripts at the same time, 
+# $1 is added
+program=zipscript$1
 
 set -C
@@ -52,109 +54,54 @@
 
 for file in ${files[@]}
-do 
+do
+   echo "processing file $file..." >> $scriptlog 2>&1 
+   runno=`basename $file | cut -d_ -f2`
+   query="SELECT fSequenceFirst FROM RunData WHERE fRunNumber="$runno
+   echo " sending query: $query" >> $scriptlog 2>&1 
+   if ! seq=`sendquery`
+   then
+      echo "querying seq for run $runno from the db did not work -> continue" >> $scriptlog 2>&1
+      printprocesslog "WARN query $seq for run $runno from the db did not work"
+      continue
+   fi
+   if [ "$seq" == "" ] 
+   then
+      echo "no seq found for run $runno -> locking only run..." >> $scriptlog 2>&1
+      seq=$runno
+   fi
+   echo "locking sequence $seq..."  >> $scriptlog 2>&1 
+   lockfile=$lockpath/calzip$seq.txt
+   checklock continue >> $scriptlog 2>&1
+   query="UPDATE SequenceProcessStatus set fNotZipping=NULL WHERE fSequenceFirst=$seq"
+   echo " sending query: $query" >> $scriptlog 2>&1 
+   if ! sendquery 
+   then
+      echo "locking $seq for callisto in db did not work ..." >> $scriptlog 2>&1
+      printprocesslog "WARN locking $seq for callisto in db did not work"
+      rm -v $lockfile >> $scriptlog 2>&1
+      continue
+   fi
    echo "zipping $file ..." >> $scriptlog 2>&1
-#   if ssh pegasus nice -n 19 gzip -1f $file >> $scriptlog 2>&1
-   if ssh phoenix nice -n 19 gzip -1f $file >> $scriptlog 2>&1
-
+   if ssh -x phoenix nice -n 19 gzip -1f $file >> $scriptlog 2>&1
    then 
-      chmod a-w $file >> $scriptlog 2>&1
+      gzfile=$file".gz"
+      chmod a-w $gzfile >> $scriptlog 2>&1
+   else
+      printprocesslog "WARN zipping $file did not work"
    fi
+   echo "unlocking sequence $seq..."  >> $scriptlog 2>&1 
+   query="UPDATE SequenceProcessStatus set fNotZipping=Now() WHERE fSequenceFirst=$seq"
+   echo " sending query: $query" >> $scriptlog 2>&1 
+   if ! sendquery 
+   then
+      echo "unlocking $seq for callisto in db did not work ..." >> $scriptlog 2>&1
+      printprocesslog "ERROR unlocking $seq for callisto in db did not work"
+      rm -v $lockfile >> $scriptlog 2>&1
+      continue
+   fi
+   rm -v $lockfile >> $scriptlog 2>&1
 done
 
+lockfile=$lockpath/lock-$program.txt
 finish >> $scriptlog 2>&1
 
-
-
-# old code for running script locally
-
-#rawdatapath=$datapath/rawfiles
-##h:     0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-#pnos=( 2 2 2 2 2 2 2 2 2 2  2  2  2  2  2  2  2  2  2  2  2  2  2  2 )
-#sl1=30 #sleeping time before new directory
-#sl2=60 #sleeping time before new process check
-#
-#dirs=`find $rawdatapath -type d | grep -v timecorrlogs | sort`
-##dirs=`find $rawdatapath -type d | grep -v timecorrlogs | sort -r`
-#
-#for dir in ${dirs[@]}
-#do
-#   cont=`echo $dir | cut -d/ -f7`
-#   if [ "$cont" == "" ]
-#   then
-#      continue
-#   fi
-#
-#   if ! ls $dir/*.raw >/dev/null 2>&1
-#   then
-#      echo "no unzipped rawfiles in $dir left"
-#      continue
-#   fi
-#
-#   echo "sleeping $sl1..."
-#   sleep $sl1
-#
-#   h=`date +%k`
-#   count=`ps aux | grep gzip | grep -v grep | wc -l`
-#   echo "count: $count - h: $h - pno: ${pnos[$h]}"
-#   while [ "$count" -ge "${pnos[$h]}" ]
-#   do
-#      echo "sleeping $sl2..."
-#      sleep $sl2
-#      h=`date +%k`
-#      count=`ps aux | grep gzip | grep -v grep | wc -l`
-#      echo "count: $count - h: $h - pno: ${pnos[$h]}"
-#   done
-#   echo $dir
-#   du -hs $dir
-#   echo "gzip -1f $dir/*.raw &"
-#   gzip -1f $dir/*.raw &
-#done
-#
-
-
-# old code for running script with condor
-
-#rawdatapath=$datapath/rawfiles
-##h:     0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
-#pnos=( 2 2 2 2 2 2 2 2 2 2  2  2  2  2  2  2  2  2  2  2  2  2  2  2 )
-#sl1=30 #sleeping time before new directory
-#sl2=60 #sleeping time before new process check
-#
-#dirs=`find $rawdatapath -type d | grep -v timecorrlogs | sort`
-##dirs=`find $rawdatapath -type d | grep -v timecorrlogs | sort -r`
-#
-#for dir in ${dirs[@]}
-#do
-#   cont=`echo $dir | cut -d/ -f7`
-#   if [ "$cont" == "" ]
-#   then
-#      continue
-#   fi
-#
-#   if ! ls $dir/*.raw >/dev/null 2>&1
-#   then
-#      echo "no unzipped rawfiles in $dir left"
-#      continue
-#   fi
-#
-#   echo "sleeping $sl1..."
-#   sleep $sl1
-#
-#   h=`date +%k`
-#   count=`grep gzip .condor_run.* | wc -l`
-#   echo "count: $count - h: $h - pno: ${pnos[$h]}"
-#   while [ "$count" -ge "${pnos[$h]}" ]
-#   do
-#      echo "sleeping $sl2..."
-#      sleep $sl2
-#      h=`date +%k`
-#      count=`grep gzip .condor_run.* | wc -l`
-#      echo "count: $count - h: $h - pno: ${pnos[$h]}"
-#   done
-#   echo $dir
-#   du -hs $dir
-#   condor_run gzip -1f $dir/*.raw &
-#
-#done
-#
-
