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

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