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

Last change on this file since 9006 was 8886, checked in by snruegam, 17 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.6 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-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
44source `dirname $0`/sourcefile
45printprocesslog "INFO starting $0"
46program=callisto
47column=fCallisto
48
49set -C
50
51scriptlog=$runlogpath/run$program-$datetime.log
52date >> $scriptlog 2>&1
53
54# get sequence #
55gettodo >> $scriptlog 2>&1
56sequence=$process
57
58# lock sequ for cal
59lockfile=$lockpath/lock-$table-$column-$sequence.txt
60checklock >> $scriptlog 2>&1
61
62cd $mars
63
64# run calibration for sequence
65echo "run $program for sequence $sequence..." >> $scriptlog 2>&1
66printprocesslog "INFO starting $program for sequence $sequence"
67no=`printf %08d $sequence | cut -c 0-4`
68no2=`printf %08d $sequence`
69outpath="$datapath/$program/$no/$no2"
70makedir $outpath >> $scriptlog 2>&1
71sequfile="$sequpath/$no/sequence$no2.txt"
72
73# define callisto.rc files
74callistorcnew=$setuppath/$program/callisto.rc
75#callistorcmux=$setuppath/$program/callisto_mux.rc
76callistorcmux=$setuppath/$program/callisto_mux_new.rc
77# find callisto.rc file
78if [ -e $outpath/callisto.rc ]
79then
80 echo "found $program.rc in $outpath -> using this " >> $scriptlog 2>&1
81 callistorcseq=$outpath/callisto.rc
82else
83 echo "no $program.rc found in $outpath -> making link " >> $scriptlog 2>&1
84 if [ $sequence -gt 200000 ]
85 then
86 ln -vs $callistorcmux $outpath/callisto.rc >> $scriptlog 2>&1
87 else
88 ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
89 fi
90 callistorcseq=$outpath/callisto.rc
91fi
92
93# lock sequ for zipping
94lockfile=$lockpath/calzip$sequence.txt
95# if lockfile is already existing, 1 is returned
96if ! checklock return 1 >> $scriptlog 2>&1
97then
98 # reset lockfile name
99 lockfile=$lockpath/lock-$table-$column-$sequence.txt
100 finish >> $scriptlog 2>&1
101fi
102
103primvar=$no2
104setstatus "start" >> $scriptlog 2>&1
105
106# stage the needed files; to be removed as soon as the correct stub file size has been determined
107echo "staging files:" >> $scriptlog 2>&1
108day=`grep Night $sequfile | cut -c 18-27 | sed -e "s/-/\//g"`
109runs=`grep ^Runs $sequfile | cut -d: -f2`
110i=0
111
112for run in ${runs[@]}
113do
114 files[i]=20*_0*${run}_[PCD]_*_E.raw.gz
115 echo ${datapath}/rawfiles/${day}/${files[i]} >> $scriptlog 2>&1
116 let i++
117done
118
119ssh -nx phoenix "cd ${datapath}/rawfiles/${day}; /opt/SUNWsamfs/bin/stage ${files[@]}"
120
121
122echo "./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
123./callisto -b -q -v4 -f --log=$outpath/$program$no2.log --html=$outpath/$program$no2.html --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
124check1=$?
125
126# remove lockfile for zip and reset lockfile name
127rm -v $lockfile >> $scriptlog 2>&1
128lockfile=$lockpath/lock-$table-$column-$sequence.txt
129
130case $check1 in
131 0) echo " check1=$check1 -> everything ok -> doing update..." >> $scriptlog 2>&1
132 printprocesslog "INFO $program finished successfully for sequence $sequence"
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 if [ "$calfiles" = "" ]
138 then
139 echo " no files found -> continue with next sequence" >> $scriptlog 2>&1
140 printprocesslog "ERROR no calfiles found"
141 fi
142 echo " files to be updated: "$calfiles >> $scriptlog 2>&1
143
144 merpplogpath=$outpath"/merpplogs"
145 makedir $merpplogpath >> $scriptlog 2>&1
146
147 printprocesslog "INFO doing merppupdate for sequence $sequence"
148 # updated calibrated data files with the information from the cc and caco files
149 for calfile in ${calfiles[@]}
150 do
151 echo "calfile: "$calfile >> $scriptlog 2>&1
152 # find cc and caco file
153 # if file is missing continue with next sequence
154 date=`date --date \`basename $calfile | cut -d_ -f1\` +%Y/%m/%d`
155 ccpath=$subsystempath/cc/$date
156 cacopath=$subsystempath/caco/$date
157 runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
158 ccfile=`find $ccpath -name 20[0-2][0-9][01][0-9][0-3][0-9]_*${runno}_[PDCS]_*_S.rep`
159 source=`echo $ccfile | cut -d_ -f4`
160 cacofile=`find /magic/subsystemdata/caco/$date -name dc_20[0-2][0-9]_[01][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
161 if [ "$ccfile" = "" ]
162 then
163 echo "no ccfile found for run "$runno >> $scriptlog 2>&1
164 printprocesslog "ERROR ccfile $ccfile not found for $calfile"
165 com=$Fnoccfile
166 comadd=$runno
167 check=0
168 break
169 fi
170 if [ "$cacofile" = "" ]
171 then
172 echo "cacofile with no $runno not found" >> $scriptlog 2>&1
173 echo "finding cacofile..." >> $scriptlog 2>&1
174 for (( i = 0; i <= 10; i++ ))
175 do
176 newrun=`echo $runno - $i | bc`
177 cacofile=`find $cacopath -name *$newrun*`
178 if [ "$cacofile" = "" ]
179 then
180 if [ $i -eq 9 ]
181 then
182 echo "no cacofile found for runno $newrun in $cacopath" >> $scriptlog 2>&1
183 printprocesslog "ERROR cacofile $cacofile not found for $calfile"
184 com=$Fnocacofile
185 comadd=$runno
186 check=0
187 break 2
188 fi
189 continue
190 else
191 echo "cacofile: "$cacofile >> $scriptlog 2>&1
192 break
193 fi
194 done
195 fi
196 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
197 ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --html=$merpplogpath/merppccupdate$runno.html --auto-time-stop --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
198 check2=$?
199 case $check2 in
200 0) echo " check2=$check2 -> everything ok, merppccupdate worked -> continue" >> $scriptlog 2>&1
201 printprocesslog "INFO merppupdated $calfile sucessfully with $ccfile"
202 ;;
203 *) echo " check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
204 printprocesslog "ERROR merppccupdate with file $ccfile failed for $calfile"
205 com=$Fmerppcc
206 comadd=$runno
207 check=$check2
208 break ;;
209 esac
210 echo "./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null" >> $scriptlog 2>&1
211 ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --html=$merpplogpath/merppcacoupdate$runno.html --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
212 check3=$?
213 case $check3 in
214 0) echo " check3=$check3 -> everything ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1
215 printprocesslog "INFO merppupdated $calfile sucessfully with $cacofile"
216 ;;
217 *) echo " check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
218 printprocesslog "ERROR merppcacoupdate with file $cacofile failed for $calfile"
219 com=$Fmerppcaco
220 comadd=$runno
221 check=$check3
222 break ;;
223 esac
224 done
225 printprocesslog "INFO finished merppupdate successfully for sequence $sequence"
226 ;;
227 *) echo " check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1
228 printprocesslog "ERROR $program failed for sequence $sequence (return code $check1)"
229 com=$Fcallisto
230 check=$check1
231 ;;
232esac
233
234setstatus "stop" >> $scriptlog 2>&1
235
236finish >> $scriptlog 2>&1
237
Note: See TracBrowser for help on using the repository browser.