| 1 | #!/bin/bash
|
|---|
| 2 | #
|
|---|
| 3 | source `dirname $0`/../Sourcefile.sh
|
|---|
| 4 | printprocesslog "INFO starting $0"
|
|---|
| 5 |
|
|---|
| 6 | #root=/opt/root_svn/bin/thisroot.sh
|
|---|
| 7 | #source $root
|
|---|
| 8 | #factpath=/home/fact/FACT++.in-run-fad-loss
|
|---|
| 9 |
|
|---|
| 10 | #anapath=/loc_data/analysis
|
|---|
| 11 |
|
|---|
| 12 | #rerun="yes"
|
|---|
| 13 | #rerun="no"
|
|---|
| 14 | # not needed anymore as the variable is set automatically
|
|---|
| 15 | # depending on whether the rawfile existed locally,
|
|---|
| 16 | # i.e. depending on whether the rsync in needed
|
|---|
| 17 | # still needed in case all rawfiles have been rsynced already
|
|---|
| 18 |
|
|---|
| 19 | # get date (before 18h there is no new data to be processed)
|
|---|
| 20 | datepath=`date --date="-18HOUR" +%Y/%m/%d`
|
|---|
| 21 | #datepath="2013/03/24"
|
|---|
| 22 | printprocesslog "INFO processing "$datepath
|
|---|
| 23 | night=`echo $datepath | sed -e 's/\///g'`
|
|---|
| 24 |
|
|---|
| 25 | auxpathnewdaq=/newdaq/aux/$datepath
|
|---|
| 26 | # create aux directory on daq, if not yet there
|
|---|
| 27 | auxpath=/loc_data/aux/$datepath
|
|---|
| 28 | makedir $auxpath
|
|---|
| 29 | # create path for info files needed for analysis
|
|---|
| 30 | infopath=$anapath/info/$datepath
|
|---|
| 31 | makedir $infopath
|
|---|
| 32 | echo "" > $infopath/runrow.txt
|
|---|
| 33 | # create path for sequence files
|
|---|
| 34 | seqpath=$anapath/sequences/$datepath
|
|---|
| 35 | makedir $seqpath
|
|---|
| 36 | rawpathnewdaq=/newdaq/raw/$datepath
|
|---|
| 37 | rawpath=/loc_data/raw/$datepath
|
|---|
| 38 |
|
|---|
| 39 | # needed auxiliary files:
|
|---|
| 40 | # drive file with information about current source position
|
|---|
| 41 | drivefile=$auxpath/${night}.DRIVE_CONTROL_SOURCE_POSITION.fits
|
|---|
| 42 | drivefilenewdaq=$auxpathnewdaq/${night}.DRIVE_CONTROL_SOURCE_POSITION.fits
|
|---|
| 43 | # drive file with information about tracking position
|
|---|
| 44 | drivefile2=$auxpath/${night}.DRIVE_CONTROL_TRACKING_POSITION.fits
|
|---|
| 45 | drivefilenewdaq2=$auxpathnewdaq/${night}.DRIVE_CONTROL_TRACKING_POSITION.fits
|
|---|
| 46 | # file with magic weather information
|
|---|
| 47 | mweatherfile=$auxpath/${night}.MAGIC_WEATHER_DATA.fits
|
|---|
| 48 | mweatherfilenewdaq=$auxpathnewdaq/${night}.MAGIC_WEATHER_DATA.fits
|
|---|
| 49 | # file with trigger rates
|
|---|
| 50 | ratesfile=$auxpath/${night}.FTM_CONTROL_TRIGGER_RATES.fits
|
|---|
| 51 | ratesfilenewdaq=$auxpathnewdaq/${night}.FTM_CONTROL_TRIGGER_RATES.fits
|
|---|
| 52 | # file with trigger rates
|
|---|
| 53 | tempfile=$auxpath/${night}.FSC_CONTROL_TEMPERATURE.fits
|
|---|
| 54 | tempfilenewdaq=$auxpathnewdaq/${night}.FSC_CONTROL_TEMPERATURE.fits
|
|---|
| 55 | # file with trigger rates
|
|---|
| 56 | humfile=$auxpath/${night}.FSC_CONTROL_HUMIDITY.fits
|
|---|
| 57 | humfilenewdaq=$auxpathnewdaq/${night}.FSC_CONTROL_HUMIDITY.fits
|
|---|
| 58 |
|
|---|
| 59 | function rsync_aux_file()
|
|---|
| 60 | {
|
|---|
| 61 | if ls $1
|
|---|
| 62 | then
|
|---|
| 63 | printprocesslog "INFO rsync "$1
|
|---|
| 64 | #if ! rsync -av --stats $1 $2
|
|---|
| 65 | if ! rsync -av $1 $2
|
|---|
| 66 | then
|
|---|
| 67 | printprocesslog "WARN rsync of "$1" failed."
|
|---|
| 68 | fi
|
|---|
| 69 | fi
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | printprocesslog "INFO get lists of raw files on newdaq and daq"
|
|---|
| 73 | #files=( `ssh newdaq "find $rawpath -type f 2>/dev/null | sort"` )
|
|---|
| 74 | #files=( `ssh 172.16.100.100 "find $rawpath -type f 2>/dev/null | sort"` )
|
|---|
| 75 | files=( `find $rawpathnewdaq -type f 2>/dev/null | sort` )
|
|---|
| 76 | if [ ${#files[@]} -eq 0 ]
|
|---|
| 77 | then
|
|---|
| 78 | printprocesslog "INFO no raw files available yet for "$datepath
|
|---|
| 79 | finish
|
|---|
| 80 | fi
|
|---|
| 81 | fileslocal=( `find $rawpath -type f | sort` )
|
|---|
| 82 |
|
|---|
| 83 | # create raw directory on daq, if not yet there
|
|---|
| 84 | makedir $rawpath
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 | while [ ${#fileslocal[@]} -lt ${#files[@]} ] || [ "$rerun" = "yes" ]
|
|---|
| 88 | do
|
|---|
| 89 | ##if ssh newdaq "ls $drivefile"
|
|---|
| 90 | #if ls $drivefilenewdaq
|
|---|
| 91 | #then
|
|---|
| 92 | # printprocesslog "INFO rsync "$drivefilenewdaq
|
|---|
| 93 | # #if ! rsync -av --progress newdaq:$drivefile $drivefile
|
|---|
| 94 | # #if ! rsync -av --progress 172.16.100.100:$drivefile $drivefile
|
|---|
| 95 | # if ! rsync -av --stats $drivefilenewdaq $drivefile
|
|---|
| 96 | # then
|
|---|
| 97 | # printprocesslog "WARN rsync of "$drivefilenewdaq" failed."
|
|---|
| 98 | # fi
|
|---|
| 99 | #fi
|
|---|
| 100 | rsync_aux_file $drivefilenewdaq $drivefile
|
|---|
| 101 |
|
|---|
| 102 | # files on newdaq
|
|---|
| 103 | for file in ${files[@]}
|
|---|
| 104 | do
|
|---|
| 105 | printprocesslog "processing "$file
|
|---|
| 106 | localfile=`echo $file | sed -e 's/newdaq/loc_data/'`
|
|---|
| 107 | echo "processing "$file" "$localfile
|
|---|
| 108 |
|
|---|
| 109 | if [ "`echo $file | grep -o drs`" == "drs" ]
|
|---|
| 110 | then
|
|---|
| 111 | nondrsfile=`echo $file | sed -e 's/[.]drs//g'`
|
|---|
| 112 | #tstop=`ssh newdaq "source $root ; $factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'"`
|
|---|
| 113 | #tstop=`ssh 172.16.100.100 "source $root ; $factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'"`
|
|---|
| 114 | tstop=`$factpath/fitsdump -h $nondrsfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
|---|
| 115 | else
|
|---|
| 116 | #tstop=`ssh newdaq "source $root ; $factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'"`
|
|---|
| 117 | #tstop=`ssh 172.16.100.100 "source $root ; $factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'"`
|
|---|
| 118 | tstop=`$factpath/fitsdump -h $file 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
|---|
| 119 | fi
|
|---|
| 120 | if [ "$tstop" == "0" ]
|
|---|
| 121 | then
|
|---|
| 122 | printprocesslog "WARN "$file" not yet closed."
|
|---|
| 123 | #fileaccessed=`ssh newdaq "find $file -amin -30"`
|
|---|
| 124 | #fileaccessed=`ssh 172.16.100.100 "find $file -amin -30"`
|
|---|
| 125 | fileaccessed=`find $file -amin -30`
|
|---|
| 126 | #echo "fileaccessed: "$fileaccessed
|
|---|
| 127 | if ! [ "$fileaccessed" == "" ]
|
|---|
| 128 | then
|
|---|
| 129 | printprocesslog "INFO "$file" was accessed in the last 30 minutes => continue"
|
|---|
| 130 | continue
|
|---|
| 131 | else
|
|---|
| 132 | printprocesslog "WARN: "$file" has empty TSTOP but was not touched for 30 minutes"
|
|---|
| 133 | fileerror="yes"
|
|---|
| 134 | fi
|
|---|
| 135 | fi
|
|---|
| 136 |
|
|---|
| 137 | if ! ls $localfile >/dev/null 2>&1
|
|---|
| 138 | then
|
|---|
| 139 | #if ! rsync -av --progress newdaq:$file $file
|
|---|
| 140 | #if ! rsync -av --progress 172.16.100.100:$file $file
|
|---|
| 141 | if ! rsync -av --stats $file $localfile
|
|---|
| 142 | then
|
|---|
| 143 | printprocesslog "ERROR something went wrong with rsync of "$file
|
|---|
| 144 | rm $localfile
|
|---|
| 145 | continue
|
|---|
| 146 | fi
|
|---|
| 147 | printprocesslog "INFO "$file" rsynced successfully."
|
|---|
| 148 | rerun="no"
|
|---|
| 149 | else
|
|---|
| 150 | rerun="yes"
|
|---|
| 151 | fi
|
|---|
| 152 |
|
|---|
| 153 |
|
|---|
| 154 | if [ "`echo $localfile | grep -o drs`" != "drs" ]
|
|---|
| 155 | then
|
|---|
| 156 | runtype=`$factpath/fitsdump -h $localfile 2>/dev/null | grep RUNTYPE | grep -E -o "['][a-z0-9._-]+[']" | sed -e "s/'//g" -e "s/_/-/g" -e "s/[.]//g"`
|
|---|
| 157 | runnum=`echo $localfile | cut -d_ -f3 | cut -d. -f1`
|
|---|
| 158 | roi=`$factpath/fitsdump -h $localfile 2>/dev/null | grep ROI | grep -v ROITM | grep -E -o "[0-9][0-9][0-9][0-9]?" | sed -e "s/'//g" -e "s/_/-/g" -e "s/[.]//g"`
|
|---|
| 159 | printprocesslog "DEBUG runnum "$runnum" runtype "$runtype" roi "$roi
|
|---|
| 160 | if [ "$runtype" == "drs-time-upshifted" ]
|
|---|
| 161 | then
|
|---|
| 162 | continue
|
|---|
| 163 | fi
|
|---|
| 164 | if [ "$runtype" == "data" ]
|
|---|
| 165 | then
|
|---|
| 166 | if [ "$fileerror" = "yes" ]
|
|---|
| 167 | then
|
|---|
| 168 | printprocesslog "INFO do not further process corrupted file "$localfile
|
|---|
| 169 | fileerror=
|
|---|
| 170 | continue
|
|---|
| 171 | fi
|
|---|
| 172 | seqfile=$seqpath/${night}_${runnum}.seq
|
|---|
| 173 | printprocesslog "INFO write data-seq "$seqfile
|
|---|
| 174 | echo "# written by automatic analysis in LP" >$seqfile
|
|---|
| 175 | echo "" >> $seqfile
|
|---|
| 176 | echo "Sequence: "`echo $night | cut -c3-8`$runnum >> $seqfile
|
|---|
| 177 | echo "Night: "`echo $datepath | sed -e 's/\//-/g'` >> $seqfile
|
|---|
| 178 | echo "" >> $seqfile
|
|---|
| 179 | echo "DrsSequence: "$drsseq >> $seqfile
|
|---|
| 180 | echo "" >> $seqfile
|
|---|
| 181 | echo "CalRuns: "`echo $runrow | grep -E -o '[0-9]{3}light-pulser-ext300' | sed -e 's/light-pulser-ext300//g'` >> $seqfile
|
|---|
| 182 | echo "PedRuns: "`echo $runrow | grep -E -o '[0-9]{3}pedestal300' | sed -e 's/pedestal300//g'` >> $seqfile
|
|---|
| 183 | echo "DatRuns: "$runnum >> $seqfile
|
|---|
| 184 | echo "" >> $seqfile
|
|---|
| 185 | echo "DrsFiles: "$drsfile >> $seqfile
|
|---|
| 186 | echo "" >> $seqfile
|
|---|
| 187 | echo "#DrsFile: "$drsfile >> $seqfile
|
|---|
| 188 | echo "" >> $seqfile
|
|---|
| 189 |
|
|---|
| 190 | tstopi=`$factpath/fitsdump -h $localfile 2>/dev/null | grep TSTOPI | grep -E -o '[0-9]+'`
|
|---|
| 191 | tstopf=`$factpath/fitsdump -h $localfile 2>/dev/null | grep TSTOPF | grep -E -o '[.][0-9]+'`
|
|---|
| 192 | tstop=${tstopi}${tstopf}
|
|---|
| 193 | coordinates=( `${factpath}/fitsdump ${drivefile} -c Ra_src Dec_src -r --filter='Time<'${tstop} 2>/dev/null | tail -1 2>&1` )
|
|---|
| 194 | if [ "${coordinates[0]}" == "" ] || [ "${coordinates[1]}" == "" ]
|
|---|
| 195 | then
|
|---|
| 196 | printprocesslog "WARN couldn't get coordinates ("${coordinates[@]}") from "$drivefile
|
|---|
| 197 | continue
|
|---|
| 198 | fi
|
|---|
| 199 | if [ "${coordinates[0]}" == "0" ] || [ "${coordinates[1]}" == "0" ]
|
|---|
| 200 | then
|
|---|
| 201 | printprocesslog "WARN coordinates "${coordinates[@]}
|
|---|
| 202 | continue
|
|---|
| 203 | fi
|
|---|
| 204 | printprocesslog "DEBUG coordinates "${coordinates[@]}
|
|---|
| 205 | query="SELECT fSourceKEY FROM scheduling.source WHERE "
|
|---|
| 206 | query=$query" fRightAscension BETWEEN "${coordinates[0]}"-0.01 AND "${coordinates[0]}"+0.01 "
|
|---|
| 207 | query=$query" AND fDeclination BETWEEN "${coordinates[1]}"-0.01 AND "${coordinates[1]}"+0.01 "
|
|---|
| 208 | sourcekey=`sendquery`
|
|---|
| 209 | if [ "$sourcekey" == "" ]
|
|---|
| 210 | then
|
|---|
| 211 | printprocesslog "WARN sourcekey empty - coordinates"${coordinates[@]}
|
|---|
| 212 | fi
|
|---|
| 213 | callistolog=`dirname $seqfile | sed -e "s/sequences/${sourcekey}\/callisto/"`"/"$night"_"$runnum"-calibration.log"
|
|---|
| 214 | if ! [ -e $callistolog ]
|
|---|
| 215 | then
|
|---|
| 216 | rsync_aux_file $drivefilenewdaq2 $drivefile2
|
|---|
| 217 | rsync_aux_file $mweatherfilenewdaq $mweatherfile
|
|---|
| 218 | rsync_aux_file $ratesfilenewdaq $ratesfile
|
|---|
| 219 | rsync_aux_file $tempfilenewdaq $tempfile
|
|---|
| 220 | rsync_aux_file $humfilenewdaq $humfile
|
|---|
| 221 | printprocesslog "INFO starting RunCallisto.sh for "$sourcekey" "$seqfile
|
|---|
| 222 | echo "INFO starting RunCallisto.sh for "$sourcekey" "$seqfile
|
|---|
| 223 | `dirname $0`/RunCallisto.sh $sourcekey $seqfile &
|
|---|
| 224 | # do not overload system in case of a lot of files to be processed
|
|---|
| 225 | if [ "$rerun" = "yes" ]
|
|---|
| 226 | then
|
|---|
| 227 | sleep 600
|
|---|
| 228 | printprocesslog "INFO rerun=yes -> sleep 600..."
|
|---|
| 229 | fi
|
|---|
| 230 | fi
|
|---|
| 231 | continue
|
|---|
| 232 | fi
|
|---|
| 233 | printprocesslog "DEBUG runrow "$runrow" (from variable) "
|
|---|
| 234 | runrow=`cat $infopath/runrow.txt`
|
|---|
| 235 | printprocesslog "DEBUG runrow "$runrow" (from file) "
|
|---|
| 236 | runrow=$runrow$runnum$runtype$roi"_"
|
|---|
| 237 | echo $runrow > $infopath/runrow.txt
|
|---|
| 238 | if echo $runrow | grep -E '[0-9]{3}drs-pedestal1024_[0-9]{3}drs-gain1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-time1024_[0-9]{3}pedestal300_[0-9]{3}pedestal300_'
|
|---|
| 239 | then
|
|---|
| 240 | runrow2=`echo $runrow | grep -E -o '[0-9]{3}drs-pedestal1024_[0-9]{3}drs-gain1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-pedestal1024_[0-9]{3}drs-time1024_[0-9]{3}pedestal300_[0-9]{3}pedestal300_'`
|
|---|
| 241 | run1=`echo $runrow2 | cut -d_ -f1 | sed -e 's/drs-pedestal1024//g'`
|
|---|
| 242 | run2=`echo $runrow2 | cut -d_ -f2 | sed -e 's/drs-gain1024//g'`
|
|---|
| 243 | run3=`echo $runrow2 | cut -d_ -f3 | sed -e 's/drs-pedestal1024//g'`
|
|---|
| 244 | run4=`echo $runrow2 | cut -d_ -f4 | sed -e 's/drs-pedestal1024//g'`
|
|---|
| 245 | run5=`echo $runrow2 | cut -d_ -f5 | sed -e 's/drs-time1024//g'`
|
|---|
| 246 | run6=`echo $runrow2 | cut -d_ -f6 | sed -e 's/pedestal300//g'`
|
|---|
| 247 | run7=`echo $runrow2 | cut -d_ -f7 | sed -e 's/pedestal300//g'`
|
|---|
| 248 | seqfile=$seqpath/${night}_${run1}.drs.seq
|
|---|
| 249 | printprocesslog "INFO write drs-seq "$seqfile
|
|---|
| 250 | echo "# written by automatic analysis in LP" > $seqfile
|
|---|
| 251 | echo "" >> $seqfile
|
|---|
| 252 | echo "Sequence: "`echo $night | cut -c3-8`$run1 >> $seqfile
|
|---|
| 253 | echo "Night: "`echo $datepath | sed -e 's/\//-/g'` >> $seqfile
|
|---|
| 254 | echo "" >> $seqfile
|
|---|
| 255 | echo "CalRuns: "$run2 >> $seqfile
|
|---|
| 256 | echo "PedRuns: "$run6" "$run7 >> $seqfile
|
|---|
| 257 | echo "DatRuns: "$run5 >> $seqfile
|
|---|
| 258 | echo "DrsRuns: "$run1" "$run3" "$run4 >> $seqfile
|
|---|
| 259 | echo "DrsFiles: "$run3" "$run6 >> $seqfile
|
|---|
| 260 | echo "" >> $seqfile
|
|---|
| 261 | echo "#DrsFile: "$run6 >> $seqfile
|
|---|
| 262 | echo "" >> $seqfile
|
|---|
| 263 | echo "" > $infopath/runrow.txt
|
|---|
| 264 | drsseq=$run1
|
|---|
| 265 | drsfile=$run6
|
|---|
| 266 | fi
|
|---|
| 267 | if echo $runrow | grep -E '[0-9]{3}pedestal300_[0-9]{3}light-pulser-ext300_'
|
|---|
| 268 | then
|
|---|
| 269 | echo "" > $infopath/runrow.txt
|
|---|
| 270 | fi
|
|---|
| 271 | fi
|
|---|
| 272 | done
|
|---|
| 273 |
|
|---|
| 274 | # get new file lists
|
|---|
| 275 | printprocesslog "INFO get new file lists for "$datepath
|
|---|
| 276 | #files=( `ssh newdaq "find $rawpath -type f | sort"` )
|
|---|
| 277 | #files=( `ssh 172.16.100.100 "find $rawpath -type f | sort"` )
|
|---|
| 278 | files=( `find $rawpathnewdaq -type f | sort` )
|
|---|
| 279 | fileslocal=( `find $rawpath -type f | sort` )
|
|---|
| 280 |
|
|---|
| 281 | # update=
|
|---|
| 282 | # if [ ${#fileslocal[@]} -eq ${#files[@]} ]
|
|---|
| 283 | # then
|
|---|
| 284 | # sleep 60
|
|---|
| 285 | # echo "sleep 60..."
|
|---|
| 286 | # #files=( `ssh newdaq "find $rawpath -type f | sort"` )
|
|---|
| 287 | # files=( `ssh 172.16.100.100 "find $rawpath -type f | sort"` )
|
|---|
| 288 | # fileslocal=( `find $rawpath -type f | sort` )
|
|---|
| 289 | # fi
|
|---|
| 290 | done
|
|---|
| 291 |
|
|---|
| 292 |
|
|---|
| 293 |
|
|---|
| 294 |
|
|---|