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

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