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/$program.rc
|
---|
47 | callistorcmarapr05=$setuppath/$program/$program_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 | 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 $program..." >> $scriptlog 2>&1
|
---|
173 | setstatus "start"
|
---|
174 |
|
---|
175 | ./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
|
---|
176 | check1=$?
|
---|
177 |
|
---|
178 | case $check1 in
|
---|
179 | 0) echo "check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
|
---|
180 | # running merpp update if calibration worked
|
---|
181 | # finding files, which have to be updated
|
---|
182 | echo "finding files to be updated" >> $scriptlog 2>&1
|
---|
183 | calfiles=`find $outpath -name *_Y_* `
|
---|
184 | echo "files to be updated: "$calfiles >> $scriptlog 2>&1
|
---|
185 | if [ "$calfiles" = "" ]
|
---|
186 | then
|
---|
187 | echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
|
---|
188 | continue
|
---|
189 | fi
|
---|
190 |
|
---|
191 | merpplogpath=$outpath"/merpplogs"
|
---|
192 | makedir $merpplogpath >> $scriptlog 2>&1
|
---|
193 |
|
---|
194 | # updated calibrated data files with the information from the cc and caco files
|
---|
195 | for calfile in ${calfiles[@]}
|
---|
196 | do
|
---|
197 | echo "calfile: "$calfile >> $scriptlog 2>&1
|
---|
198 | # find cc and caco file
|
---|
199 | # if file is missing continue with next sequence
|
---|
200 | runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
|
---|
201 | 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`
|
---|
202 | source=`echo $ccfile | cut -d_ -f4`
|
---|
203 | cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
|
---|
204 | # cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
|
---|
205 | echo "runno: "$runno >> $scriptlog 2>&1
|
---|
206 | echo "ccfile: "$ccfile >> $scriptlog 2>&1
|
---|
207 | if [ "$ccfile" = "" ]
|
---|
208 | then
|
---|
209 | echo "no ccfile found for run "$runno >> $scriptlog 2>&1
|
---|
210 | com="no ccfile for run $runno"
|
---|
211 | check=0
|
---|
212 | break
|
---|
213 | fi
|
---|
214 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
215 | if [ "$cacofile" = "" ]
|
---|
216 | then
|
---|
217 | echo "no cacofile found for run "$runno >> $scriptlog 2>&1
|
---|
218 | echo "finding cacofile..." >> $scriptlog 2>&1
|
---|
219 | for (( i = 0; i <= 10; i++ ))
|
---|
220 | do
|
---|
221 | newrun=`echo $runno - $i | bc`
|
---|
222 | # echo "$missingcacorun + $i = $newrun"
|
---|
223 | path=`dirname $ccfile`
|
---|
224 | path=`echo $path | sed -e 's/cc/caco/'`
|
---|
225 | echo "path: "$path >> $scriptlog 2>&1
|
---|
226 | cacofile=`find $path -name *$newrun*`
|
---|
227 | if [ "$cacofile" = "" ]
|
---|
228 | then
|
---|
229 | continue
|
---|
230 | else
|
---|
231 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
232 | break
|
---|
233 | fi
|
---|
234 | done
|
---|
235 | echo "no cacofile found" >> $scriptlog 2>&1
|
---|
236 | com="no cacofile for run $runno"
|
---|
237 | check=0
|
---|
238 | break
|
---|
239 | fi
|
---|
240 | ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
|
---|
241 | check2=$?
|
---|
242 | case $check2 in
|
---|
243 | 0) echo "check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
|
---|
244 | *) echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
|
---|
245 | com="merppccupdate failed for run $runno"
|
---|
246 | check=$check2
|
---|
247 | break ;;
|
---|
248 | esac
|
---|
249 | ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
|
---|
250 | check3=$?
|
---|
251 | case $check3 in
|
---|
252 | 0) echo "check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
|
---|
253 | *) echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
|
---|
254 | com="merppcacoupdate failed for run $runno"
|
---|
255 | check=$check3
|
---|
256 | break ;;
|
---|
257 | esac
|
---|
258 | done
|
---|
259 | ;;
|
---|
260 | *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
|
---|
261 | com="calibration failed"
|
---|
262 | check=$check1
|
---|
263 | ;;
|
---|
264 | esac
|
---|
265 | # set status
|
---|
266 | echo "inserting the status for $program for sequence $sequence into the db" >> $scriptlog 2>&1
|
---|
267 | setstatus "stop"
|
---|
268 | done
|
---|
269 |
|
---|
270 | rm -v $todofile >> $scriptlog 2>&1
|
---|
271 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
272 |
|
---|
273 | set +C
|
---|
274 |
|
---|
275 | date >> $scriptlog 2>&1
|
---|
276 |
|
---|