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

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