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