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

Last change on this file since 18093 was 18093, checked in by Daniela Dorner, 10 years ago
fixed bug: drs runs had been excluded by last fix
  • Property svn:executable set to *
File size: 17.3 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# create aux directory on daq, if not yet there
29auxpath=/loc_data/aux/$datepath
30makedir $auxpath >/dev/null
31# create path for info files needed for analysis
32infopath=$anapath/info/$datepath
33makedir $infopath >/dev/null
34echo "" > $infopath/runrow.txt
35# create path for callisto output
36calpath=$anapath/callisto/$datepath
37makedir $calpath >/dev/null
38rawpathnewdaq=/newdaq/raw/$datepath
39rawpath=/loc_data/raw/$datepath
40
41# needed auxiliary files:
42# drive file with information about current source position
43drivefile=$auxpath/${date}.DRIVE_CONTROL_SOURCE_POSITION.fits
44drivefilenewdaq=$auxpathnewdaq/${date}.DRIVE_CONTROL_SOURCE_POSITION.fits
45# drive file with information about tracking position
46drivefile2=$auxpath/${date}.DRIVE_CONTROL_TRACKING_POSITION.fits
47drivefilenewdaq2=$auxpathnewdaq/${date}.DRIVE_CONTROL_TRACKING_POSITION.fits
48# file with magic weather information
49mweatherfile=$auxpath/${date}.MAGIC_WEATHER_DATA.fits
50mweatherfilenewdaq=$auxpathnewdaq/${date}.MAGIC_WEATHER_DATA.fits
51# file with trigger rates
52ratesfile=$auxpath/${date}.FTM_CONTROL_TRIGGER_RATES.fits
53ratesfilenewdaq=$auxpathnewdaq/${date}.FTM_CONTROL_TRIGGER_RATES.fits
54# file with trigger rates
55tempfile=$auxpath/${date}.FSC_CONTROL_TEMPERATURE.fits
56tempfilenewdaq=$auxpathnewdaq/${date}.FSC_CONTROL_TEMPERATURE.fits
57# file with trigger rates
58humfile=$auxpath/${date}.FSC_CONTROL_HUMIDITY.fits
59humfilenewdaq=$auxpathnewdaq/${date}.FSC_CONTROL_HUMIDITY.fits
60
61function rsync_aux_file()
62{
63 if ls $1 >/dev/null 2>&1
64 then
65 printprocesslog "INFO rsync "$1
66 # rsync
67 # from newdaq (/newdaq = /fact on newdaq), rsync server newdaq::newdaq/
68 # to daq (/daq = /loc_data on daq)
69 rsyncservernewdaq=`echo $1 | sed -e 's/^\//172.16.100.100::/'`
70 # old
71 #if ! rsync -a -T $rsynctempdir $1 $2
72 # new (workaround for problems on daq)
73 if ! rsync -a -T $rsynctempdir $rsyncservernewdaq $2
74 then
75 printprocesslog "WARN rsync of "$1" failed."
76 fi
77 else
78 printprocesslog "WARN "$1" missing."
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
142 # files on newdaq
143 for file in ${files[@]}
144 do
145 printprocesslog "processing "$file
146 #echo "processing "$file
147 localfile=`echo $file | sed -e 's/newdaq/loc_data/'`
148
149 source `dirname $0`/../Sourcefile.sh
150
151 # check if file is already transferred
152 if ! ls $localfile >/dev/null 2>&1
153 then
154 # check if it is drs-file
155 # get stop time from raw-file
156 if [ "`echo $file | grep -o drs`" == "drs" ]
157 then
158 nondrs=`basename $file | sed -e 's/[.]drs//g'`
159 nondrsfile=`find -L $rawpath -name $nondrs.*z`
160 tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
161 else
162 tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
163 fi
164 # when stop time is 0, file is not closed
165 # when an error is returned the tstop is empty
166 if [ "$tstop" == "0" ] || [ "$tstop" == "" ]
167 then
168 printprocesslog "WARN "$file" not yet closed."
169 # if a file is not closed and not touched for 30 minutes,
170 # it is assumed corrupted and still transferred
171 fileaccessed=`find $file -amin -30`
172 if ! [ "$fileaccessed" == "" ]
173 then
174 printprocesslog "INFO "$file" was accessed in the last 30 minutes => continue"
175 continue
176 else
177 printprocesslog "WARN: "$file" has empty TSTOP but was not touched for 30 minutes"
178 fileerror="yes"
179 fi
180 fi
181
182 # rsync
183 # from newdaq (/newdaq = /fact on newdaq), rsync server newdaq::newdaq/
184 # to daq (/daq = /loc_data on daq)
185 # to access rsync server via the dedicated network between
186 # daq and newdaq, use 172.16.100.100::newdaq
187 filersyncserver=`echo $file | sed -e 's/^\//172.16.100.100::/'`
188 # old
189 ##if ! rsync -av --stats --progress --bwlimit=$bwlimit $file $localfile
190 #if ! rsync -a -T $rsynctempdir --bwlimit=$bwlimit $file $localfile
191 # new
192 if ! rsync -a -W -T $rsynctempdir --bwlimit=$bwlimit $filersyncserver $localfile
193 then
194 printprocesslog "ERROR something went wrong with rsync of "$file
195 rm $localfile
196 continue
197 fi
198 printprocesslog "INFO "$file" rsynced successfully."
199 fi
200
201 # for .drs.fits files no further treatment needed
202 if [ "`echo $localfile | grep -o drs`" == "drs" ]
203 then
204 continue
205 fi
206
207# # temporary check
208# if [ "`echo $file | grep -o drs`" == "drs" ]
209# then
210# nondrs=`basename $file | sed -e 's/[.]drs//g'`
211# nondrsfile=`find -L $rawpath -name $nondrs.*z`
212# tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
213# else
214# tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
215# fi
216# # when stop time is 0, file is not closed
217# # when an error is returned the tstop is empty
218# if [ "$tstop" == "0" ] || [ "$tstop" == "" ]
219# then
220# printprocesslog "WARN "$file" not yet closed. -> continue (temporary check)"
221# continue
222# fi
223# # end temporary check
224
225 # treat other files (.fits.fz)
226 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"`
227 if [ "$runtype" != "data" ]
228 then
229 # skip a non-data run when it has not 1000 evts
230 # as this means probably an fad-loss
231 # and these runs are repeated in that case
232 numevts=`$factpath/fitsdump -h $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
233 if [ $numevts -ne 1000 ]
234 then
235 printprocesslog "INFO file "$file" is a non-data file ("$runtype") and has not 1000 events ("$numevts")"
236 continue
237 fi
238 fi
239
240 # get run number
241 runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
242
243 # what is needed to process the different runs?
244 # P: run#(P), run#(drs-file)
245 # C: run#(C), run#(drs-file), run#(drs-time)
246 # D: run#(D), run#(drs-file), run#(drs-time), ?
247 # what is drs-file? pedestal, roi300, has drs.fits
248 callistolog=$calpath"/"$date"_"$runnum"-calibration.log"
249 case $runtype in
250 data) # treat D-runs
251 if [ "$fileerror" = "yes" ]
252 then
253 printprocesslog "INFO do not further process corrupted file "$localfile
254 fileerror=
255 continue
256 fi
257
258 # some accounting
259 printprocesslog "DEBUG counting callisto logs and set data files +1."
260 # get number of callisto logs
261 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`
262 # count runs to be calibrated
263 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
264 printprocesslog "DEBUG running callistos: "$runcallistocount" #runs: "$numcalibrated" #callisto-logs: "${#callistofiles[@]}
265
266 # do not overload system in case of a lot of files to be processed
267 # numruncallistos is set in setup.fact.lp.data
268 if [ $runcallistocount -ge $numruncallistos ]
269 then
270 printprocesslog "INFO "$runcallistocount" RunCallisto.sh are running -> continue"
271 continue
272 fi
273
274 # starting calibration
275 if ! [ -e $callistolog ]
276 then
277 rsync_aux_file $drivefilenewdaq2 $drivefile2
278 rsync_aux_file $mweatherfilenewdaq $mweatherfile
279 rsync_aux_file $ratesfilenewdaq $ratesfile
280 rsync_aux_file $tempfilenewdaq $tempfile
281 rsync_aux_file $humfilenewdaq $humfile
282 if [ -e $drstime ]
283 then
284 calfile=$calpath"/"$date"_"$runnum"_C.root"
285 printprocesslog "INFO starting RunCallisto.sh for drun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" outpath "$outpath" calfile "$calfile
286 #echo "INFO starting RunCallisto.sh for drun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" outpath "$outpath" calfile "$calfile
287 `dirname $0`/RunCallisto.sh "drun" $callistolog $localfile $drscalib $drstime $calpath $calfile &
288 fi
289 fi
290 continue
291 ;;
292 pedestal) # treat P-runs
293 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"`
294 if [ $roi -eq 300 ]
295 then
296 # check drs-file
297 drsfile=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
298 if [ -e $drsfile ]
299 then
300 # set name of drs-file
301 drscalib=$drsfile
302 continue
303 #else
304 # not needed for QLA
305 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
306 #if ! [ -e $callistolog ]
307 #then
308 # pedfile=$calpath"/"$date"_"$runnum"-pedestal.root"
309 # # count runs to be calibrated
310 # printprocesslog "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
311 # echo "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
312 # `dirname $0`/RunCallisto.sh "prun" $callistolog $localfile $drscalib $pedfile &
313 #fi
314 fi
315 fi
316 ;;
317 light-pulser-ext) # treat C-runs
318 # do lp-treatment -> not needed for QLA
319 #lpfile=$calpath"/"$date"_"$runnum"-lightpulser.root"
320 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
321 #if ! [ -e $callistolog ]
322 #then
323 # if [ -e $drstime ]
324 # then
325 # # count runs to be calibrated
326 # printprocesslog "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
327 # echo "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
328 # `dirname $0`/RunCallistoNew.sh "crun" $callistolog $localfile $drscalib $drstime $lpfile &
329 # fi
330 #fi
331 ;;
332 drs-time) # treat C-runs
333 # do drs-timing calibration
334 drstime=$calpath"/"$date"_"$runnum"-drstime.root"
335 # starting calibration
336 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
337 if ! [ -e $callistolog ]
338 then
339 # count runs to be calibrated
340 printprocesslog "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
341 #echo "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
342 `dirname $0`/RunCallisto.sh "time" $callistolog $localfile $drsped $drstime &
343 fi
344 ;;
345 drs-pedestal) # get drs-pedestal
346 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"`
347 drs=`$factpath/fitsdump -h $localfile 2>/dev/null | grep DRSCALIB | grep -E -o " T " `
348 if [ $roi -eq 1024 ] && [ "$drs" == " T " ]
349 then
350 drsped=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
351 fi
352 ;;
353 *) # other runs
354 printprocesslog "INFO file "$file" has runtype "$runtype" -> continue "
355 continue
356 ;;
357 esac
358 done
359 printprocesslog "INFO status after loop: "$runcallistocount" callistos running, "$numcalibrated" data runs to process in total, "${#callistofiles[@]}" have already a callisto-logfile "
360
361 # get new file lists
362 printprocesslog "INFO get new file lists for "$datepath
363 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` )
364 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` )
365 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
366 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
367 printprocesslog "INFO status after for-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
368
369 # wait and get new file lists
370 update=
371 if [ ${#fileslocal[@]} -eq ${#files[@]} ]
372 then
373 printprocesslog "INFO wait 60 seconds."
374 sleep 60
375 printprocesslog "INFO get new file lists for "$datepath
376 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` )
377 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` )
378 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
379 fi
380 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
381 printprocesslog "INFO status after wait end of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
382 sleep 30
383 printprocesslog "INFO sleep 30"
384done
385
386
387
Note: See TracBrowser for help on using the repository browser.