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

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