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

Last change on this file since 15520 was 15520, checked in by Daniela Dorner, 11 years ago
removed logging to console to avoid emails from cron
  • Property svn:executable set to *
File size: 14.5 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="-19HOUR" +%Y/%m/%d`
8date=`date --date="-19HOUR" +%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 >/dev/null 2>&1
51 then
52 printprocesslog "INFO rsync "$1
53 #if ! rsync -av --stats $1 $2
54 #if ! rsync -av $1 $2
55 if ! rsync -a $1 $2
56 then
57 printprocesslog "WARN rsync of "$1" failed."
58 fi
59 else
60 printprocesslog "WARN "$1" missing."
61 fi
62}
63
64diskusage=( `df -P /raid10 | grep raid10 ` )
65# check if more than 700 GB are left on /loc_data
66if [ ${diskusage[3]} -lt 800000000 ]
67then
68 echo "WARN less than 700 left on /raid10 on node "$HOSTNAME
69 printprocesslog "WARN less than 700 left on /raid10 on node "$HOSTNAME
70 df -h /raid10
71 finish
72fi
73
74printprocesslog "INFO get lists of raw files on newdaq and daq"
75files=( `find $rawpathnewdaq -type f 2>/dev/null | sort` )
76if [ ${#files[@]} -eq 0 ]
77then
78 printprocesslog "INFO no raw files available yet for "$datepath
79 finish
80fi
81fileslocal=( `find $rawpath -type f | sort` )
82callistofiles=( `find $anapath/callisto -type f -name $date*-calibration.log | sort` )
83numdataruns=0
84
85# create raw directory on daq, if not yet there
86makedir $rawpath
87
88#echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
89printprocesslog "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
90
91while [ ${#fileslocal[@]} -ne ${#files[@]} ] || [ $numdataruns -ne ${#callistofiles[@]} ]
92do
93 numdataruns=0
94 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
95 printprocesslog "INFO status beginning of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
96
97 rsync_aux_file $drivefilenewdaq $drivefile
98
99 # files on newdaq
100 for file in ${files[@]}
101 do
102 printprocesslog "processing "$file
103 localfile=`echo $file | sed -e 's/newdaq/loc_data/'`
104 #echo "processing "$file" "$localfile
105
106 if [ "`echo $file | grep -o drs`" == "drs" ]
107 then
108 nondrsfile=`echo $file | sed -e 's/[.]drs//g'`
109 tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
110 else
111 tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
112 fi
113 if [ "$tstop" == "0" ]
114 then
115 printprocesslog "WARN "$file" not yet closed."
116 fileaccessed=`find $file -amin -30`
117 if ! [ "$fileaccessed" == "" ]
118 then
119 printprocesslog "INFO "$file" was accessed in the last 30 minutes => continue"
120 continue
121 else
122 printprocesslog "WARN: "$file" has empty TSTOP but was not touched for 30 minutes"
123 fileerror="yes"
124 fi
125 fi
126
127 source `dirname $0`/../Sourcefile.sh
128 if ! ls $localfile >/dev/null 2>&1
129 then
130 #if ! rsync -av --stats --progress --bwlimit=$bwlimit $file $localfile
131 if ! rsync -a --bwlimit=$bwlimit $file $localfile
132 then
133 printprocesslog "ERROR something went wrong with rsync of "$file
134 rm $localfile
135 continue
136 fi
137 printprocesslog "INFO "$file" rsynced successfully."
138 fi
139
140
141 if [ "`echo $localfile | grep -o drs`" != "drs" ]
142 then
143 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"`
144 runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
145 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"`
146 numevts=`$factpath/fitsdump -h $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
147 printprocesslog "DEBUG runnum "$runnum" runtype "$runtype" roi "$roi" numevts "$numevts
148 if [ "$runtype" == "drs-time-upshifted" ]
149 then
150 printprocesslog "INFO file "$file" has runtype drs-time-upshifted -> continue "
151 continue
152 fi
153 if [ "$runtype" == "data" ]
154 then
155 if [ "$fileerror" = "yes" ]
156 then
157 printprocesslog "INFO do not further process corrupted file "$localfile
158 fileerror=
159 continue
160 fi
161 seqfile=$seqpath/${night}_${runnum}.seq
162 printprocesslog "INFO write data-seq "$seqfile
163 echo "# written by automatic analysis in LP" >$seqfile
164 echo "" >> $seqfile
165 echo "Sequence: "`echo $night | cut -c3-8`$runnum >> $seqfile
166 echo "Night: "`echo $datepath | sed -e 's/\//-/g'` >> $seqfile
167 echo "" >> $seqfile
168 echo "DrsSequence: "$drsseq >> $seqfile
169 echo "" >> $seqfile
170 echo "CalRuns: "`echo $runrow | grep -E -o '[0-9]{3}light-pulser-ext300' | sed -e 's/light-pulser-ext300//g'` >> $seqfile
171 echo "PedRuns: "`echo $runrow | grep -E -o '[0-9]{3}pedestal300' | sed -e 's/pedestal300//g'` >> $seqfile
172 echo "DatRuns: "$runnum >> $seqfile
173 echo "" >> $seqfile
174 echo "DrsFiles: "$drsfile >> $seqfile
175 echo "" >> $seqfile
176 echo "#DrsFile: "$drsfile >> $seqfile
177 echo "" >> $seqfile
178
179# tstopi=`$factpath/fitsdump -h $localfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
180# tstopf=`$factpath/fitsdump -h $localfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
181# tstop=${tstopi}${tstopf}
182# coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
183# if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
184# then
185# printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
186# #echo "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
187# continue
188# fi
189# if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
190# then
191# printprocesslog "WARN coordinates "${coordinates[@]}
192# #echo "WARN coordinates "${coordinates[@]}
193# continue
194# fi
195# printprocesslog "DEBUG coordinates "${coordinates[@]}
196# query="SELECT fSourceKEY FROM scheduling.source WHERE "
197# query=$query" fRightAscension BETWEEN "${coordinates[0]}"-0.01 AND "${coordinates[0]}"+0.01 "
198# query=$query" AND fDeclination BETWEEN "${coordinates[1]}"-0.01 AND "${coordinates[1]}"+0.01 "
199# sourcekey=`sendquery`
200# if [ "$sourcekey" == "" ]
201# then
202# printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
203# fi
204
205 printprocesslog "INFO counting callisto logs and data files +1."
206 # get number of callisto logs
207 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`
208 # count data runs
209 numdataruns=`echo " $numdataruns + 1 " | bc -l`
210 #echo "numdata +1"
211
212 #echo "cal: "$callistocount" numdat: "$numdataruns" numcallog: "${#callistofiles[@]}
213 printprocesslog "INFO running callistos: "$callistocount" #data-runs: "$numdataruns" #callisto-logs: "${#callistofiles[@]}
214 # do not overload system in case of a lot of files to be processed
215 # callistocount is set in setup.fact.lp.data
216 if [ $callistocount -ge $numcallistos ]
217 then
218 printprocesslog "INFO "$callistocount" RunCallisto.sh are running -> continue"
219 #echo "INFO "$callistocount" RunCallisto.sh are running -> continue"
220 continue
221 fi
222 callistolog=`dirname $seqfile | sed -e "s/sequences/callisto/"`"/"$night"_"$runnum"-calibration.log"
223 if ! [ -e $callistolog ]
224 then
225 rsync_aux_file $drivefilenewdaq2 $drivefile2
226 rsync_aux_file $mweatherfilenewdaq $mweatherfile
227 rsync_aux_file $ratesfilenewdaq $ratesfile
228 rsync_aux_file $tempfilenewdaq $tempfile
229 rsync_aux_file $humfilenewdaq $humfile
230 #printprocesslog "INFO starting RunCallisto.sh for "$sourcekey" "$seqfile
231 #echo "INFO starting RunCallisto.sh for "$sourcekey" "$seqfile
232 #`dirname $0`/RunCallisto.sh $sourcekey $seqfile &
233 printprocesslog "INFO starting RunCallisto.sh for "$seqfile
234 #echo "INFO starting RunCallisto.sh for "$seqfile
235 `dirname $0`/RunCallisto.sh $seqfile &
236 fi
237 continue
238 else
239 # skip a non-data run when it has not 1000 evts
240 # as this means probably an fad-loss
241 if [ $numevts -ne 1000 ]
242 then
243 printprocesslog "INFO file "$file" is a non-data file ("$runtype") and has not 1000 events ("$nmevts")"
244 continue
245 fi
246 fi
247 printprocesslog "DEBUG runrow "$runrow" (from variable) "
248 runrow=`cat $infopath/runrow.txt`
249 printprocesslog "DEBUG runrow "$runrow" (from file) "
250 runrow=$runrow$runnum$runtype$roi"_"
251 echo $runrow > $infopath/runrow.txt
252 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_' >/dev/null
253 then
254 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_'`
255 run1=`echo $runrow2 | cut -d_ -f1 | sed -e 's/drs-pedestal1024//g'`
256 run2=`echo $runrow2 | cut -d_ -f2 | sed -e 's/drs-gain1024//g'`
257 run3=`echo $runrow2 | cut -d_ -f3 | sed -e 's/drs-pedestal1024//g'`
258 run4=`echo $runrow2 | cut -d_ -f4 | sed -e 's/drs-pedestal1024//g'`
259 run5=`echo $runrow2 | cut -d_ -f5 | sed -e 's/drs-time1024//g'`
260 run6=`echo $runrow2 | cut -d_ -f6 | sed -e 's/pedestal300//g'`
261 run7=`echo $runrow2 | cut -d_ -f7 | sed -e 's/pedestal300//g'`
262 seqfile=$seqpath/${night}_${run1}.drs.seq
263 printprocesslog "INFO write drs-seq "$seqfile
264 echo "# written by automatic analysis in LP" > $seqfile
265 echo "" >> $seqfile
266 echo "Sequence: "`echo $night | cut -c3-8`$run1 >> $seqfile
267 echo "Night: "`echo $datepath | sed -e 's/\//-/g'` >> $seqfile
268 echo "" >> $seqfile
269 echo "CalRuns: "$run2 >> $seqfile
270 echo "PedRuns: "$run6" "$run7 >> $seqfile
271 echo "DatRuns: "$run5 >> $seqfile
272 echo "DrsRuns: "$run1" "$run3" "$run4 >> $seqfile
273 echo "DrsFiles: "$run3" "$run6 >> $seqfile
274 echo "" >> $seqfile
275 echo "#DrsFile: "$run6 >> $seqfile
276 echo "" >> $seqfile
277 echo "" > $infopath/runrow.txt
278 drsseq=$run1
279 drsfile=$run6
280 fi
281 if echo $runrow | grep -E '[0-9]{3}pedestal300_[0-9]{3}light-pulser-ext300_' >/dev/null
282 then
283 echo "" > $infopath/runrow.txt
284 fi
285 fi
286 done
287 printprocesslog "INFO status after loop: "$callistocount" callistos running, "$numdataruns" data runs to process in total, "${#callistofiles[@]}" have already a callisto-logfile "
288
289 # get new file lists
290 printprocesslog "INFO get new file lists for "$datepath
291 files=( `find $rawpathnewdaq -type f | sort` )
292 fileslocal=( `find $rawpath -type f | sort` )
293 callistofiles=( `find $anapath/callisto -type f -name $date*-calibration.log | sort` )
294 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
295 printprocesslog "INFO status after for-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
296
297 # wait and get new file lists
298 update=
299 if [ ${#fileslocal[@]} -eq ${#files[@]} ]
300 then
301 printprocesslog "INFO wait 60 seconds."
302 sleep 60
303 #echo "sleep 60..."
304 printprocesslog "INFO get new file lists for "$datepath
305 files=( `find $rawpathnewdaq -type f | sort` )
306 fileslocal=( `find $rawpath -type f | sort` )
307 callistofiles=( `find $anapath/callisto -type f -name $date*-calibration.log | sort` )
308 fi
309 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
310 printprocesslog "INFO status after wait end of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #data-runs:"$numdataruns
311done
312
313
314
315
Note: See TracBrowser for help on using the repository browser.