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

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