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

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