1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # option whether to fill all row or only those where information is missing
|
---|
4 | # $doupdate might be given as environment variable
|
---|
5 | if [ "$doupdate" = "" ]
|
---|
6 | then
|
---|
7 | doupdate="yes" # update all entries (needed when new fields have been added)
|
---|
8 | doupdate="no" # fill only entries which are not yet existing (default)
|
---|
9 | fi
|
---|
10 |
|
---|
11 | source `dirname $0`/../Sourcefile.sh
|
---|
12 | printprocesslog "INFO starting $0 with option doupdate="$doupdate
|
---|
13 |
|
---|
14 | logfile=$runlogpath"/FillAusCamHum-"$datetime".log"
|
---|
15 | date >> $logfile
|
---|
16 |
|
---|
17 | # check if software is available
|
---|
18 | if ! ls $factpath/fitsdump >/dev/null 2>&1
|
---|
19 | then
|
---|
20 | printprocesslog "ERROR "$factpath"/fitsdump is not available."
|
---|
21 | finish
|
---|
22 | fi
|
---|
23 |
|
---|
24 | # get dates
|
---|
25 | if [ "$certaindate" != "" ]
|
---|
26 | then
|
---|
27 | getdates $certaindate
|
---|
28 | else
|
---|
29 | # get all night
|
---|
30 | #getdates "all"
|
---|
31 | # get last 6 nights
|
---|
32 | getdates 6
|
---|
33 | fi
|
---|
34 |
|
---|
35 |
|
---|
36 | printprocesslog "INFO processing the following night(s): "${dates[@]}
|
---|
37 | echo `date`": processing the following night(s): "${dates[@]} >> $logfile 2>&1
|
---|
38 |
|
---|
39 | cd $mars
|
---|
40 |
|
---|
41 | # do filling of aux data
|
---|
42 | for date in ${dates[@]}
|
---|
43 | do
|
---|
44 | auxdir=$auxdata/$date
|
---|
45 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
46 | if [ $runnumber -lt 20120328 ]
|
---|
47 | then
|
---|
48 | continue
|
---|
49 | fi
|
---|
50 |
|
---|
51 | # get file numbers from DB
|
---|
52 | # but only for not-corrupted files
|
---|
53 | query="SELECT fRunID from RunInfo WHERE fNight="$runnumber" AND fFitsFileErrors=0 AND fRunTypeKey=1 "
|
---|
54 | if [ "$doupdate" = "no" ]
|
---|
55 | then
|
---|
56 | query=$query" AND ISNULL(fNum27Sec) "
|
---|
57 | fi
|
---|
58 | printprocesslog "DEBUG get filenumbers from DB: QUERY: "$query
|
---|
59 |
|
---|
60 | filenumbers=( `sendquery $query` )
|
---|
61 | printprocesslog "INFO processing "${#filenumbers[@]}" files from date "$date
|
---|
62 | echo "INFO processing "${#filenumbers[@]}" files from date "$date >> $logfile 2>&1
|
---|
63 | # proceed only if there are files available
|
---|
64 | if [ ${#filenumbers} -eq 0 ]
|
---|
65 | then
|
---|
66 | printprocesslog "INFO No files found in the DB for night "$date
|
---|
67 | continue
|
---|
68 | fi
|
---|
69 |
|
---|
70 | # fill
|
---|
71 | counter=0
|
---|
72 | for filenum in ${filenumbers[@]}
|
---|
73 | do
|
---|
74 | printprocesslog "INFO processing file number "$runnumber"_"`printf %03d $filenum`
|
---|
75 | echo `date`": processing file number "$runnumber"_"`printf %03d $filenum` >> $logfile 2>&1
|
---|
76 |
|
---|
77 | cfile=$datapath"/callisto/"$date"/"$runnumber"_"`printf %03d $filenum`"_C.root"
|
---|
78 | if ! [ -e $cfile ]
|
---|
79 | then
|
---|
80 | printprocesslog "INFO "$cfile" does not yet exist"
|
---|
81 | continue
|
---|
82 | fi
|
---|
83 |
|
---|
84 | printprocesslog "INFO filling rates from " $cfile
|
---|
85 | rates=( `root -q -b -l fact/processing/swtrig.C\("\"$cfile\""\) | grep "result" | grep -E -o '[0-9]+'` )
|
---|
86 |
|
---|
87 | # build query to update runinfo in DB
|
---|
88 | query="UPDATE RunInfo SET "
|
---|
89 |
|
---|
90 | if [ "${rates[0]}" == "" ]
|
---|
91 | then
|
---|
92 | query=$query"fNum27Sec=NULL, "
|
---|
93 | query=$query"fNumThreshold500=NULL, "
|
---|
94 | query=$query"fNumThreshold750=NULL, "
|
---|
95 | query=$query"fNumThreshold1000=NULL, "
|
---|
96 | query=$query"fNumThreshold1250=NULL, "
|
---|
97 | query=$query"fNumThreshold2500=NULL, "
|
---|
98 | query=$query"fNumThreshold5000=NULL, "
|
---|
99 | query=$query"fNumThreshold10000=NULL"
|
---|
100 | else
|
---|
101 | query=$query"fNum27Sec="${rates[0]}", "
|
---|
102 | query=$query"fNumThreshold500="${rates[1]}", "
|
---|
103 | query=$query"fNumThreshold750="${rates[2]}", "
|
---|
104 | query=$query"fNumThreshold1000="${rates[3]}", "
|
---|
105 | query=$query"fNumThreshold1250="${rates[4]}", "
|
---|
106 | query=$query"fNumThreshold2500="${rates[5]}", "
|
---|
107 | query=$query"fNumThreshold5000="${rates[6]}", "
|
---|
108 | query=$query"fNumThreshold10000="${rates[7]}
|
---|
109 | fi
|
---|
110 |
|
---|
111 | # add where condition
|
---|
112 | query=$query" WHERE fNight="$runnumber" AND fRunID="$filenum
|
---|
113 |
|
---|
114 | # send query to DB
|
---|
115 | sendquery >/dev/null
|
---|
116 |
|
---|
117 | counter=`echo " $counter + 1 " | bc -l`
|
---|
118 | done
|
---|
119 | #echo "processed "$counter" files."
|
---|
120 | done
|
---|
121 |
|
---|
122 | finish
|
---|
123 |
|
---|
124 |
|
---|