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