source: trunk/DataCheck/QuickLook/Step1.sh@ 15384

Last change on this file since 15384 was 15381, checked in by Daniela Dorner, 12 years ago
added limitation for number of callisto jobs, added check on number of events to allow for automic reconnect in Main.js, make sure that all callistos are processed, removed variable $rerun, removed not needed lines
  • Property svn:executable set to *
File size: 12.1 KB
Line 
1#!/bin/bash
2#
3source `dirname $0`/../Sourcefile.sh
4printprocesslog "INFO starting $0"
5
6# get date (before 18h there is no new data to be processed)
7datepath=`date --date="-18HOUR" +%Y/%m/%d`
8date=`date --date="-18HOUR" +%Y%m%d`
9#datepath="2013/04/17"
10#date="20130417"
11printprocesslog "INFO processing "$datepath
12night=`echo $datepath | sed -e 's/\///g'`
13
14auxpathnewdaq=/newdaq/aux/$datepath
15# create aux directory on daq, if not yet there
16auxpath=/loc_data/aux/$datepath
17makedir $auxpath
18# create path for info files needed for analysis
19infopath=$anapath/info/$datepath
20makedir $infopath
21echo "" > $infopath/runrow.txt
22# create path for sequence files
23seqpath=$anapath/sequences/$datepath
24makedir $seqpath
25rawpathnewdaq=/newdaq/raw/$datepath
26rawpath=/loc_data/raw/$datepath
27
28# needed auxiliary files:
29# drive file with information about current source position
30drivefile=$auxpath/${night}.DRIVE_CONTROL_SOURCE_POSITION.fits
31drivefilenewdaq=$auxpathnewdaq/${night}.DRIVE_CONTROL_SOURCE_POSITION.fits
32# drive file with information about tracking position
33drivefile2=$auxpath/${night}.DRIVE_CONTROL_TRACKING_POSITION.fits
34drivefilenewdaq2=$auxpathnewdaq/${night}.DRIVE_CONTROL_TRACKING_POSITION.fits
35# file with magic weather information
36mweatherfile=$auxpath/${night}.MAGIC_WEATHER_DATA.fits
37mweatherfilenewdaq=$auxpathnewdaq/${night}.MAGIC_WEATHER_DATA.fits
38# file with trigger rates
39ratesfile=$auxpath/${night}.FTM_CONTROL_TRIGGER_RATES.fits
40ratesfilenewdaq=$auxpathnewdaq/${night}.FTM_CONTROL_TRIGGER_RATES.fits
41# file with trigger rates
42tempfile=$auxpath/${night}.FSC_CONTROL_TEMPERATURE.fits
43tempfilenewdaq=$auxpathnewdaq/${night}.FSC_CONTROL_TEMPERATURE.fits
44# file with trigger rates
45humfile=$auxpath/${night}.FSC_CONTROL_HUMIDITY.fits
46humfilenewdaq=$auxpathnewdaq/${night}.FSC_CONTROL_HUMIDITY.fits
47
48function rsync_aux_file()
49{
50 if ls $1
51 then
52 printprocesslog "INFO rsync "$1
53 #if ! rsync -av --stats $1 $2
54 if ! rsync -av $1 $2
55 then
56 printprocesslog "WARN rsync of "$1" failed."
57 fi
58 fi
59}
60
61printprocesslog "INFO get lists of raw files on newdaq and daq"
62files=( `find $rawpathnewdaq -type f 2>/dev/null | sort` )
63if [ ${#files[@]} -eq 0 ]
64then
65 printprocesslog "INFO no raw files available yet for "$datepath
66 finish
67fi
68fileslocal=( `find $rawpath -type f | sort` )
69callistofiles=( `find $anapath -type f -name $date*-calibration.log | sort` )
70numdataruns=0
71
72# create raw directory on daq, if not yet there
73makedir $rawpath
74
75echo ${#fileslocal[@]}" "${#files[@]}" "${#callistofiles[@]}
76
77while [ ${#fileslocal[@]} -ne ${#files[@]} ] || [ $numdataruns -ne ${#callistofiles[@]} ]
78do
79 numdataruns=0
80 rsync_aux_file $drivefilenewdaq $drivefile
81
82 # files on newdaq
83 for file in ${files[@]}
84 do
85 printprocesslog "processing "$file
86 localfile=`echo $file | sed -e 's/newdaq/loc_data/'`
87 echo "processing "$file" "$localfile
88
89 if [ "`echo $file | grep -o drs`" == "drs" ]
90 then
91 nondrsfile=`echo $file | sed -e 's/[.]drs//g'`
92 tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
93 else
94 tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
95 fi
96 if [ "$tstop" == "0" ]
97 then
98 printprocesslog "WARN "$file" not yet closed."
99 fileaccessed=`find $file -amin -30`
100 if ! [ "$fileaccessed" == "" ]
101 then
102 printprocesslog "INFO "$file" was accessed in the last 30 minutes => continue"
103 continue
104 else
105 printprocesslog "WARN: "$file" has empty TSTOP but was not touched for 30 minutes"
106 fileerror="yes"
107 fi
108 fi
109
110 source `dirname $0`/../Sourcefile.sh
111 if ! ls $localfile >/dev/null 2>&1
112 then
113 if ! rsync -av --stats --progress --bwlimit=$bwlimit $file $localfile
114 then
115 printprocesslog "ERROR something went wrong with rsync of "$file
116 rm $localfile
117 continue
118 fi
119 printprocesslog "INFO "$file" rsynced successfully."
120 fi
121
122
123 if [ "`echo $localfile | grep -o drs`" != "drs" ]
124 then
125 runtype=`$factpath/fitsdump -h $localfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z0-9._-]+[']" | sed -e "s/'//g" -e "s/_/-/g" -e "s/[.]//g"`
126 runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
127 roi=`$factpath/fitsdump -h $localfile 2>/dev/null | grep ROI | grep -v ROITM | grep -E -o "[0-9][0-9][0-9][0-9]?" | sed -e "s/'//g" -e "s/_/-/g" -e "s/[.]//g"`
128 numevts=`$factpath/fitsdump -h $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
129 printprocesslog "DEBUG runnum "$runnum" runtype "$runtype" roi "$roi" numevts "$numevts
130 if [ "$runtype" == "drs-time-upshifted" ]
131 then
132 printprocesslog "INFO file "$file" has runtype drs-time-upshifted -> continue "
133 continue
134 fi
135 if [ "$runtype" == "data" ]
136 then
137 numdataruns=`echo " $numdataruns + 1 " | bc -l`
138 if [ "$fileerror" = "yes" ]
139 then
140 printprocesslog "INFO do not further process corrupted file "$localfile
141 fileerror=
142 continue
143 fi
144 seqfile=$seqpath/${night}_${runnum}.seq
145 printprocesslog "INFO write data-seq "$seqfile
146 echo "# written by automatic analysis in LP" >$seqfile
147 echo "" >> $seqfile
148 echo "Sequence: "`echo $night | cut -c3-8`$runnum >> $seqfile
149 echo "Night: "`echo $datepath | sed -e 's/\//-/g'` >> $seqfile
150 echo "" >> $seqfile
151 echo "DrsSequence: "$drsseq >> $seqfile
152 echo "" >> $seqfile
153 echo "CalRuns: "`echo $runrow | grep -E -o '[0-9]{3}light-pulser-ext300' | sed -e 's/light-pulser-ext300//g'` >> $seqfile
154 echo "PedRuns: "`echo $runrow | grep -E -o '[0-9]{3}pedestal300' | sed -e 's/pedestal300//g'` >> $seqfile
155 echo "DatRuns: "$runnum >> $seqfile
156 echo "" >> $seqfile
157 echo "DrsFiles: "$drsfile >> $seqfile
158 echo "" >> $seqfile
159 echo "#DrsFile: "$drsfile >> $seqfile
160 echo "" >> $seqfile
161
162 tstopi=`$factpath/fitsdump -h $localfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
163 tstopf=`$factpath/fitsdump -h $localfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
164 tstop=${tstopi}${tstopf}
165 coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
166 if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
167 then
168 printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
169 continue
170 fi
171 if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
172 then
173 printprocesslog "WARN coordinates "${coordinates[@]}
174 continue
175 fi
176 printprocesslog "DEBUG coordinates "${coordinates[@]}
177 query="SELECT fSourceKEY FROM scheduling.source WHERE "
178 query=$query" fRightAscension BETWEEN "${coordinates[0]}"-0.01 AND "${coordinates[0]}"+0.01 "
179 query=$query" AND fDeclination BETWEEN "${coordinates[1]}"-0.01 AND "${coordinates[1]}"+0.01 "
180 sourcekey=`sendquery`
181 if [ "$sourcekey" == "" ]
182 then
183 printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
184 fi
185 callistocount=`ps aux | grep RunCallisto | grep -E -o '20[12][0-9][01][0-9][0-3][0-9]_[0-9][0-9][0-9]' | sort | uniq | wc -l`
186
187 echo "cal: "$callistocount" numdat: "$numdataruns" numcallog: "${#callistofiles[@]}
188 # do not overload system in case of a lot of files to be processed
189 # callistocount is set in setup.fact.lp.data
190 if [ $callistocount -ge $numcallistos ]
191 then
192 printprocesslog "INFO "$callistocount" RunCallisto.sh are running -> continue"
193 echo "INFO "$callistocount" RunCallisto.sh are running -> continue"
194 continue
195 fi
196 callistolog=`dirname $seqfile | sed -e "s/sequences/${sourcekey}\/callisto/"`"/"$night"_"$runnum"-calibration.log"
197 if ! [ -e $callistolog ]
198 then
199 rsync_aux_file $drivefilenewdaq2 $drivefile2
200 rsync_aux_file $mweatherfilenewdaq $mweatherfile
201 rsync_aux_file $ratesfilenewdaq $ratesfile
202 rsync_aux_file $tempfilenewdaq $tempfile
203 rsync_aux_file $humfilenewdaq $humfile
204 printprocesslog "INFO starting RunCallisto.sh for "$sourcekey" "$seqfile
205 echo "INFO starting RunCallisto.sh for "$sourcekey" "$seqfile
206 `dirname $0`/RunCallisto.sh $sourcekey $seqfile &
207 fi
208 continue
209 else
210 # skip a non-data run when it has not 1000 evts
211 # as this means probably an fad-loss
212 if [ $numevts -ne 1000 ]
213 then
214 printprocesslog "INFO file "$file" is a non-data file ("$runtype") and has not 1000 events ("$nmevts")"
215 continue
216 fi
217 fi
218 printprocesslog "DEBUG runrow "$runrow" (from variable) "
219 runrow=`cat $infopath/runrow.txt`
220 printprocesslog "DEBUG runrow "$runrow" (from file) "
221 runrow=$runrow$runnum$runtype$roi"_"
222 echo $runrow > $infopath/runrow.txt
223 if echo $runrow | grep -E '[0-9]{3}drs-pedestal1024_[0-9]{3}drs-gain1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-time1024_[0-9]{3}pedestal300_[0-9]{3}pedestal300_'
224 then
225 runrow2=`echo $runrow | grep -E -o '[0-9]{3}drs-pedestal1024_[0-9]{3}drs-gain1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-time1024_[0-9]{3}pedestal300_[0-9]{3}pedestal300_'`
226 run1=`echo $runrow2 | cut -d_ -f1 | sed -e 's/drs-pedestal1024//g'`
227 run2=`echo $runrow2 | cut -d_ -f2 | sed -e 's/drs-gain1024//g'`
228 run3=`echo $runrow2 | cut -d_ -f3 | sed -e 's/drs-pedestal1024//g'`
229 run4=`echo $runrow2 | cut -d_ -f4 | sed -e 's/drs-pedestal1024//g'`
230 run5=`echo $runrow2 | cut -d_ -f5 | sed -e 's/drs-time1024//g'`
231 run6=`echo $runrow2 | cut -d_ -f6 | sed -e 's/pedestal300//g'`
232 run7=`echo $runrow2 | cut -d_ -f7 | sed -e 's/pedestal300//g'`
233 seqfile=$seqpath/${night}_${run1}.drs.seq
234 printprocesslog "INFO write drs-seq "$seqfile
235 echo "# written by automatic analysis in LP" > $seqfile
236 echo "" >> $seqfile
237 echo "Sequence: "`echo $night | cut -c3-8`$run1 >> $seqfile
238 echo "Night: "`echo $datepath | sed -e 's/\//-/g'` >> $seqfile
239 echo "" >> $seqfile
240 echo "CalRuns: "$run2 >> $seqfile
241 echo "PedRuns: "$run6" "$run7 >> $seqfile
242 echo "DatRuns: "$run5 >> $seqfile
243 echo "DrsRuns: "$run1" "$run3" "$run4 >> $seqfile
244 echo "DrsFiles: "$run3" "$run6 >> $seqfile
245 echo "" >> $seqfile
246 echo "#DrsFile: "$run6 >> $seqfile
247 echo "" >> $seqfile
248 echo "" > $infopath/runrow.txt
249 drsseq=$run1
250 drsfile=$run6
251 fi
252 if echo $runrow | grep -E '[0-9]{3}pedestal300_[0-9]{3}light-pulser-ext300_'
253 then
254 echo "" > $infopath/runrow.txt
255 fi
256 fi
257 done
258 printprocesslog "INFO status after loop: "$callistocount" callistos running, "$numdataruns" data runs to process in total, "${#callistofiles[@]}" have already a callisto-logfile "
259
260 # get new file lists
261 printprocesslog "INFO get new file lists for "$datepath
262 files=( `find $rawpathnewdaq -type f | sort` )
263 fileslocal=( `find $rawpath -type f | sort` )
264 callistofiles=( `find $anapath -type f -name $date*-calibration.log | sort` )
265
266 update=
267 if [ ${#fileslocal[@]} -eq ${#files[@]} ]
268 then
269 sleep 60
270 echo "sleep 60..."
271 files=( `find $rawpathnewdaq -type f | sort` )
272 fileslocal=( `find $rawpath -type f | sort` )
273 callistofiles=( `find $anapath -type f -name $date*-calibration.log | sort` )
274 fi
275done
276
277
278
279
Note: See TracBrowser for help on using the repository browser.