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-2004
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | #
|
---|
28 |
|
---|
29 | export ROOTSYS=/opt/root_v3.10.02
|
---|
30 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ROOTSYS/lib
|
---|
31 | export PATH=$PATH:$ROOTSYS/bin
|
---|
32 |
|
---|
33 | set -C
|
---|
34 |
|
---|
35 | mars=/home/operator/Mars
|
---|
36 | macrospath=$mars/datacenter/macros
|
---|
37 | scriptspath=$mars/datacenter/scripts
|
---|
38 | callistorcnew=/magic/datacenter/setup/callisto/callisto.rc
|
---|
39 |
|
---|
40 | table=SequenceProcessStatus
|
---|
41 | column=fCallisto
|
---|
42 | date=NULL
|
---|
43 | datetime=`date +%F-%H-%M-%S`
|
---|
44 | year=`date +%Y`
|
---|
45 | pno=8 # number of processes, i.e. number of todo-files
|
---|
46 |
|
---|
47 | todofile=/magic/datacenter/lists/ToDo-$table-$column
|
---|
48 | lockpath=/magic/datacenter/locks
|
---|
49 | logpath=/magic/datacenter/autologs
|
---|
50 | getstatuslogpath=$logpath/getstatus/callisto/$year
|
---|
51 | getstatuslog=$getstatuslogpath/getstatus-callisto-$datetime.log
|
---|
52 |
|
---|
53 | scriptlogpath=$logpath/run/callisto/`date +%Y/%m/%d`
|
---|
54 | if [ ! -d $scriptlogpath ]
|
---|
55 | then
|
---|
56 | mkdir -pv $scriptlogpath
|
---|
57 | if [ ! -d $scriptlogpath ]
|
---|
58 | then
|
---|
59 | echo "could not make scriptlogpath "$scriptlogpath
|
---|
60 | exit
|
---|
61 | fi
|
---|
62 | fi
|
---|
63 |
|
---|
64 | scriptlog=$scriptlogpath/runcallisto-$datetime.log
|
---|
65 |
|
---|
66 | date >> $scriptlog 2>&1
|
---|
67 |
|
---|
68 |
|
---|
69 | if [ ! -d $getstatuslogpath ]
|
---|
70 | then
|
---|
71 | mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
|
---|
72 | if [ ! -d $getstatuslogpath ]
|
---|
73 | then
|
---|
74 | echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
|
---|
75 | date >> $scriptlog 2>&1
|
---|
76 | exit
|
---|
77 | fi
|
---|
78 | fi
|
---|
79 |
|
---|
80 | cd $mars
|
---|
81 |
|
---|
82 | date > $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1
|
---|
83 | checklock0=$?
|
---|
84 | case $checklock0 in
|
---|
85 | 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
|
---|
86 | 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
|
---|
87 | echo "-> getting list for callisto is running -> exit" >> $scriptlog 2>&1
|
---|
88 | date >> $scriptlog 2>&1
|
---|
89 | exit;;
|
---|
90 | *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
|
---|
91 | esac
|
---|
92 |
|
---|
93 | echo "checking if other todo-files are there" >> $scriptlog 2>&1
|
---|
94 | if ls $todofile-[1-9].txt >> $scriptlog 2>&1
|
---|
95 | then
|
---|
96 | echo "other file(s) on disk " >> $scriptlog 2>&1
|
---|
97 | echo " -> choose one file and start calibrating" >> $scriptlog 2>&1
|
---|
98 | else
|
---|
99 | # echo "run checkfilesforsequenceavail" >> $scriptlog 2>&1
|
---|
100 | # $scriptspath/checkfilesforsequenceavail
|
---|
101 |
|
---|
102 | echo "getting list..." >> $scriptlog 2>&1
|
---|
103 | check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
|
---|
104 |
|
---|
105 | case $check0 in
|
---|
106 | 1) echo "check0=$check0 -> everthing ok -> run callisto" >> $scriptlog 2>&1;;
|
---|
107 | *) echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
|
---|
108 | esac
|
---|
109 | echo "cutting to-do-file" >> $scriptlog 2>&1
|
---|
110 | echo "getting no of lines" >> $scriptlog 2>&1
|
---|
111 | lines=`cat $todofile.txt | wc -l`
|
---|
112 | echo "number of lines: "$lines >> $scriptlog 2>&1
|
---|
113 | nofiles=`expr $lines / \( $pno - 1 \)`
|
---|
114 | echo "number of files: "$nofiles >> $scriptlog 2>&1
|
---|
115 | echo "deviding todo-file" >> $scriptlog 2>&1
|
---|
116 | for (( j=1 ; j <= $pno ; j++ ))
|
---|
117 | do
|
---|
118 | begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
|
---|
119 | end=$(echo "$begin + $nofiles - 1" | bc -l)
|
---|
120 | echo "begin: "$begin >> $scriptlog 2>&1
|
---|
121 | echo "end: "$end >> $scriptlog 2>&1
|
---|
122 | file=${todofile}-${j}.txt
|
---|
123 | echo "file: "$file >> $scriptlog 2>&1
|
---|
124 | sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
|
---|
125 | done
|
---|
126 |
|
---|
127 | rm -v $todofile.txt >> $scriptlog 2>&1
|
---|
128 | fi
|
---|
129 |
|
---|
130 | rm -v $lockpath/lock-getting-callisto-list.txt >> $scriptlog 2>&1
|
---|
131 |
|
---|
132 | nr=bla
|
---|
133 | echo "finding the right todo-file" >> $scriptlog 2>&1
|
---|
134 | for (( i = 1; i <= $pno ; i++ ))
|
---|
135 | do
|
---|
136 | if ! ls $todofile-$i.txt >> $scriptlog 2>&1
|
---|
137 | then
|
---|
138 | echo "file is not on disk -> continue" >> $scriptlog 2>&1
|
---|
139 | continue
|
---|
140 | fi
|
---|
141 | date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1
|
---|
142 | checklock=$?
|
---|
143 | case $checklock in
|
---|
144 | 0) echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
|
---|
145 | nr=${i}
|
---|
146 | break;;
|
---|
147 | 1) echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
|
---|
148 | *) echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
|
---|
149 | esac
|
---|
150 | done
|
---|
151 |
|
---|
152 | case $nr in
|
---|
153 | bla) echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
|
---|
154 | date >> $scriptlog 2>&1
|
---|
155 | exit;;
|
---|
156 | 12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
|
---|
157 | esac
|
---|
158 |
|
---|
159 |
|
---|
160 | sequences=(`cat $todofile-$nr.txt`)
|
---|
161 |
|
---|
162 | if [ "$sequences" = "" ]
|
---|
163 | then
|
---|
164 | echo "nothing to do -> exit" >> $scriptlog 2>&1
|
---|
165 | rm -v $todofile-$nr.txt >> $scriptlog 2>&1
|
---|
166 | rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
|
---|
167 | date >> $scriptlog 2>&1
|
---|
168 | exit
|
---|
169 | fi
|
---|
170 |
|
---|
171 | echo "sequences: "${sequences[@]} >> $scriptlog 2>&1
|
---|
172 |
|
---|
173 | for sequence in ${sequences[@]}
|
---|
174 | do
|
---|
175 | no=`printf %08d $sequence | cut -c 4`
|
---|
176 | outpath="/magic/data/callisto/"`printf %04d $no`"/"`printf %08d $sequence`
|
---|
177 | echo "outpath: "$outpath >> $scriptlog 2>&1
|
---|
178 | if [ ! -d $outpath ]
|
---|
179 | then
|
---|
180 | mkdir -pv $outpath >> $scriptlog 2>&1
|
---|
181 | if [ ! -d $outpath ]
|
---|
182 | then
|
---|
183 | echo "could not make outpath $outpath -> continue " >> $scriptlog 2>&1
|
---|
184 | continue
|
---|
185 | fi
|
---|
186 | fi
|
---|
187 | sequfile="/magic/sequences/"`printf %04d $no`"/sequence"`printf %08d $sequence`".txt"
|
---|
188 | echo "sequfile: "$sequfile >> $scriptlog 2>&1
|
---|
189 |
|
---|
190 | if [ -e $outpath/callisto.rc ]
|
---|
191 | then
|
---|
192 | echo "found callisto.rc in $outpath -> using this " >> $scriptlog 2>&1
|
---|
193 | callistorcseq=$outpath/callisto.rc
|
---|
194 | else
|
---|
195 | echo "no callisto.rc found in $outpath -> making link " >> $scriptlog 2>&1
|
---|
196 | ln -vs $callistorcnew $outpath/callisto.rc >> $scriptlog 2>&1
|
---|
197 | callistorcseq=$outpath/callisto.rc
|
---|
198 | fi
|
---|
199 |
|
---|
200 | echo "run callisto..." >> $scriptlog 2>&1
|
---|
201 | ./callisto -b -q -f -raw --log=$outpath/callisto$sequence.log --out=$outpath --config=$callistorcseq $sequfile 2>> $scriptlog > /dev/null
|
---|
202 | check1=$?
|
---|
203 |
|
---|
204 | case $check1 in
|
---|
205 | 0) echo "check1=$check1 -> everthing ok -> doing update..." >> $scriptlog 2>&1
|
---|
206 | echo "finding files to be updated" >> $scriptlog 2>&1
|
---|
207 | calfiles=`find $outpath -name *_Y_* `
|
---|
208 | echo "files to be updated: "$calfiles >> $scriptlog 2>&1
|
---|
209 | if [ "$calfiles" = "" ]
|
---|
210 | then
|
---|
211 | echo "no files found -> continue with next sequence" >> $scriptlog 2>&1
|
---|
212 | continue
|
---|
213 | fi
|
---|
214 |
|
---|
215 | merpplogpath=$outpath"/merpplogs"
|
---|
216 | if [ ! -d $merpplogpath ]
|
---|
217 | then
|
---|
218 | mkdir -pv $merpplogpath >> $scriptlog 2>&1
|
---|
219 | if [ ! -d $merpplogpath ]
|
---|
220 | then
|
---|
221 | echo "could not make merpplogpath "$merpplogpath >> $scriptlog 2>&1
|
---|
222 | continue
|
---|
223 | fi
|
---|
224 | fi
|
---|
225 |
|
---|
226 | for calfile in ${calfiles[@]}
|
---|
227 | do
|
---|
228 | echo "calfile: "$calfile >> $scriptlog 2>&1
|
---|
229 | runno=`echo $calfile | cut -d_ -f2 | sed -e 's/^0//' | sed -e 's/^0//' | sed -e 's/^0//' `
|
---|
230 | 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`
|
---|
231 | cacofile=`find /magic/subsystemdata/caco/ -name dc_[2][0][0-2][0-9]_[0,1][0-9]_[0-3][0-9]_*${runno}_*.txt`
|
---|
232 | echo "runno: "$runno >> $scriptlog 2>&1
|
---|
233 | echo "ccfile: "$ccfile >> $scriptlog 2>&1
|
---|
234 | if [ "$ccfile" = "" ]
|
---|
235 | then
|
---|
236 | echo "no ccfile found for run "$runno >> $scriptlog 2>&1
|
---|
237 | break
|
---|
238 | fi
|
---|
239 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
240 | if [ "$cacofile" = "" ]
|
---|
241 | then
|
---|
242 | echo "no cacofile found for run "$runno >> $scriptlog 2>&1
|
---|
243 | echo "finding cacofile..." >> $scriptlog 2>&1
|
---|
244 | for (( i = 0; i <= 10; i++ ))
|
---|
245 | do
|
---|
246 | newrun=`echo $runno - $i | bc`
|
---|
247 | # echo "$missingcacorun + $i = $newrun"
|
---|
248 | path=`dirname $ccfile`
|
---|
249 | path=`echo $path | sed -e 's/cc/caco/'`
|
---|
250 | echo "path: "$path >> $scriptlog 2>&1
|
---|
251 | cacofile=`find $path -name *$newrun*`
|
---|
252 | if [ "$cacofile" = "" ]
|
---|
253 | then
|
---|
254 | continue
|
---|
255 | else
|
---|
256 | break
|
---|
257 | echo "cacofile: "$cacofile >> $scriptlog 2>&1
|
---|
258 | fi
|
---|
259 | done
|
---|
260 | fi
|
---|
261 | ./merpp -u --log=$merpplogpath/merppccupdate$runno.log --runfile=$runno $ccfile $calfile 2>> $scriptlog> /dev/null
|
---|
262 | check2=$?
|
---|
263 | case $check2 in
|
---|
264 | 0) echo "check2=$check2 -> everthing ok, merppccupdate worked -> continue" >> $scriptlog 2>&1;;
|
---|
265 | *) echo "check2=$check2 -> ERROR -> merppccupdate failed" >> $scriptlog 2>&1
|
---|
266 | continue 2 ;;
|
---|
267 | esac
|
---|
268 | ./merpp -u --log=$merpplogpath/merppcacoupdate$runno.log --auto-time $cacofile $calfile 2>> $scriptlog> /dev/null
|
---|
269 | check3=$?
|
---|
270 | case $check3 in
|
---|
271 | 0) echo "check3=$check3 -> everthing ok, merppcacoupdate worked -> continue" >> $scriptlog 2>&1;;
|
---|
272 | *) echo "check3=$check3 -> ERROR -> merppcacoupdate failed" >> $scriptlog 2>&1
|
---|
273 | continue 2 ;;
|
---|
274 | esac
|
---|
275 | done
|
---|
276 |
|
---|
277 | echo "inserting the status for callisto for sequence $sequence into the db" >> $scriptlog 2>&1
|
---|
278 | setstatuslogpath=$logpath/setstatus/callisto/`printf %04d $no`
|
---|
279 | if [ ! -d $setstatuslogpath ]
|
---|
280 | then
|
---|
281 | mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
|
---|
282 | if [ ! -d $setstatuslogpath ]
|
---|
283 | then
|
---|
284 | echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
|
---|
285 | continue
|
---|
286 | fi
|
---|
287 | fi
|
---|
288 | setstatuslog=$setstatuslogpath/setstatus-callisto
|
---|
289 | check4=`root -q -b $macrospath/setstatus.C+\("\"$sequence\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog-$sequence.log | grep int | sed -e 's/(int)//'`
|
---|
290 | case $check4 in
|
---|
291 | 1) echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
|
---|
292 | *) echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
|
---|
293 | esac
|
---|
294 | ;;
|
---|
295 | *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
|
---|
296 | esac
|
---|
297 | done
|
---|
298 |
|
---|
299 | rm -v $todofile-$nr.txt >> $scriptlog 2>&1
|
---|
300 | rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
|
---|
301 |
|
---|
302 | set +C
|
---|
303 |
|
---|
304 | date >> $scriptlog 2>&1
|
---|
305 |
|
---|