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

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