source: trunk/Mars/datacenter/tools/resetdataset@ 11486

Last change on this file since 11486 was 8530, checked in by Daniela Dorner, 18 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.2 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 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
31datasetpath=/magic/datasets
32#datasetpath=/test/bu.2006.10.05/datasets
33
34function 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
51while [ "$1" ]
52do
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
74done
75
76if [ "$dataset" = "" ]
77then
78 echo "Please give the number for the dataset you want to reset."
79 usage
80fi
81
82if [ "$pw" = "" ] || [ "$user" = "" ]
83then
84 echo "Please give user and password for the DB $db."
85 usage
86fi
87
88if [ "$db" = "" ]
89then
90 echo "Please give the DB in which you want to reset."
91 usage
92fi
93
94
95alias mymysql='mysql -u $user --password=$pw --host=vela $db -s -e'
96
97whereclause1=" WHERE fDataSetNumber=$dataset"
98statusreset=", fStartTime=NULL, fFailedTime=NULL, fFailedCode=NULL, fFailedCodeAdd=NULL, fReturnCode=NULL"
99query1="UPDATE DataSetProcessStatus SET fStarFilesAvail=NULL, fGanymed=NULL, fFillGanymed=NULL"
100query1=$query1$statusreset$whereclause1
101
102query2="DELETE FROM Ganymed "$whereclause1
103
104no=`printf %08d $dataset`
105no2=`echo $no | cut -c 0-5`
106datasetfile=$datasetpath/$no2/dataset$no.txt
107if ! ls $datasetfile 2>&1 >/dev/null
108then
109 echo "There's no datasetfile $datasetfile"
110 exit
111fi
112echo " getting sequence numbers from $datasetfile"
113
114seqon=`grep "SequencesOn" $datasetfile | grep -v '#' | sed -e 's/SequencesOn://' -e 's/^ //g' -e 's/ $//g' -e 's/ /,/g'`
115seqoff=`grep "SequencesOff" $datasetfile | grep -v '#' | sed -e 's/SequencesOff://' -e 's/^ //g' -e 's/ $//g' -e 's/ /,/g'`
116
117echo " Found the following on sequences: $seqon"
118echo " Found the following off sequences: $seqoff"
119
120if [ "$seqoff" = "" ]
121then
122 whereclause2=" WHERE fSequenceFirst IN ($seqon)"
123else
124 whereclause2=" WHERE fSequenceFirst IN ($seqon,$seqoff)"
125fi
126query3="UPDATE SequenceProcessStatus SET fAllFilesAvail=NULL, fCallisto=NULL, fStar=NULL "
127query3=$query3$statusreset$whereclause2
128
129query4="DELETE FROM Calibration"$whereclause2
130query5="DELETE FROM Star"$whereclause2
131
132
133echo ""
134echo "The following queries would be executed:"
135echo "Q1: "$query1
136echo "Q2: "$query2
137echo "Q3: "$query3
138echo "Q4: "$query4
139echo "Q5: "$query5
140echo ""
141echo " DB: "$db
142echo "user: " $user
143echo ""
144echo "Are you sure you want to continue?"
145echo "please insert y, if you want continue"
146echo " n, if you want quit"
147
148answer=`head -n 1`
149case $answer in
150 y) echo "continue resetting DB"
151 ;;
152 n) exit
153 ;;
154 *) echo "your answer is not clear -> exit"
155 exit
156 ;;
157esac
158
159mymysql "$query1"
160mymysql "$query2"
161mymysql "$query3"
162mymysql "$query4"
163mymysql "$query5"
164
Note: See TracBrowser for help on using the repository browser.