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

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