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

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