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