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

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