source: trunk/MagicSoft/Mars/datacenter/scripts/sourcefile@ 7936

Last change on this file since 7936 was 7936, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 10.8 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 05/2005 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2006
23#
24#
25# ========================================================================
26#
27# This a resource file for the scripts, in which the standard paths and
28# functions, which are needed more often are stored.
29# Only constant variables are stored here, changing variables are stored
30# in datacenter/scripts/setup
31#
32
33source `dirname $0`/setup
34
35mars=`dirname $0 | sed -e 's/\/datacenter\/scripts//'`
36macrospath=$mars/datacenter/macros
37scriptspath=$mars/datacenter/scripts
38
39webpath=/www/htdocs/datacenter
40
41processlogpath=$logpath/run/`date +%Y/%m/%d`
42processlog=$processlogpath/process`date +%F`.log
43
44datetime=`date +%F-%H-%M-%S`
45
46check="ok"
47
48#failed codes
49#sequence build status
50Fbuildsequ=1
51Fdoexcl=2
52#run process status
53Ftimecorr=3
54Ffillraw=4
55Fsinope=5
56Ffillsinope=6
57Fresetexcl=7
58#sequence process status
59Fwritesequfile=8
60Ffilesavail=9
61Fnoccfile=10
62Fnocacofile=11
63Fmerppcc=12
64Fmerppcaco=13
65Fcallisto=14
66Ffillcalib=15
67Ffillsignal=16
68Fstar=17
69Ffillstar=18
70#dataset process status
71Fstardone=19
72Fganymed=20
73Ffillganymed=21
74
75#
76# setup for jobmanager
77#
78steps=$mars/steps.rc
79# resetting values
80pno=0
81totalpno=0
82running=0
83queued=0
84runningscript=0
85queuedscript=0
86stillinqueue=0
87
88function setzero()
89{
90 val=$@
91 if [ "$val" == "" ]
92 then
93 test=`condor_q -global`
94 if [ "$test" == "" ]
95 then
96 echo $max
97 else
98 echo 0
99 fi
100 else
101 echo $val
102 fi
103}
104
105
106
107# in the following the function, which are needed by several scripts, are
108# defined
109
110function printprocesslog
111{
112 makedir $processlogpath
113 echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "$@ >> $processlog
114}
115
116# function to exit a script properly
117function finish()
118{
119 rm -v $todofile
120 rm -v $lockfile
121 date
122 exit
123}
124
125# function to do continue in a loop and produce according logging
126function cont()
127{
128 date
129 echo ""
130 continue
131}
132
133# function to make sure that a directory is made
134function makedir()
135{
136 if [ ! -d $@ ]
137 then
138 mkdir -pv $@
139 if [ ! -d $@ ]
140 then
141 echo "could not make dir "$@
142 finish
143 fi
144 fi
145}
146
147# function to check if a process is already locked
148function checklock()
149{
150 date > $lockfile
151 checklock0=$?
152 case $checklock0 in
153 0) echo " checklock0=$checklock0 -> continue " ;;
154 1) echo " checklock0=$checklock0 -> file $lockfile exists -> exit"
155 date
156 exit;;
157 *) echo " checklock0=$checklock0 -> something went completely wrong" ;;
158 esac
159}
160
161# function calling the macro, which is producing the todo-list
162function getdolistroot()
163{
164 datetime=`date +%F-%H-%M-%S`
165 year=`date +%Y`
166 date=NULL
167
168 getstatuslogpath=$logpath/getstatus/$program/$year
169 getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log
170 makedir $getstatuslogpath
171
172 # get todo list
173 echo "getting todo list..."
174 check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\,"\"$listpath\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
175
176 case $check0 in
177 1) echo " check0=$check0 -> everything ok, got todo list -> run $program";;
178 *) echo " check0=$check0 -> ERROR -> could not get todo list -> exit"
179 finish ;;
180 esac
181
182}
183
184function resetstatusvalues()
185{
186 statustime=NULL
187 starttime=NULL
188 returncode=NULL
189 failedcode=NULL
190 failedcodeadd=NULL
191 failedtime=NULL
192}
193
194function printstatusvalues()
195{
196 echo "the current values are:"
197 echo " statustime=$statustime"
198 echo " starttime=$starttime"
199 echo " returncode=$returncode"
200 echo " failedcode=$failedcode"
201 echo " failedcodeadd=$failedcodeadd"
202 echo " failedtime=$failedtime"
203 echo "-- check: -$check-"
204 echo ""
205}
206
207# function evaluating the statusvalues
208function evalstatus()
209{
210 case $@ in
211 start) echo "setstatus start"
212 starttime="Now()"
213 ;;
214 stop) echo "setstatus stop"
215 case $check in
216 ok) echo " ok"
217 statustime="Now()"
218 ;;
219 no) echo "nothing new"
220 check="ok"
221 ;;
222 *) echo " failed"
223 starttime=noreset
224 returncode=$check
225 failedcode=$com
226 if ! [ "$comadd" = "" ]
227 then
228 failedcodeadd=$comadd
229 fi
230 failedtime="Now()"
231 check="ok"
232 ;;
233 esac
234 ;;
235 *) echo "error -> exit"
236 exit
237 ;;
238 esac
239}
240
241# function calling the macro to set the status, after a process has finished
242function setstatusroot()
243{
244 # set status values
245 resetstatusvalues
246 evalstatus $@
247
248# printstatusvalues
249 # set status
250 setstatuslogpath=$logpath/setstatus/$program/$var1
251 makedir $setstatuslogpath
252 setstatuslog=$setstatuslogpath/setstatus-$@-$program-$var2.log
253 checkstatus=`root -q -b $macrospath/setstatus.C+\("\"$var2\""\,"\"$table\""\,"\"$column\""\,"\"$statustime\""\,"\"$returncode\""\,"\"$failedcode\""\,"\"$failedcodeadd\""\,"\"$starttime\""\,"\"$failedtime\""\) | tee $setstatuslog | grep int | sed -e 's/(int)//'`
254 case $checkstatus in
255 1) echo " checkstatus=$checkstatus -> everything ok, status has been set";;
256 *) echo " checkstatus=$checkstatus -> ERROR -> step could not be set -> exit"
257 finish ;;
258 esac
259}
260
261function getdbsetup()
262{
263 db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
264 pw=`grep Password $mars/sql.rc | grep -v '#' | sed -e 's/Password: //' -e 's/ //g'`
265 us=`grep User $mars/sql.rc | grep -v '#' | sed -e 's/User: //' -e 's/ //g'`
266# echo "setup: "
267# echo " db: "$db
268# echo " pw: "$pw
269# echo " us: "$us
270}
271
272function getstepinfo()
273{
274 table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'`
275 coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
276 needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
277 influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
278 primary=`grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"`
279# echo " column $column - table $table - coltab $coltab"
280# echo " needs: $needs"
281# echo " influences: $influences"
282# echo " primary: $primary"
283}
284
285# function to get todolist
286function getdolist()
287{
288 echo "getting todolist..."
289 getdbsetup
290 getstepinfo
291 # get query
292 query=" select $primary from $table where "
293 if ! echo $needs | grep '#' > /dev/null
294 then
295 for need in $needs
296 do
297 query=$query" not isnull($need) and"
298 done
299 fi
300 query=$query" isnull($column) "
301 query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
302 query=$query" order by $primary desc "
303# echo " QUERY: "$query
304 if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
305 then
306 echo "ERROR could not query process from db -> exit"
307 finish
308 fi
309
310 if [ "$process" = "" ]
311 then
312 echo " => nothing to do"
313 finish
314 else
315 todofile=$listpath/ToDo-$table-$column.txt
316
317 if ls $todofile > /dev/null 2>&1
318 then
319 echo "$todofile exists already"
320 finish
321 fi
322 echo "found processes, writing todofile..."
323 echo $process > $todofile
324 fi
325}
326
327# function to get todo (process)
328function gettodo()
329{
330 process=
331 echo "getting todo..."
332 getdbsetup
333 getstepinfo
334 # get query
335 query=" select $primary from $table where "
336 if ! echo $needs | grep '#' > /dev/null
337 then
338 for need in $needs
339 do
340 query=$query" not isnull($need) and"
341 done
342 fi
343 query=$query" isnull($column) "
344 query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
345 query=$query" order by $primary desc "
346 query=$query" limit 0, 1 "
347# echo " QUERY: "$query
348 if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
349 then
350 echo "ERROR could not query process from db -> exit"
351 finish
352 fi
353
354 if [ "$process" = "" ]
355 then
356 echo " => nothing to do -> exit"
357 finish
358 fi
359}
360
361# function to get the number of processes which still have to be done
362function getstatus()
363{
364 printprocesslog "this is a test"`date`
365 numproc=
366# echo "getting status..."
367 getdbsetup
368 column=${scriptscolname[$i]}
369 getstepinfo
370 # get query
371 query=" select count(*) from $table where "
372 if ! echo $needs | grep '#' > /dev/null
373 then
374 for need in $needs
375 do
376 query=$query" not isnull($need) and"
377 done
378 fi
379 query=$query" isnull($column) "
380 query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
381 query=$query" group by $column "
382# echo " QUERY: "$query
383 if ! numproc=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
384 then
385 echo "ERROR could not query number of todo proceses from db -> continue"
386 cont
387 fi
388}
389
390# function to set status of a process in the db
391function setstatus()
392{
393 resetstatusvalues
394 evalstatus $@
395 getdbsetup
396 getstepinfo
397 # get query
398 reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'`
399 if [ "$reset" = "no" ]
400 then
401 echo "YOU CAN'T RESET $column for $var2!!!"
402 finish
403 fi
404 query=" update $table set $column=$statustime"
405 if ! echo $influences | grep '#' > /dev/null
406 then
407 for influence in $influences
408 do
409 query=$query", $influence=NULL"
410 done
411 fi
412 query=$query", fStartTime=$starttime, fFailedTime=$failedtime, fFailedCode=$failedcode, fFailedCodeAdd=$failedcodeadd, fReturnCode=$returncode "
413 query=$query" where $primary=$var2"
414 echo " QUERY: "$query
415 if ! mysql -s -u $us --password=$pw --host=hercules $db -e " $query "
416 then
417 echo "ERROR could not insert status into db -> exit"
418 finish
419 fi
420
421}
Note: See TracBrowser for help on using the repository browser.