Changeset 12609
- Timestamp:
- 11/22/11 06:18:09 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataCheck/CheckRawData.sh
r12583 r12609 3 3 today=`date +%F` 4 4 logfile=/home/`whoami`/DataCheck/log/CheckRaw$today.log 5 6 skipmd5sum="no" # fill md5 sums in any case 7 skipmd5sum="iffilled" # fill md5 sum only if they are not yet in db 8 #skipmd5sum="yes" # do not fill md5 sums in any case 9 10 doupdate="yes" # update all entries 11 #doupdate="no" # fill only entries which are not yet existing 12 13 echo "" >> $logfile 2>&1 14 echo "" >> $logfile 2>&1 15 echo "" >> $logfile 2>&1 16 echo `date`"executing "$0"..." >> $logfile 2>&1 17 echo "=====> doupdate: "$doupdate >> $logfile 2>&1 18 echo "=====> skipmd5sum: "$skipmd5sum >> $logfile 2>&1 5 19 6 20 password=`cat /home/fact/DataCheck/.pw` … … 16 30 # get last 3 nights 17 31 dates=( `date +%Y/%m/%d` `date +%Y/%m/%d --date="-1day"` `date +%Y/%m/%d --date="-2day"` `date +%Y/%m/%d --date="-3day"` ) 18 dates=( `date +%Y/%m/%d --date="- 1day"` )32 dates=( `date +%Y/%m/%d --date="-2day"` ) 19 33 20 34 # do rsync for rawfiles of these dates … … 26 40 rawdir=/loc_data/raw/$date 27 41 runnumber=`echo $date | sed -e 's/\///g'` 28 echo `date`": processing files in "$rawdir >> $logfile 42 echo `date`": processing files in "$rawdir >> $logfile 2>&1 29 43 # check if data are available from that night 30 44 if ! [ -d $rawdir ] 31 45 then 32 echo `date`": no data available in "$rawdir >> $logfile 46 echo `date`": no data available in "$rawdir >> $logfile 2>&1 33 47 continue 34 48 fi 35 49 36 50 # find all fits-files starting with the oldest file 37 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 51 echo `date`": finding files to be zipped in $rawdir..." >> $logfile 2>&1 38 52 fitsfiles=`find $rawdir -type f -name '*.fits'| sort ` 39 53 40 54 # loop to zip files 41 echo `date`": zipping files in $rawdir..." >> $logfile55 echo `date`": checking files in $rawdir..." >> $logfile 2>&1 42 56 for file in $fitsfiles 43 57 do 44 # check if raw file was accessed in the last 30 minutes 45 isnew=`find $file -amin -30` 58 echo "" >> $logfile 2>&1 59 echo "checking file "$file >> $logfile 2>&1 60 # check if raw file was changed in the last 30 minutes 61 isnew=`find $file -cmin -30` 46 62 if [ "$isnew" != "" ] 47 63 then 48 echo $file" is not older than 30 min => continue" >> $logfile 64 echo $file" is not older than 30 min => continue" >> $logfile 2>&1 49 65 continue 50 66 fi … … 54 70 if [ "$isnew" != "" ] 55 71 then 56 echo $file" is a drs file => continue" >> $logfile 72 echo $file" is a drs file => continue" >> $logfile 2>&1 57 73 continue 58 74 fi … … 70 86 then 71 87 # if times are not the same, the file is still open => no zip 72 echo `date`": file "$file" not yet closed => continue" >> $logfile 88 echo `date`": file "$file" not yet closed => continue" >> $logfile 2>&1 73 89 continue 74 90 fi 75 91 else 76 92 # if the origfile doesn't exist, the data was probably written not on daq but on data 77 echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 78 fi 79 80 # get md5sum 81 md5sum=`md5sum $file | cut -d' ' -f1` 82 zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'` 83 md5sumzip=`md5sum $zipfile | cut -d' ' -f1` 93 echo `date`": file "$file" was probably taken on data and not daq " >> $logfile 2>&1 94 fi 84 95 85 96 # get and check run and file number … … 101 112 fi 102 113 114 # check if entry already exists 115 query3="SELECT fRunNumber FROM RunInfo WHERE fRunNumber="$runnumber" AND fFileNumber="$filenumberfromfileorig 116 echo "Q3:"$query3 >> $logfile 2>&1 2>&1 117 result3=`/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query3"` 118 119 # only proceed with file 120 # if information is not yet in database 121 # and no update is wished ($doupdate) 122 if [ "$result3" != "" ] && [ "$doupdate" == "no" ] 123 then 124 echo $file" has been inserted already => continue " >> $logfile 2>&1 125 continue 126 fi 127 128 # check if entry has already checksums 129 query5="SELECT fRunNumber FROM RunInfo WHERE fRunNumber="$runnumber" AND fFileNumber="$filenumberfromfileorig 130 query5=$query5" AND NOT ISNULL(fMd5sumRaw) AND NOT ISNULL(fMd5sumRawZip)" 131 echo "Q5:"$query5 >> $logfile 2>&1 2>&1 132 result5=`/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query5"` 133 134 # get md5sums of raw and zip file 135 # to safe time for tests and update this can be skipped ($skipmd5sum) 136 md5sum= 137 md5sumzip= 138 if [ "$skipmd5sum" == "no" ] || [ "$skipmd5sum" == "iffilled" ] 139 then 140 #echo "skip: "$skipmd5sum >> $logfile 2>&1 141 #echo "res5: -"$result5"-" >> $logfile 2>&1 142 #if [ "$skipmd5sum" == "no" ] || [ "$result5$skipmd5sum" == "iffilled" ] 143 if [ "$skipmd5sum" == "no" ] || [ "$result5" == "" ] 144 then 145 echo "calculation md5sum for raw..." >> $logfile 2>&1 146 md5sum=`md5sum $file | cut -d' ' -f1` 147 zipfile=`echo $file | sed -e 's/raw/zipraw/' -e 's/fits/fits.gz/'` 148 echo "calculation md5sum for zipraw..." >> $logfile 2>&1 149 md5sumzip=`md5sum $zipfile | cut -d' ' -f1` 150 fi 151 fi 152 153 # check if this run has drs file 154 drsfile=`echo $file | sed -e 's/fits/drs.fits/'` 155 numdrsfiles=`ls $drsfile 2>/dev/null | wc -l` 156 103 157 # get other variables from header 104 158 runtype=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z-]+[']" | sed -e "s/'//g"` 105 159 roi=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep NROI | grep -v NROITM | grep -E -o '[0-9]{1,4}'` 106 160 numevents=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep Events | grep -E -o '[0-9]+'` 161 runstart=`/home/fact/FACT++/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}'` 162 runstop=`/home/fact/FACT++/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}'` 163 if [ "$runstart" == "" ] 164 then 165 runstart=`/home/fact/FACT++/fitsdump -h -t Events $file 2>/dev/null | grep 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}'` 166 fi 167 if [ "$runstop" == "" ] 168 then 169 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}'` 170 fi 107 171 108 172 # check if fits file is corrupted 109 fitsfileerror="no"173 numfitserrors=0 110 174 checkfitsfile=`fverify $file | grep '0 error(s)'` 111 175 if [ "$checkfitsfile" == "" ] 112 176 then 113 fitsfileerror="yes" 114 fi 115 echo "summary for file"$file 116 echo " errors: "$fitsfileerror 117 echo " runnumber error: "$runnumbererror 118 echo " number error: "$numbererror 119 echo " roi: "$roi 120 echo " runtype: "$runtype 121 echo " numevents: "$numevents 122 echo " md5sum: "$md5sum 123 echo " md5sum(zip): "$md5sumzip 124 # check wehter entry has been made (status table) 177 numfitserrors=1 178 fi 125 179 # get runtype 126 180 query2="SELECT fRunTypeKEY FROM RunType WHERE fRunTypeName='"$runtype"'" 127 echo "Q2:"$query2 181 echo "Q2:"$query2 >> $logfile 2>&1 128 182 result2=( `/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query2"` ) 129 183 if [ ${#result2} -eq 0 ] 130 184 then 131 185 echo "Could not query fRunTypeKey for runtype "$runtype 186 echo "Could not query fRunTypeKey for runtype "$runtype >> $logfile 2>&1 132 187 exit 133 188 fi 134 # check if entry already exists 135 query3="SELECT fRunNumber FROM RunInfo WHERE fRunNumber="$runnumber" AND fFileNumber="$filenumberfromfileorig 136 echo "Q3:"$query3 137 resul3=`/usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query3"` 189 # insert or update depending on whether run exists 138 190 if [ "$result3" == "" ] 139 191 then 140 192 query4="INSERT" 141 193 querymid=" fRunNumber="$runnumber", fFileNumber="$filenumberfromfileorig", " 194 querystop="" 142 195 else 143 196 query4="UPDATE" … … 145 198 fi 146 199 query4=$query4" RunInfo SET "$querymid" fRunTypeKey="${result2[1]}", fNumEvents="$numevents", fROI="$roi 147 query4=$query4", fMd5sumRaw='"$md5sum"', fMd5sumRawZip='"$md5sumzip"'" 148 echo "Q4:"$query4 200 if [ "$md5sum" != "" ] 201 then 202 query4=$query4", fMd5sumRaw='"$md5sum"', fMd5sumRawZip='"$md5sumzip"'" 203 fi 204 query4=$query4", fHasDrsFile="$numdrsfiles 205 query4=$query4", fFitsFileErrors="$numfitserrors 206 query4=$query4", fRunStart='"$runstart"', fRunStop='"$runstop"'" 207 query4=$query4" "$querystop 208 echo "Q4:"$query4 >> $logfile 2>&1 149 209 if ! /usr/bin/mysql -u operator --host=fact01.fact.local --password=$password FactData -e "$query4" 150 210 then 151 echo "insert/update of "$numfromfile" to mysql" 152 fi 153 exit 211 echo "insert/update of "$numfromfile" to mysql" >> $logfile 2>&1 212 fi 213 214 # print summary for debug 215 echo "*******" >> $logfile 2>&1 216 echo "summary for file "$file >> $logfile 2>&1 217 echo "*******" >> $logfile 2>&1 218 echo " errors: "$numfitserrors" (1 means errors exist)" >> $logfile 2>&1 219 echo " number of drs files: "$numdrsfiles >> $logfile 2>&1 220 echo " runnumber error: "$runnumbererror >> $logfile 2>&1 221 echo " number error: "$numbererror >> $logfile 2>&1 222 echo " roi: "$roi >> $logfile 2>&1 223 echo " runtype: "$runtype >> $logfile 2>&1 224 echo " numevents: "$numevents >> $logfile 2>&1 225 echo " md5sum: "$md5sum >> $logfile 2>&1 226 echo " md5sum(zip): "$md5sumzip >> $logfile 2>&1 227 echo " start: "$runstart >> $logfile 2>&1 228 echo " stop: "$runstop >> $logfile 2>&1 229 230 # missing 231 # check wether entry has been made (status table) 154 232 done 155 233 done
Note:
See TracChangeset
for help on using the changeset viewer.