Index: trunk/MagicSoft/Mars/datacenter/scripts/makecallistolinks
===================================================================
--- trunk/MagicSoft/Mars/datacenter/scripts/makecallistolinks	(revision 8482)
+++ trunk/MagicSoft/Mars/datacenter/scripts/makecallistolinks	(revision 9056)
@@ -50,61 +50,47 @@
 callistorcseq=callisto.rc
 callistorcnew=callisto_Dec04Jan05.rc
-# reason why calibration with standard callisto.rc fails
-#reason1="Pulse is too much to the right, cannot go beyond logain limits!"
-#.* == hi or lo
-reason1="Pulse is too much to the right, out of .*-gain range"
-#reason2="No entry for resource id '2[45]' found in"
-echo "reason1: "$reason1 >> $scriptlog 2>&1
-#echo "reason2: "$reason2 >> $scriptlog 2>&1
 
-# find files containing reason 
-files=`find $datapath/callisto/ -name callisto*.log`
-if [ "$files" = "" ]
+# query failed callistos (returncode 13) from DB
+query="SELECT fSequenceFirst, fTelescopeNumber from SequenceProcessStatus where fReturnCode=13 and fProgramId=14"
+primaries=( `sendquery` )
+echo ${primaries[@]}
+if [ ${#primaries[@]} -eq 0 ]
 then 
    echo "nothing to do -> exit"  >> $scriptlog 2>&1
    finish >> $scriptlog 2>&1
 fi
+num=`expr ${#primaries[@]} / 2 `
 
 cd $mars
 
-# make links for callisto.rc for which the callisto.log contains reason
 printprocesslog "INFO linking callisto.rc files"
-for file in $files
-do 
-#   pulse=`cat $file | grep "$reason1\|$reason2"`
-   pulse=`cat $file | grep "$reason1"`
-   sequ=`echo $file | cut -d/ -f6`
-   path=`dirname $file`
-   callistorc=$path/$callistorcseq
+for (( s=0 ; s < $num ; s++ ))
+do
+   sequence=${primaries[$s+$s]}
+   telnum=${primaries[$s+$s+1]}
+   callistorc=$datapath/callisto/`printf %08d $sequence | cut -c 0-4`/`printf %08d $sequence`/$callistorcseq
+   if ! ls -l $callistorc 2>/dev/null | grep $callistorcnew >> $scriptlog 2>&1
+   then 
+      printprocesslog "INFO linking $callistorcnew to $callistorc for sequ $sequence"
+      # resetting the calibration
+      echo "resetting the callisto for sequence $sequence" >> $scriptlog 2>&1
 
-   if [ ! "$pulse" = "" ]
-   then
-      if ! ls -l $callistorc | grep $callistorcnew >> $scriptlog 2>&1
+      query="UPDATE SequenceProcessStatus set fStartTime=NULL, fFailedTime=NULL, fProgramId=NULL, fReturnCode=NULL where fSequenceFirst=$sequence and fTelescopeNumber=$telnum"
+      if ! sendquery >> $scriptlog 2>&1
       then 
-         printprocesslog "INFO linking $callistorcnew to $callistorc for sequ $sequ"
-         # resetting the calibration
-         echo "resetting the callisto for sequence $sequ" >> $scriptlog 2>&1
-         echo "  reason: $pulse" >> $scriptlog 2>&1
-         resetlogpath=$logpath/resetcallisto
-         makedir $resetlogpath >> $scriptlog 2>&1
-         resetlog=$resetlogpath/reset-callisto-$sequ.log
-
-         check1=`root -q -b $macrospath/resetcolumn.C+\("\"$column\""\,"\"$table\""\,"\"$sequ\""\,"\"$sequ\""\,kFALSE\) | tee $resetlog | intgrep`
-         case $check1 in
-            1)   echo " check1=$check1 -> everything ok, callisto has been reset " >> $scriptlog 2>&1
-                 printprocesslog "INFO resetted calibration successfully for sequence $sequ"
-                 ;;
-            0)   echo " check1=$check1 -> no connection to db -> continue..." >> $scriptlog 2>&1 
-                 printprocesslog "WARN connection to DB failed"
-                 check="no"
-                 ;;
-            *)   echo " check1=$check1 -> ERROR -> step could not be resetted -> continue " >> $scriptlog 2>&1
-                 printprocesslog "ERROR resetcolumn.C failed for fCallisto for sequ $sequ"
-                 continue 
-                 ;;
-         esac
-         #linking callisto.rc
-         ln -vfs $setuppath/callisto/$callistorcnew $callistorc >> $scriptlog 2>&1
+         printprocesslog "ERROR resetting calibration failed for sequence $sequence"
+         continue
+      else 
+         printprocesslog "INFO resetted calibration successfully for sequence $sequence"
       fi
+      
+      #linking callisto.rc
+      if ln -vfs $setuppath/callisto/$callistorcnew $callistorc >> $scriptlog 2>&1
+      then 
+         printprocesslog "INFO link callisto.rc successfully for sequence $sequence"
+      else 
+         printprocesslog "ERROR linking callisto.rc failed for sequence $sequence"
+      fi
+      
    fi
 done
