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=$pw --host=vela $db -s -e'
|
---|
96 |
|
---|
97 | whereclause1=" WHERE fDataSetNumber=$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 | if [ "$seqoff" = "" ]
|
---|
121 | then
|
---|
122 | whereclause2=" WHERE fSequenceFirst IN ($seqon)"
|
---|
123 | else
|
---|
124 | whereclause2=" WHERE fSequenceFirst IN ($seqon,$seqoff)"
|
---|
125 | fi
|
---|
126 | query3="UPDATE SequenceProcessStatus SET fCallisto=NULL, fStar=NULL "
|
---|
127 | query3=$query3$statusreset$whereclause2
|
---|
128 |
|
---|
129 | query4="DELETE FROM Calibration"$whereclause2
|
---|
130 | query5="DELETE FROM Star"$whereclause2
|
---|
131 |
|
---|
132 |
|
---|
133 | echo ""
|
---|
134 | echo "The following queries would be executed:"
|
---|
135 | echo "Q1: "$query1
|
---|
136 | echo "Q2: "$query2
|
---|
137 | echo "Q3: "$query3
|
---|
138 | echo "Q4: "$query4
|
---|
139 | echo "Q5: "$query5
|
---|
140 | echo ""
|
---|
141 | echo " DB: "$db
|
---|
142 | echo "user: " $user
|
---|
143 | echo ""
|
---|
144 | echo "Are you sure you want to continue?"
|
---|
145 | echo "please insert y, if you want continue"
|
---|
146 | echo " n, if you want quit"
|
---|
147 |
|
---|
148 | answer=`head -n 1`
|
---|
149 | case $answer in
|
---|
150 | y) echo "continue resetting DB"
|
---|
151 | ;;
|
---|
152 | n) exit
|
---|
153 | ;;
|
---|
154 | *) echo "your answer is not clear -> exit"
|
---|
155 | exit
|
---|
156 | ;;
|
---|
157 | esac
|
---|
158 |
|
---|
159 | mymysql "$query1"
|
---|
160 | mymysql "$query2"
|
---|
161 | mymysql "$query3"
|
---|
162 | mymysql "$query4"
|
---|
163 | mymysql "$query5"
|
---|
164 |
|
---|