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

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