source: trunk/Mars/scripts/processsequence@ 10503

Last change on this file since 10503 was 8560, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.3 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 10/2006 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2007
23#
24#
25# ========================================================================
26#
27#
28#
29##############################################################################
30#
31# This script can be used to run the following steps for one sequence:
32# - callisto
33# - merppupdate
34# - star
35#
36# You have to set the path, where your Mars version can be found, the outpath,
37# where you want to store the output and the sequencenumber of the sequence
38# you want to process
39#
40##############################################################################
41
42#to be set by the user (if you don't use the command-line options)
43#path of your output directory
44outpath=""
45#give either sequence number or sequence file (including path)
46sequence=""
47sequfile=""
48
49function usage()
50{
51 echo "Usage: $0 [options]"
52 echo "options:"
53 echo -n " --sequ sequence# "
54 echo " giving number of sequence which shall be processed "
55 echo -n " --sequ-file sequfile "
56 echo " giving sequencfile (including path) of sequence which shall be processed "
57 echo -n " --out outpath "
58 echo " giving the path where all outputfiles are stored "
59 echo -n " -cal "
60 echo " running only calibration"
61 echo -n " --cal-rc "
62 echo " giving a differnt callisto rc file"
63 echo -n " --star-rc "
64 echo " giving a differnt star rc file"
65 echo -n " -b "
66 echo " running in non-interactive mode (i.e. you are not asked if the paths are ok)"
67 echo -n " -star "
68 echo " running only star"
69 echo ""
70 echo "Remarks: "
71 echo " - you can set the needed variables also in the script "
72 echo " - you have to set the outpath and either the sequence number or the sequence "
73 echo " file (if both is set, the sequence given by the sequencefile is processed)"
74 echo " - you have to execute the script from your mars directory"
75 echo " - in your outpath a calibration directory (callisto/sequencenumber), a "
76 echo " directory for the image fiels (star/sequencenumber) and a directory for "
77 echo " the merpplogs in the calibration directory are created. "
78 echo ""
79 exit
80}
81
82function checkreturncode()
83{
84 case $check in
85 0) echo "$program finished sucessfully"
86 echo ""
87 ;;
88 [1-9]|[0-9][0-9]|1[0-1][0-9]|12[0-7])
89 echo -n "ERROR@$HOSTNAME: $program returned $check - please check the logfile $logfile"
90 if [ "$program" == "callisto" ]
91 then
92 echo -n " - for more details see http://www.astro.uni-wuerzburg.de/datacenter/instructions/intern/errorcoding.txt"
93 fi
94 echo " you executed the following command: "$command
95 exit
96 ;;
97 *) echo -n "ERROR@$HOSTNAME: $program returned $check - please check the logfile $logfile"
98 echo -n " $program returned a signal > 127 ($check)"
99 echo " you executed the following command: "$command
100 exit;;
101 esac
102}
103
104subsystempath=/magic/subsystemdata
105
106interactive="yes"
107
108# get options from the command line
109while [ "$1" ]
110do
111 case $1 in
112 --sequ) shift
113 sequence=$1
114 ;;
115 --out) shift
116 outpath=$1
117 ;;
118 -b) interactive='no'
119 ;;
120 -cal) cal='yes'
121 ;;
122 -star) star='yes'
123 ;;
124 --sequ-file) shift
125 sequfile=$1
126 ;;
127 --star-rc) shift
128 starrc=$1
129 ;;
130 --cal-rc) shift
131 calrc=$1
132 ;;
133 -h) usage
134 ;;
135 *) echo "unknown option $1 "
136 usage
137 ;;
138 esac
139 shift
140done
141
142if [ "$outpath" = "" ]
143then
144 echo "WARNING outpath has not been set"
145 echo ""
146 usage
147fi
148
149if [ "$sequence" = "" ] && [ "$sequfile" = "" ]
150then
151 echo "WARNING neither sequ nor sequfile has been set"
152 echo ""
153 usage
154fi
155
156echo ""
157echo "You have set the variables to: "
158echo " outpath: "$outpath
159
160# get sequence file and number
161if [ "$sequfile" = "" ]
162then
163 if ! n8=`printf %08d $sequence`
164 then
165 echo "your sequence number is not valid"
166 usage
167 exit
168 fi
169 no=`echo $n8 | cut -c 1-4`
170 sequfile="/magic/sequences/"$no"/sequence$n8.txt"
171 echo " sequence: "$sequence
172 echo " sequfile: "$sequfile
173else
174 echo " sequfile: "$sequfile
175 # get sequence number from file (for path and log names)
176 array=( `grep "Sequence: " $sequfile` )
177 n8=`printf %08d ${array[1]}`
178fi
179
180# define outpaths for callisto and star
181calpath=$outpath"/callisto/$n8"
182echo " path where calibration files are stored : "$calpath
183if ! [ "$cal" = "yes" ] || [ "$star" = "yes" ]
184then
185 starpath=$outpath"/star/$n8"
186 echo " path where star files are stored : "$starpath
187fi
188
189# rcfiles
190if ! [ "$calrc" = "" ]
191then
192 echo "You chose a different callisto rc file: $calrc "
193fi
194if ! [ "$starrc" = "" ]
195then
196 echo "You chose a different star rc file: $starrc "
197fi
198
199# interactive mode
200# user is asked if paths are correct
201if [ "$interactive" = "yes" ]
202then
203 echo ""
204 echo "paths ok? continue?"
205 echo "please insert y, if you want continue"
206 echo " n, if you want quit"
207
208 answer=`head -n 1`
209 case $answer in
210 y) echo "continue processing sequence"
211 ;;
212 n) exit
213 ;;
214 *) echo "your answer is not clear -> exit"
215 exit
216 ;;
217 esac
218fi
219
220# calibrate sequence
221if ! [ "$star" = "yes" ] || [ "$cal" = "yes" ]
222then
223 mkdir -pv $calpath
224
225 program=callisto
226 echo "run $program..."
227 logfile=$calpath/$program$n8.log
228 command="./$program -b -q -f --log=$logfile --out=$calpath "
229 if ! [ "$calrc" = "" ]
230 then
231 command=$command" --config=$calrc "
232 fi
233 command=$command" $sequfile "
234 echo $command
235 $command
236 check=$?
237 checkreturncode
238
239 calfiles=`find $calpath -name 20[0-2][0-9][01][0-9][0-3][0-9]_*_Y_*.root`
240
241 echo "run merpp update for calibrated files..."
242 echo "calibrated data files: "$calfiles
243
244 for calfile in ${calfiles[@]}
245 do
246 echo "calfile: "$calfile
247 outpath=`dirname $calfile`
248
249 runno=`basename $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
250 echo "finding cc and cacofile for run $runno..."
251 date=`date --date \`basename $calfile | cut -d_ -f1\` +%Y/%m/%d`
252 ccpath=$subsystempath/cc/$date
253 cacopath=$subsystempath/caco/$date
254 ccfile=`find $ccpath -name 20[0-2][0-9][01][0-9][0-3][0-9]_*${runno}_[PDCS]_*_S.rep`
255 source=`echo $ccfile | cut -d_ -f4`
256 cacofile=`find $cacopath -name dc_20[0-2][0-9]_[01][0-9]_[0-3][0-9]_*${runno}_${source}.txt`
257 if [ "$cacofile" = "" ]
258 then
259 echo "no cacofile found for run "$runno
260 echo "finding cacofile..."
261 for (( i = 0; i <= 10; i++ ))
262 do
263 newrun=`echo $runno - $i | bc`
264 cacofile=`find $cacopath -name *$newrun*`
265 if [ "$cacofile" = "" ]
266 then
267 continue
268 else
269 break
270 fi
271 done
272 fi
273 if [ "$ccfile" = "" ]
274 then
275 echo "no ccfile found for run "$runno
276 exit
277 fi
278 if [ "$cacofile" = "" ]
279 then
280 echo "no cacofile found for run "$runno
281 exit
282 fi
283 echo "ccfile: "$ccfile
284 echo "cacofile: "$cacofile
285
286 merpplogpath=$outpath"/merpplogs"
287 mkdir -pv $merpplogpath
288
289 program=merppccupdate
290 logfile=$merpplogpath/$program$runno.log
291 command="./merpp -u --log=$logfile --runfile=$runno $ccfile $calfile "
292 echo $command
293 $command
294 check=$?
295 checkreturncode
296
297 program=merppcacoupdate
298 logfile=$merpplogpath/$program$runno.log
299 command="./merpp -u --log=$logfile --auto-time $cacofile $calfile"
300 echo $command
301 $command
302 check=$?
303 checkreturncode
304
305 done
306 echo "merppupdate is finished"
307 echo ""
308fi
309
310# run star for sequence
311if ! [ "$cal" = "yes" ] || [ "$star" = "yes" ]
312then
313 mkdir -pv $starpath
314
315 program=star
316 echo "run $program..."
317 logfile=$starpath/$program$n8.log
318 command="./$program -b -q -f --log=$logfile --out=$starpath "
319 if ls $calpath >/dev/null 2>&1
320 then
321 command=$command"--ind=$calpath "
322 fi
323 if ! [ "$starrc" = "" ]
324 then
325 command=$command" --config=$starrc "
326 fi
327 command=$command" $sequfile"
328 echo $command
329 $command
330 check=$?
331 checkreturncode
332fi
333
Note: See TracBrowser for help on using the repository browser.