[570] | 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 | dateSelected= |
---|
| 35 | #use -sim option to simulate processing (debug the script as if...) |
---|
| 36 | simulationMode=Off |
---|
| 37 | while [ $# -gt 0 ] |
---|
| 38 | do |
---|
| 39 | case "$1" in |
---|
| 40 | -src) sourceRadio=$2; shift;; |
---|
[583] | 41 | -date) dateSelected=$2; shift;; |
---|
[571] | 42 | -sim) simulationMode=On;; |
---|
[570] | 43 | -h) |
---|
| 44 | echo >&2 \ |
---|
| 45 | "usage: $0 -src souce -date YYYYMMDD [-sim]" |
---|
| 46 | exit 1;; |
---|
| 47 | *) break;; # terminate while loop |
---|
| 48 | esac |
---|
| 49 | shift |
---|
| 50 | done |
---|
| 51 | |
---|
| 52 | if [ ${simulationMode} = "On" ]; then |
---|
| 53 | $ECHO "INFO ${scriptName} running in SIMUL mode" |
---|
| 54 | fi |
---|
| 55 | |
---|
| 56 | |
---|
| 57 | if [ "<${sourceRadio}>" = "<>" ]; then |
---|
| 58 | $ECHO "FATAL: You have forgotten to select the source option (-src)" |
---|
| 59 | exit 1 |
---|
| 60 | fi |
---|
| 61 | |
---|
| 62 | case ${sourceRadio} in |
---|
| 63 | Abell85) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 64 | Abell2440) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 65 | Abell1205) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
[598] | 66 | NGC4383) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
[635] | 67 | NGC4383DR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 68 | 3C273) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 69 | 3C273DR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 70 | 3C161DR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
| 71 | 3C161BDR) $ECHO "INFO (${scriptName}): process ${sourceRadio}";; |
---|
[570] | 72 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen" |
---|
| 73 | exit 1;; |
---|
| 74 | esac |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
| 78 | |
---|
| 79 | #Path to public backupable path |
---|
| 80 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 81 | |
---|
| 82 | |
---|
| 83 | #temporary files to synchronize scripts |
---|
| 84 | tmppublicpath=${TMPPUBLICPATH} |
---|
| 85 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 86 | #clean previous spurious files |
---|
| 87 | $RM -f ${tmppublicpath}/*.finished |
---|
| 88 | |
---|
| 89 | |
---|
| 90 | #Path where the job will do temporary IO |
---|
[579] | 91 | . ${SCRIPTPATH}/isInteractive.sh |
---|
| 92 | isInteractive=$(isInteractive) |
---|
| 93 | if [ ${isInteractive} == "1" ]; then |
---|
| 94 | $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!" |
---|
| 95 | exit 0; |
---|
[570] | 96 | fi |
---|
[579] | 97 | |
---|
| 98 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
| 99 | iojobpath=$(set_iojobpath) |
---|
[570] | 100 | cd ${iojobpath} |
---|
| 101 | |
---|
| 102 | localpath="${sourceRadio}" |
---|
| 103 | $MKDIR -p ./${localpath} |
---|
| 104 | cd ./${localpath} |
---|
| 105 | |
---|
| 106 | #save the top directory |
---|
| 107 | topDir=`pwd` |
---|
| 108 | |
---|
| 109 | #Path of the utility scripts |
---|
[575] | 110 | scriptpath=${SCRIPTPATH} |
---|
[570] | 111 | |
---|
| 112 | |
---|
| 113 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
| 114 | #get the daq current irod status |
---|
| 115 | #tag=`${DATE} +%F` |
---|
| 116 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 117 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
| 118 | |
---|
| 119 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
| 120 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 121 | exit 1 |
---|
| 122 | fi |
---|
| 123 | |
---|
| 124 | # |
---|
| 125 | $ECHO "You have selected sourceRadio = $sourceRadio [date = ${dateSelected}]" |
---|
[626] | 126 | #JEC 14/12/11 One should take care of DR extension for Drift Scan |
---|
| 127 | #tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 128 | tableau=( `$GREP -i "${sourceRadio}/${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
[570] | 129 | IFS=' |
---|
| 130 | ' |
---|
| 131 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 132 | IFS=$DefaultIFS |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | for i in ${tableau[@]} |
---|
| 136 | do |
---|
| 137 | # start a "fresh" session |
---|
| 138 | cd ${topDir} |
---|
| 139 | $LS | $XARGS -i $RM -rf {} |
---|
| 140 | |
---|
| 141 | $ECHO "DEBUG (${scriptName}): irods root dir $i" |
---|
| 142 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"` |
---|
| 143 | |
---|
| 144 | $LS -lrt |
---|
| 145 | |
---|
| 146 | ###### |
---|
| 147 | $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}" |
---|
| 148 | #go to the .../source/date-sourcelowercase directory |
---|
| 149 | $MKDIR -p ${topDir}/${dateDAQ}${srclower} |
---|
| 150 | cd ${topDir}/${dateDAQ}${srclower} |
---|
| 151 | aboveOnOffDir=`pwd` |
---|
| 152 | $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>" |
---|
| 153 | # So the input files are there, so the fits file can be determined |
---|
| 154 | mode="Off" |
---|
[583] | 155 | |
---|
| 156 | input4gainOk1=`ils ${i}/Off 2>&1 | $GREP -i "^ERROR" | $WC -l` |
---|
| 157 | input4gainOk2=`ils ${i}/Off 2>&1 | $GREP -i "gaincycle"` |
---|
| 158 | if [ $input4gainOk1 -eq 0 -a "<${input4gainOk2}>" != "<>" ]; then |
---|
| 159 | gaincycle=`$ECHO ${input4gainOk2} | $AWK '($1 == "C-"){print $2}'| $XARGS -i basename {}` |
---|
| 160 | else |
---|
| 161 | $ECHO "INFO ${scriptName}: no gaincycle for ${i}" |
---|
| 162 | continue |
---|
| 163 | fi |
---|
| 164 | |
---|
[570] | 165 | spectraGenDirName=`$ECHO ${gaincycle} | $AWK '{match($0,"[a-zA-Z]+",arr); print arr[0]}'` |
---|
| 166 | cycleNumber=`$ECHO ${gaincycle} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'` |
---|
| 167 | #care: the gaincycle variable contains the cycle number |
---|
| 168 | $ECHO "DEBUG (${scriptName}): START download the fits files" |
---|
| 169 | inFileDirectory="./${mode}" |
---|
| 170 | $MKDIR -p ${inFileDirectory} |
---|
| 171 | irodsDownDir="${i}/${mode}/${gaincycle}" |
---|
| 172 | OUT=./getInFits.$$ |
---|
| 173 | iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1 |
---|
| 174 | $LS ${inFileDirectory}/${gaincycle} |
---|
| 175 | igetStatus=`$GREP "^ERROR" ${OUT}` |
---|
| 176 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 177 | $ECHO "FATAL (${scriptName}): error while iget fits files:" |
---|
| 178 | $ECHO $igetStatus |
---|
| 179 | continue |
---|
| 180 | fi |
---|
| 181 | $RM -f ${OUT} |
---|
| 182 | $ECHO "DEBUG (${scriptName}): END download the fits files" |
---|
| 183 | #Get sca files |
---|
| 184 | $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}" |
---|
| 185 | OUT1=./getScaStatus.$$ |
---|
[599] | 186 | # $RM -f ${tmppublicpath}/getscafiles.finished |
---|
[570] | 187 | ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1 |
---|
[583] | 188 | # AST 21/10/2011: comment while as it blocks the job |
---|
| 189 | # while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do |
---|
| 190 | # $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished" |
---|
| 191 | # date +%T |
---|
| 192 | # sleep 30 |
---|
| 193 | # done |
---|
[599] | 194 | # $RM ${tmppublicpath}/getscafiles.finished |
---|
[570] | 195 | $ECHO "DEBUG (${scriptName}): END" |
---|
| 196 | # |
---|
| 197 | getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}` |
---|
| 198 | # |
---|
| 199 | if [ "<${getScaStatus}>" != "<>" ]; then |
---|
| 200 | $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ" |
---|
| 201 | $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}" |
---|
| 202 | $CAT ${OUT1} |
---|
| 203 | $ECHO "DEBUG (${scriptName}): END" |
---|
| 204 | continue |
---|
| 205 | fi |
---|
| 206 | $RM -f ${OUT1} |
---|
| 207 | $ECHO "DEBUG (${scriptName}): where am i `pwd`" |
---|
| 208 | $LS -lrt |
---|
| 209 | |
---|
| 210 | scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}` |
---|
| 211 | # |
---|
| 212 | #the default spectra name is medfiltmtx, otherwise use -specname <a_string> |
---|
| 213 | logFile="analyse_GAIN_${sourceRadio}_${dateDAQ}.log" |
---|
| 214 | $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`" |
---|
| 215 | if [ ${simulationMode} = "On" ]; then |
---|
| 216 | $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}" |
---|
| 217 | cat > ${logFile} <<EOF |
---|
| 218 | Ok gain finished |
---|
| 219 | EOF |
---|
| 220 | |
---|
| 221 | else |
---|
| 222 | ${scriptpath}/Objs/analyse -act gain -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debuglev 1 >& ${logFile} |
---|
| 223 | fi |
---|
| 224 | # |
---|
| 225 | $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods" |
---|
| 226 | rcstatus=`$GREP -i "OK gain finished" ${logFile} | $WC -l` |
---|
| 227 | if [ ${rcstatus} -eq 0 ]; then |
---|
| 228 | $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}" |
---|
| 229 | $ECHO " START logfile" |
---|
| 230 | $CAT ${logFile} |
---|
| 231 | $ECHO " END logFile" |
---|
| 232 | #clean and leave |
---|
| 233 | cd ${aboveOnOffDir} |
---|
| 234 | $RM -rf ./* |
---|
| 235 | continue |
---|
| 236 | fi |
---|
| 237 | #Save into Irods |
---|
| 238 | $ECHO "DEBUG (${scriptName}): START save output files" |
---|
| 239 | $LS ${aboveOnOffDir} |
---|
| 240 | #use -f option of iput ONLY to force override |
---|
| 241 | if [ ${simulationMode} = "On" ]; then |
---|
| 242 | $ECHO "SIMUL: here we look for gain file and put them in Irods" |
---|
| 243 | else |
---|
| 244 | $FIND . -name "gain_*" -print | $XARGS -i iput -f -v -K {} ${i} |
---|
| 245 | fi |
---|
| 246 | #save analysis logfile |
---|
| 247 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 248 | $CP ${logFile} ${tmppublicpath} |
---|
| 249 | $ECHO "DEBUG (${scriptName}): END save output files" |
---|
| 250 | #clean |
---|
| 251 | cd ${aboveOnOffDir} |
---|
| 252 | $LS | $XARGS -i $RM -rf {} |
---|
| 253 | |
---|
| 254 | done |
---|
| 255 | |
---|
| 256 | exit 0 |
---|