[507] | 1 | #!/bin/sh -xvf |
---|
| 2 | #download SCA file, proceed to introspection, and upload results |
---|
| 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 | |
---|
| 29 | #$ECHO "SHOULD BE RETUNED FOR THE inPath cmd line of analyse.cc (Sorry...): 21/7/11 by JEC" |
---|
| 30 | #exit 1 |
---|
| 31 | |
---|
| 32 | #Process cmd line args: the -src option is mandatory (source name as Abell85) |
---|
| 33 | sourceRadio= |
---|
| 34 | #use -sim option to simulate processing (debug the script as if...) |
---|
| 35 | simulationMode=Off |
---|
| 36 | while [ $# -gt 0 ] |
---|
| 37 | do |
---|
| 38 | case "$1" in |
---|
| 39 | -src) sourceRadio=$2; shift;; |
---|
[529] | 40 | -sim) simulationMode=On;; |
---|
[507] | 41 | -h) |
---|
| 42 | echo >&2 \ |
---|
| 43 | "usage: $0 -src souce [-sim]" |
---|
| 44 | exit 1;; |
---|
| 45 | *) break;; # terminate while loop |
---|
| 46 | esac |
---|
| 47 | shift |
---|
| 48 | done |
---|
| 49 | |
---|
| 50 | if [ ${simulationMode} = "On" ]; then |
---|
| 51 | $ECHO "INFO ${scriptName} running in SIMUL mode" |
---|
| 52 | fi |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | if [ "<${sourceRadio}>" = "<>" ]; then |
---|
| 56 | $ECHO "FATAL: You have forgotten to select the source option (-src)" |
---|
| 57 | exit 1 |
---|
| 58 | fi |
---|
| 59 | |
---|
| 60 | case ${sourceRadio} in |
---|
| 61 | Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 62 | Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 63 | Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 64 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen" |
---|
| 65 | exit 1;; |
---|
| 66 | esac |
---|
| 67 | |
---|
| 68 | |
---|
| 69 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
| 70 | |
---|
| 71 | #Path to public backupable path |
---|
| 72 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | #temporary files to synchronize scripts |
---|
[516] | 76 | tmppublicpath=${TMPPUBLICPATH} |
---|
[507] | 77 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | #Path where the job will do temporary IO |
---|
| 81 | if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then |
---|
| 82 | iojobpath="/sps/baoradio/AmasNancay/JEC" |
---|
| 83 | $MKDIR -p $iojobpath |
---|
[542] | 84 | $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!" |
---|
| 85 | exit 0; |
---|
[507] | 86 | elif [ ${ENVIRONMENT} = "BATCH" ] ; then |
---|
| 87 | iojobpath=${TMPBATCH} |
---|
| 88 | else |
---|
| 89 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed" |
---|
| 90 | exit 1 |
---|
| 91 | fi |
---|
[512] | 92 | cd ${iojobpath} |
---|
[507] | 93 | |
---|
| 94 | localpath="${sourceRadio}" |
---|
| 95 | $MKDIR -p ./${localpath} |
---|
| 96 | cd ./${localpath} |
---|
| 97 | |
---|
| 98 | #save the top directory |
---|
| 99 | topDir=`pwd` |
---|
| 100 | |
---|
| 101 | #Path of the utility scripts |
---|
[510] | 102 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay" |
---|
[507] | 103 | |
---|
| 104 | |
---|
[540] | 105 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
[507] | 106 | #get the daq current irod status |
---|
[540] | 107 | #tag=`${DATE} +%F` |
---|
| 108 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 109 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
[507] | 110 | |
---|
| 111 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
[540] | 112 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 113 | exit 1 |
---|
| 114 | # $RM -f ${tmppublicpath}/statusdaq.finished |
---|
| 115 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
| 116 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
| 117 | # sleep 30 |
---|
| 118 | # done |
---|
| 119 | # $RM ${tmppublicpath}/statusdaq.finished |
---|
[507] | 120 | #protect against remove/rewriting |
---|
[540] | 121 | # $CHMOD -v 444 ${OUT1} |
---|
| 122 | # |
---|
[507] | 123 | fi |
---|
| 124 | |
---|
| 125 | # |
---|
| 126 | #We forbib to perform the gain for all the sources in one shot! |
---|
| 127 | # |
---|
| 128 | #if [ ! "<${sourceRadio}>" = "All" ]; then |
---|
| 129 | $ECHO "You have selected sourceRadio = $sourceRadio" |
---|
| 130 | tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 131 | #else |
---|
| 132 | # tableau=( `$CAT ${OUT1} | $AWK '( NF==4 ) { print $2 }'` ) |
---|
| 133 | #fi |
---|
| 134 | IFS=' |
---|
| 135 | ' |
---|
| 136 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 137 | IFS=$DefaultIFS |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | for i in ${tableau[@]} |
---|
| 141 | do |
---|
| 142 | $ECHO "DEBUG (${scriptName}): irods root dir $i" |
---|
| 143 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"` |
---|
[540] | 144 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
[507] | 145 | #Look if the date has changed since beginning of the job! |
---|
[540] | 146 | # curtag=`${DATE} +%F` |
---|
| 147 | # if [ "<${curtag}>" != "<${tag}>" ]; then |
---|
| 148 | # tag=${curtag} |
---|
[507] | 149 | #it is necessary to update the daq status as the day has changed during the processing... (batch can take a long time...) |
---|
[540] | 150 | # OUT1=${publicpath}/baodaqstatus-${curtag}.txt |
---|
| 151 | # $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..." |
---|
| 152 | # $RM -f ${tmppublicpath}/statusdaq.finished |
---|
| 153 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
| 154 | # while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do |
---|
| 155 | # sleep 30 |
---|
| 156 | # done |
---|
| 157 | # $RM ${tmppublicpath}/statusdaq.finished |
---|
[507] | 158 | #protect against remove/rewriting |
---|
[540] | 159 | # $CHMOD -v 444 ${OUT1} |
---|
| 160 | # fi |
---|
[507] | 161 | # |
---|
| 162 | # look if the fits file of the gains already exists |
---|
| 163 | alreadyDone=`ils ${i} 2>&1 | $GREP -i "gain_.*\.fits" | $WC -l` |
---|
| 164 | if [ ${alreadyDone} -gt 0 ]; then |
---|
| 165 | $ECHO "INFO (${scriptName}): Fits file for gains already exists" |
---|
| 166 | continue |
---|
| 167 | fi |
---|
| 168 | # Something should be done... |
---|
| 169 | #look if the files for the input to gain computations have been done |
---|
| 170 | somethingTodo=1 |
---|
| 171 | input4gainOk1=`ils ${i}/Off 2>&1 | $GREP -i "^ERROR" | $WC -l` |
---|
| 172 | input4gainOk2=`ils ${i}/Off 2>&1 | $GREP -i "gaincycle"` |
---|
| 173 | if [ $input4gainOk1 -eq 0 -a "<${input4gainOk2}>" != "<>" ]; then |
---|
| 174 | gaincycle=`$ECHO ${input4gainOk2} | $AWK '($1 == "C-"){print $2}'| $XARGS -i basename {}` |
---|
| 175 | input4gainOk3=`ils ${i}/Off/${gaincycle} 2>&1 | $GREP -i "medfiltmtx" | $WC -l` |
---|
| 176 | if [ $input4gainOk3 -gt 0 ]; then |
---|
| 177 | somethingTodo=0 |
---|
| 178 | fi |
---|
| 179 | fi |
---|
| 180 | if [ $somethingTodo -eq 1 ]; then |
---|
| 181 | # |
---|
| 182 | $ECHO ">>>>>>>>>>>>>>>> Do proc_script $sourceRadio $dateDAQ GAIN" |
---|
| 183 | $RM -f ${tmppublicpath}/proc_script.finished |
---|
| 184 | if [ ${simulationMode} = "On" ]; then |
---|
| 185 | $ECHO "SIMUL: ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ GAIN" |
---|
| 186 | else |
---|
| 187 | ${scriptpath}/proc_script.sh $sourceRadio $dateDAQ GAIN |
---|
| 188 | while [ ! -e "${tmppublicpath}/proc_script.finished" ]; do |
---|
| 189 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/proc_script.finished" |
---|
| 190 | date +%T |
---|
| 191 | sleep 60 |
---|
| 192 | done |
---|
| 193 | fi |
---|
| 194 | $ECHO "INFO (${scriptName}): proc_script has finished" |
---|
| 195 | $RM ${tmppublicpath}/proc_script.finished |
---|
| 196 | #Todo see if there is errors in the log file before copy |
---|
| 197 | $ECHO ">>>>>>>>>>>>>>>> Done proc_script $sourceRadio $dateDAQ GAIN" |
---|
| 198 | ###### |
---|
| 199 | fi |
---|
| 200 | ###### |
---|
| 201 | $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}" |
---|
| 202 | #go to the .../source/date-sourcelowercase directory |
---|
| 203 | $MKDIR -p ${topDir}/${dateDAQ}${srclower} |
---|
| 204 | cd ${topDir}/${dateDAQ}${srclower} |
---|
| 205 | aboveOnOffDir=`pwd` |
---|
| 206 | $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>" |
---|
| 207 | # So the input files are there, so the fits file can be determined |
---|
| 208 | mode="Off" |
---|
| 209 | spectraGenDirName=`$ECHO ${gaincycle} | $AWK '{match($0,"[a-zA-Z]+",arr); print arr[0]}'` |
---|
| 210 | cycleNumber=`$ECHO ${gaincycle} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'` |
---|
| 211 | #care: the gaincycle variable contains the cycle number |
---|
| 212 | $ECHO "DEBUG (${scriptName}): START download the fits files" |
---|
| 213 | inFileDirectory="./${mode}" |
---|
| 214 | $MKDIR -p ${inFileDirectory} |
---|
| 215 | irodsDownDir="${i}/${mode}/${gaincycle}" |
---|
| 216 | OUT=./getInFits.$$ |
---|
| 217 | iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1 |
---|
| 218 | $LS ${inFileDirectory}/${gaincycle} |
---|
| 219 | igetStatus=`$GREP "^ERROR" ${OUT}` |
---|
| 220 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 221 | $ECHO "FATAL (${scriptName}): error while iget fits files:" |
---|
| 222 | $ECHO $igetStatus |
---|
| 223 | continue |
---|
| 224 | fi |
---|
| 225 | $RM -f ${OUT} |
---|
| 226 | $ECHO "DEBUG (${scriptName}): END download the fits files" |
---|
| 227 | #Get sca files |
---|
| 228 | $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}" |
---|
| 229 | OUT1=./getScaStatus.$$ |
---|
| 230 | $RM -f ${tmppublicpath}/getscafiles.finished |
---|
| 231 | ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1 |
---|
| 232 | while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do |
---|
| 233 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished" |
---|
| 234 | date +%T |
---|
| 235 | sleep 30 |
---|
| 236 | done |
---|
| 237 | $RM ${tmppublicpath}/getscafiles.finished |
---|
| 238 | $ECHO "DEBUG (${scriptName}): END" |
---|
| 239 | # |
---|
| 240 | getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}` |
---|
| 241 | # |
---|
| 242 | if [ "<${getScaStatus}>" != "<>" ]; then |
---|
| 243 | $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ" |
---|
| 244 | $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}" |
---|
| 245 | $CAT ${OUT1} |
---|
| 246 | $ECHO "DEBUG (${scriptName}): END" |
---|
| 247 | continue |
---|
| 248 | fi |
---|
| 249 | $RM -f ${OUT1} |
---|
| 250 | $ECHO "DEBUG (${scriptName}): where am i `pwd`" |
---|
| 251 | $LS -lrt |
---|
| 252 | |
---|
| 253 | scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}` |
---|
| 254 | # |
---|
| 255 | #the default spectra name is medfiltmtx, otherwise use -specname <a_string> |
---|
| 256 | logFile="analyse_GAIN_${sourceRadio}_${dateDAQ}.log" |
---|
| 257 | $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`" |
---|
| 258 | if [ ${simulationMode} = "On" ]; then |
---|
[522] | 259 | $ECHO "SIMUL: ${scriptpath}/Objs/analyse -act gain -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debug 1 >& ${logFile}" |
---|
[507] | 260 | cat > ${logFile} <<EOF |
---|
| 261 | Ok gain finished |
---|
| 262 | EOF |
---|
| 263 | |
---|
| 264 | else |
---|
| 265 | ${scriptpath}/Objs/analyse -act gain -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debuglev 1 >& ${logFile} |
---|
| 266 | fi |
---|
| 267 | # |
---|
| 268 | $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods" |
---|
| 269 | rcstatus=`$GREP -i "OK gain finished" ${logFile} | $WC -l` |
---|
| 270 | if [ ${rcstatus} -eq 0 ]; then |
---|
| 271 | $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}" |
---|
| 272 | $ECHO " START logfile" |
---|
| 273 | $CAT ${logFile} |
---|
| 274 | $ECHO " END logFile" |
---|
| 275 | #clean and leave |
---|
| 276 | cd ${aboveOnOffDir} |
---|
| 277 | $RM -rf ./* |
---|
| 278 | continue |
---|
| 279 | fi |
---|
| 280 | #Save into Irods |
---|
| 281 | $ECHO "DEBUG (${scriptName}): START save output files" |
---|
| 282 | $LS ${aboveOnOffDir} |
---|
| 283 | #use -f option of iput ONLY to force override |
---|
| 284 | if [ ${simulationMode} = "On" ]; then |
---|
| 285 | $ECHO "SIMUL: here we look for gain file and put them in Irods" |
---|
| 286 | else |
---|
| 287 | $FIND . -name "gain_*" -print | $XARGS -i iput -v -K {} ${i} |
---|
| 288 | fi |
---|
| 289 | #save analysis logfile |
---|
| 290 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 291 | $CP ${logFile} ${tmppublicpath} |
---|
| 292 | $ECHO "DEBUG (${scriptName}): END save output files" |
---|
| 293 | #clean |
---|
| 294 | cd ${aboveOnOffDir} |
---|
| 295 | $RM -rf ./* |
---|
| 296 | done |
---|
| 297 | |
---|
| 298 | exit 0 |
---|