1 | #!/bin/bash
|
---|
2 |
|
---|
3 | today=`date +%F`
|
---|
4 | logfile=/home/`whoami`/DataCheck/log/CheckRaw$today.log
|
---|
5 |
|
---|
6 | # setup to use ftools
|
---|
7 | export HEADAS=/opt/heasoft-6.11/x86_64-unknown-linux-gnu-libc2.13-0/
|
---|
8 | source $HEADAS/headas-init.sh
|
---|
9 |
|
---|
10 | # get last 3 nights
|
---|
11 | dates=( `date +%Y/%m/%d` `date +%Y/%m/%d --date="-1day"` `date +%Y/%m/%d --date="-2day"` `date +%Y/%m/%d --date="-3day"` )
|
---|
12 | dates=( `date +%Y/%m/%d` )
|
---|
13 |
|
---|
14 | # do rsync for rawfiles of these dates
|
---|
15 | for date in ${dates[@]}
|
---|
16 | do
|
---|
17 | echo "" >> $logfile 2>&1
|
---|
18 | echo "" >> $logfile 2>&1
|
---|
19 | echo "" >> $logfile 2>&1
|
---|
20 | rawdir=/loc_data/aux/$date
|
---|
21 | runnumber=`echo $date | sed -e 's/\///g'`
|
---|
22 | echo `date`": processing files in "$rawdir >> $logfile
|
---|
23 | # check if data are available from that night
|
---|
24 | if ! [ -d $rawdir ]
|
---|
25 | then
|
---|
26 | echo `date`": no data available in "$rawdir >> $logfile
|
---|
27 | continue
|
---|
28 | fi
|
---|
29 |
|
---|
30 | # find all fits-files starting with the oldest file
|
---|
31 | echo `date`": finding files to be zipped in $rawdir..." >> $logfile
|
---|
32 | fitsfiles=`find $rawdir -type f -name '*fits'| sort `
|
---|
33 |
|
---|
34 | # loop to zip files
|
---|
35 | echo `date`": zipping files in $rawdir..." >> $logfile
|
---|
36 | for file in $fitsfiles
|
---|
37 | do
|
---|
38 | # check if raw file was accessed in the last 30 minutes
|
---|
39 | isnew=`find $file -amin -5`
|
---|
40 | if [ "$isnew" != "" ]
|
---|
41 | then
|
---|
42 | echo $file" is not older than 30 min => continue" >> $logfile
|
---|
43 | continue
|
---|
44 | fi
|
---|
45 |
|
---|
46 | # check if file is already finished
|
---|
47 | # original file on daq (if data was taken on daq
|
---|
48 | origfile=`echo $file | sed -e 's/loc_data/daq/'`
|
---|
49 | if [ -e $origfile ]
|
---|
50 | then
|
---|
51 | # get time of last modification as seconds since Epoch for both files
|
---|
52 | timeorig=`stat -c %Y $origfile`
|
---|
53 | timecopy=`stat -c %Y $file`
|
---|
54 | # compare times
|
---|
55 | if ! [ $timeorig -eq $timecopy ]
|
---|
56 | then
|
---|
57 | # if times are not the same, the file is still open => no zip
|
---|
58 | echo `date`": file "$file" not yet closed => continue" >> $logfile
|
---|
59 | continue
|
---|
60 | fi
|
---|
61 | else
|
---|
62 | # if the origfile doesn't exist, the data was probably written not on daq but on data
|
---|
63 | echo `date`": file "$file" was probably taken on data and not daq " >> $logfile
|
---|
64 | fi
|
---|
65 |
|
---|
66 | # md5sum -> db
|
---|
67 | # runtype
|
---|
68 | # position/source name
|
---|
69 | # # evts
|
---|
70 | # trigger setup
|
---|
71 | # roi
|
---|
72 | # check run#
|
---|
73 |
|
---|
74 | # both
|
---|
75 | md5sum=`md5sum $file | cut -d' ' -f1`
|
---|
76 | numberfromname=`echo $file | grep -E -o '20[1-9][0-9][01][0-9][0-3][0-9]_[0-9]{3}'`
|
---|
77 | runnumberfromname=`echo $file | grep -E -o '20[1-9][0-9][01][0-9][0-3][0-9]'`# + compare to $runnumber (=$date)
|
---|
78 | # aux file
|
---|
79 | tablename=`echo $file | grep -E -o '[.][A-Z_]+[.]' | sed -e 's/[.]//g'`
|
---|
80 | # raw file
|
---|
81 | runnumberfromfile=`/home/fact/FACT++/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]'`
|
---|
82 | filenumberfromfile=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep RUNID | grep -E -o '[0-9]{1,3}'`
|
---|
83 | numberfromfile=$runnumberfromfile"_"$filenumberfromfile
|
---|
84 | if [ "$numberfromfile" == "$numberfromname" ]
|
---|
85 | then
|
---|
86 | echo "numbers are identical"
|
---|
87 | fi
|
---|
88 | runtype=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"`
|
---|
89 | roi=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep NROI | grep -v NROITM | grep -E -o '[0-9]{1,4}'`
|
---|
90 | numevents=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'`
|
---|
91 |
|
---|
92 | # both
|
---|
93 | checkfitsfile=`fverify $file | grep '0 error(s)'`
|
---|
94 | if [ "$checkfitsfile" == "" ]
|
---|
95 | then
|
---|
96 | echo " "
|
---|
97 | echo $file
|
---|
98 | echo "file "$file" has probably an error"
|
---|
99 | fi
|
---|
100 | exit
|
---|
101 | done
|
---|
102 | done
|
---|
103 |
|
---|
104 |
|
---|