#!/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): Daniela Dorner 05/2005 # # Copyright: MAGIC Software Development, 2000-2006 # # # ======================================================================== # # This a resource file for the scripts, in which the standard paths and # functions, which are needed more often are stored. # Only constant variables are stored here, changing variables are stored # in datacenter/scripts/setup # source `dirname $0`/setup mars=`dirname $0 | sed -e 's/\/datacenter\/scripts//'` macrospath=$mars/datacenter/macros scriptspath=$mars/datacenter/scripts webpath=/www/htdocs/datacenter datetime=`date +%F-%H-%M-%S` check="ok" #failed codes #sequence build status Fbuildsequ=1 Fdoexcl=2 #run process status Ftimecorr=3 Ffillraw=4 Fsinope=5 Ffillsinope=6 Fresetexcl=7 #sequence process status Fwritesequfile=8 Ffilesavail=9 Fnoccfile=10 Fnocacofile=11 Fmerppcc=12 Fmerppcaco=13 Fcallisto=14 Ffillcalib=15 Ffillsignal=16 Fstar=17 Ffillstar=18 #dataset process status Fstardone=19 Fganymed=20 Ffillganymed=21 # setup for jobmanager steps=$mars/steps.rc pno=0 pnototal=0 running=0 queued=0 runningscript=0 queuedscript=0 function setzero() { val=$@ if [ "$val" == "" ] then test=`condor_q -global` if [ "$test" == "" ] then echo $max else echo 0 fi else echo $val fi } # in the following the function, which are needed by several scripts, are # defined # function to exit a script properly function finish() { rm -v $todofile rm -v $lockfile date exit } # function to do continue in a loop or exit the program depending on what is needed function contex() { echo "" if [ "$singleprocess" = "yes" ] then continue else finish fi } # function to make sure that a directory is made function makedir() { if [ ! -d $@ ] then mkdir -pv $@ if [ ! -d $@ ] then echo "could not make dir "$@ finish fi fi } # function to check if a process is already locked function checklock() { date > $lockfile checklock0=$? case $checklock0 in 0) echo " checklock0=$checklock0 -> continue " ;; 1) echo " checklock0=$checklock0 -> file $lockfile exists -> exit" date contex;; *) echo " checklock0=$checklock0 -> something went completely wrong" ;; esac } # function calling the macro, which is producing the todo-list function getdolist() { datetime=`date +%F-%H-%M-%S` year=`date +%Y` date=NULL getstatuslogpath=$logpath/getstatus/$program/$year getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log makedir $getstatuslogpath # get todo list echo "getting todo list..." check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\,"\"$listpath\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'` case $check0 in 1) echo " check0=$check0 -> everything ok, got todo list -> run $program";; *) echo " check0=$check0 -> ERROR -> could not get todo list -> exit" finish ;; esac } function resetstatusvalues() { statustime=NULL starttime=NULL returncode=NULL failedcode=NULL failedcodeadd=NULL failedtime=NULL } function printstatusvalues() { echo "the current values are:" echo " statustime=$statustime" echo " starttime=$starttime" echo " returncode=$returncode" echo " failedcode=$failedcode" echo " failedcodeadd=$failedcodeadd" echo " failedtime=$failedtime" echo "-- check: -$check-" echo "" } # function evaluating the statusvalues function evalstatus() { case $@ in start) echo "setstatus start" starttime="Now()" ;; stop) echo "setstatus stop" case $check in ok) echo " ok" statustime="Now()" ;; no) echo "nothing new" check="ok" ;; *) echo " failed" starttime=noreset returncode=$check failedcode=$com if ! [ "$comadd" = "" ] then failedcodeadd=$comadd fi failedtime="Now()" check="ok" ;; esac ;; *) echo "error -> exit" exit ;; esac } # function calling the macro to set the status, after a process has finished function setstatusroot() { # set status values resetstatusvalues evalstatus $@ # printstatusvalues # set status setstatuslogpath=$logpath/setstatus/$program/$var1 makedir $setstatuslogpath setstatuslog=$setstatuslogpath/setstatus-$@-$program-$var2.log checkstatus=`root -q -b $macrospath/setstatus.C+\("\"$var2\""\,"\"$table\""\,"\"$column\""\,"\"$statustime\""\,"\"$returncode\""\,"\"$failedcode\""\,"\"$failedcodeadd\""\,"\"$starttime\""\,"\"$failedtime\""\) | tee $setstatuslog | grep int | sed -e 's/(int)//'` case $checkstatus in 1) echo " checkstatus=$checkstatus -> everything ok, status has been set";; *) echo " checkstatus=$checkstatus -> ERROR -> step could not be set -> exit" finish ;; esac } function getdbsetup() { db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'` pw=`grep Password $mars/sql.rc | grep -v '#' | sed -e 's/Password: //' -e 's/ //g'` us=`grep User $mars/sql.rc | grep -v '#' | sed -e 's/User: //' -e 's/ //g'` # echo "setup: " # echo " db: "$db # echo " pw: "$pw # echo " us: "$us } function getstepinfo() { table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'` coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'` needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"` influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"` primary=`grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"` # echo " column $column - table $table - coltab $coltab" # echo " needs: $needs" # echo " influences: $influences" # echo " primary: $primary" } # function to get todolist function gettodo() { echo "getting todo..." getdbsetup if [ "$singleprocess" = "yes" ] then column=${scriptscolname[$i]} fi getstepinfo # get query query=" select $primary from $table where " if ! echo $needs | grep '#' > /dev/null then for need in $needs do query=$query" not isnull($need) and" done fi if ! echo $influences | grep '#' > /dev/null then for influence in $influences do query=$query" isnull($influence) and" done fi query=$query" isnull($column) " query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) " query=$query" order by $primary desc " if [ "$singleprocess" = "yes" ] then query=$query" limit 0, 1 " fi # echo " QUERY: "$query if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "` then echo "ERROR could not query process from db -> contex" rm -v $lockfile contex fi if [ "$process" = "" ] then echo " => nothing to do" rm -v $lockfile contex else if [ "$singleprocess" = "yes" ] then todofile=$listpath/ToDo-$table-$column-$process.txt echo " => found $process" else todofile=$listpath/ToDo-$table-$column.txt echo "found processes" fi # echo " list: "$todofile if ls $todofile > /dev/null 2>&1 then echo "$todofile exists already" rm -v $lockfile contex fi echo $process > $todofile fi } # function to set status of a process in the db function setstatus() { resetstatusvalues evalstatus $@ echo "setting todo..." getdbsetup getstepinfo # get query reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'` echo -$reset- if [ "$reset" = "no" ] then echo "YOU CAN'T RESET $column for $var2!!!" finish fi query=" update $table set $column=$statustime" if ! echo $influences | grep '#' > /dev/null then for influence in $influences do query=$query", $influence=NULL" done fi query=$query", fStartTime=$starttime, fFailedTime=$failedtime, fFailedCode=$failedcode, fFailedCodeAdd=$failedcodeadd, fReturnCode=$returncode " query=$query" where $primary=$var2" echo " QUERY: "$query if ! mysql -s -u $us --password=$pw --host=hercules $db -e " $query " then echo "ERROR could not insert status into db -> exit" finish fi }