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 10/2006 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2006
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This script checks from the DB which new starfiles have been produced
|
---|
28 | # and sends it to the person in charge for building datasets
|
---|
29 | #
|
---|
30 |
|
---|
31 | datasetpath=/magic/datasets
|
---|
32 | datasetpath=/test/bu.2006.10.05/datasets
|
---|
33 |
|
---|
34 | function usage()
|
---|
35 | {
|
---|
36 | echo "Usage: $0 [options]"
|
---|
37 | echo "options:"
|
---|
38 | echo -n " --ds dataset# "
|
---|
39 | echo " number of the dataset you want to reset "
|
---|
40 | echo -n " --db "
|
---|
41 | echo " name of the db in which you want to reset "
|
---|
42 | echo -n " --user "
|
---|
43 | echo " db user "
|
---|
44 | echo -n " --pw "
|
---|
45 | echo " pw of the db user "
|
---|
46 | echo ""
|
---|
47 | exit
|
---|
48 | }
|
---|
49 |
|
---|
50 |
|
---|
51 | while [ "$1" ]
|
---|
52 | do
|
---|
53 | case $1 in
|
---|
54 | --ds) shift
|
---|
55 | dataset=$1
|
---|
56 | ;;
|
---|
57 | --db) shift
|
---|
58 | db=$1
|
---|
59 | ;;
|
---|
60 | --pw) shift
|
---|
61 | pw=$1
|
---|
62 | ;;
|
---|
63 | --user) shift
|
---|
64 | user=$1
|
---|
65 | ;;
|
---|
66 | -h) usage
|
---|
67 | ;;
|
---|
68 | *) echo "unknown option $1 "
|
---|
69 | usage
|
---|
70 | exit
|
---|
71 | ;;
|
---|
72 | esac
|
---|
73 | shift
|
---|
74 | done
|
---|
75 |
|
---|
76 | if [ "$dataset" = "" ]
|
---|
77 | then
|
---|
78 | echo "Please give the number for the dataset you want to reset."
|
---|
79 | usage
|
---|
80 | fi
|
---|
81 |
|
---|
82 | if [ "$pw" = "" ] || [ "$user" = "" ]
|
---|
83 | then
|
---|
84 | echo "Please give user and password for the DB $db."
|
---|
85 | usage
|
---|
86 | fi
|
---|
87 |
|
---|
88 | if [ "$db" = "" ]
|
---|
89 | then
|
---|
90 | echo "Please give the DB in which you want to reset."
|
---|
91 | usage
|
---|
92 | fi
|
---|
93 |
|
---|
94 |
|
---|
95 | alias mymysql='mysql -u $user --password=$ps --host=vela $db -s -e'
|
---|
96 |
|
---|
97 | whereclause1=" WHERE fDataSetNumer=$dataset"
|
---|
98 | statusreset=", fStartTime=NULL, fFailedTime=NULL, fFailedCode=NULL, fFailedCodeAdd=NULL, fReturnCode=NULL"
|
---|
99 | query1="UPDATE DataSetProcessStatus SET fStarFilesAvail=NULL, fGanymed=NULL, fFillGanymed=NULL"
|
---|
100 | query1=$query1$statusreset$whereclause1
|
---|
101 |
|
---|
102 | query2="DELETE FROM GANYMED "$whereclause1
|
---|
103 |
|
---|
104 | no=`printf %08d $dataset`
|
---|
105 | no2=`echo $no | cut -c 0-5`
|
---|
106 | datasetfile=$datasetpath/$no2/dataset$no.txt
|
---|
107 | if ! ls $datasetfile 2>&1 >/dev/null
|
---|
108 | then
|
---|
109 | echo "There's no datasetfile $datasetfile"
|
---|
110 | exit
|
---|
111 | fi
|
---|
112 | echo " getting sequence numbers from $datasetfile"
|
---|
113 |
|
---|
114 | seqon=`grep "SequencesOn" $datasetfile | grep -v '#' | sed -e 's/SequencesOn://' -e 's/^ //g' -e 's/ $//g' -e 's/ /,/g'`
|
---|
115 | seqoff=`grep "SequencesOff" $datasetfile | grep -v '#' | sed -e 's/SequencesOff://' -e 's/^ //g' -e 's/ $//g' -e 's/ /,/g'`
|
---|
116 |
|
---|
117 | echo " Found the following on sequences: $seqon"
|
---|
118 | echo " Found the following off sequences: $seqoff"
|
---|
119 |
|
---|
120 | whereclause2=" WHERE fSequenceFirst IN ($seqon,$seqoff)"
|
---|
121 | query3="UPDATE SequenceProcessStatus SET fAllFilesAvail=NULL, fCallisto=NULL, fStar=NULL "
|
---|
122 | query3=$query3$setstatusreseet$whereclause2
|
---|
123 |
|
---|
124 | query4="DELETE FROM Calibration"$whereclause2
|
---|
125 | query5="DELETE FROM Star"$whereclause2
|
---|
126 |
|
---|
127 |
|
---|
128 | echo ""
|
---|
129 | echo "The following queries would be executed:"
|
---|
130 | echo "Q1: "$query1
|
---|
131 | echo "Q2: "$query2
|
---|
132 | echo "Q3: "$query3
|
---|
133 | echo "Q4: "$query4
|
---|
134 | echo "Q5: "$query5
|
---|
135 | echo ""
|
---|
136 | echo " DB: "$db
|
---|
137 | echo "user: " $user
|
---|
138 | echo ""
|
---|
139 | echo "Are you sure you want to continue?"
|
---|
140 | echo "please insert y, if you want continue"
|
---|
141 | echo " n, if you want quit"
|
---|
142 |
|
---|
143 | answer=`head -n 1`
|
---|
144 | case $answer in
|
---|
145 | y) echo "continue resetting DB"
|
---|
146 | ;;
|
---|
147 | n) exit
|
---|
148 | ;;
|
---|
149 | *) echo "your answer is not clear -> exit"
|
---|
150 | exit
|
---|
151 | ;;
|
---|
152 | esac
|
---|
153 |
|
---|
154 | mymysql "$query1"
|
---|
155 | mymysql "$query2"
|
---|
156 | mymysql "$query3"
|
---|
157 | mymysql "$query4"
|
---|
158 | mymysql "$query5"
|
---|
159 |
|
---|