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

Last change on this file since 18092 was 18092, checked in by Daniela Dorner, 10 years ago
fixed bug: runs with timestamp as runnumber are ignored now
  • Property svn:executable set to *
File size: 17.2 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][.]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][.]fits[.]?[g]?[f]?[z]?' 2>/dev/null| sort` )
108callistofiles=( `find $calpath -type f -name $date*-calibration.log 2>/dev/null| sort` )
109# get number of dataruns from DB
110query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=1"
111numdataruns=`sendquery`
112query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=6"
113numlpruns=`sendquery`
114query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=2 AND fHasDrsFile=1 AND fROI=300"
115numpedruns=`sendquery`
116query="SELECT Count(*) FROM RunInfo WHERE fNight="$date" AND fRunTypeKey=5"
117numdrstime=`sendquery`
118numpedruns=0
119#numcalibrated=`echo " $numdataruns + $numlpruns + $numpedruns + $numdrstime " | bc -l`
120numcalibrated=`echo " $numdataruns + $numdrstime " | bc -l`
121
122# create raw directory on daq, if not yet there
123makedir $rawpath >/dev/null
124
125#echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
126printprocesslog "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
127
128while [ ${#fileslocal[@]} -ne ${#files[@]} ] || [ $numcalibrated -ne ${#callistofiles[@]} ] # || [ $numcalibrated -ne 0 ] # FIXME: Logik ueberdenken u ueberarb
129do
130 # only continue with script
131 # when there is more than 10% space on daq
132 source `dirname $0`/../Sourcefile.sh
133 check_daq
134
135 numcalibrated=0
136 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
137 printprocesslog "INFO status beginning of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
138
139 rsync_aux_file $drivefilenewdaq $drivefile
140
141 # files on newdaq
142 for file in ${files[@]}
143 do
144 printprocesslog "processing "$file
145 #echo "processing "$file
146 localfile=`echo $file | sed -e 's/newdaq/loc_data/'`
147
148 source `dirname $0`/../Sourcefile.sh
149
150 # check if file is already transferred
151 if ! ls $localfile >/dev/null 2>&1
152 then
153 # check if it is drs-file
154 # get stop time from raw-file
155 if [ "`echo $file | grep -o drs`" == "drs" ]
156 then
157 nondrs=`basename $file | sed -e 's/[.]drs//g'`
158 nondrsfile=`find -L $rawpath -name $nondrs.*z`
159 tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
160 else
161 tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
162 fi
163 # when stop time is 0, file is not closed
164 # when an error is returned the tstop is empty
165 if [ "$tstop" == "0" ] || [ "$tstop" == "" ]
166 then
167 printprocesslog "WARN "$file" not yet closed."
168 # if a file is not closed and not touched for 30 minutes,
169 # it is assumed corrupted and still transferred
170 fileaccessed=`find $file -amin -30`
171 if ! [ "$fileaccessed" == "" ]
172 then
173 printprocesslog "INFO "$file" was accessed in the last 30 minutes => continue"
174 continue
175 else
176 printprocesslog "WARN: "$file" has empty TSTOP but was not touched for 30 minutes"
177 fileerror="yes"
178 fi
179 fi
180
181 # rsync
182 # from newdaq (/newdaq = /fact on newdaq), rsync server newdaq::newdaq/
183 # to daq (/daq = /loc_data on daq)
184 # to access rsync server via the dedicated network between
185 # daq and newdaq, use 172.16.100.100::newdaq
186 filersyncserver=`echo $file | sed -e 's/^\//172.16.100.100::/'`
187 # old
188 ##if ! rsync -av --stats --progress --bwlimit=$bwlimit $file $localfile
189 #if ! rsync -a -T $rsynctempdir --bwlimit=$bwlimit $file $localfile
190 # new
191 if ! rsync -a -W -T $rsynctempdir --bwlimit=$bwlimit $filersyncserver $localfile
192 then
193 printprocesslog "ERROR something went wrong with rsync of "$file
194 rm $localfile
195 continue
196 fi
197 printprocesslog "INFO "$file" rsynced successfully."
198 fi
199
200 # for .drs.fits files no further treatment needed
201 if [ "`echo $localfile | grep -o drs`" == "drs" ]
202 then
203 continue
204 fi
205
206# # temporary check
207# if [ "`echo $file | grep -o drs`" == "drs" ]
208# then
209# nondrs=`basename $file | sed -e 's/[.]drs//g'`
210# nondrsfile=`find -L $rawpath -name $nondrs.*z`
211# tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
212# else
213# tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
214# fi
215# # when stop time is 0, file is not closed
216# # when an error is returned the tstop is empty
217# if [ "$tstop" == "0" ] || [ "$tstop" == "" ]
218# then
219# printprocesslog "WARN "$file" not yet closed. -> continue (temporary check)"
220# continue
221# fi
222# # end temporary check
223
224 # treat other files (.fits.fz)
225 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"`
226 if [ "$runtype" != "data" ]
227 then
228 # skip a non-data run when it has not 1000 evts
229 # as this means probably an fad-loss
230 # and these runs are repeated in that case
231 numevts=`$factpath/fitsdump -h $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
232 if [ $numevts -ne 1000 ]
233 then
234 printprocesslog "INFO file "$file" is a non-data file ("$runtype") and has not 1000 events ("$numevts")"
235 continue
236 fi
237 fi
238
239 # get run number
240 runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
241
242 # what is needed to process the different runs?
243 # P: run#(P), run#(drs-file)
244 # C: run#(C), run#(drs-file), run#(drs-time)
245 # D: run#(D), run#(drs-file), run#(drs-time), ?
246 # what is drs-file? pedestal, roi300, has drs.fits
247 callistolog=$calpath"/"$date"_"$runnum"-calibration.log"
248 case $runtype in
249 data) # treat D-runs
250 if [ "$fileerror" = "yes" ]
251 then
252 printprocesslog "INFO do not further process corrupted file "$localfile
253 fileerror=
254 continue
255 fi
256
257 # some accounting
258 printprocesslog "DEBUG counting callisto logs and set data files +1."
259 # get number of callisto logs
260 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`
261 # count runs to be calibrated
262 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
263 printprocesslog "DEBUG running callistos: "$runcallistocount" #runs: "$numcalibrated" #callisto-logs: "${#callistofiles[@]}
264
265 # do not overload system in case of a lot of files to be processed
266 # numruncallistos is set in setup.fact.lp.data
267 if [ $runcallistocount -ge $numruncallistos ]
268 then
269 printprocesslog "INFO "$runcallistocount" RunCallisto.sh are running -> continue"
270 continue
271 fi
272
273 # starting calibration
274 if ! [ -e $callistolog ]
275 then
276 rsync_aux_file $drivefilenewdaq2 $drivefile2
277 rsync_aux_file $mweatherfilenewdaq $mweatherfile
278 rsync_aux_file $ratesfilenewdaq $ratesfile
279 rsync_aux_file $tempfilenewdaq $tempfile
280 rsync_aux_file $humfilenewdaq $humfile
281 if [ -e $drstime ]
282 then
283 calfile=$calpath"/"$date"_"$runnum"_C.root"
284 printprocesslog "INFO starting RunCallisto.sh for drun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" outpath "$outpath" calfile "$calfile
285 #echo "INFO starting RunCallisto.sh for drun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" outpath "$outpath" calfile "$calfile
286 `dirname $0`/RunCallisto.sh "drun" $callistolog $localfile $drscalib $drstime $calpath $calfile &
287 fi
288 fi
289 continue
290 ;;
291 pedestal) # treat P-runs
292 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"`
293 if [ $roi -eq 300 ]
294 then
295 # check drs-file
296 drsfile=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
297 if [ -e $drsfile ]
298 then
299 # set name of drs-file
300 drscalib=$drsfile
301 continue
302 #else
303 # not needed for QLA
304 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
305 #if ! [ -e $callistolog ]
306 #then
307 # pedfile=$calpath"/"$date"_"$runnum"-pedestal.root"
308 # # count runs to be calibrated
309 # printprocesslog "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
310 # echo "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
311 # `dirname $0`/RunCallisto.sh "prun" $callistolog $localfile $drscalib $pedfile &
312 #fi
313 fi
314 fi
315 ;;
316 light-pulser-ext) # treat C-runs
317 # do lp-treatment -> not needed for QLA
318 #lpfile=$calpath"/"$date"_"$runnum"-lightpulser.root"
319 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
320 #if ! [ -e $callistolog ]
321 #then
322 # if [ -e $drstime ]
323 # then
324 # # count runs to be calibrated
325 # printprocesslog "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
326 # echo "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
327 # `dirname $0`/RunCallistoNew.sh "crun" $callistolog $localfile $drscalib $drstime $lpfile &
328 # fi
329 #fi
330 ;;
331 drs-time) # treat C-runs
332 # do drs-timing calibration
333 drstime=$calpath"/"$date"_"$runnum"-drstime.root"
334 # starting calibration
335 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
336 if ! [ -e $callistolog ]
337 then
338 # count runs to be calibrated
339 printprocesslog "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
340 #echo "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
341 `dirname $0`/RunCallisto.sh "time" $callistolog $localfile $drsped $drstime &
342 fi
343 ;;
344 drs-pedestal) # get drs-pedestal
345 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"`
346 drs=`$factpath/fitsdump -h $localfile 2>/dev/null | grep DRSCALIB | grep -E -o " T " `
347 if [ $roi -eq 1024 ] && [ "$drs" == " T " ]
348 then
349 drsped=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
350 fi
351 ;;
352 *) # other runs
353 printprocesslog "INFO file "$file" has runtype "$runtype" -> continue "
354 continue
355 ;;
356 esac
357 done
358 printprocesslog "INFO status after loop: "$runcallistocount" callistos running, "$numcalibrated" data runs to process in total, "${#callistofiles[@]}" have already a callisto-logfile "
359
360 # get new file lists
361 printprocesslog "INFO get new file lists for "$datepath
362 files=( `find $rawpathnewdaq -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]fits[.]?[g]?[f]?[z]?' | sort` )
363 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][.]fits[.]?[g]?[f]?[z]?' | sort` )
364 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
365 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
366 printprocesslog "INFO status after for-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
367
368 # wait and get new file lists
369 update=
370 if [ ${#fileslocal[@]} -eq ${#files[@]} ]
371 then
372 printprocesslog "INFO wait 60 seconds."
373 sleep 60
374 printprocesslog "INFO get new file lists for "$datepath
375 files=( `find $rawpathnewdaq -type f -regex '.*20[0-9][0-9][01][0-9][0-3][0-9][_][0-9][0-9][0-9][.]fits[.]?[g]?[f]?[z]?' | sort` )
376 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][.]fits[.]?[g]?[f]?[z]?' | sort` )
377 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
378 fi
379 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
380 printprocesslog "INFO status after wait end of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
381 sleep 30
382 printprocesslog "INFO sleep 30"
383done
384
385
386
Note: See TracBrowser for help on using the repository browser.