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 |
|
---|
39 | user=`whoami`
|
---|
40 | program=callisto
|
---|
41 | source /home/$user/Mars/datacenter/scripts/sourcefile
|
---|
42 |
|
---|
43 | set -C
|
---|
44 |
|
---|
45 | # define callisto.rc files
|
---|
46 | callistorcnew=$setuppath/$program/callisto.rc
|
---|
47 | callistorcmarapr05=$setuppath/$program/callisto_MarApr05.rc
|
---|
48 |
|
---|
49 | table=SequenceProcessStatus
|
---|
50 | column=fCallisto
|
---|
51 | date=NULL
|
---|
52 | datetime=`date +%F-%H-%M-%S`
|
---|
53 | year=`date +%Y`
|
---|
54 | #pno=500 # number of processes, i.e. number of todo-files
|
---|
55 |
|
---|
56 | todofile=$listpath/ToDo-$table-$column
|
---|
57 | getstatuslogpath=$logpath/getstatus/$program/$year
|
---|
58 | getstatuslog=$getstatuslogpath/getstatus-$program-$datetime.log
|
---|
59 |
|
---|
60 | scriptlogpath=$logpath/run/$program/`date +%Y/%m/%d`
|
---|
61 | makedir $scriptlogpath
|
---|
62 | scriptlog=$scriptlogpath/run$program-$datetime.log
|
---|
63 |
|
---|
64 | date >> $scriptlog 2>&1
|
---|
65 |
|
---|
66 | makedir $getstatuslogpath >> $scriptlog 2>&1
|
---|
67 |
|
---|
68 | cd $mars
|
---|
69 |
|
---|
70 | # get todo file
|
---|
71 | echo "checking if other todo-files are there" >> $scriptlog 2>&1
|
---|
72 | if ls $todofile-[1-9]*.txt >> $scriptlog 2>&1
|
---|
73 | then
|
---|
74 | echo "other file(s) on disk " >> $scriptlog 2>&1
|
---|
75 | echo " -> choose one file and start calibrating" >> $scriptlog 2>&1
|
---|
76 | else
|
---|
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
|
---|
99 | fi
|
---|
100 |
|
---|
101 | # choose todo file
|
---|
102 | nr=bla
|
---|
103 | echo "finding the right todo-file" >> $scriptlog 2>&1
|
---|
104 | todofiles=`ls -r $listpath/ToDo-$table-$column-*`
|
---|
105 |
|
---|
106 | for todofile in ${todofiles[@]}
|
---|
107 | do
|
---|
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
|
---|
123 | done
|
---|
124 |
|
---|
125 | case $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;;
|
---|
130 | esac
|
---|
131 |
|
---|
132 | # get sequence(s) from todo file
|
---|
133 | sequences=(`cat $todofile`)
|
---|
134 | if [ "$sequences" = "" ]
|
---|
135 | then
|
---|
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
|
---|
141 | fi
|
---|
142 |
|
---|
143 | # run calibration for sequence(s)
|
---|
144 | echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
|
---|
145 | for sequence in ${sequences[@]}
|
---|
146 | do
|
---|
147 | no=`printf %08d $sequence | cut -c 0-4`
|
---|
148 | no2=`printf %08d $sequence`
|
---|
149 | var1=$no
|
---|
150 | var2=$no2
|
---|
151 | outpath="$datapath/$program/$no/$no2"
|
---|
152 | echo "outpath: "$outpath >> $scriptlog 2>&1
|
---|
153 | makedir $outpath >> $scriptlog 2>&1
|
---|
154 |
|
---|
155 | sequfile="$sequpath/$no/sequence$no2.txt"
|
---|
156 | echo "sequfile: "$sequfile >> $scriptlog 2>&1
|
---|
157 |
|
---|
158 | # find callisto.rc file
|
---|
159 | if [ -e $outpath/callisto.rc ]
|
---|
160 | then
|
---|
161 | echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
|
---|
162 | callistorcseq=$outpath/callisto.rc
|
---|
163 | else
|
---|
164 | echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
|
---|
165 | if [ 49735 -lt $sequence ] && [ $sequence -lt 53516 ]
|
---|
166 | then
|
---|
167 | ln -vs $callistorcmarapr05 $outpath/callisto.rc >> $scriptlog 2>&1
|
---|
168 | else
|
---|
169 | ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
|
---|
170 | fi
|
---|
171 | callistorcseq=$outpath/callisto.rc
|
---|
172 | fi
|
---|
173 |
|
---|
174 | echo "run $program..." >> $scriptlog 2>&1
|
---|
175 | setstatus "start" >> $scriptlog 2>&1
|
---|
176 |
|
---|
177 | ./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
|
---|
178 | check1=$?
|
---|
179 |
|
---|
180 | case $check1 in
|
---|
181 | 0) echo "check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
|
---|
182 | # running merpp update if calibration worked
|
---|
183 | # finding files, which have to be updated
|
---|
184 | echo "finding files to be updated" >> $scriptlog 2>&1
|
---|
185 | calfiles=`find $outpath -name *_Y_* `
|
---|
186 | echo "files to be updated: "$calfiles >> $scriptlog 2>&1
|
---|
187 | if [ "$calfiles" = "" ]
|
---|
188 | then
|
---|
189 | echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
|
---|
190 | continue
|
---|
191 | fi
|
---|
192 |
|
---|
193 | merpplogpath=$outpath"/merpplogs"
|
---|
194 | makedir $merpplogpath >> $scriptlog 2>&1
|
---|
195 |
|
---|
196 | # updated calibrated data files with the information from the cc and caco files
|
---|
197 | for calfile in ${calfiles[@]}
|
---|
198 | do
|
---|
199 | echo "calfile: "$calfile >> $scriptlog 2>&1
|
---|
200 | # find cc and caco file
|
---|
201 | # if file is missing continue with next sequence
|
---|
202 | runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
|
---|
203 | 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`
|
---|
204 | source=`echo $ccfile | cut -d_ -f4`
|
---|
205 | cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
|
---|
206 | # cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
|
---|
207 | echo "runno: "$runno >> $scriptlog 2>&1
|
---|
208 | echo "ccfile: "$ccfile >> $scriptlog 2>&1
|
---|
209 | if [ "$ccfile" = "" ]
|
---|
210 | then
|
---|
211 | echo "no ccfile found for run "$runno >> $scriptlog 2>&1
|
---|
212 | com="no ccfile for run $runno"
|
---|
213 | check=0
|
---|
214 | break
|
---|
215 | fi
|
---|
216 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
217 | if [ "$cacofile" = "" ]
|
---|
218 | then
|
---|
219 | echo "no cacofile found for run "$runno >> $scriptlog 2>&1
|
---|
220 | echo "finding cacofile..." >> $scriptlog 2>&1
|
---|
221 | for (( i = 0; i <= 10; i++ ))
|
---|
222 | do
|
---|
223 | newrun=`echo $runno - $i | bc`
|
---|
224 | # echo "$missingcacorun + $i = $newrun"
|
---|
225 | path=`dirname $ccfile`
|
---|
226 | path=`echo $path | sed -e 's/cc/caco/'`
|
---|
227 | echo "path: "$path >> $scriptlog 2>&1
|
---|
228 | cacofile=`find $path -name *$newrun*`
|
---|
229 | if [ "$cacofile" = "" ]
|
---|
230 | then
|
---|
231 | continue
|
---|
232 | else
|
---|
233 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
234 | break
|
---|
235 | fi
|
---|
236 | done
|
---|
237 | echo "no cacofile found" >> $scriptlog 2>&1
|
---|
238 | com="no cacofile for run $runno"
|
---|
239 | check=0
|
---|
240 | break
|
---|
241 | fi
|
---|
242 | ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
|
---|
243 | check2=$?
|
---|
244 | case $check2 in
|
---|
245 | 0) echo "check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
|
---|
246 | *) echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
|
---|
247 | com="merppccupdate failed for run $runno"
|
---|
248 | check=$check2
|
---|
249 | break ;;
|
---|
250 | esac
|
---|
251 | ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
|
---|
252 | check3=$?
|
---|
253 | case $check3 in
|
---|
254 | 0) echo "check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
|
---|
255 | *) echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
|
---|
256 | com="merppcacoupdate failed for run $runno"
|
---|
257 | check=$check3
|
---|
258 | break ;;
|
---|
259 | esac
|
---|
260 | done
|
---|
261 | ;;
|
---|
262 | *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
|
---|
263 | com="calibration failed"
|
---|
264 | check=$check1
|
---|
265 | ;;
|
---|
266 | esac
|
---|
267 | # set status
|
---|
268 | echo "inserting the status for $program for sequence $sequence into the db" >> $scriptlog 2>&1
|
---|
269 | setstatus "stop" >> $scriptlog 2>&1
|
---|
270 | done
|
---|
271 |
|
---|
272 | rm -v $todofile >> $scriptlog 2>&1
|
---|
273 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
274 |
|
---|
275 | set +C
|
---|
276 |
|
---|
277 | date >> $scriptlog 2>&1
|
---|
278 |
|
---|