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