source: trunk/MagicSoft/Mars/datacenter/scripts/runcallisto@ 7239

Last change on this file since 7239 was 7233, checked in by Daniela Dorner, 21 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.9 KB
Line 
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
29user=`whoami`
30source /home/$user/Mars/datacenter/scripts/sourcefile
31
32set -C
33
34callistorcnew=$setuppath/callisto/callisto.rc
35
36table=SequenceProcessStatus
37column=fCallisto
38date=NULL
39datetime=`date +%F-%H-%M-%S`
40year=`date +%Y`
41pno=500 # number of processes, i.e. number of todo-files
42
43todofile=$listpath/ToDo-$table-$column
44getstatuslogpath=$logpath/getstatus/callisto/$year
45getstatuslog=$getstatuslogpath/getstatus-callisto-$datetime.log
46
47scriptlogpath=$logpath/run/callisto/`date +%Y/%m/%d`
48makedir $scriptlogpath
49scriptlog=$scriptlogpath/runcallisto-$datetime.log
50
51date >> $scriptlog 2>&1
52
53makedir $getstatuslogpath >> $scriptlog 2>&1
54
55cd $mars
56
57date > $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1
58checklock0=$?
59case $checklock0 in
60 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
61 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
62 echo "-> getting list for callisto is running -> exit" >> $scriptlog 2>&1
63 date >> $scriptlog 2>&1
64 exit;;
65 *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
66esac
67
68echo "checking if other todo-files are there" >> $scriptlog 2>&1
69if ls $todofile-[1-9]*.txt >> $scriptlog 2>&1
70then
71 echo "other file(s) on disk " >> $scriptlog 2>&1
72 echo " -> choose one file and start calibrating" >> $scriptlog 2>&1
73else
74# echo "run checkfilesforsequenceavail" >> $scriptlog 2>&1
75# $scriptspath/checkfilesforsequenceavail
76
77 echo "getting list..." >> $scriptlog 2>&1
78 check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\,"\"$listpath\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
79
80 case $check0 in
81 1) echo "check0=$check0 -> everthing ok -> run callisto" >> $scriptlog 2>&1;;
82 *) echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
83 esac
84 echo "cutting to-do-file" >> $scriptlog 2>&1
85 echo "getting no of lines" >> $scriptlog 2>&1
86 lines=`cat $todofile.txt | wc -l`
87 echo "number of lines: "$lines >> $scriptlog 2>&1
88 while (( "$lines" < "$pno" ))
89 do
90 echo "# of lines ($lines) < # of processes ($pno) "
91 pno=`expr $pno / 2`
92 done
93 echo "pno: "$pno
94 nofiles=`expr $lines / \( $pno - 1 \)`
95 nofiles=`expr $nofiles + 1 `
96 echo "number of files: "$nofiles >> $scriptlog 2>&1
97 echo "deviding todo-file" >> $scriptlog 2>&1
98 for (( j=1 ; j <= $pno ; j++ ))
99 do
100 begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
101 end=$(echo "$begin + $nofiles - 1" | bc -l)
102 echo "begin: "$begin >> $scriptlog 2>&1
103 echo "end: "$end >> $scriptlog 2>&1
104 file=${todofile}-${j}.txt
105 echo "file: "$file >> $scriptlog 2>&1
106 sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
107 done
108
109 rm -v $todofile.txt >> $scriptlog 2>&1
110fi
111
112rm -v $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1
113
114nr=bla
115echo "finding the right todo-file" >> $scriptlog 2>&1
116for (( i = 1; i <= $pno ; i++ ))
117do
118 if ! ls $todofile-$i.txt >> $scriptlog 2>&1
119 then
120 echo "file is not on disk -> continue" >> $scriptlog 2>&1
121 continue
122 fi
123 date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1
124 checklock=$?
125 case $checklock in
126 0) echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
127 nr=${i}
128 break;;
129 1) echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
130 *) echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
131 esac
132done
133
134case $nr in
135 bla) echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
136 date >> $scriptlog 2>&1
137 exit;;
138 12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
139esac
140
141
142sequences=(`cat $todofile-$nr.txt`)
143
144if [ "$sequences" = "" ]
145then
146 echo "nothing to do -> exit" >> $scriptlog 2>&1
147 rm -v $todofile-$nr.txt >> $scriptlog 2>&1
148 rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
149 date >> $scriptlog 2>&1
150 exit
151fi
152
153echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
154
155for sequence in ${sequences[@]}
156do
157 no=`printf %08d $sequence | cut -c 0-4`
158 no2=`printf %08d $sequence`
159 outpath="$datapath/callisto/$no/$no2"
160 echo "outpath: "$outpath >> $scriptlog 2>&1
161 makedir $outpath >> $scriptlog 2>&1
162
163 sequfile="$sequpath/$no/sequence$no2.txt"
164 echo "sequfile: "$sequfile >> $scriptlog 2>&1
165
166 if [ -e $outpath/callisto.rc ]
167 then
168 echo "found callisto.rc in $outpath -> using this " >> $scriptlog 2>&1
169 callistorcseq=$outpath/callisto.rc
170 else
171 echo "no callisto.rc found in $outpath -> making link " >> $scriptlog 2>&1
172 ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
173 callistorcseq=$outpath/callisto.rc
174 fi
175
176 echo "run callisto..." >> $scriptlog 2>&1
177 ./callisto -b -q -v4 -f -raw --log=$outpath/callisto$no2.log --html=$outpath/callisto$no2.html --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
178 check1=$?
179
180 case $check1 in
181 0) echo "check1=$check1 -> everthing ok -> doing update..." >> $scriptlog 2>&1
182 echo "finding files to be updated" >> $scriptlog 2>&1
183 calfiles=`find $outpath -name *_Y_* `
184 echo "files to be updated: "$calfiles >> $scriptlog 2>&1
185 if [ "$calfiles" = "" ]
186 then
187 echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
188 continue
189 fi
190
191 merpplogpath=$outpath"/merpplogs"
192 makedir $merpplogpath >> $scriptlog 2>&1
193
194 for calfile in ${calfiles[@]}
195 do
196 echo "calfile: "$calfile >> $scriptlog 2>&1
197 runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
198 ccfile=`find /magic/subsystemdata/cc/ -name [2][0][0-2][0-9][0,1][0-9][0-3][0-9]_*${runno}_[P,D,C,S]_*_S.rep`
199 cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
200 echo "runno: "$runno >> $scriptlog 2>&1
201 echo "ccfile: "$ccfile >> $scriptlog 2>&1
202 if [ "$ccfile" = "" ]
203 then
204 echo "no ccfile found for run "$runno >> $scriptlog 2>&1
205 break
206 fi
207 echo "cacofile: "$cacofile >> $scriptlog 2>&1
208 if [ "$cacofile" = "" ]
209 then
210 echo "no cacofile found for run "$runno >> $scriptlog 2>&1
211 echo "finding cacofile..." >> $scriptlog 2>&1
212 for (( i = 0; i <= 10; i++ ))
213 do
214 newrun=`echo $runno - $i | bc`
215 # echo "$missingcacorun + $i = $newrun"
216 path=`dirname $ccfile`
217 path=`echo $path | sed -e 's/cc/caco/'`
218 echo "path: "$path >> $scriptlog 2>&1
219 cacofile=`find $path -name *$newrun*`
220 if [ "$cacofile" = "" ]
221 then
222 continue
223 else
224 break
225 echo "cacofile: "$cacofile >> $scriptlog 2>&1
226 fi
227 done
228 fi
229 ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
230 check2=$?
231 case $check2 in
232 0) echo "check2=$check2 -> everthing ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
233 *) echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
234 continue 2 ;;
235 esac
236 ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
237 check3=$?
238 case $check3 in
239 0) echo "check3=$check3 -> everthing ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
240 *) echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
241 continue 2 ;;
242 esac
243 done
244
245 echo "inserting the status for callisto for sequence $sequence into the db" >> $scriptlog 2>&1
246 setstatuslogpath=$logpath/setstatus/callisto/$no
247 makedir $setstatuslogpath >> $scriptlog 2>&1
248 setstatuslog=$setstatuslogpath/setstatus-callisto-$no2.log
249
250 check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog | grep int | sed -e 's/(int)//'`
251 case $check4 in
252 1) echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
253 *) echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
254 esac
255 ;;
256 *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
257 esac
258done
259
260rm -v $todofile-$nr.txt >> $scriptlog 2>&1
261rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
262
263set +C
264
265date >> $scriptlog 2>&1
266
Note: See TracBrowser for help on using the repository browser.