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

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