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

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