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

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