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

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