source: branches/trigger_burst_research/QuickLook/Step1.sh@ 20004

Last change on this file since 20004 was 18269, checked in by Daniela Dorner, 9 years ago
implemented usage of general drs-time-calib file
  • 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" == "" ]
234 then
235 printprocesslog "WARN could not get number of events from file "$file" -> continue "
236 #echo "WARN could not get number of events from file "$file" -> continue "
237 continue
238 fi
239 if [ $numevts -ne 1000 ]
240 then
241 printprocesslog "INFO file "$file" is a non-data file ("$runtype") and has not 1000 events ("$numevts")"
242 continue
243 fi
244 fi
245
246 # get run number
247 runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
248
249 # what is needed to process the different runs?
250 # P: run#(P), run#(drs-file)
251 # C: run#(C), run#(drs-file), run#(drs-time)
252 # D: run#(D), run#(drs-file), run#(drs-time), ?
253 # what is drs-file? pedestal, roi300, has drs.fits
254 callistolog=$calpath"/"$date"_"$runnum"-calibration.log"
255 case $runtype in
256 data) # treat D-runs
257 if [ "$fileerror" = "yes" ]
258 then
259 printprocesslog "INFO do not further process corrupted file "$localfile
260 fileerror=
261 continue
262 fi
263
264 # some accounting
265 printprocesslog "DEBUG counting callisto logs and set data files +1."
266 # get number of callisto logs
267 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`
268 # count runs to be calibrated
269 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
270 printprocesslog "DEBUG running callistos: "$runcallistocount" #runs: "$numcalibrated" #callisto-logs: "${#callistofiles[@]}
271
272 # do not overload system in case of a lot of files to be processed
273 # numruncallistos is set in setup.fact.lp.data
274 if [ $runcallistocount -ge $numruncallistos ]
275 then
276 printprocesslog "INFO "$runcallistocount" RunCallisto.sh are running -> continue"
277 continue
278 fi
279
280 # starting calibration
281 if ! [ -e $callistolog ]
282 then
283 rsync_aux_file $drivefilenewdaq2 $drivefile2
284 rsync_aux_file $mweatherfilenewdaq $mweatherfile
285 rsync_aux_file $ratesfilenewdaq $ratesfile
286 rsync_aux_file $tempfilenewdaq $tempfile
287 rsync_aux_file $humfilenewdaq $humfile
288
289 calfile=$calpath"/"$date"_"$runnum"_C.root"
290 printprocesslog "INFO starting RunCallisto.sh for drun "$localfile" logfile "$callistolog" drs-calib "$drscalib" outpath "$outpath" calfile "$calfile
291 `dirname $0`/RunCallisto.sh "drun" $callistolog $localfile $drscalib $calpath $calfile &
292 fi
293 continue
294 ;;
295 pedestal) # treat P-runs
296 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"`
297 if [ $roi -eq 300 ]
298 then
299 # check drs-file
300 drsfile=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
301 if [ -e $drsfile ]
302 then
303 # set name of drs-file
304 drscalib=$drsfile
305 continue
306 #else
307 # not needed for QLA
308 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
309 #if ! [ -e $callistolog ]
310 #then
311 # pedfile=$calpath"/"$date"_"$runnum"-pedestal.root"
312 # # count runs to be calibrated
313 # printprocesslog "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
314 # echo "INFO starting RunCallisto.sh for prun "$localfile" logfile "$callistolog" drs-calib "$drscalib" pedfile "$pedfile
315 # `dirname $0`/RunCallisto.sh "prun" $callistolog $localfile $drscalib $pedfile &
316 #fi
317 fi
318 fi
319 ;;
320 light-pulser-ext) # treat C-runs
321 # do lp-treatment -> not needed for QLA
322 #lpfile=$calpath"/"$date"_"$runnum"-lightpulser.root"
323 #numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
324 #if ! [ -e $callistolog ]
325 #then
326 # if [ -e $drstime ]
327 # then
328 # # count runs to be calibrated
329 # printprocesslog "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
330 # echo "INFO starting RunCallisto.sh for crun "$localfile" logfile "$callistolog" drs-calib "$drscalib" drs-time "$drstime" lpfile "$lpfile
331 # `dirname $0`/RunCallistoNew.sh "crun" $callistolog $localfile $drscalib $drstime $lpfile &
332 # fi
333 #fi
334 ;;
335 drs-time) # treat drs-time runs
336 # do drs-timing calibration
337 drstime=$calpath"/"$date"_"$runnum"-drstime.root"
338 # starting calibration
339 numcalibrated=`echo " $numcalibrated + 1 " | bc -l`
340 if ! [ -e $callistolog ]
341 then
342 # count runs to be calibrated
343 printprocesslog "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
344 #echo "INFO starting RunCallisto.sh for time "$localfile" logfile "$callistolog" drs-ped "$drsped" drstime "$drstime
345 `dirname $0`/RunCallisto.sh "time" $callistolog $localfile $drsped $drstime &
346 fi
347 ;;
348 drs-pedestal) # get drs-pedestal
349 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"`
350 drs=`$factpath/fitsdump -h $localfile 2>/dev/null | grep DRSCALIB | grep -E -o " T " `
351 if [ $roi -eq 1024 ] && [ "$drs" == " T " ]
352 then
353 drsped=`echo $localfile | sed -e 's/[.]fits[.]fz/.drs.fits/g'`
354 fi
355 ;;
356 *) # other runs
357 printprocesslog "INFO file "$file" has runtype "$runtype" -> continue "
358 continue
359 ;;
360 esac
361 done
362 printprocesslog "INFO status after loop: "$runcallistocount" callistos running, "$numcalibrated" data runs to process in total, "${#callistofiles[@]}" have already a callisto-logfile "
363
364 # get new file lists
365 printprocesslog "INFO get new file lists for "$datepath
366 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` )
367 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` )
368 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
369 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
370 printprocesslog "INFO status after for-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
371
372 # wait and get new file lists
373 update=
374 if [ ${#fileslocal[@]} -eq ${#files[@]} ]
375 then
376 printprocesslog "INFO wait 60 seconds."
377 sleep 60
378 printprocesslog "INFO get new file lists for "$datepath
379 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` )
380 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` )
381 callistofiles=( `find $calpath -type f -name $date*-calibration.log | sort` )
382 fi
383 #echo "INFO #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
384 printprocesslog "INFO status after wait end of while-loop #files-daq:"${#fileslocal[@]}" #files-newdaq:"${#files[@]}" #callisto-logs:"${#callistofiles[@]}" #runs:"$numcalibrated
385 sleep 30
386 printprocesslog "INFO sleep 30"
387done
388
389
390
Note: See TracBrowser for help on using the repository browser.