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

Last change on this file since 7030 was 7030, checked in by Daniela Dorner, 21 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 10.8 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=24 # number of processes, i.e. number of todo-files
41
42todofile=/magic/datacenter/lists/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 echo "number of files: "$nofiles >> $scriptlog 2>&1
114 echo "deviding todo-file" >> $scriptlog 2>&1
115 for (( j=1 ; j <= $pno ; j++ ))
116 do
117 begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
118 end=$(echo "$begin + $nofiles - 1" | bc -l)
119 echo "begin: "$begin >> $scriptlog 2>&1
120 echo "end: "$end >> $scriptlog 2>&1
121 file=${todofile}-${j}.txt
122 echo "file: "$file >> $scriptlog 2>&1
123 sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
124 done
125
126 rm -v $todofile.txt >> $scriptlog 2>&1
127fi
128
129rm -v $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1
130
131nr=bla
132echo "finding the right todo-file" >> $scriptlog 2>&1
133for (( i = 1; i <= $pno ; i++ ))
134do
135 if ! ls $todofile-$i.txt >> $scriptlog 2>&1
136 then
137 echo "file is not on disk -> continue" >> $scriptlog 2>&1
138 continue
139 fi
140 date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1
141 checklock=$?
142 case $checklock in
143 0) echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
144 nr=${i}
145 break;;
146 1) echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
147 *) echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
148 esac
149done
150
151case $nr in
152 bla) echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
153 date >> $scriptlog 2>&1
154 exit;;
155 12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
156esac
157
158
159sequences=(`cat $todofile-$nr.txt`)
160
161if [ "$sequences" = "" ]
162then
163 echo "nothing to do -> exit" >> $scriptlog 2>&1
164 rm -v $todofile-$nr.txt >> $scriptlog 2>&1
165 rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
166 date >> $scriptlog 2>&1
167 exit
168fi
169
170echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
171
172for sequence in ${sequences[@]}
173do
174 no=`printf %08d $sequence | cut -c 4`
175 outpath="/magic/data/callisto/"`printf %04d $no`"/"`printf %08d $sequence`
176 echo "outpath: "$outpath >> $scriptlog 2>&1
177 if [ ! -d $outpath ]
178 then
179 mkdir -pv $outpath >> $scriptlog 2>&1
180 if [ ! -d $outpath ]
181 then
182 echo "could not make outpath $outpath -> continue " >> $scriptlog 2>&1
183 continue
184 fi
185 fi
186 sequfile="/magic/sequences/"`printf %04d $no`"/sequence"`printf %08d $sequence`".txt"
187 echo "sequfile: "$sequfile >> $scriptlog 2>&1
188
189 if [ -e $outpath/callisto.rc ]
190 then
191 echo "found callisto.rc in $outpath -> using this " >> $scriptlog 2>&1
192 callistorcseq=$outpath/callisto.rc
193 else
194 echo "no callisto.rc found in $outpath -> making link " >> $scriptlog 2>&1
195 ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
196 callistorcseq=$outpath/callisto.rc
197 fi
198
199 echo "run callisto..." >> $scriptlog 2>&1
200 ./callisto -b -q -f -raw --log=$outpath/callisto$sequence.log --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
201 check1=$?
202
203 case $check1 in
204 0) echo "check1=$check1 -> everthing ok -> doing update..." >> $scriptlog 2>&1
205 echo "finding files to be updated" >> $scriptlog 2>&1
206 calfiles=`find $outpath -name *_Y_* `
207 echo "files to be updated: "$calfiles >> $scriptlog 2>&1
208 if [ "$calfiles" = "" ]
209 then
210 echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
211 continue
212 fi
213
214 merpplogpath=$outpath"/merpplogs"
215 if [ ! -d $merpplogpath ]
216 then
217 mkdir -pv $merpplogpath >> $scriptlog 2>&1
218 if [ ! -d $merpplogpath ]
219 then
220 echo "could not make merpplogpath "$merpplogpath >> $scriptlog 2>&1
221 continue
222 fi
223 fi
224
225 for calfile in ${calfiles[@]}
226 do
227 echo "calfile: "$calfile >> $scriptlog 2>&1
228 runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
229 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`
230 cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
231 echo "runno: "$runno >> $scriptlog 2>&1
232 echo "ccfile: "$ccfile >> $scriptlog 2>&1
233 if [ "$ccfile" = "" ]
234 then
235 echo "no ccfile found for run "$runno >> $scriptlog 2>&1
236 break
237 fi
238 echo "cacofile: "$cacofile >> $scriptlog 2>&1
239 if [ "$cacofile" = "" ]
240 then
241 echo "no cacofile found for run "$runno >> $scriptlog 2>&1
242 echo "finding cacofile..." >> $scriptlog 2>&1
243 for (( i = 0; i <= 10; i++ ))
244 do
245 newrun=`echo $runno - $i | bc`
246 # echo "$missingcacorun + $i = $newrun"
247 path=`dirname $ccfile`
248 path=`echo $path | sed -e 's/cc/caco/'`
249 echo "path: "$path >> $scriptlog 2>&1
250 cacofile=`find $path -name *$newrun*`
251 if [ "$cacofile" = "" ]
252 then
253 continue
254 else
255 break
256 echo "cacofile: "$cacofile >> $scriptlog 2>&1
257 fi
258 done
259 fi
260 ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
261 check2=$?
262 case $check2 in
263 0) echo "check2=$check2 -> everthing ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
264 *) echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
265 continue 2 ;;
266 esac
267 ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
268 check3=$?
269 case $check3 in
270 0) echo "check3=$check3 -> everthing ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
271 *) echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
272 continue 2 ;;
273 esac
274 done
275
276 echo "inserting the status for callisto for sequence $sequence into the db" >> $scriptlog 2>&1
277 setstatuslogpath=$logpath/setstatus/callisto/`printf %04d $no`
278 if [ ! -d $setstatuslogpath ]
279 then
280 mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
281 if [ ! -d $setstatuslogpath ]
282 then
283 echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
284 continue
285 fi
286 fi
287 setstatuslog=$setstatuslogpath/setstatus-callisto
288 check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
289 case $check4 in
290 1) echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
291 *) echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
292 esac
293 ;;
294 *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
295 esac
296done
297
298rm -v $todofile-$nr.txt >> $scriptlog 2>&1
299rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
300
301set +C
302
303date >> $scriptlog 2>&1
304
Note: See TracBrowser for help on using the repository browser.