[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;; |
---|
| 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}";; |
---|
| 66 | *) ECHO "FATAL (${scriptName}): process ${sourceRadio} not yet foreseen" |
---|
| 67 | exit 1;; |
---|
| 68 | esac |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" ` |
---|
| 72 | |
---|
| 73 | #Path to public backupable path |
---|
| 74 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | #temporary files to synchronize scripts |
---|
| 78 | tmppublicpath=${TMPPUBLICPATH} |
---|
| 79 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 80 | #clean previous spurious files |
---|
| 81 | $RM -f ${tmppublicpath}/*.finished |
---|
| 82 | |
---|
| 83 | |
---|
| 84 | #Path where the job will do temporary IO |
---|
| 85 | if [ ${ENVIRONMENT} = "INTERACTIVE" ]; then |
---|
| 86 | iojobpath="/sps/baoradio/AmasNancay/JEC" |
---|
| 87 | $MKDIR -p $iojobpath |
---|
| 88 | $ECHO "Usage in INTERACTIVE may be destructive... To be used with great care !!!!" |
---|
| 89 | exit 0; |
---|
| 90 | elif [ ${ENVIRONMENT} = "BATCH" ] ; then |
---|
| 91 | iojobpath=${TMPBATCH} |
---|
| 92 | else |
---|
| 93 | $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed" |
---|
| 94 | exit 1 |
---|
| 95 | fi |
---|
| 96 | cd ${iojobpath} |
---|
| 97 | |
---|
| 98 | localpath="${sourceRadio}" |
---|
| 99 | $MKDIR -p ./${localpath} |
---|
| 100 | cd ./${localpath} |
---|
| 101 | |
---|
| 102 | #save the top directory |
---|
| 103 | topDir=`pwd` |
---|
| 104 | |
---|
| 105 | #Path of the utility scripts |
---|
| 106 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay" |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
| 110 | #get the daq current irod status |
---|
| 111 | #tag=`${DATE} +%F` |
---|
| 112 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 113 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
| 114 | |
---|
| 115 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
| 116 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 117 | exit 1 |
---|
| 118 | fi |
---|
| 119 | |
---|
| 120 | # |
---|
| 121 | $ECHO "You have selected sourceRadio = $sourceRadio [date = ${dateSelected}]" |
---|
| 122 | tableau=( `$GREP -i "${dateSelected}${srclower}" ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 123 | IFS=' |
---|
| 124 | ' |
---|
| 125 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 126 | IFS=$DefaultIFS |
---|
| 127 | |
---|
| 128 | |
---|
| 129 | for i in ${tableau[@]} |
---|
| 130 | do |
---|
| 131 | # start a "fresh" session |
---|
| 132 | cd ${topDir} |
---|
| 133 | $LS | $XARGS -i $RM -rf {} |
---|
| 134 | |
---|
| 135 | $ECHO "DEBUG (${scriptName}): irods root dir $i" |
---|
| 136 | dateDAQ=`$ECHO ${i} | $AWK '{split($0,a,"/"); print a[6];}' | $AWK "{sub(/${srclower}/,\"\"); print}"` |
---|
| 137 | |
---|
| 138 | $LS -lrt |
---|
| 139 | |
---|
| 140 | ###### |
---|
| 141 | $ECHO ">>>>>>>>>>>>> ANALYSIS Part of ${sourceRadio} ${dateDAQ}" |
---|
| 142 | #go to the .../source/date-sourcelowercase directory |
---|
| 143 | $MKDIR -p ${topDir}/${dateDAQ}${srclower} |
---|
| 144 | cd ${topDir}/${dateDAQ}${srclower} |
---|
| 145 | aboveOnOffDir=`pwd` |
---|
| 146 | $ECHO "DEBUG (${scriptName}): we are in directory: <`pwd`>" |
---|
| 147 | # So the input files are there, so the fits file can be determined |
---|
| 148 | mode="Off" |
---|
| 149 | spectraGenDirName=`$ECHO ${gaincycle} | $AWK '{match($0,"[a-zA-Z]+",arr); print arr[0]}'` |
---|
| 150 | cycleNumber=`$ECHO ${gaincycle} | $AWK '{match($0,"[0-9]+",arr); print arr[0]}'` |
---|
| 151 | #care: the gaincycle variable contains the cycle number |
---|
| 152 | $ECHO "DEBUG (${scriptName}): START download the fits files" |
---|
| 153 | inFileDirectory="./${mode}" |
---|
| 154 | $MKDIR -p ${inFileDirectory} |
---|
| 155 | irodsDownDir="${i}/${mode}/${gaincycle}" |
---|
| 156 | OUT=./getInFits.$$ |
---|
| 157 | iget -r -f -K ${irodsDownDir} ${inFileDirectory} > ${OUT} 2>&1 |
---|
| 158 | $LS ${inFileDirectory}/${gaincycle} |
---|
| 159 | igetStatus=`$GREP "^ERROR" ${OUT}` |
---|
| 160 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 161 | $ECHO "FATAL (${scriptName}): error while iget fits files:" |
---|
| 162 | $ECHO $igetStatus |
---|
| 163 | continue |
---|
| 164 | fi |
---|
| 165 | $RM -f ${OUT} |
---|
| 166 | $ECHO "DEBUG (${scriptName}): END download the fits files" |
---|
| 167 | #Get sca files |
---|
| 168 | $ECHO "DEBUG (${scriptName}): START call getscafiles.sh ${sourceRadio} ${dateDAQ}" |
---|
| 169 | OUT1=./getScaStatus.$$ |
---|
| 170 | $RM -f ${tmppublicpath}/getscafiles.finished |
---|
| 171 | ${scriptpath}/getscafiles.sh ${sourceRadio} ${dateDAQ} > ${OUT1} 2>&1 |
---|
| 172 | while [ ! -f "${tmppublicpath}/getscafiles.finished" ]; do |
---|
| 173 | $ECHO "INFO (${scriptName}): waiting for ${tmppublicpath}/getscafiles.finished" |
---|
| 174 | date +%T |
---|
| 175 | sleep 30 |
---|
| 176 | done |
---|
| 177 | $RM ${tmppublicpath}/getscafiles.finished |
---|
| 178 | $ECHO "DEBUG (${scriptName}): END" |
---|
| 179 | # |
---|
| 180 | getScaStatus=`$GREP "^\(FATAL\|ERROR\)" ${OUT1}` |
---|
| 181 | # |
---|
| 182 | if [ "<${getScaStatus}>" != "<>" ]; then |
---|
| 183 | $ECHO "FATAL (${scriptName}): error to get sca file for $sourceRadio $dateDAQ" |
---|
| 184 | $ECHO "DEBUG (${scriptName}): START with cat ${OUT1}" |
---|
| 185 | $CAT ${OUT1} |
---|
| 186 | $ECHO "DEBUG (${scriptName}): END" |
---|
| 187 | continue |
---|
| 188 | fi |
---|
| 189 | $RM -f ${OUT1} |
---|
| 190 | $ECHO "DEBUG (${scriptName}): where am i `pwd`" |
---|
| 191 | $LS -lrt |
---|
| 192 | |
---|
| 193 | scaFile=`$FIND . -name "sca*.sum.trans" | $XARGS -i basename {}` |
---|
| 194 | # |
---|
| 195 | #the default spectra name is medfiltmtx, otherwise use -specname <a_string> |
---|
| 196 | logFile="analyse_GAIN_${sourceRadio}_${dateDAQ}.log" |
---|
| 197 | $ECHO "DEBUG (${scriptName}): execute the analysis... should not take long. `date`" |
---|
| 198 | if [ ${simulationMode} = "On" ]; then |
---|
| 199 | $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}" |
---|
| 200 | cat > ${logFile} <<EOF |
---|
| 201 | Ok gain finished |
---|
| 202 | EOF |
---|
| 203 | |
---|
| 204 | else |
---|
| 205 | ${scriptpath}/Objs/analyse -act gain -inPath ${iojobpath} -source ${sourceRadio} -date ${dateDAQ} -sca ${scaFile} -specdir ${spectraGenDirName} -mode ${mode} -numcycle ${cycleNumber},${cycleNumber} -debuglev 1 >& ${logFile} |
---|
| 206 | fi |
---|
| 207 | # |
---|
| 208 | $ECHO "DEBUG (${scriptName}): analysis finished `date`. Look for errors before saving to Irods" |
---|
| 209 | rcstatus=`$GREP -i "OK gain finished" ${logFile} | $WC -l` |
---|
| 210 | if [ ${rcstatus} -eq 0 ]; then |
---|
| 211 | $ECHO "INFO (${scriptName}): analysis problem for ${sourceRadio} ${dateDAQ}" |
---|
| 212 | $ECHO " START logfile" |
---|
| 213 | $CAT ${logFile} |
---|
| 214 | $ECHO " END logFile" |
---|
| 215 | #clean and leave |
---|
| 216 | cd ${aboveOnOffDir} |
---|
| 217 | $RM -rf ./* |
---|
| 218 | continue |
---|
| 219 | fi |
---|
| 220 | #Save into Irods |
---|
| 221 | $ECHO "DEBUG (${scriptName}): START save output files" |
---|
| 222 | $LS ${aboveOnOffDir} |
---|
| 223 | #use -f option of iput ONLY to force override |
---|
| 224 | if [ ${simulationMode} = "On" ]; then |
---|
| 225 | $ECHO "SIMUL: here we look for gain file and put them in Irods" |
---|
| 226 | else |
---|
| 227 | $FIND . -name "gain_*" -print | $XARGS -i iput -f -v -K {} ${i} |
---|
| 228 | fi |
---|
| 229 | #save analysis logfile |
---|
| 230 | $LS -l ${tmppublicpath} > /dev/null |
---|
| 231 | $CP ${logFile} ${tmppublicpath} |
---|
| 232 | $ECHO "DEBUG (${scriptName}): END save output files" |
---|
| 233 | #clean |
---|
| 234 | cd ${aboveOnOffDir} |
---|
| 235 | $LS | $XARGS -i $RM -rf {} |
---|
| 236 | |
---|
| 237 | done |
---|
| 238 | |
---|
| 239 | exit 0 |
---|