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

Last change on this file since 7909 was 7909, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.3 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
39program=callisto
40source `dirname $0`/sourcefile
41
42set -C
43
44# define callisto.rc files
45callistorcnew=$setuppath/$program/callisto.rc
46callistorcmarapr05=$setuppath/$program/callisto_MarApr05.rc
47
48column=fCallisto
49#pno=500 # number of processes, i.e. number of todo-files
50
51lockfile=$lockpath/lock-getting-$program-list.txt
52
53scriptlogpath=$logpath/run/$program/`date +%Y/%m/%d`
54makedir $scriptlogpath
55scriptlog=$scriptlogpath/run$program-$datetime.log
56
57date >> $scriptlog 2>&1
58
59# get todo file
60echo "checking if other todo-files are there" >> $scriptlog 2>&1
61if ls $todofile-[1-9]*.txt >> $scriptlog 2>&1
62then
63 echo "other file(s) on disk " >> $scriptlog 2>&1
64 echo " -> choose one file and start calibrating" >> $scriptlog 2>&1
65else
66 # check if getting of list is already running
67 checklock "getting list of" >> $scriptlog 2>&1
68 # get todo list
69 gettodo >> $scriptlog 2>&1
70 rm -v $lockfile >> $scriptlog 2>&1
71fi
72
73# choose todo file
74nr=bla
75echo "finding the right todo-file" >> $scriptlog 2>&1
76todofiles=`ls -r $listpath/ToDo-$table-$column-*`
77
78for todofile in ${todofiles[@]}
79do
80 if ! ls $todofile >> $scriptlog 2>&1
81 then
82 echo "file is not on disk -> continue" >> $scriptlog 2>&1
83 continue
84 fi
85 lockfile=`echo $todofile | sed -e 's/lists/locks/' -e 's/ToDo/lock/'`
86 date > $lockfile >> $scriptlog 2>&1
87 checklock=$?
88 case $checklock in
89 0) echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
90 nr=${i}
91 break;;
92 1) echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
93 *) echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
94 esac
95done
96
97case $nr in
98 bla) echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
99 date >> $scriptlog 2>&1
100 exit;;
101 12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
102esac
103
104# get sequence(s) from todo file
105sequences=(`cat $todofile`)
106if [ "$sequences" = "" ]
107then
108 echo "nothing to do -> exit" >> $scriptlog 2>&1
109 finish >> $scriptlog 2>&1
110fi
111
112cd $mars
113
114# run calibration for sequence(s)
115echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
116for sequence in ${sequences[@]}
117do
118 no=`printf %08d $sequence | cut -c 0-4`
119 no2=`printf %08d $sequence`
120 var1=$no
121 var2=$no2
122 outpath="$datapath/$program/$no/$no2"
123 echo "outpath: "$outpath >> $scriptlog 2>&1
124 makedir $outpath >> $scriptlog 2>&1
125
126 sequfile="$sequpath/$no/sequence$no2.txt"
127 echo "sequfile: "$sequfile >> $scriptlog 2>&1
128
129 # find callisto.rc file
130 if [ -e $outpath/callisto.rc ]
131 then
132 echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
133 callistorcseq=$outpath/callisto.rc
134 else
135 echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
136 if [ 49735 -lt $sequence ] && [ $sequence -lt 53516 ]
137 then
138 ln -vs $callistorcmarapr05 $outpath/callisto.rc >> $scriptlog 2>&1
139 else
140 ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
141 fi
142 callistorcseq=$outpath/callisto.rc
143 fi
144
145 echo "run $program..." >> $scriptlog 2>&1
146 setstatus "start" >> $scriptlog 2>&1
147
148 ./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
149 check1=$?
150
151 case $check1 in
152 0) echo "check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
153 # running merpp update if calibration worked
154 # finding files, which have to be updated
155 echo "finding files to be updated" >> $scriptlog 2>&1
156 calfiles=`find $outpath -name *_Y_* `
157 echo "files to be updated: "$calfiles >> $scriptlog 2>&1
158 if [ "$calfiles" = "" ]
159 then
160 echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
161 continue
162 fi
163
164 merpplogpath=$outpath"/merpplogs"
165 makedir $merpplogpath >> $scriptlog 2>&1
166
167 # updated calibrated data files with the information from the cc and caco files
168 for calfile in ${calfiles[@]}
169 do
170 echo "calfile: "$calfile >> $scriptlog 2>&1
171 # find cc and caco file
172 # if file is missing continue with next sequence
173 runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
174 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`
175 source=`echo $ccfile | cut -d_ -f4`
176 cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
177# cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
178 echo "runno: "$runno >> $scriptlog 2>&1
179 echo "ccfile: "$ccfile >> $scriptlog 2>&1
180 if [ "$ccfile" = "" ]
181 then
182 echo "no ccfile found for run "$runno >> $scriptlog 2>&1
183 com=$Fnoccfile
184 comadd=$runno
185 check=0
186 break
187 fi
188 echo "cacofile: "$cacofile >> $scriptlog 2>&1
189 if [ "$cacofile" = "" ]
190 then
191 echo "cacofile with no $runno not found" >> $scriptlog 2>&1
192 echo "finding cacofile..." >> $scriptlog 2>&1
193 for (( i = 0; i <= 10; i++ ))
194 do
195 newrun=`echo $runno - $i | bc`
196 # echo "$missingcacorun + $i = $newrun"
197 path=`dirname $ccfile`
198 path=`echo $path | sed -e 's/cc/caco/'`
199 echo "path: "$path >> $scriptlog 2>&1
200 cacofile=`find $path -name *$newrun*`
201 if [ "$cacofile" = "" ]
202 then
203 if [ $i -eq 9 ]
204 then
205 echo "no cacofile found" >> $scriptlog 2>&1
206 com=$Fnocacofile
207 comadd=$runno
208 check=0
209 fi
210 continue
211 else
212 echo "cacofile: "$cacofile >> $scriptlog 2>&1
213 break
214 fi
215 done
216 fi
217 ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
218 check2=$?
219 case $check2 in
220 0) echo "check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
221 *) echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
222 com=$Fmerppcc
223 comadd=$runno
224 check=$check2
225 break ;;
226 esac
227 ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
228 check3=$?
229 case $check3 in
230 0) echo "check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
231 *) echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
232 com=$Fmerppcaco
233 comadd=$runno
234 check=$check3
235 break ;;
236 esac
237 done
238 ;;
239 *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
240 com=$Fcallisto
241 check=$check1
242 ;;
243 esac
244 # set status
245 echo "inserting the status for $program for sequence $sequence into the db" >> $scriptlog 2>&1
246 setstatus "stop" >> $scriptlog 2>&1
247done
248
249finish >> $scriptlog 2>&1
250
Note: See TracBrowser for help on using the repository browser.