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

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