1 | #!/bin/bash
|
---|
2 | #
|
---|
3 |
|
---|
4 | source `dirname $0`/../Sourcefile.sh
|
---|
5 | printprocesslog "INFO starting $0"
|
---|
6 |
|
---|
7 | # get and check variables
|
---|
8 | if ! [ "$1" = "" ]
|
---|
9 | then
|
---|
10 | starfile=$1
|
---|
11 | fi
|
---|
12 |
|
---|
13 | if [ "$starfile" = "" ]
|
---|
14 | then
|
---|
15 | echo "ERROR variable starfile empty."
|
---|
16 | printprocesslog "ERROR variable starfile empty."
|
---|
17 | finish
|
---|
18 | fi
|
---|
19 |
|
---|
20 | # getting coordinates from raw and drive or DB
|
---|
21 | date=`echo $starfile | grep -o -E '20[0-9][0-9]/[0-3][0-9]/[0-3][0-9]'`
|
---|
22 | drivefile=$auxdata"/"$date"/"`basename $starfile | cut -d_ -f1`".DRIVE_CONTROL_SOURCE_POSITION.fits"
|
---|
23 | rawfile=$rawdata"/"$date"/"`basename $starfile | sed -e 's/_I.root/.fits.fz/'`
|
---|
24 | if [ -e $rawfile ]
|
---|
25 | then
|
---|
26 | printprocesslog "INFO processing "$rawfile
|
---|
27 | tstopi=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
---|
28 | tstopf=`$factpath/fitsdump -h $rawfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
|
---|
29 | tstop=${tstopi}${tstopf}
|
---|
30 | else
|
---|
31 | printprocesslog "WARN "$rawfile" not found."
|
---|
32 | fi
|
---|
33 | if [ "$tstop" == "" ]
|
---|
34 | then
|
---|
35 | printprocesslog "WARN tstop empty "$rawfile
|
---|
36 | fi
|
---|
37 | if ! ls $drivefile >/dev/null 2>&1
|
---|
38 | then
|
---|
39 | printprocesslog "WARN "$drivefile" missing."
|
---|
40 | fi
|
---|
41 | if ls $drivefile >/dev/null 2>&1 && ! [ "$tstop" == "" ]
|
---|
42 | then
|
---|
43 | printprocesslog "INFO getting coordinates from "$drivefile
|
---|
44 | coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
|
---|
45 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
---|
46 | then
|
---|
47 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
---|
48 | echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
---|
49 | finish
|
---|
50 | fi
|
---|
51 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
---|
52 | then
|
---|
53 | printprocesslog "WARN coordinates "${coordinates[@]}
|
---|
54 | echo "WARN coordinates "${coordinates[@]}
|
---|
55 | finish
|
---|
56 | fi
|
---|
57 | else
|
---|
58 | night=`echo $date | sed -e 's/\///g'`
|
---|
59 | runid=`basename $starfile | cut -d_ -f2`
|
---|
60 | printprocesslog "INFO getting coordinates from DB."
|
---|
61 | query="SELECT fSourceKEY FROM RunInfo WHERE fNight="$night" AND fRunID="$runid
|
---|
62 | sourcekey=`sendquery`
|
---|
63 | if [ "$sourcekey" == "" ]
|
---|
64 | then
|
---|
65 | printprocesslog "WARN sourcekey empty for "$night"_"$runid" - coordinates"${coordinates[@]}
|
---|
66 | finish
|
---|
67 | fi
|
---|
68 | query="SELECT Round(fRightAscension,6), Round(fDeclination,6) from Source WHERE fSourceKey="$sourcekey
|
---|
69 | coordinates=( `sendquery` )
|
---|
70 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
---|
71 | then
|
---|
72 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") for "$night"_"$runid" from DB."
|
---|
73 | finish
|
---|
74 | fi
|
---|
75 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
---|
76 | then
|
---|
77 | printprocesslog "WARN coordinates "${coordinates[@]}" for "$night"_"$runid
|
---|
78 | finish
|
---|
79 | fi
|
---|
80 | fi
|
---|
81 | ra=${coordinates[0]}
|
---|
82 | dec=${coordinates[1]}
|
---|
83 |
|
---|
84 |
|
---|
85 | outpath=`dirname $starfile | sed -e 's/star/ganymed_run/'`
|
---|
86 | makedir $outpath
|
---|
87 |
|
---|
88 | output=$outpath/`basename $starfile | cut -d_ -f1-2`
|
---|
89 | logfile=$output"-ganymed.log"
|
---|
90 | ganymedfile=$output"-analysis.root"
|
---|
91 |
|
---|
92 | cd $mars
|
---|
93 |
|
---|
94 | # run ganymed
|
---|
95 | printprocesslog "INFO starting ganymed.C for starfile "$starfile
|
---|
96 |
|
---|
97 | printprocesslog "DEBUG root -q -b fact/analysis/ganymed.C\($ra\,$dec\,"\"$starfile\""\,"\"$output\""\) | tee $logfile | intgrep"
|
---|
98 | check1=`root -q -b fact/analysis/ganymed.C\($ra\,$dec\,"\"$starfile\""\,"\"$output\""\) | tee $logfile | intgrep`
|
---|
99 |
|
---|
100 | case $check1 in
|
---|
101 | 0) printprocesslog "INFO ganymed.C was successful for starfile "$starfile" ra "$ra" dec "$dec" (check1=$check1)"
|
---|
102 |
|
---|
103 | echo "run numevts.C for "$ganymedfile" for table "$resulttable1 >> $logfile 2>&1
|
---|
104 | printprocesslog "INFO run numevts.C for "$ganyemdfile" for table "$resulttable1
|
---|
105 | printprocesslog "DEBUG root -q -b -l fact/processing/numevents.C+\("\"$ganymedfile"\"\,"\"$starfile"\"\,"\"$resulttable1"\"\,kFALSE\)"
|
---|
106 | check1=`root -q -b -l fact/processing/numevents.C+\("\"$ganymedfile"\"\,"\"$starfile"\"\,"\"$resulttable1"\"\,kFALSE\) | tee $logfile | intgrep`
|
---|
107 | case $check1 in
|
---|
108 | 1) printprocesslog "INFO filling numevts.C was successfully for "$ganymedfile" and table "$resulttable1" (check1=$check1)"
|
---|
109 | ;;
|
---|
110 | 0) printprocesslog "WARN connection to DB failed in numevts.C (check1=$check1)"
|
---|
111 | ;;
|
---|
112 | *) printprocesslog "ERROR numevts.C failed for "$ganymedfile" and table "$resulttable1" (check1=$check1)"
|
---|
113 | ;;
|
---|
114 | esac
|
---|
115 | ;;
|
---|
116 | *) printprocesslog "ERROR ganymed.C failed for starfile "$starfile" ra "$ra" dec "$dec" (check1=$check1)"
|
---|
117 | ;;
|
---|
118 | esac
|
---|
119 |
|
---|
120 | finish
|
---|
121 |
|
---|