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

Last change on this file since 18779 was 18770, checked in by Daniela Dorner, 8 years ago
implemented usage of new function check_file_avail
  • Property svn:executable set to *
File size: 17.5 KB
Line 
1#!/bin/bash
2#
3
4# remarks:
5# rsync-server still used
6# move fileerror check to main-loop?
7
8source `dirname $0`/../Sourcefile.sh
9printprocesslog "INFO starting $0"
10
11# get date (before 18h there is no new data to be processed)
12if [ "$certaindate" != "" ]
13then
14 checkstring=`echo $certaindate | grep -E -o '^20[0-9][0-9]\/[01][0-9]\/[0-3][0-9]$'`
15 if [ "$checkstring" = "" ]
16 then
17 echo "Please give the variable certaindate in the correct format (YYYY/MM/DD)"
18 finish
19 fi
20 datepath=$certaindate
21else
22 datepath=`date --date="-19HOUR" +%Y/%m/%d`
23fi
24date=`echo $datepath | sed -e 's/\///g'`
25printprocesslog "INFO processing "$datepath
26
27auxpathnewdaq=/newdaq/aux/$datepath
28#auxpathnewdaq=/loc_data/aux/$datepath #to run on newdaq
29# create aux directory on daq, if not yet there
30auxpath=/loc_data/aux/$datepath
31makedir $auxpath >/dev/null
32# create path for info files needed for analysis
33infopath=$anapath/info/$datepath
34makedir $infopath >/dev/null
35echo "" > $infopath/runrow.txt
36# create path for callisto output
37calpath=$anapath/callisto/$datepath
38makedir $calpath >/dev/null
39rawpathnewdaq=/newdaq/raw/$datepath
40#rawpathnewdaq=/loc_data/raw/$datepath #to run on newdaq
41rawpath=/loc_data/raw/$datepath
42
43# needed auxiliary files:
44# drive file with information about current source position
45drivefile=$auxpath/${date}.DRIVE_CONTROL_SOURCE_POSITION.fits
46drivefilenewdaq=$auxpathnewdaq/${date}.DRIVE_CONTROL_SOURCE_POSITION.fits
47# drive file with information tracking position
48drivefile2=$auxpath/${date}.DRIVE_CONTROL_TRACKING_POSITION.fits
49drivefilenewdaq2=$auxpathnewdaq/${date}.DRIVE_CONTROL_TRACKING_POSITION.fits
50# file with magic weather information
51mweatherfile=$auxpath/${date}.MAGIC_WEATHER_DATA.fits
52mweatherfilenewdaq=$auxpathnewdaq/${date}.MAGIC_WEATHER_DATA.fits
53# file with trigger rates
54ratesfile=$auxpath/${date}.FTM_CONTROL_TRIGGER_RATES.fits
55ratesfilenewdaq=$auxpathnewdaq/${date}.FTM_CONTROL_TRIGGER_RATES.fits
56# file with trigger rates
57tempfile=$auxpath/${date}.FSC_CONTROL_TEMPERATURE.fits
58tempfilenewdaq=$auxpathnewdaq/${date}.FSC_CONTROL_TEMPERATURE.fits
59# file with trigger rates
60humfile=$auxpath/${date}.FSC_CONTROL_HUMIDITY.fits
61humfilenewdaq=$auxpathnewdaq/${date}.FSC_CONTROL_HUMIDITY.fits
62
63function rsync_aux_file()
64{
65 if check_file_avail $1
66 then
67 printprocesslog "INFO rsync "$1
68 # rsync
69 # from newdaq (/newdaq = /fact on newdaq), rsync server newdaq::newdaq/
70 # to daq (/daq = /loc_data on daq)
71 rsyncservernewdaq=`echo $1 | sed -e 's/^\//172.16.100.100::/'`
72 # old
73 if ! rsync -a -T $rsynctempdir $1 $2
74 # new (workaround for problems on daq)
75 #if ! rsync -a -T $rsynctempdir $rsyncservernewdaq $2
76 then
77 printprocesslog "WARN rsync of "$1" failed."
78 fi
79 fi
80}
81
82function check_daq()
83{
84 diskusage=( `df -P /raid10 | grep raid10 ` )
85 # check if more than 700 GB are left on /loc_data
86 if [ ${diskusage[3]} -lt $disklimitdaq ]
87 then
88 echo "WARN less than 700 left on /raid10 on node "$HOSTNAME
89 printprocesslog "WARN less than 700 left on /raid10 on node "$HOSTNAME
90 df -h /raid10
91 finish
92 fi
93}
94
95check_daq
96
97printprocesslog "INFO get lists of raw files on newdaq and daq"
98files=( `find $rawpathnewdaq -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]d?r?s?[.]?fits[.]?[g]?[f]?[z]?' 2>/dev/null | sort` )
99# to treat links use:
100#files=( `find -L $rawpathnewdaq -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]fits[.]?[g]?[f]?[z]?' 2>/dev/null | sort` )
101
102if [ ${#files[@]} -eq 0 ]
103then
104 printprocesslog "INFO no raw files available yet for "$datepath
105 finish
106fi
107fileslocal=( `find -L $rawpath -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]d?r?s?[.]?fits[.]?[g]?[f]?[z]?' 2>/dev/null| sort` )
108
109callistofiles=( `find $calpath -type f -name $date*-calibration.log 2>/dev/null| sort` )
110# get number of dataruns from DB
111query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=1"
112numdataruns=`sendquery`
113query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=6"
114numlpruns=`sendquery`
115query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=2 AND fHasDrsFile=1 AND fROI=300"
116numpedruns=`sendquery`
117query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=5"
118numdrstime=`sendquery`
119numpedruns=0
120#numcalibrated=`echo " $numdataruns + $numlpruns + $numpedruns + $numdrstime " | bc -l`
121numcalibrated=`echo " $numdataruns + $numdrstime " | bc -l`
122
123# create raw directory on daq, if not yet there
124makedir $rawpath >/dev/null
125
126#echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
127printprocesslog "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
128
129while [ ${#fileslocal[@]} -ne ${#files[@]} ] || [ $numcalibrated -ne ${#callistofiles[@]} ] # || [ $numcalibrated -ne 0 ] # FIXME: Logik ueberdenken u ueberarb
130do
131 # only continue with script
132 # when there is more than 10% space on daq
133 source `dirname $0`/../Sourcefile.sh
134 check_daq
135
136 numcalibrated=0
137 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
138 printprocesslog "INFO status beginning of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
139
140 rsync_aux_file $drivefilenewdaq $drivefile
141 rsync_aux_file $drivefilenewdaq2 $drivefile2
142
143 # files on newdaq
144 for file in ${files[@]}
145 do
146 printprocesslog "processing "$file
147 #echo "processing "$file
148 localfile=`echo $file | sed -e 's/newdaq/loc_data/'`
149
150 source `dirname $0`/../Sourcefile.sh
151
152 # check if file is already transferred
153 if ! ls $localfile >/dev/null 2>&1
154 then
155 # check if it is drs-file
156 # get stop time from raw-file
157 if [ "`echo $file | grep -o drs`" == "drs" ]
158 then
159 nondrs=`basename $file | sed -e 's/[.]drs//g'`
160 nondrsfile=`find -L $rawpath -name $nondrs.*z`
161 tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
162 else
163 tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
164 fi
165 # when stop time is 0, file is not closed
166 # when an error is returned the tstop is empty
167 if [ "$tstop" == "0" ] || [ "$tstop" == "" ]
168 then
169 printprocesslog "DEBUG "$file" not yet closed."
170 # if a file is not closed and not touched for 30 minutes,
171 # it is assumed corrupted and still transferred
172 fileaccessed=`find $file -amin -30`
173 if ! [ "$fileaccessed" == "" ]
174 then
175 printprocesslog "INFO "$file" was accessed in the last 30 minutes => continue"
176 continue
177 else
178 printprocesslog "WARN: "$file" has empty TSTOP but was not touched for 30 minutes"
179 fileerror="yes"
180 fi
181 fi
182
183 # rsync
184 # from newdaq (/newdaq = /fact on newdaq), rsync server newdaq::newdaq/
185 # to daq (/daq = /loc_data on daq)
186 # to access rsync server via the dedicated network between
187 # daq and newdaq, use 172.16.100.100::newdaq
188 filersyncserver=`echo $file | sed -e 's/^\//172.16.100.100::/'`
189 # old
190 ##if ! rsync -av --stats --progress --bwlimit=$bwlimit $file $localfile
191 if ! rsync -a -T $rsynctempdir --bwlimit=$bwlimit $file $localfile
192 # new
193 #if ! rsync -a -W -T $rsynctempdir --bwlimit=$bwlimit $filersyncserver $localfile
194 then
195 printprocesslog "ERROR something went wrong with rsync of "$file
196 rm $localfile
197 continue
198 fi
199 printprocesslog "INFO "$file" rsynced successfully."
200 fi
201
202 # for .drs.fits files no further treatment needed
203 if [ "`echo $localfile | grep -o drs`" == "drs" ]
204 then
205 continue
206 fi
207
208# # temporary check (needed to run on newdaq)
209# if [ "`echo $file | grep -o drs`" == "drs" ]
210# then
211# nondrs=`basename $file | sed -e 's/[.]drs//g'`
212# nondrsfile=`find -L $rawpath -name $nondrs.*z`
213# tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
214# else
215# tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
216# fi
217# # when stop time is 0, file is not closed
218# # when an error is returned the tstop is empty
219# if [ "$tstop" == "0" ] || [ "$tstop" == "" ]
220# then
221# printprocesslog "WARN "$file" not yet closed. -> continue (temporary check)"
222# continue
223# fi
224# # end temporary check
225
226 # treat other files (.fits.fz)
227 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"`
228 if [ "$runtype" != "data" ]
229 then
230 # skip a non-data run when it has not 1000 evts
231 # as this means probably an fad-loss
232 # and these runs are repeated in that case
233 numevts=`$factpath/fitsdump -h $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
234 if [ "$numevts" == "" ]
235 then
236 printprocesslog "WARN could not get number of events from file "$file" -> continue "
237 #echo "WARN could not get number of events from file "$file" -> continue "
238 continue
239 fi
240 if [ $numevts -ne 1000 ]
241 then
242 printprocesslog "INFO file "$file" is a non-data file ("$runtype") and has not 1000 events ("$numevts")"
243 continue
244 fi
245 fi
246
247 # get run number
248 runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
249
250 # what is needed to process the different runs?
251 # P: run#(P), run#(drs-file)
252 # C: run#(C), run#(drs-file), run#(drs-time)
253 # D: run#(D), run#(drs-file), run#(drs-time), ?
254 # what is drs-file? pedestal, roi300, has drs.fits
255 callistolog=$calpath"/"$date"_"$runnum"-calibration.log"
256 case $runtype in
257 data) # treat D-runs
258 if [ "$fileerror" = "yes" ]
259 then
260 printprocesslog "INFO do not further process corrupted file "$localfile
261 fileerror=
262 continue
263 fi
264
265 # some accounting
266 printprocesslog "DEBUG counting callisto logs and set data files +1."
267 # get number of callisto logs
268 runcallistocount=`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`
269 # count runs to be calibrated
270 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
271 printprocesslog "DEBUG running callistos: "$runcallistocount" #runs: "$numcalibrated" #callisto-logs: "${#callistofiles[@]}
272
273 # do not overload system in case of a lot of files to be processed
274 # numruncallistos is set in setup.fact.lp.data
275 if [ $runcallistocount -ge $numruncallistos ]
276 then
277 printprocesslog "INFO "$runcallistocount" RunCallisto.sh are running -> continue"
278 continue
279 fi
280
281 # starting calibration
282 if ! [ -e $callistolog ]
283 then
284 rsync_aux_file $drivefilenewdaq $drivefile
285 rsync_aux_file $drivefilenewdaq2 $drivefile2
286 rsync_aux_file $mweatherfilenewdaq $mweatherfile
287 rsync_aux_file $ratesfilenewdaq $ratesfile
288 rsync_aux_file $tempfilenewdaq $tempfile
289 rsync_aux_file $humfilenewdaq $humfile
290
291 calfile=$calpath"/"$date"_"$runnum"_C.root"
292 printprocesslog "INFO starting RunCallisto.sh for drun "$localfile" logfile "$callistolog" drs-calib "$drscalib" outpath "$outpath" calfile "$calfile
293 `dirname $0`/RunCallisto.sh "drun" $callistolog $localfile $drscalib $calpath $calfile &
294 fi
295 continue
296 ;;
297 pedestal) # treat P-runs
298 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"`
299 if [ $roi -eq 300 ]
300 then
301 # check drs-file
302 drsfile=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
303 if [ -e $drsfile ]
304 then
305 # set name of drs-file
306 drscalib=$drsfile
307 continue
308 #else
309 # not needed for QLA
310 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
311 #if ! [ -e $callistolog ]
312 #then
313 # pedfile=$calpath"/"$date"_"$runnum"-pedestal.root"
314 # # count runs to be calibrated
315 # printprocesslog "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
316 # echo "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
317 # `dirname $0`/RunCallisto.sh "prun" $callistolog $localfile $drscalib $pedfile &
318 #fi
319 fi
320 fi
321 ;;
322 light-pulser-ext) # treat C-runs
323 # do lp-treatment -> not needed for QLA
324 #lpfile=$calpath"/"$date"_"$runnum"-lightpulser.root"
325 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
326 #if ! [ -e $callistolog ]
327 #then
328 # if [ -e $drstime ]
329 # then
330 # # count runs to be calibrated
331 # printprocesslog "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
332 # echo "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
333 # `dirname $0`/RunCallistoNew.sh "crun" $callistolog $localfile $drscalib $drstime $lpfile &
334 # fi
335 #fi
336 ;;
337 drs-time) # treat drs-time runs
338 # do drs-timing calibration
339 drstime=$calpath"/"$date"_"$runnum"-drstime.root"
340 # starting calibration
341 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
342 if ! [ -e $callistolog ]
343 then
344 # count runs to be calibrated
345 printprocesslog "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
346 #echo "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
347 `dirname $0`/RunCallisto.sh "time" $callistolog $localfile $drsped $drstime &
348 fi
349 ;;
350 drs-pedestal) # get drs-pedestal
351 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"`
352 drs=`$factpath/fitsdump -h $localfile 2>/dev/null | grep DRSCALIB | grep -E -o " T " `
353 if [ $roi -eq 1024 ] && [ "$drs" == " T " ]
354 then
355 drsped=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
356 fi
357 ;;
358 *) # other runs
359 printprocesslog "INFO file "$file" has runtype "$runtype" -> continue "
360 continue
361 ;;
362 esac
363 done
364 printprocesslog "INFO status after loop: "$runcallistocount" callistos running, "$numcalibrated" data runs to process in total, "${#callistofiles[@]}" have already a callisto-logfile "
365
366 # get new file lists
367 printprocesslog "INFO get new file lists for "$datepath
368 files=( `find $rawpathnewdaq -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]d?r?s?[.]?fits[.]?[g]?[f]?[z]?' | sort` )
369 fileslocal=( `find -L $rawpath -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]d?r?s?[.]?fits[.]?[g]?[f]?[z]?' | sort` )
370 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
371 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
372 printprocesslog "INFO status after for-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
373
374 # wait and get new file lists
375 update=
376 if [ ${#fileslocal[@]} -eq ${#files[@]} ]
377 then
378 printprocesslog "INFO wait 60 seconds."
379 sleep 60
380 printprocesslog "INFO get new file lists for "$datepath
381 files=( `find $rawpathnewdaq -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]d?r?s?[.]?fits[.]?[g]?[f]?[z]?' | sort` )
382 fileslocal=( `find -L $rawpath -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]d?r?s?[.]?fits[.]?[g]?[f]?[z]?' | sort` )
383 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
384 fi
385 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
386 printprocesslog "INFO status after wait end of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
387 sleep 30
388 printprocesslog "INFO sleep 30"
389done
390
391
392
Note: See TracBrowser for help on using the repository browser.