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-2007
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script is launching the calibration of sequences.
|
---|
28 | #
|
---|
29 | # As callisto takes some time, only one sequence is processed at once.
|
---|
30 | # First the script gets a sequence number from the database, for which
|
---|
31 | # the calibration has to be done (function gettodo). After setting the
|
---|
32 | # status in the database (set fStartTime to know, that the sequence is
|
---|
33 | # already being processed), the sequence is calibrated and the merpp
|
---|
34 | # update is done. Afterwards the status in the database is updated
|
---|
35 | # according to the return value of the program. In case one of the merpp
|
---|
36 | # update failes, also the corresponding runnumber is inserted into the
|
---|
37 | # database.
|
---|
38 | # The important INFOs, WARNings and ERRORs are written not only to the
|
---|
39 | # scriptlog but also to the processlog.
|
---|
40 | #
|
---|
41 | # The callisto.rc files are stored in the setup directory
|
---|
42 | #
|
---|
43 |
|
---|
44 | source `dirname $0`/sourcefile
|
---|
45 | printprocesslog "INFO starting $0"
|
---|
46 | program=callisto
|
---|
47 | column=fCallisto
|
---|
48 |
|
---|
49 | set -C
|
---|
50 |
|
---|
51 | scriptlog=$runlogpath/run$program-$datetime.log
|
---|
52 | date >> $scriptlog 2>&1
|
---|
53 |
|
---|
54 | # get sequence #
|
---|
55 | gettodo >> $scriptlog 2>&1
|
---|
56 | sequence=$process
|
---|
57 |
|
---|
58 | # lock sequ for cal
|
---|
59 | lockfile=$lockpath/lock-$table-$column-$sequence.txt
|
---|
60 | checklock >> $scriptlog 2>&1
|
---|
61 |
|
---|
62 | cd $mars
|
---|
63 |
|
---|
64 | # run calibration for sequence
|
---|
65 | echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
|
---|
66 | printprocesslog "INFO starting $program for sequence $sequence"
|
---|
67 | no=`printf %08d $sequence | cut -c 0-4`
|
---|
68 | no2=`printf %08d $sequence`
|
---|
69 | outpath="$datapath/$program/$no/$no2"
|
---|
70 | makedir $outpath >> $scriptlog 2>&1
|
---|
71 | sequfile="$sequpath/$no/sequence$no2.txt"
|
---|
72 |
|
---|
73 | # define callisto.rc files
|
---|
74 | callistorcnew=$setuppath/$program/callisto.rc
|
---|
75 | callistorcmux=$setuppath/$program/callisto_mux.rc
|
---|
76 | # find callisto.rc file
|
---|
77 | if [ -e $outpath/callisto.rc ]
|
---|
78 | then
|
---|
79 | echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
|
---|
80 | callistorcseq=$outpath/callisto.rc
|
---|
81 | else
|
---|
82 | echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
|
---|
83 | if [ $sequence -gt 200000 ]
|
---|
84 | then
|
---|
85 | ln -vs $callistorcmux $outpath/callisto.rc >> $scriptlog 2>&1
|
---|
86 | else
|
---|
87 | ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
|
---|
88 | fi
|
---|
89 | callistorcseq=$outpath/callisto.rc
|
---|
90 | fi
|
---|
91 |
|
---|
92 | # lock sequ for zipping
|
---|
93 | lockfile=$lockpath/calzip$sequence.txt
|
---|
94 | # if lockfile is already existing, 1 is returned
|
---|
95 | if ! checklock return 1 >> $scriptlog 2>&1
|
---|
96 | then
|
---|
97 | # reset lockfile name
|
---|
98 | lockfile=$lockpath/lock-$table-$column-$sequence.txt
|
---|
99 | finish >> $scriptlog 2>&1
|
---|
100 | fi
|
---|
101 |
|
---|
102 | primvar=$no2
|
---|
103 | setstatus "start" >> $scriptlog 2>&1
|
---|
104 |
|
---|
105 | echo "./callisto -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null" >> $scriptlog 2>&1
|
---|
106 | ./callisto -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
|
---|
107 | check1=$?
|
---|
108 |
|
---|
109 | # remove lockfile for zip and reset lockfile name
|
---|
110 | rm -v $lockfile >> $scriptlog 2>&1
|
---|
111 | lockfile=$lockpath/lock-$table-$column-$sequence.txt
|
---|
112 |
|
---|
113 | case $check1 in
|
---|
114 | 0) echo " check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
|
---|
115 | printprocesslog "INFO $program finished successfully for sequence $sequence"
|
---|
116 | # running merpp update if calibration worked
|
---|
117 | # finding files, which have to be updated
|
---|
118 | echo "finding files to be updated..." >> $scriptlog 2>&1
|
---|
119 | calfiles=`find $outpath -name *_Y_* `
|
---|
120 | if [ "$calfiles" = "" ]
|
---|
121 | then
|
---|
122 | echo " no files found -> continue with next sequence" >> $scriptlog 2>&1
|
---|
123 | printprocesslog "ERROR no calfiles found"
|
---|
124 | fi
|
---|
125 | echo " files to be updated: "$calfiles >> $scriptlog 2>&1
|
---|
126 |
|
---|
127 | merpplogpath=$outpath"/merpplogs"
|
---|
128 | makedir $merpplogpath >> $scriptlog 2>&1
|
---|
129 |
|
---|
130 | printprocesslog "INFO doing merppupdate for sequence $sequence"
|
---|
131 | # updated calibrated data files with the information from the cc and caco files
|
---|
132 | for calfile in ${calfiles[@]}
|
---|
133 | do
|
---|
134 | echo "calfile: "$calfile >> $scriptlog 2>&1
|
---|
135 | # find cc and caco file
|
---|
136 | # if file is missing continue with next sequence
|
---|
137 | date=`date --date \`basename $calfile | cut -d_ -f1\` +%Y/%m/%d`
|
---|
138 | ccpath=$subsystempath/cc/$date
|
---|
139 | cacopath=$subsystempath/caco/$date
|
---|
140 | runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
|
---|
141 | ccfile=`find $ccpath -name 20[0-2][0-9][01][0-9][0-3][0-9]_*${runno}_[PDCS]_*_S.rep`
|
---|
142 | source=`echo $ccfile | cut -d_ -f4`
|
---|
143 | cacofile=`find /magic/subsystemdata/caco/$date -name dc_20[0-2][0-9]_[01][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
|
---|
144 | if [ "$ccfile" = "" ]
|
---|
145 | then
|
---|
146 | echo "no ccfile found for run "$runno >> $scriptlog 2>&1
|
---|
147 | printprocesslog "ERROR ccfile $ccfile not found for $calfile"
|
---|
148 | com=$Fnoccfile
|
---|
149 | comadd=$runno
|
---|
150 | check=0
|
---|
151 | break
|
---|
152 | fi
|
---|
153 | if [ "$cacofile" = "" ]
|
---|
154 | then
|
---|
155 | echo "cacofile with no $runno not found" >> $scriptlog 2>&1
|
---|
156 | echo "finding cacofile..." >> $scriptlog 2>&1
|
---|
157 | for (( i = 0; i <= 10; i++ ))
|
---|
158 | do
|
---|
159 | newrun=`echo $runno - $i | bc`
|
---|
160 | cacofile=`find $cacopath -name *$newrun*`
|
---|
161 | if [ "$cacofile" = "" ]
|
---|
162 | then
|
---|
163 | if [ $i -eq 9 ]
|
---|
164 | then
|
---|
165 | echo "no cacofile found for runno $newrun in $cacopath" >> $scriptlog 2>&1
|
---|
166 | printprocesslog "ERROR cacofile $cacofile not found for $calfile"
|
---|
167 | com=$Fnocacofile
|
---|
168 | comadd=$runno
|
---|
169 | check=0
|
---|
170 | break 2
|
---|
171 | fi
|
---|
172 | continue
|
---|
173 | else
|
---|
174 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
175 | break
|
---|
176 | fi
|
---|
177 | done
|
---|
178 | fi
|
---|
179 | echo "./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
|
---|
180 | ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
|
---|
181 | check2=$?
|
---|
182 | case $check2 in
|
---|
183 | 0) echo " check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1
|
---|
184 | printprocesslog "INFO merppupdated $calfile sucessfully with $ccfile"
|
---|
185 | ;;
|
---|
186 | *) echo " check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
|
---|
187 | printprocesslog "ERROR merppccupdate with file $ccfile failed for $calfile"
|
---|
188 | com=$Fmerppcc
|
---|
189 | comadd=$runno
|
---|
190 | check=$check2
|
---|
191 | break ;;
|
---|
192 | esac
|
---|
193 | echo "./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
|
---|
194 | ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
|
---|
195 | check3=$?
|
---|
196 | case $check3 in
|
---|
197 | 0) echo " check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1
|
---|
198 | printprocesslog "INFO merppupdated $calfile sucessfully with $cacofile"
|
---|
199 | ;;
|
---|
200 | *) echo " check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
|
---|
201 | printprocesslog "ERROR merppcacoupdate with file $cacofile failed for $calfile"
|
---|
202 | com=$Fmerppcaco
|
---|
203 | comadd=$runno
|
---|
204 | check=$check3
|
---|
205 | break ;;
|
---|
206 | esac
|
---|
207 | done
|
---|
208 | printprocesslog "INFO finished merppupdate successfully for sequence $sequence"
|
---|
209 | ;;
|
---|
210 | *) echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
|
---|
211 | printprocesslog "ERROR $program failed for sequence $sequence (return code $check1)"
|
---|
212 | com=$Fcallisto
|
---|
213 | check=$check1
|
---|
214 | ;;
|
---|
215 | esac
|
---|
216 |
|
---|
217 | setstatus "stop" >> $scriptlog 2>&1
|
---|
218 |
|
---|
219 | finish >> $scriptlog 2>&1
|
---|
220 |
|
---|