source: trunk/MagicSoft/Mars/datacenter/scripts/runganymed@ 7219

Last change on this file since 7219 was 7213, checked in by Daniela Dorner, 20 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 7.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-2004
23#
24#
25# ========================================================================
26#
27#
28
29user=`whoami`
30source /home/$user/Mars/datacenter/scripts/sourcefile
31
32set -C
33
34table=DataSetProcessStatus
35column=fGanymed
36date=NULL
37datetime=`date +%F-%H-%M-%S`
38year=`date +%Y`
39pno=24 # number of processes, i.e. number of todo-files
40
41todofile=$listpath/ToDo-$table-$column
42getstatuslogpath=$logpath/getstatus/ganymed/$year
43getstatuslog=$getstatuslogpath/getstatus-ganymed-$datetime.log
44
45scriptlogpath=$logpath/run/ganymed/`date +%Y/%m/%d`
46if [ ! -d $scriptlogpath ]
47then
48 mkdir -pv $scriptlogpath
49 if [ ! -d $scriptlogpath ]
50 then
51 echo "could not make scriptlogpath "$scriptlogpath
52 exit
53 fi
54fi
55
56scriptlog=$scriptlogpath/runganymed-$datetime.log
57
58date >> $scriptlog 2>&1
59
60
61if [ ! -d $getstatuslogpath ]
62then
63 mkdir -pv $getstatuslogpath >> $scriptlog 2>&1
64 if [ ! -d $getstatuslogpath ]
65 then
66 echo "could not make getstatuslogpath "$getstatuslogpath >> $scriptlog 2>&1
67 date >> $scriptlog 2>&1
68 exit
69 fi
70fi
71
72cd $mars
73
74date > $lockpath/lock-getting-ganymed-list.txt >> $scriptlog 2>&1
75checklock0=$?
76case $checklock0 in
77 0) echo "checklock0=$checklock0 -> continue " >> $scriptlog 2>&1;;
78 1) echo "checklock0=$checklock0 -> file exists " >> $scriptlog 2>&1
79 echo "-> getting list for ganymed is running -> exit" >> $scriptlog 2>&1
80 date >> $scriptlog 2>&1
81 exit;;
82 *) echo "checklock0=$checklock0 -> something went completely wrong" >> $scriptlog 2>&1;;
83esac
84
85echo "checking if other todo-files are there" >> $scriptlog 2>&1
86if ls $todofile-[1-9]*.txt >> $scriptlog 2>&1
87then
88 echo "other file(s) on disk " >> $scriptlog 2>&1
89 echo " -> choose one file and run ganymed" >> $scriptlog 2>&1
90else
91 echo "getting list..." >> $scriptlog 2>&1
92 check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
93
94 case $check0 in
95 1) echo "check0=$check0 -> everthing ok -> run ganymed" >> $scriptlog 2>&1;;
96 *) echo "check0=$check0 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
97 esac
98 echo "cutting to-do-file" >> $scriptlog 2>&1
99 echo "getting no of lines" >> $scriptlog 2>&1
100 lines=`cat $todofile.txt | wc -l`
101 echo "number of lines: "$lines >> $scriptlog 2>&1
102 while (( "$lines" < "$pno" ))
103 do
104 echo "# of lines ($lines) < # of processes ($pno) "
105 pno=`expr $pno / 2`
106 done
107 echo "pno: "$pno >> $scriptlog 2>&1
108 nofiles=`expr $lines / \( $pno - 1 \)`
109 echo "number of files: "$nofiles >> $scriptlog 2>&1
110 echo "deviding todo-file" >> $scriptlog 2>&1
111 for (( j=1 ; j <= $pno ; j++ ))
112 do
113 begin=$(echo "1 + ( ($j - 1) * $nofiles)" | bc -l)
114 end=$(echo "$begin + $nofiles - 1" | bc -l)
115 echo "begin: "$begin >> $scriptlog 2>&1
116 echo "end: "$end >> $scriptlog 2>&1
117 file=${todofile}-${j}.txt
118 echo "file: "$file >> $scriptlog 2>&1
119 sed -ne ''"$begin"','"$end"'w '"$file"'' $todofile.txt
120 done
121
122 rm -v $todofile.txt >> $scriptlog 2>&1
123fi
124
125rm -v $lockpath/lock-getting-ganymed-list.txt >> $scriptlog 2>&1
126
127nr=bla
128echo "finding the right todo-file" >> $scriptlog 2>&1
129for (( i = 1; i <= $pno ; i++ ))
130do
131 if ! ls $todofile-$i.txt >> $scriptlog 2>&1
132 then
133 echo "file is not on disk -> continue" >> $scriptlog 2>&1
134 continue
135 fi
136 date > $lockpath/lock-$table-$column-$i.txt >> $scriptlog 2>&1
137 checklock=$?
138 case $checklock in
139 0) echo "checklock=$checklock -> setting number" >> $scriptlog 2>&1
140 nr=${i}
141 break;;
142 1) echo "checklock=$checklock -> file exists -> continue" >> $scriptlog 2>&1;;
143 *) echo "checklock=$checklock -> something went completely wrong" >> $scriptlog 2>&1;;
144 esac
145done
146
147case $nr in
148 bla) echo "everything is beeing processed -> exit" >> $scriptlog 2>&1
149 date >> $scriptlog 2>&1
150 exit;;
151 12345678) echo "process nr: "$nr >> $scriptlog 2>&1;;
152esac
153
154
155datasets=(`cat $todofile-$nr.txt`)
156
157if [ "$datasets" = "" ]
158then
159 echo "nothing to do -> exit" >> $scriptlog 2>&1
160 rm -v $todofile-$nr.txt >> $scriptlog 2>&1
161 rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
162 date >> $scriptlog 2>&1
163 exit
164fi
165
166echo "datasets: "${datasets[@]} >> $scriptlog 2>&1
167
168for dataset in ${datasets[@]}
169do
170 no=`printf %08d $dataset | cut -c 0-5`
171 no2=`printf %08d $dataset`
172 outpath="$datapath/ganymed/$no/$no2"
173 echo "outpath: "$outpath >> $scriptlog 2>&1
174 if [ ! -d $outpath ]
175 then
176 mkdir -pv $outpath >> $scriptlog 2>&1
177 if [ ! -d $outpath ]
178 then
179 echo "could not make outpath $outpath -> continue " >> $scriptlog 2>&1
180 continue
181 fi
182 fi
183 datasetfile="/magic/datasets/$no/dataset$no2.txt"
184 echo "datasetfile: "$datasetfile >> $scriptlog 2>&1
185 wobble=`grep 'WobbleMode:' $datasetfile` >> $scriptlog 2>&1
186 wobble2=`echo $wobble | grep ^\#` >> $scriptlog 2>&1
187 if [ "$wobble2" = "" ]
188 then
189 mode="wobble" >> $scriptlog 2>&1
190 else
191 mode="onoff" >> $scriptlog 2>&1
192 fi
193 ganymedrc=/magic/datacenter/setup/ganymed/ganymed_$mode.rc
194
195 echo "run ganymed..." >> $scriptlog 2>&1
196 ./ganymed -b -q -v4 -f --sum --config=$ganymedrc --log=$outpath/ganymed$no2.log --html=$outpath/ganymed$no2.html --out=$outpath $datasetfile 2>> $scriptlog> /dev/null
197 check1=$?
198
199 case $check1 in
200 0) echo "check1=$check1 -> everthing ok " >> $scriptlog 2>&1
201 echo "-> inserting the status for ganymed for dataset $dataset into the db" >> $scriptlog 2>&1
202 setstatuslogpath=$logpath/setstatus/ganymed/$no
203 if [ ! -d $setstatuslogpath ]
204 then
205 mkdir -pv $setstatuslogpath >> $scriptlog 2>&1
206 if [ ! -d $setstatuslogpath ]
207 then
208 echo "could not make setstatuslogpath "$setstatuslogpath >> $scriptlog 2>&1
209 continue
210 fi
211 fi
212 setstatuslog=$setstatuslogpath/setstatus-ganymed-$no2.log
213 check4=`root -q -b $macrospath/setstatus.C+\("\"$dataset\""\,"\"$table\""\,"\"$column\""\,"\"Now()\""\) | tee $setstatuslog | grep int | sed -e 's/(int)//'`
214 case $check4 in
215 1) echo "check4=$check4 -> everthing ok, status has been set" >> $scriptlog 2>&1;;
216 *) echo "check4=$check4 -> ERROR -> step could not be set" >> $scriptlog 2>&1;;
217 esac
218 ;;
219 *) echo "check1=$check1 -> ERROR -> step has to be repeated" >> $scriptlog 2>&1;;
220 esac
221done
222
223rm -v $todofile-$nr.txt >> $scriptlog 2>&1
224rm -v $lockpath/lock-$table-$column-$nr.txt >> $scriptlog 2>&1
225
226set +C
227
228date >> $scriptlog 2>&1
229
Note: See TracBrowser for help on using the repository browser.