[570] | 1 | #!/bin/sh -xvf
|
---|
| 2 | #do calibration
|
---|
| 3 | DATE=/bin/date
|
---|
| 4 | GREP=/bin/grep
|
---|
| 5 | AWK=/bin/awk
|
---|
| 6 | ECHO=/bin/echo
|
---|
| 7 | WC=/usr/bin/wc
|
---|
| 8 | CAT=/bin/cat
|
---|
| 9 | PRINTF=/usr/bin/printf
|
---|
| 10 | FIND=/usr/bin/find
|
---|
| 11 | MKDIR=/bin/mkdir
|
---|
| 12 | XARGS=/usr/bin/xargs
|
---|
| 13 | SORT=/bin/sort
|
---|
| 14 | RM=/bin/rm
|
---|
| 15 | TR=/usr/bin/tr
|
---|
| 16 | CP=/bin/cp
|
---|
| 17 | LS=/bin/ls
|
---|
| 18 | CHMOD=/bin/chmod
|
---|
| 19 |
|
---|
| 20 | DefaultIFS=$' \t\n'
|
---|
| 21 | IFS=$DefaultIFS
|
---|
| 22 |
|
---|
| 23 | #set Irods environment
|
---|
| 24 | . /usr/local/shared/bin/irods_env.sh -noverbose
|
---|
| 25 |
|
---|
| 26 | scriptName="`basename $0`"
|
---|
| 27 | $ECHO "Processing script ${scriptName} at `date`"
|
---|
| 28 | #which source to analyse
|
---|
| 29 |
|
---|
| 30 | #Process cmd line args: the -src option is mandatory (source name as Abell85)
|
---|
| 31 | sourceRadio=
|
---|
| 32 | dateSelected=
|
---|
| 33 | freqBAOCalib=1346
|
---|
| 34 | bwBAOCalib=6.25
|
---|
| 35 | #use -sim option to simulate processing (debug the script as if...)
|
---|
| 36 | simulationMode=Off
|
---|
| 37 | while [ $# -gt 0 ]
|
---|
[572] | 38 | do
|
---|
[570] | 39 | case "$1" in
|
---|
| 40 | -src) sourceRadio=$2; shift;;
|
---|
| 41 | -date) dateSelected=$2; shift;;
|
---|
| 42 | -freq) freqBAOCalib=$2; shift;;
|
---|
| 43 | -bwd) bwBAOCalib=$2; shift;;
|
---|
| 44 | -sim) simulationMode=On;;
|
---|
[572] | 45 | -h)
|
---|
| 46 | echo >&2 \
|
---|
| 47 | "usage: $0 -src souce -date YYYYMMDD [-freq freq in MHz (default ${freqBAOCalib})] [-bwd bandwidth in MHz (default ${bwBAOCalib})]"
|
---|
| 48 | exit 1;;
|
---|
| 49 | *) break;; # terminate while loop
|
---|
| 50 | esac
|
---|
| 51 | shift
|
---|
[570] | 52 | done
|
---|
| 53 |
|
---|
| 54 | if [ ${simulationMode} = "On" ]; then
|
---|
| 55 | $ECHO "INFO ${scriptName} running in SIMUL mode"
|
---|
| 56 | fi
|
---|
| 57 |
|
---|
| 58 | if [ "<${sourceRadio}>" = "<>" ]; then
|
---|
| 59 | $ECHO "FATAL: You have forgotten to select the source option (-src)"
|
---|
| 60 | exit 1
|
---|
| 61 | fi
|
---|
| 62 |
|
---|
| 63 | case ${sourceRadio} in
|
---|
| 64 | Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
| 65 | Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
| 66 | Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
[601] | 67 | NGC4383) $ECHO "INFO (${scriptName}): process ${sourceRadio}";;
|
---|
[570] | 68 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen"
|
---|
| 69 | exit 1;;
|
---|
| 70 | esac
|
---|
| 71 |
|
---|
| 72 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
|
---|
| 73 |
|
---|
| 74 | #Path to public backupable path
|
---|
| 75 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
|
---|
| 76 |
|
---|
| 77 |
|
---|
| 78 | #temporary files to synchronize scripts
|
---|
| 79 | tmppublicpath=${TMPPUBLICPATH}
|
---|
| 80 | #wakeup the NFS disk
|
---|
| 81 | $LS -l ${tmppublicpath} > /dev/null
|
---|
| 82 | #clean previous spurious files
|
---|
| 83 | $RM -f ${tmppublicpath}/*.finished
|
---|
| 84 |
|
---|
| 85 | #Path where the job will do temporary IO
|
---|
[579] | 86 | . ${SCRIPTPATH}/isInteractive.sh
|
---|
| 87 | isInteractive=$(isInteractive)
|
---|
| 88 | if [ ${isInteractive} == "1" ]; then
|
---|
| 89 | $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!"
|
---|
| 90 | exit 0;
|
---|
[570] | 91 | fi
|
---|
[579] | 92 |
|
---|
| 93 | . ${SCRIPTPATH}/set_iojobpath.sh
|
---|
| 94 | iojobpath=$(set_iojobpath)
|
---|
[570] | 95 | cd ${iojobpath}
|
---|
| 96 |
|
---|
| 97 | localpath="${sourceRadio}"
|
---|
| 98 | $MKDIR -p ./${localpath}
|
---|
| 99 | cd ./${localpath}
|
---|
| 100 |
|
---|
| 101 | #save the top directory
|
---|
| 102 | topDir=`pwd`
|
---|
| 103 |
|
---|
| 104 | #Path of the utility scripts
|
---|
[575] | 105 | scriptpath=${SCRIPTPATH}
|
---|
[570] | 106 |
|
---|
| 107 | #JEC 1/10/11 Use generic baodaqstatus name
|
---|
| 108 | OUT1=${publicpath}/baodaqstatus-current.txt
|
---|
| 109 | #
|
---|
| 110 | #get the daq current irod status
|
---|
| 111 | #tag=`${DATE} +%F`
|
---|
| 112 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt
|
---|
| 113 | #
|
---|
| 114 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
|
---|
| 115 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
|
---|
| 116 | exit 1
|
---|
| 117 | fi
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | #Nb: if we want to implement a loop on sources we have to take care of srclower...
|
---|
| 121 |
|
---|
| 122 | $ECHO "You have selected sourceRadio = $sourceRadio[date = ${dateSelected}]"
|
---|
| 123 | tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
|
---|
| 124 | IFS='
|
---|
| 125 | '
|
---|
| 126 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
| 127 | IFS=$DefaultIFS
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | for i in ${tableau[@]}
|
---|
| 131 | do
|
---|
| 132 | #
|
---|
| 133 | # start a "fresh" session
|
---|
| 134 | cd ${topDir}
|
---|
| 135 | $LS | $XARGS -i $RM -rf {}
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | $ECHO "DEBUG: (${scriptName}) irods root dir $i"
|
---|
| 139 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"`
|
---|
| 140 |
|
---|
| 141 | $ECHO "DEBUG: (${scriptName}): we are in directory `pwd` the topDir=${topDir}"
|
---|
| 142 | $LS -lrt
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | # alreadyDone=`ils ${i} 2>&1 | $GREP -i "calib_.*\.txt" | $WC -l`
|
---|
| 146 | # if [ ${alreadyDone} -gt 0 ]; then
|
---|
| 147 | # $ECHO "INFO (${scriptName}): calibration coef files already exist"
|
---|
| 148 | # continue
|
---|
| 149 | # fi
|
---|
| 150 |
|
---|
| 151 | gainDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l`
|
---|
| 152 | if [ ! ${gainDone} -gt 0 ]; then
|
---|
| 153 | $ECHO "FATAL (${scriptName}): gain file DOES NOT exist skip `basename $i` "
|
---|
| 154 | continue
|
---|
| 155 | fi
|
---|
| 156 |
|
---|
| 157 | ######
|
---|
| 158 | $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}"
|
---|
| 159 | #go to the .../source/date-sourcelowercase directory
|
---|
| 160 | #download Off/calibcycle<> and On/calibcycle<> directories
|
---|
| 161 | $MKDIR -p ${topDir}/${dateDAQ}${srclower}
|
---|
| 162 | cd ${topDir}/${dateDAQ}${srclower}
|
---|
| 163 | aboveOnOffDir=`pwd`
|
---|
| 164 | $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>"
|
---|
| 165 | #
|
---|
| 166 | mode="Off"
|
---|
| 167 | $ECHO "DEBUG (${scriptName}): START download the ${mode} calib fits files"
|
---|
| 168 | inFileDirectory="./${mode}"
|
---|
| 169 | $MKDIR -p ${inFileDirectory}
|
---|
| 170 | listOfCalibCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "calibcycle"|$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.11n` )
|
---|
| 171 | IFS='
|
---|
| 172 | '
|
---|
| 173 | listOfCalibCycle=( $( $PRINTF "%s\n" "${listOfCalibCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
| 174 | IFS=$DefaultIFS
|
---|
| 175 |
|
---|
| 176 | firstCycleOff=`$ECHO ${listOfCalibCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
|
---|
| 177 | nCyclesOff=`expr ${#listOfCalibCycle[*]} - 1`
|
---|
| 178 |
|
---|
| 179 | lastCycleOff=`$ECHO ${listOfCalibCycle[${nCyclesOff}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
|
---|
| 180 |
|
---|
| 181 | listOfCalibCycle=( "${listOfCalibCycle[@]/#/${i}/${mode}/}" )
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | for j in ${listOfCalibCycle[@]}
|
---|
| 185 | do
|
---|
| 186 | irodsDownDir="${j}"
|
---|
| 187 | OUT=./getInFits.$$
|
---|
| 188 | iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
|
---|
| 189 | igetStatus=`$GREP "^ERROR" ${OUT}`
|
---|
| 190 | if [ "<$igetStatus>" != "<>" ]; then
|
---|
| 191 | $ECHO "FATAL (${scriptName}): error while iget fits files:"
|
---|
| 192 | $ECHO $igetStatus
|
---|
| 193 | $ECHO " ==> skip this run $sourceRadio $dateDAQ"
|
---|
| 194 | continue
|
---|
| 195 | fi
|
---|
| 196 | $RM -f ${OUT}
|
---|
| 197 | done
|
---|
| 198 | $ECHO "DEBUG (${scriptName}): END download the ${mode} calib fits files"
|
---|
| 199 | #
|
---|
| 200 | mode="On"
|
---|
| 201 | $ECHO "DEBUG (${scriptName}): START download the ${mode} calib fits files"
|
---|
| 202 | inFileDirectory="./${mode}"
|
---|
| 203 | $MKDIR -p ${inFileDirectory}
|
---|
| 204 |
|
---|
| 205 | listOfCalibCycle=( `ils ${i}/${mode} 2>&1 | $GREP -i "calibcycle" |$AWK 'BEGIN{FS="C- "}{print $2}' | $XARGS -i basename {} | $SORT -k1.11n` )
|
---|
| 206 | IFS='
|
---|
| 207 | '
|
---|
| 208 | listOfCalibCycle=( $( $PRINTF "%s\n" "${listOfCalibCycle[@]}" | $AWK 'x[$0]++ == 0' ) )
|
---|
| 209 | IFS=$DefaultIFS
|
---|
| 210 |
|
---|
| 211 | firstCycleOn=`$ECHO ${listOfCalibCycle[0]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
|
---|
| 212 | nCyclesOn=`expr ${#listOfCalibCycle[*]} - 1`
|
---|
| 213 |
|
---|
| 214 | lastCycleOn=`$ECHO ${listOfCalibCycle[${nCyclesOn}]} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'`
|
---|
| 215 |
|
---|
| 216 | listOfCalibCycle=( "${listOfCalibCycle[@]/#/${i}/${mode}/}" )
|
---|
| 217 |
|
---|
| 218 |
|
---|
| 219 | #
|
---|
| 220 | #Check if there is the same number of cycles in Off and On mode
|
---|
| 221 | #
|
---|
| 222 | #first cycle = max(firstCycleOn, firstCycleOff)
|
---|
| 223 | #last cycle = min(lastCycleOn,lastCycleOff)
|
---|
| 224 |
|
---|
| 225 | if [ ${firstCycleOn} -eq ${firstCycleOff} -a ${lastCycleOn} -eq ${lastCycleOff} ]; then
|
---|
| 226 | firstCycle=${firstCycleOff}
|
---|
| 227 | lastCycle=${lastCycleOff}
|
---|
| 228 | else
|
---|
| 229 | $ECHO "INFO (${scriptName}): missmatch between Off and On mode"
|
---|
| 230 | $ECHO "${firstCycleOn} != ${firstCycleOff} OR ${lastCycleOn} != ${lastCycleOff}"
|
---|
| 231 | firstCycle=${firstCycleOff}
|
---|
| 232 | if [ ${firstCycleOn} -gt ${firstCycle} ]; then
|
---|
| 233 | firstCycle=${firstCycleOn}
|
---|
| 234 | fi
|
---|
| 235 | lastCycle=${lastCycleOff}
|
---|
| 236 | if [ ${lastCycleOn} -lt ${lastCycle} ]; then
|
---|
| 237 | lastCycle=${lastCycleOn}
|
---|
| 238 | fi
|
---|
| 239 | fi
|
---|
| 240 | $ECHO "INFO (${scriptName}): use cycles [${firstCycle}, ${lastCycle}]"
|
---|
| 241 |
|
---|
| 242 |
|
---|
| 243 | for j in ${listOfCalibCycle[@]}
|
---|
| 244 | do
|
---|
| 245 | irodsDownDir="${j}"
|
---|
| 246 | OUT=./getInFits.$$
|
---|
| 247 | iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1
|
---|
| 248 | igetStatus=`$GREP "^ERROR" ${OUT}`
|
---|
| 249 | if [ "<$igetStatus>" != "<>" ]; then
|
---|
| 250 | $ECHO "FATAL (${scriptName}): error while iget fits files:"
|
---|
| 251 | $ECHO $igetStatus
|
---|
| 252 | $ECHO " ==> skip this run $sourceRadio $dateDAQ"
|
---|
| 253 | continue
|
---|
| 254 | fi
|
---|
| 255 | $RM -f ${OUT}
|
---|
| 256 | done
|
---|
| 257 | $ECHO "DEBUG (${scriptName}): END download the ${mode} calib fits files"
|
---|
| 258 | #Get sca file
|
---|
| 259 | $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}"
|
---|
| 260 | OUT1=./getScaStatus.$$
|
---|
| 261 | $RM -f ${tmppublicpath}/getscafiles.finished
|
---|
| 262 | ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1
|
---|
[584] | 263 | # while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do
|
---|
| 264 | # $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished"
|
---|
| 265 | # date +%T
|
---|
| 266 | # sleep 30
|
---|
| 267 | # done
|
---|
[570] | 268 | $RM ${tmppublicpath}/getscafiles.finished
|
---|
| 269 | $ECHO "DEBUG (${scriptName}): END"
|
---|
| 270 | #
|
---|
| 271 | getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}`
|
---|
| 272 | #
|
---|
| 273 | if [ "<${getScaStatus}>" != "<>" ]; then
|
---|
| 274 | $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ"
|
---|
| 275 | $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}"
|
---|
| 276 | $CAT ${OUT1}
|
---|
| 277 | $ECHO "DEBUG (${scriptName}): END"
|
---|
| 278 | continue
|
---|
| 279 | fi
|
---|
| 280 | $RM -f ${OUT1}
|
---|
| 281 |
|
---|
| 282 | scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}`
|
---|
| 283 |
|
---|
| 284 | #prepare job submission
|
---|
| 285 | cd ${aboveOnOffDir}
|
---|
| 286 | #the default spectra name is medfiltmtx, otherwise use -specname <a_string>
|
---|
| 287 |
|
---|
| 288 | logFile="analyse_CALIB_${sourceRadio}_${dateDAQ}.log"
|
---|
| 289 | $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`"
|
---|
| 290 | if [ ${simulationMode} = "On" ]; then
|
---|
[584] | 291 | $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act calib -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir calibcycle -numcycle ${firstCycle},${lastCycle} -calibopt mean -debug 1 -freqBAOCalib ${freqBAOCalib} -bwBAOCalib ${bwBAOCalib} >& ${logFile}"
|
---|
[570] | 292 | cat > ${logFile} <<EOF
|
---|
| 293 | Ok calibration finished
|
---|
[572] | 294 | EOF
|
---|
| 295 | #WARNING: the EOF must start at 1st column overwise the rest of the script is part of the file cat...
|
---|
[570] | 296 | else
|
---|
[585] | 297 | ${scriptpath}/Objs/analyse -act calib -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir calibcycle -numcycle ${firstCycle},${lastCycle} -calibopt mean -debug 1 -freqBAOCalib ${freqBAOCalib} -bwBAOCalib ${bwBAOCalib} >& ${logFile}
|
---|
[570] | 298 | fi
|
---|
[572] | 299 | #
|
---|
[570] | 300 | $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods"
|
---|
| 301 | rcstatus=`$GREP -i "Ok calibration finished" ${logFile} | $WC -l`
|
---|
| 302 | if [ ${rcstatus} -eq 0 ]; then
|
---|
| 303 | $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}"
|
---|
| 304 | $ECHO " START logfile"
|
---|
| 305 | $CAT ${logFile}
|
---|
| 306 | $ECHO " END logFile"
|
---|
| 307 | #clean and leave
|
---|
| 308 | cd ${aboveOnOffDir}
|
---|
| 309 | $LS | $XARGS -i $RM -rf {}
|
---|
| 310 | continue
|
---|
| 311 | fi
|
---|
| 312 | #Save into Irods
|
---|
| 313 | $ECHO "DEBUG (${scriptName}): START save output files"
|
---|
| 314 | $LS ${aboveOnOffDir}
|
---|
| 315 | #use -f option for iput ONLY to force override
|
---|
| 316 | if [ ${simulationMode} = "On" ]; then
|
---|
| 317 | $ECHO "SIMUL: here we look for calib file and put them in Irods"
|
---|
| 318 | else
|
---|
| 319 | $LS -lrth
|
---|
[585] | 320 | $FIND . -name "calib_*" -print | $XARGS -i iput -f -v -K {} ${i}
|
---|
[570] | 321 | fi
|
---|
| 322 | #save analysis logfile
|
---|
| 323 | $LS -l ${tmppublicpath} > /dev/null
|
---|
| 324 | $CP ${logFile} ${tmppublicpath}
|
---|
| 325 | $ECHO "DEBUG (${scriptName}): END save output files"
|
---|
| 326 | #clean up to avoid scratch SIZE EXCEED LIMIT
|
---|
| 327 | cd ${aboveOnOffDir}
|
---|
| 328 | $LS | $XARGS -i $RM -rf {}
|
---|
| 329 |
|
---|
| 330 | done
|
---|
| 331 |
|
---|
| 332 | exit 0
|
---|