| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # ========================================================================
|
|---|
| 4 | #
|
|---|
| 5 | # *
|
|---|
| 6 | # * This file is part of MARS, the MAGIC Analysis and Reconstruction
|
|---|
| 7 | # * Software. It is distributed to you in the hope that it can be a useful
|
|---|
| 8 | # * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
|---|
| 9 | # * It is distributed WITHOUT ANY WARRANTY.
|
|---|
| 10 | # *
|
|---|
| 11 | # * Permission to use, copy, modify and distribute this software and its
|
|---|
| 12 | # * documentation for any purpose is hereby granted without fee,
|
|---|
| 13 | # * provided that the above copyright notice appear in all copies and
|
|---|
| 14 | # * that both that copyright notice and this permission notice appear
|
|---|
| 15 | # * in supporting documentation. It is provided "as is" without express
|
|---|
| 16 | # * or implied warranty.
|
|---|
| 17 | # *
|
|---|
| 18 | #
|
|---|
| 19 | #
|
|---|
| 20 | # Author(s): Daniela Dorner 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
|
|---|
| 21 | #
|
|---|
| 22 | # Copyright: MAGIC Software Development, 2000-2004
|
|---|
| 23 | #
|
|---|
| 24 | #
|
|---|
| 25 | # ========================================================================
|
|---|
| 26 | #
|
|---|
| 27 | #
|
|---|
| 28 |
|
|---|
| 29 | export ROOTSYS=/opt/root_v3.10.02
|
|---|
| 30 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
|
|---|
| 31 | export PATH=$PATH:$ROOTSYS/bin
|
|---|
| 32 |
|
|---|
| 33 | set -C
|
|---|
| 34 |
|
|---|
| 35 | mars=/home/operator/Mars
|
|---|
| 36 | macrospath=$mars/datacenter/macros
|
|---|
| 37 | scriptspath=$mars/datacenter/scripts
|
|---|
| 38 |
|
|---|
| 39 | table=SequenceProcessStatus
|
|---|
| 40 | column=fStar
|
|---|
| 41 | date=NULL
|
|---|
| 42 | datetime=`date +%F-%H-%M-%S`
|
|---|
| 43 | year=`date +%Y`
|
|---|
| 44 | pno=24 # number of processes, i.e. number of todo-files
|
|---|
| 45 |
|
|---|
| 46 | todofile=/magic/datacenter/lists/ToDo-$table-$column
|
|---|
| 47 | lockpath=/magic/datacenter/locks
|
|---|
| 48 | logpath=/magic/datacenter/autologs
|
|---|
| 49 | getstatuslogpath=$logpath/getstatus/star/$year
|
|---|
| 50 | getstatuslog=$getstatuslogpath/getstatus-star-$datetime.log
|
|---|
| 51 |
|
|---|
| 52 | scriptlogpath=$logpath/run/star/`date +%Y/%m/%d`
|
|---|
| 53 | if [ ! -d $scriptlogpath ]
|
|---|
| 54 | then
|
|---|
| 55 | mkdir -pv $scriptlogpath
|
|---|
| 56 | if [ ! -d $scriptlogpath ]
|
|---|
| 57 | then
|
|---|
| 58 | echo "could not make scriptlogpath "$scriptlogpath
|
|---|
| 59 | exit
|
|---|
| 60 | fi
|
|---|
| 61 | fi
|
|---|
| 62 |
|
|---|
| 63 | scriptlog=$scriptlogpath/runstar-$datetime.log
|
|---|
| 64 |
|
|---|
| 65 | date >> $scriptlog 2>&1
|
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 | if [ ! -d $getstatuslogpath ]
|
|---|
| 69 | then
|
|---|
| 70 | mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
|
|---|
| 71 | if [ ! -d $getstatuslogpath ]
|
|---|
| 72 | then
|
|---|
| 73 | echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
|
|---|
| 74 | date >> $scriptlog 2>&1
|
|---|
| 75 | exit
|
|---|
| 76 | fi
|
|---|
| 77 | fi
|
|---|
| 78 |
|
|---|
| 79 | cd $mars
|
|---|
| 80 |
|
|---|
| 81 | date > $lockpath/lock-getting-star-list.txt >> $scriptlog 2>&1
|
|---|
| 82 | checklock0=$?
|
|---|
| 83 | case $checklock0 in
|
|---|
| 84 | 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
|
|---|
| 85 | 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
|
|---|
| 86 | echo "-> getting list for star is running -> exit" >> $scriptlog 2>&1
|
|---|
| 87 | date >> $scriptlog 2>&1
|
|---|
| 88 | exit;;
|
|---|
| 89 | *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
|
|---|
| 90 | esac
|
|---|
| 91 |
|
|---|
| 92 | echo "checking if other todo-files are there" >> $scriptlog 2>&1
|
|---|
| 93 | if ls $todofile-[1-9]*.txt >> $scriptlog 2>&1
|
|---|
| 94 | then
|
|---|
| 95 | echo "other file(s) on disk " >> $scriptlog 2>&1
|
|---|
| 96 | echo " -> choose one file and start calculation of image parameter" >> $scriptlog 2>&1
|
|---|
| 97 | else
|
|---|
| 98 | echo "getting list..." >> $scriptlog 2>&1
|
|---|
| 99 | check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
|
|---|
| 100 |
|
|---|
| 101 | case $check0 in
|
|---|
| 102 | 1) echo "check0=$check0 -> everthing ok -> run star" >> $scriptlog 2>&1;;
|
|---|
| 103 | *) echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
|
|---|
| 104 | esac
|
|---|
| 105 | echo "cutting to-do-file" >> $scriptlog 2>&1
|
|---|
| 106 | echo "getting no of lines" >> $scriptlog 2>&1
|
|---|
| 107 | lines=`cat $todofile.txt | wc -l`
|
|---|
| 108 | echo "number of lines: "$lines >> $scriptlog 2>&1
|
|---|
| 109 | while (( "$lines" < "$pno" ))
|
|---|
| 110 | do
|
|---|
| 111 | echo "# of lines ($lines) < # of processes ($pno) "
|
|---|
| 112 | pno=`expr $pno / 2`
|
|---|
| 113 | done
|
|---|
| 114 | echo "pno: "$pno
|
|---|
| 115 | nofiles=`expr $lines / \( $pno - 1 \)`
|
|---|
| 116 | echo "number of files: "$nofiles >> $scriptlog 2>&1
|
|---|
| 117 | echo "deviding todo-file" >> $scriptlog 2>&1
|
|---|
| 118 | for (( j=1 ; j <= $pno ; j++ ))
|
|---|
| 119 | do
|
|---|
| 120 | begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
|
|---|
| 121 | end=$(echo "$begin + $nofiles - 1" | bc -l)
|
|---|
| 122 | echo "begin: "$begin >> $scriptlog 2>&1
|
|---|
| 123 | echo "end: "$end >> $scriptlog 2>&1
|
|---|
| 124 | file=${todofile}-${j}.txt
|
|---|
| 125 | echo "file: "$file >> $scriptlog 2>&1
|
|---|
| 126 | sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
|
|---|
| 127 | done
|
|---|
| 128 |
|
|---|
| 129 | rm -v $todofile.txt >> $scriptlog 2>&1
|
|---|
| 130 | fi
|
|---|
| 131 |
|
|---|
| 132 | rm -v $lockpath/lock-getting-star-list.txt >> $scriptlog 2>&1
|
|---|
| 133 |
|
|---|
| 134 | nr=bla
|
|---|
| 135 | echo "finding the right todo-file" >> $scriptlog 2>&1
|
|---|
| 136 | for (( i = 1; i <= $pno ; i++ ))
|
|---|
| 137 | do
|
|---|
| 138 | if ! ls $todofile-$i.txt >> $scriptlog 2>&1
|
|---|
| 139 | then
|
|---|
| 140 | echo "file is not on disk -> continue" >> $scriptlog 2>&1
|
|---|
| 141 | continue
|
|---|
| 142 | fi
|
|---|
| 143 | date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1
|
|---|
| 144 | checklock=$?
|
|---|
| 145 | case $checklock in
|
|---|
| 146 | 0) echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
|
|---|
| 147 | nr=${i}
|
|---|
| 148 | break;;
|
|---|
| 149 | 1) echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
|
|---|
| 150 | *) echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
|
|---|
| 151 | esac
|
|---|
| 152 | done
|
|---|
| 153 |
|
|---|
| 154 | case $nr in
|
|---|
| 155 | bla) echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
|
|---|
| 156 | date >> $scriptlog 2>&1
|
|---|
| 157 | exit;;
|
|---|
| 158 | 12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
|
|---|
| 159 | esac
|
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 | sequences=(`cat $todofile-$nr.txt`)
|
|---|
| 163 |
|
|---|
| 164 | if [ "$sequences" = "" ]
|
|---|
| 165 | then
|
|---|
| 166 | echo "nothing to do -> exit" >> $scriptlog 2>&1
|
|---|
| 167 | rm -v $todofile-$nr.txt >> $scriptlog 2>&1
|
|---|
| 168 | rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
|
|---|
| 169 | date >> $scriptlog 2>&1
|
|---|
| 170 | exit
|
|---|
| 171 | fi
|
|---|
| 172 |
|
|---|
| 173 | echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
|
|---|
| 174 |
|
|---|
| 175 | for sequence in ${sequences[@]}
|
|---|
| 176 | do
|
|---|
| 177 | no=`printf %08d $sequence | cut -c 4`
|
|---|
| 178 | outpath="/magic/data/star/"`printf %04d $no`"/"`printf %08d $sequence`
|
|---|
| 179 | inpath=`echo $outpath | sed -e 's/star/callisto/'`
|
|---|
| 180 | echo "inpath: "$inpath >> $scriptlog 2>&1
|
|---|
| 181 | echo "outpath: "$outpath >> $scriptlog 2>&1
|
|---|
| 182 | if [ ! -d $outpath ]
|
|---|
| 183 | then
|
|---|
| 184 | mkdir -pv $outpath >> $scriptlog 2>&1
|
|---|
| 185 | if [ ! -d $outpath ]
|
|---|
| 186 | then
|
|---|
| 187 | echo "could not make outpath $outpath -> continue " >> $scriptlog 2>&1
|
|---|
| 188 | continue
|
|---|
| 189 | fi
|
|---|
| 190 | fi
|
|---|
| 191 | sequfile="/magic/sequences/"`printf %04d $no`"/sequence"`printf %08d $sequence`".txt"
|
|---|
| 192 | echo "sequfile: "$sequfile >> $scriptlog 2>&1
|
|---|
| 193 |
|
|---|
| 194 | echo "run star..." >> $scriptlog 2>&1
|
|---|
| 195 | ./star -b -q -f --log=$outpath/star$sequence.log --ind=$inpath --out=$outpath $sequfile 2>> $scriptlog> /dev/null
|
|---|
| 196 | check1=$?
|
|---|
| 197 |
|
|---|
| 198 | case $check1 in
|
|---|
| 199 | 0) echo "check1=$check1 -> everthing ok " >> $scriptlog 2>&1
|
|---|
| 200 | echo "-> inserting the status for star for sequence $sequence into the db" >> $scriptlog 2>&1
|
|---|
| 201 | setstatuslogpath=$logpath/setstatus/star/`printf %04d $no`
|
|---|
| 202 | if [ ! -d $setstatuslogpath ]
|
|---|
| 203 | then
|
|---|
| 204 | mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
|
|---|
| 205 | if [ ! -d $setstatuslogpath ]
|
|---|
| 206 | then
|
|---|
| 207 | echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
|
|---|
| 208 | continue
|
|---|
| 209 | fi
|
|---|
| 210 | fi
|
|---|
| 211 | setstatuslog=$setstatuslogpath/setstatus-star
|
|---|
| 212 | check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
|
|---|
| 213 | case $check4 in
|
|---|
| 214 | 1) echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
|
|---|
| 215 | *) echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
|
|---|
| 216 | esac
|
|---|
| 217 | ;;
|
|---|
| 218 | *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
|
|---|
| 219 | esac
|
|---|
| 220 | done
|
|---|
| 221 |
|
|---|
| 222 | rm -v $todofile-$nr.txt >> $scriptlog 2>&1
|
|---|
| 223 | rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
|
|---|
| 224 |
|
|---|
| 225 | set +C
|
|---|
| 226 |
|
|---|
| 227 | date >> $scriptlog 2>&1
|
|---|
| 228 |
|
|---|