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

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