source: trunk/DataCheck/Processing/CheckRawData.sh@ 16959

Last change on this file since 16959 was 15593, checked in by Daniela Dorner, 12 years ago
added creating of row in table RatesFileAvailISDCStatus
  • Property svn:executable set to *
File size: 24.8 KB
Line 
1#!/bin/bash
2
3# this script has been written to run on La Palma on the machine data
4# i.e. paths are only working on this machine
5# the script starts from the zipped files
6# this causes a delay until files are in the database
7# because they have to be rsynced and zipped first (see RsyncRawData.sh, ZipRawData.sh)
8#
9# starting from 2012/06/05 the keywords CHECKSUM and DATASUM are
10# available in the fits header of the rawfile
11# starting from this time the md5sums are not calculated anymore (not true, only from 2012/12/17)
12#
13
14# todo
15# tempfile for fitsdump -h output
16
17## options:
18#skipmd5sum="no" # fill md5 sums in any case
19#skipmd5sum="iffilled" # fill md5 sum only if they are not yet in db # default
20#skipmd5sum="yes" # do not fill md5 sums in any case #new default since 2012/06/05 when the checksum is available in heaser
21
22doupdate="yes" # update all entries
23doupdate="no" # fill only entries which are not yet existing #default
24
25root=/opt/root_svn/bin/thisroot.sh
26
27source `dirname $0`/../Sourcefile.sh
28printprocesslog "INFO starting $0 with options doupdate="$doupdate #" and skipmd5sum="$skipmd5sum
29
30# setup to use ftools
31source $HEADAS/headas-init.sh
32
33# check if software is available
34if ! ls $factpath/fitsdump >/dev/null 2>&1
35then
36 printprocesslog "ERROR "$factpath"/fitsdump is not available."
37 finish
38fi
39
40# check if paths are available
41if ! ls /daq/raw >/dev/null 2>&1
42then
43 printprocesslog "ERROR /daq/raw is not available."
44 finish
45fi
46if ! ls /newdaq/raw >/dev/null 2>&1
47then
48 printprocesslog "ERROR /newdaq/raw is not available."
49 finish
50fi
51if ! ls /loc_data/zipraw >/dev/null 2>&1
52then
53 printprocesslog "ERROR /loc_data/zipraw is not available."
54 finish
55fi
56
57# get last 3, 6 or 9 nights
58dates=( `date +%Y/%m/%d --date="-12hour"` `date +%Y/%m/%d --date="-36hour"` `date +%Y/%m/%d --date="-60hour"` \
59 `date +%Y/%m/%d --date="-84hour"` `date +%Y/%m/%d --date="-108hour"` `date +%Y/%m/%d --date="-132hour"` \
60# `date +%Y/%m/%d --date="-156hour"` `date +%Y/%m/%d --date="-180hour"` `date +%Y/%m/%d --date="-204hour"` \
61 )
62#dates=( `find /loc_data/zipraw/ -mindepth 3 -type d | sort | sed -e 's/\/loc_data\/zipraw\///g'` ) #all available dates in /loc_data/zipraw
63#dates=( `find /loc_data/aux/ -mindepth 3 -type d | sort | sed -e 's/\/loc_data\/aux\///g'` ) #all available dates in /loc_data/zipraw
64
65#dates=( "2013/03/30" )
66
67# do check for rawfiles of these dates
68for date in ${dates[@]}
69do
70 date2=`echo $date | sed -e 's/\///g'`
71 night=
72 query="SELECT fNight FROM AuxFilesAvailISDCStatus WHERE fNight="$date2
73 night=`sendquery`
74 if [ "$night" == "" ] && ls /loc_data/zipraw/$date >/dev/null 2>&1
75 then
76 printprocesslog "INFO insert "$date2" to AuxFilesAvailISDCStatus"
77 query="INSERT AuxFilesAvailISDCStatus SET fNight="$date2", fPriority="$date2
78 sendquery >/dev/null 2>&1
79 fi
80 night=
81 query="SELECT fNight FROM DriveFileAvailISDCStatus WHERE fNight="$date2
82 night=`sendquery`
83 if [ "$night" == "" ] && ls /loc_data/zipraw/$date >/dev/null 2>&1
84 then
85 printprocesslog "INFO insert "$date2" to DriveFileAvailISDCStatus"
86 query="INSERT DriveFileAvailISDCStatus SET fNight="$date2", fPriority="$date2
87 sendquery >/dev/null 2>&1
88 fi
89 night=
90 query="SELECT fNight FROM RatesFileAvailISDCStatus WHERE fNight="$date2
91 night=`sendquery`
92 if [ "$night" == "" ] && ls /loc_data/zipraw/$date >/dev/null 2>&1
93 then
94 printprocesslog "INFO insert "$date2" to RatesFileAvailISDCStatus"
95 query="INSERT RatesFileAvailISDCStatus SET fNight="$date2", fPriority="$date2
96 sendquery >/dev/null 2>&1
97 fi
98 night=
99 query="SELECT fNight FROM AuxDataInsertStatus WHERE fNight="$date2
100 night=`sendquery`
101 if [ "$night" == "" ] && ls /loc_data/zipraw/$date >/dev/null 2>&1
102 then
103 printprocesslog "INFO insert "$date2" to AuxDataInsertStatus"
104 query="INSERT AuxDataInsertStatus SET fNight="$date2", fPriority="$date2
105 sendquery >/dev/null 2>&1
106 fi
107 ziprawdir=/loc_data/zipraw/$date
108 # check if data are available from that night
109 if ! [ -d $ziprawdir ]
110 then
111 printprocesslog "INFO "$ziprawdir" does not exist."
112 continue
113 else
114 printprocesslog "INFO processing "$ziprawdir"..."
115 fi
116
117 # find all fits.gz files starting with the oldest file
118 printprocesslog "INFO finding files to be checked in $ziprawdir..."
119 fitsgzfiles=`find $ziprawdir -type f -name '*.fits.gz'| sort `
120
121 # get runnumber from date
122 runnumber=`echo $date | sed -e 's/\///g'`
123
124 # loop to check files
125 for file in $fitsgzfiles
126 do
127 filecorrupt="no"
128 printprocesslog "INFO checking file "$file
129 #echo "INFO checking file "$file" at "`date`
130
131 # raw and original file
132 # file: /loc_data/zipraw
133 # rawfile: /daq/raw
134 # origfile: /newdaq/raw
135 rawfile=`echo $file | sed -e 's/loc_data/daq/' -e 's/zipraw/raw/' -e 's/fits[.]gz/fits/'`
136 rawfile2=`echo $file | sed -e 's/zipraw/raw/' -e 's/fits[.]gz/fits/'`
137 origfile=`echo $rawfile | sed -e 's/daq/newdaq/'`
138
139 # check if it is drs file
140 isdrs=`ls $file | grep drs`
141 if [ "$isdrs" != "" ]
142 then
143 printprocesslog "INFO "$file" is a drs file. -> continue"
144 continue
145 fi
146
147# not needed anymore as files are only rsynced from newdaq to daq when they are closed
148# # check if file is already finished
149# # original file on daq (if data was taken on daq
150# if [ -e $origfile ]
151# then
152# # check if raw file was changed in the last 30 minutes
153# isnew=`find $origfile -cmin -30`
154# if [ "$isnew" != "" ]
155# then
156# printprocesslog "WARN "$origfile" is not older than 30 min. -> continue"
157# continue
158# fi
159#
160# # get time of last modification as seconds since Epoch for both files
161# timeorig=`stat -c %Y $origfile`
162# timecopy=`stat -c %Y $rawfile`
163# # compare times
164# if ! [ $timeorig -eq $timecopy ]
165# then
166# # if times are not the same, the file is still open => no check
167# printprocesslog "INFO file "$rawfile" not yet closed. -> continue"
168# continue
169# fi
170# else
171# # if the origfile doesn't exist, the data was probably written not on daq but on data
172# printprocesslog "INFO file "$rawfile" was probably taken on data and not daq."
173# fi
174
175 # get run and file number form filename
176 runnumbererror="no"
177 numbererror="no"
178 numberfromname=`echo $file | grep -E -o '20[1-9][0-9][01][0-9][0-3][0-9]_[0-9]{3}'`
179 runnumberfromname=`echo $numberfromname | cut -d_ -f1`
180 filenumberfromname=`echo $numberfromname | cut -d_ -f2 | sed -e 's/^0//g' -e 's/^0//g'`
181 if [ "$runnumber" != "$runnumberfromname" ]
182 then
183 runnumbererror="yes"
184 printprocesslog "ERROR for file "$file": runnumber from date ("$runnumber") and filename ("$runnumberfromname") don't agree."
185 fi
186
187 # check if entry already exists
188 query="SELECT fNight FROM RunInfo WHERE Concat(fNight, '_', LPAD(fRunID, 3, 0))='"$numberfromname"'"
189 printprocesslog "DEBUG check if entry already exists in DB. QUERY: "$query
190 #result3=`/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query3"`
191 result3=`sendquery`
192
193 # only proceed with file
194 # if information is not yet in database
195 # and no update is wished ($doupdate)
196 if [ "$result3" != "" ] && [ "$doupdate" == "no" ]
197 then
198 printprocesslog "INFO "$file" has been inserted already. -> continue "
199 continue
200 fi
201
202 runtype=
203 # check if fits file is corrupted
204 numfitserrors=0
205 #checkfitsfile=`fverify $rawfile 2>/dev/null | grep '0 error(s)'`
206 #numfitserrors=`fverify $rawfile 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'`
207# ftools missing on daq
208# numfitserrors=`ssh daq "export HEADAS=/opt/heasoft-6.11/x86_64-unknown-linux-gnu-libc2.13-0/ ; source $HEADAS/headas-init.sh ; fverify $rawfile2 2>/dev/null | grep -o '[0-9][ ]error(s)' | grep -E -o '[0-9]'"`
209# echo $rawfile2" ------ "$numfitserrors
210 #if [ "$checkfitsfile" == "" ]
211 if [ $numfitserrors -gt 0 ]
212 then
213 printprocesslog "WARN "$rawfile2" has "$numfitserrors" fitserror(s). "
214 #fitsdumperrors=`$factpath/fitsdump -h -t Events $file 2>&1 | grep corrupted`
215 fitsdumperrors=`$factpath/fitsdump -h $file 2>&1 | grep corrupted`
216 if [ "$fitsdumperrors" != "" ]
217 then
218 filecorrupt="yes"
219 fi
220 #numfitserrors=1
221 fi
222
223 # check if file was closed properly
224 if [ "`echo $file | grep -o drs`" == "drs" ]
225 then
226 nondrsfile=`echo $file | sed -e 's/[.]drs//g'`
227 tstop=`ssh newdaq "source $root ; $factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'"`
228 else
229 tstop=`ssh newdaq "source $root ; $factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'"`
230 fi
231 if [ "$tstop" == "0" ]
232 then
233 echo $file" not yet closed."
234 echo "WARN: $file has empty TSTOP"
235 filecorrupt="yes"
236 fi
237
238 numdrsfiles=
239 step=
240 #if [ $numfitserrors -eq 0 ]
241 if [ "$filecorrupt" == "no" ]
242 then
243 # get run and file number from file
244 #runnumberfromfile=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep NIGHT | grep -E -o '20[1-9][0-9][01][0-9][0-3][0-9]'`
245 runnumberfromfile=`$factpath/fitsdump -h $file 2>/dev/null | grep NIGHT | grep -E -o '20[1-9][0-9][01][0-9][0-3][0-9]'`
246 #filenumberfromfileorig=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep RUNID | grep -E -o '[0-9]{1,3}'`
247 filenumberfromfileorig=`$factpath/fitsdump -h $file 2>/dev/null | grep RUNID | grep -E -o '[0-9]{1,3}'`
248 if [ "$runnumberfromfile" = "" ] || [ "$filenumberfromfileorig" = "" ]
249 then
250 printprocesslog "ERROR couldn't get run or file number from file name ("$file")."
251 fi
252 numberfromfile=$runnumberfromfile"_"`printf %03d $filenumberfromfileorig`
253 # compare numbers
254 if [ "$numberfromfile" != "$numberfromname" ]
255 then
256 numbererror="yes"
257 printprocesslog "ERROR for file "$file": number from filename ("$numberfromname") and file ("$numberfromfile") don't agree."
258 fi
259
260 # get checksums from header
261 #checksum=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep CHECKSUM | grep -E -o '[a-zA-Z0-9]{16}'`
262 checksum=`$factpath/fitsdump -h $file 2>/dev/null | grep CHECKSUM | grep -E -o '[a-zA-Z0-9]{16}'`
263 if [ "$checksum" == "" ]
264 then
265 printprocesslog "WARN checksum for file "$file" is empty."
266 fi
267 #datasum=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep DATASUM | grep -E -o '[0-9]{1,10}'`
268 datasum=`$factpath/fitsdump -h $file 2>/dev/null | grep DATASUM | grep -E -o '[0-9]{1,10}'`
269 if [ "$datasum" == "" ]
270 then
271 printprocesslog "WARN datasum for file "$file" is empty."
272 fi
273
274 # check if this run has drs file
275 # in case file is available, get STEP from header
276 # in the very beginning only drs-files were existing
277 # in the beginning the keywords DRSCALIB and STEP were not existing
278 drsfile=`echo $file | sed -e 's/fits/drs.fits/'`
279 numdrsfiles=`ls $drsfile 2>/dev/null | wc -l`
280 #drscalib=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep DRSCALIB | grep -E -o "['][TF][']" | sed -e "s/'//g"`
281 drscalib=`$factpath/fitsdump -h $file 2>/dev/null | grep DRSCALIB | grep -E -o "[\ ][TF][\ ]" | sed -e "s/\ //g"`
282 if [ "$drscalib" == "T" ]
283 then
284 #step=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep DRSSTEP | grep -E -o "['][012][']" | sed -e "s/'//g"`
285 step=`$factpath/fitsdump -h $file 2>/dev/null | grep DRSSTEP | grep -E -o "[\ ][012][\ ]" | sed -e "s/\ //g"`
286 #stepfromdrs=`$factpath/fitsdump -h -t Events $drsfile 2>/dev/null | grep STEP | grep -E -o "['][012][']" | sed -e "s/'//g"`
287 stepfromdrs=`$factpath/fitsdump -h $drsfile 2>/dev/null | grep STEP | grep -E -o "[\ ][012][\ ]?" | sed -e "s/\ //g"`
288 if [ "$stepfromdrs" != "$step" ]
289 then
290 printprocesslog "ERROR for file "$file" step from drsfile ("$stepfromdrs") and from file ("$step") do not agree."
291 if [ "$stepfromdrsfile" != "" ] && [ "$step" == "" ]
292 then
293 step=$stepfromdrsfile
294 printprocesslog "WARN setting drsstep from drsfile ("$stepfromdrs") although value differs from the one in file "$file"."
295 fi
296 fi
297 if ! [ $numdrsfiles -eq 1 ]
298 then
299 printprocesslog "ERROR for file "$file" number of drsfiles ("$numdrsfiles") and information from header ("$drscalib") don't agree."
300 fi
301 if [ "$step" = "" ]
302 then
303 printprocesslog "ERROR file "$file" has drsfiles ("$numdrsfiles"), but step ("$step") is empty."
304 fi
305 else
306 if ! [ "$drscalib" == "F" ]
307 then
308 printprocesslog "WARN for file "$file" DRSCALIB is neither T nor F."
309 fi
310 fi
311 #echo $numdrsfiles" "$stepfromdrs" "$step" "$drscalib" ("$file")"
312
313 # get other variables from header
314 #runtype=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z0-9._-]+[']" | sed -e "s/'//g" -e "s/_/-/g" -e "s/[.]//g"`
315 runtype=`$factpath/fitsdump -h $file 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z0-9._-]+[']" | sed -e "s/'//g" -e "s/_/-/g" -e "s/[.]//g"`
316 #echo "runtype for file "$file": "$runtype
317 #roi=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep NROI | grep -v NROITM | grep -E -o '[0-9]{1,4}'`
318 roi=`$factpath/fitsdump -h $file 2>/dev/null | grep NROI | grep -v NROITM | grep -E -o '[0-9]{1,4}'`
319 #roitm=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep NROITM | grep -E -o '[0-9]{1,4}'`
320 roitm=`$factpath/fitsdump -h $file 2>/dev/null | grep NROITM | grep -E -o '[0-9]{1,4}'`
321 #numevents=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
322 numevents=`$factpath/fitsdump -h $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
323 #numphys=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRG ' | grep -E -o '[0-9]+'`
324 numphys=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRG ' | grep -E -o '[0-9]+'`
325 #numext1=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGEXT1' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
326 numext1=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGEXT1' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
327 #numext2=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGEXT2' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
328 numext2=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGEXT2' | grep -E -o '[ ][0-9]+[ ]' | sed -e 's/\ //g'`
329 #numelp=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGLPE' | grep -E -o '[0-9]+'`
330 numelp=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGLPE' | grep -E -o '[0-9]+'`
331 #numilp=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGLPI' | grep -E -o '[0-9]+'`
332 numilp=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGLPI' | grep -E -o '[0-9]+'`
333 #numoth=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGMISC' | grep -E -o '[0-9]+'`
334 numoth=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGMISC' | grep -E -o '[0-9]+'`
335 #numped=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGPED' | grep -E -o '[0-9]+'`
336 numped=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGPED' | grep -E -o '[0-9]+'`
337 #numtime=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'NTRGTIM' | grep -E -o '[0-9]+'`
338 numtime=`$factpath/fitsdump -h $file 2>/dev/null | grep 'NTRGTIM' | grep -E -o '[0-9]+'`
339 #compiled=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'COMPILED' | grep -E -o "['][a-zA-Z]+[ ][ 12][0-9][ ]20[0-9][0-9][ ][0-2][0-9]:[0-5][0-9]:[0-5][0-9][']" | sed -e "s/'//g"`
340 compiled=`$factpath/fitsdump -h $file 2>/dev/null | grep 'COMPILED' | grep -E -o "['][a-zA-Z]+[ ][ 12][0-9][ ]20[0-9][0-9][ ][0-2][0-9]:[0-5][0-9]:[0-5][0-9][']" | sed -e "s/'//g"`
341 if ! [ "$compiled" == "" ]
342 then
343 compiletime=`date +'%F %H:%M:%S' --date="${compiled}" `
344 else
345 compiletime=
346 fi
347 #revnum=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep 'REVISION' | grep -E -o "['][0-9]+[:]?[0-9]*[MSP]*[']" | sed -e "s/'//g"`
348 revnum=`$factpath/fitsdump -h $file 2>/dev/null | grep 'REVISION' | grep -E -o "['][0-9]+[:]?[0-9]*[MSP]*[']" | sed -e "s/'//g"`
349 # in newest data start time is in DATE-OBS
350 # in older data start time is in TSTART
351 # in the beginning TSTART was empty
352 #runstart=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep DATE-OBS | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
353 runstart=`$factpath/fitsdump -h $file 2>/dev/null | grep DATE-OBS | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
354 #runstart2=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep TSTART | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
355 runstart2=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTART | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
356 if [ "$runstart" == "" ]
357 then
358 if [ "$runstart2" == "" ]
359 then
360 #runstart=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep DATE | grep -v 'DATE-' | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
361 runstart=`$factpath/fitsdump -h $file 2>/dev/null | grep DATE | grep -v 'DATE-' | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
362 else
363 runstart=$runstart2
364 fi
365 fi
366 # in newest data start time is in DATE-END
367 # in older data start time is in TSTOP
368 # in the beginning TSTOP was empty
369 #runstop=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep DATE-END | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
370 runstop=`$factpath/fitsdump -h $file 2>/dev/null | grep DATE-END | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
371 #runstop2=`$factpath/fitsdump -h -t Events $file 2>/dev/null | grep TSTOP | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
372 runstop2=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOP | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9]T[0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{6}'`
373 if [ "$runstop" == "" ]
374 then
375 if [ "$runstop2" == "" ]
376 then
377 runstop=`stat $file 2>/dev/null | grep Modify | grep -E -o '20[1-9][0-9][\-][01][0-9][\-][0-3][0-9][ ][0-2][0-9]:[0-6][0-9]:[0-6][0-9][.][0-9]{9}'`
378 else
379 runstop=$runstop2
380 fi
381 fi
382 fi
383
384 # set runtype to 'unknown', if no runtype could be retrieved from file
385 if [ "$runtype" == "" ]
386 then
387 runtype="n/a"
388 fi
389 # on 15.11.2011 the runtypes had different names
390 if [ "$date" == "2011/11/15" ]
391 then
392 if [ "$runtype" == "drs-calib" ]
393 then
394 runtype="drs-gain"
395 fi
396 if [ "$runtype" == "drs-time-calib" ]
397 then
398 runtype="drs-time"
399 fi
400 if [ "$runtype" == "pedestal" ]
401 then
402 runtype="drs-pedestal"
403 fi
404 if [ "$runtype" == "light-pulser" ]
405 then
406 runtype="light-pulser-ext"
407 fi
408 if [ "$runtype" == "pedestal-on" ]
409 then
410 runtype="pedestal"
411 fi
412 fi
413 # get runtype
414 query="SELECT fRunTypeKEY FROM RunType WHERE fRunTypeName='"$runtype"'"
415 printprocesslog "DEBUG get run type from DB. QUERY:"$query
416 #result2=( `/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query2"` )
417 result2=( `sendquery` )
418 if [ ${#result2} -eq 0 ]
419 then
420 printprocesslog "ERROR "$numberfromname": Could not query fRunTypeKey for runtype "$runtype" ."
421 continue
422 fi
423
424# # check if entry has already checksums
425# query="SELECT fNight FROM RunInfo WHERE Concat(fNight, '_', LPAD(fRunID, 3, 0))='"$numberfromname"'"
426# query=$query" AND NOT ISNULL(fMd5sumRaw) AND NOT ISNULL(fMd5sumRawZip)"
427# printprocesslog "DEBUG check if md5sums are alreay in DB. QUERY:"$query
428# #result5=`/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query5"`
429# result5=`sendquery`
430#
431# # get md5sums of raw and zip file
432# # to safe time for tests and update this can be skipped ($skipmd5sum)
433# md5sum=
434# md5sumzip=
435# if [ "$skipmd5sum" == "no" ] || [ "$skipmd5sum" == "iffilled" ]
436# then
437# #echo "skip: "$skipmd5sum >> $logfile 2>&1
438# #echo "res5: -"$result5"-" >> $logfile 2>&1
439# #if [ "$skipmd5sum" == "no" ] || [ "$result5$skipmd5sum" == "iffilled" ]
440# if [ "$skipmd5sum" == "no" ] || [ "$result5" == "" ]
441# then
442# #zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'`
443# # only do the md5sum if the zipfile is already available
444# if ls $file >/dev/null 2>&1
445# then
446# printprocesslog "INFO calculation md5sum for rawfile "$rawfile
447# md5sum=`md5sum $rawfile | cut -d' ' -f1`
448# printprocesslog "INFO calculation md5sum for zipfile "$file
449# md5sumzip=`md5sum $file | cut -d' ' -f1`
450# fi
451# fi
452# fi
453
454 # insert or update depending on whether run exists
455 if [ "$result3" == "" ]
456 then
457 query="INSERT"
458 querymid=" fNight="$runnumber", fRunID="$filenumberfromname", "
459 querystop=
460 else
461 query="UPDATE"
462 querymid=
463 querystop=" WHERE fNight="$runnumber" AND fRunID="$filenumberfromname
464 fi
465 query=$query" RunInfo SET "$querymid" fRunTypeKey="${result2[0]}
466 #if [ $numfitserrors -eq 0 ]
467 if [ "$filecorrupt" == "no" ]
468 then
469 query=$query", fRunStart='"$runstart"', fRunStop='"$runstop"'"
470 if [ "$numevents" != "" ]
471 then
472 query=$query", fNumEvents="$numevents
473 fi
474 if [ "$roi" != "" ]
475 then
476 query=$query", fROI="$roi
477 fi
478 if [ "$roitm" != "" ]
479 then
480 query=$query", fROITimeMarker="$roitm
481 fi
482 if [ "$numphys" != "" ]
483 then
484 query=$query", fNumPhysicsTrigger="$numphys
485 fi
486 if [ "$numext1" != "" ]
487 then
488 query=$query", fNumExt1Trigger="$numext1
489 fi
490 if [ "$numext2" != "" ]
491 then
492 query=$query", fNumExt2Trigger="$numext2
493 fi
494 if [ "$numelp" != "" ]
495 then
496 query=$query", fNumELPTrigger="$numelp
497 fi
498 if [ "$numilp" != "" ]
499 then
500 query=$query", fNumILPTrigger="$numilp
501 fi
502 if [ "$numped" != "" ]
503 then
504 query=$query", fNumPedestalTrigger="$numped
505 fi
506 if [ "$numtime" != "" ]
507 then
508 query=$query", fNumTimeTrigger="$numtime
509 fi
510 if [ "$numoth" != "" ]
511 then
512 query=$query", fNumOtherTrigger="$numoth
513 fi
514 fi
515 if [ "$checksum" != "" ]
516 then
517 query=$query", fCheckSum='"$checksum"'"
518 fi
519 if [ "$datasum" != "" ]
520 then
521 query=$query", fDataSum='"$datasum"'"
522 fi
523# if [ "$md5sum" != "" ]
524# then
525# query=$query", fMd5sumRaw='"$md5sum"', fMd5sumRawZip='"$md5sumzip"'"
526# fi
527 if [ "$numdrsfiles" != "" ]
528 then
529 query=$query", fHasDrsFile="$numdrsfiles
530 fi
531 if [ "$step" != "" ]
532 then
533 query=$query", fDrsStep="$step
534 fi
535 if [ "$compiletime" != "" ]
536 then
537 query=$query", fCompileTime='"$compiletime"'"
538 fi
539 if [ "$revnum" != "" ]
540 then
541 query=$query", fRevisionNumber='"$revnum"'"
542 fi
543 query=$query", fFitsFileErrors="$numfitserrors
544 query=$query" "$querystop
545 # send query to DB
546 #echo $query
547 sendquery >/dev/null
548 done
549done
550
551finish
552
Note: See TracBrowser for help on using the repository browser.