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

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