| 1 | #!/bin/sh
 | 
|---|
| 2 | #
 | 
|---|
| 3 | #Script sh d'extraction de fichiers d'irod 
 | 
|---|
| 4 | # Auteur: JE Campagne (LAL Orsay)
 | 
|---|
| 5 | # Creation: 2 mai 2011
 | 
|---|
| 6 | # adaptation pour le CC 17 juin 2011
 | 
|---|
| 7 | DATE=/bin/date
 | 
|---|
| 8 | GREP=/bin/grep
 | 
|---|
| 9 | AWK=/bin/awk
 | 
|---|
| 10 | ECHO=/bin/echo
 | 
|---|
| 11 | TR=/usr/bin/tr
 | 
|---|
| 12 | MKDIR=/bin/mkdir
 | 
|---|
| 13 | CAT=/bin/cat
 | 
|---|
| 14 | RM=/bin/rm
 | 
|---|
| 15 | LS=/bin/ls
 | 
|---|
| 16 | DefaultIFS=$' \t\n'
 | 
|---|
| 17 | IFS=$DefaultIFS
 | 
|---|
| 18 | 
 | 
|---|
| 19 | scriptName="`basename $0`"
 | 
|---|
| 20 | $ECHO "Processing script ${scriptName} at `date`"
 | 
|---|
| 21 | 
 | 
|---|
| 22 | 
 | 
|---|
| 23 | 
 | 
|---|
| 24 | if [ ! $# = 4 ]; then
 | 
|---|
| 25 |   $ECHO "usage: ${scriptName} <source:ex. Abell85> <date:YYYYMMDD> first last"
 | 
|---|
| 26 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 27 | #  touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 28 |   exit 0
 | 
|---|
| 29 | fi
 | 
|---|
| 30 | 
 | 
|---|
| 31 | # Irods environment settings
 | 
|---|
| 32 | #export PATH=$PATH:/home/bao/irods2.5_LinuxSL5
 | 
|---|
| 33 | . /usr/local/shared/bin/irods_env.sh -noverbose
 | 
|---|
| 34 | 
 | 
|---|
| 35 | sourceRadio=$1
 | 
|---|
| 36 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
 | 
|---|
| 37 | dateDAQ=$2
 | 
|---|
| 38 | 
 | 
|---|
| 39 | #Path to public backupable path
 | 
|---|
| 40 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
 | 
|---|
| 41 | 
 | 
|---|
| 42 | #temporary files to synchronize scripts
 | 
|---|
| 43 | tmppublicpath=${TMPPUBLICPATH}
 | 
|---|
| 44 | $LS -l ${tmppublicpath} > /dev/null
 | 
|---|
| 45 | 
 | 
|---|
| 46 | 
 | 
|---|
| 47 | #Path where the job will do temporary IO
 | 
|---|
| 48 | if [ ${ENVIRONMENT} == "INTERACTIVE" ]; then
 | 
|---|
| 49 |     iojobpath="/sps/baoradio/AmasNancay/JEC"
 | 
|---|
| 50 |     $MKDIR -p $iojobpath
 | 
|---|
| 51 | elif [ ${ENVIRONMENT} == "BATCH" ] ; then
 | 
|---|
| 52 |     iojobpath=${TMPBATCH}
 | 
|---|
| 53 | else
 | 
|---|
| 54 |    $ECHO "FATAL (${scriptName}): environment is ${ENVIRONMENT} not allowed"
 | 
|---|
| 55 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 56 | #   touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 57 |    exit 1
 | 
|---|
| 58 | fi
 | 
|---|
| 59 | cd ${iojobpath}
 | 
|---|
| 60 | 
 | 
|---|
| 61 | localpath="${sourceRadio}/${dateDAQ}${srclower}"
 | 
|---|
| 62 | $MKDIR -p ./${localpath}
 | 
|---|
| 63 | cd ./${localpath}
 | 
|---|
| 64 | 
 | 
|---|
| 65 | #Path of the utility scripts
 | 
|---|
| 66 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
 | 
|---|
| 67 | 
 | 
|---|
| 68 | 
 | 
|---|
| 69 | #determine the sequence of signal files to download
 | 
|---|
| 70 | #JEC 1/10/11 Use generic baodaqstatus name 
 | 
|---|
| 71 | #get the daq current irod status
 | 
|---|
| 72 | #tag=`${DATE} +%F`
 | 
|---|
| 73 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt
 | 
|---|
| 74 | OUT1=${publicpath}/baodaqstatus-current.txt
 | 
|---|
| 75 | 
 | 
|---|
| 76 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
 | 
|---|
| 77 | #     $ECHO "We should bring the DAQ status more up to date, this take few 
 | 
|---|
| 78 | # sec..."
 | 
|---|
| 79 | #     $RM -f ${tmppublicpath}/statusdaq.finished
 | 
|---|
| 80 | #     ${scriptpath}/statusdaq.sh > ${OUT1}
 | 
|---|
| 81 | #     while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
 | 
|---|
| 82 | #       $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
 | 
|---|
| 83 | #       date +%T
 | 
|---|
| 84 | #       sleep 30
 | 
|---|
| 85 | #     done
 | 
|---|
| 86 | #     $RM ${tmppublicpath}/statusdaq.finished
 | 
|---|
| 87 |     $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
 | 
|---|
| 88 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 89 | #    touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 90 |     exit 1
 | 
|---|
| 91 | fi
 | 
|---|
| 92 | 
 | 
|---|
| 93 | nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'` 
 | 
|---|
| 94 | if [ "<${nfiles}>" == "<>" ]; then
 | 
|---|
| 95 |     $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>"
 | 
|---|
| 96 |     $CAT $OUT1
 | 
|---|
| 97 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 98 | #    touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 99 |     exit 1
 | 
|---|
| 100 | fi
 | 
|---|
| 101 | 
 | 
|---|
| 102 | 
 | 
|---|
| 103 | firstFile=$3
 | 
|---|
| 104 | if [ ${firstFile} -gt  ${nfiles} ]; then
 | 
|---|
| 105 |     $ECHO "FATAL (${scriptName}): ${firstFile} >  ${nfiles}"
 | 
|---|
| 106 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 107 | #    touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 108 |     exit 1
 | 
|---|
| 109 | fi
 | 
|---|
| 110 | 
 | 
|---|
| 111 | 
 | 
|---|
| 112 | lastFile=$4
 | 
|---|
| 113 | if [ ${lastFile} -gt  ${nfiles} ]; then
 | 
|---|
| 114 |     $ECHO "FATAL (${scriptName}): ${lastFile} >  ${nfiles}"
 | 
|---|
| 115 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 116 | #    touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 117 |     exit 1
 | 
|---|
| 118 | fi
 | 
|---|
| 119 | 
 | 
|---|
| 120 | if [ ${firstFile} -gt  ${lastFile} ]; then
 | 
|---|
| 121 |     $ECHO "FATAL (${scriptName}): ${firstFile} >  ${lastFile}"
 | 
|---|
| 122 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 123 | #    touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 124 |     exit 1
 | 
|---|
| 125 | fi
 | 
|---|
| 126 | 
 | 
|---|
| 127 | 
 | 
|---|
| 128 | dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}"
 | 
|---|
| 129 | dirLocal="."
 | 
|---|
| 130 | 
 | 
|---|
| 131 | ##$ECHO "Ready to download [${firstFile},${lastFile}] in $dirLocal from $dirIrod"
 | 
|---|
| 132 | #Nb we are in the localpath
 | 
|---|
| 133 | $MKDIR -p Fiber1
 | 
|---|
| 134 | $MKDIR -p Fiber2
 | 
|---|
| 135 | 
 | 
|---|
| 136 | OUT2=./igetStatus.$$
 | 
|---|
| 137 | 
 | 
|---|
| 138 | n=$firstFile
 | 
|---|
| 139 | while [[ $n -le $lastFile ]]; do
 | 
|---|
| 140 |    iget -r -f -v -K ${dirIrod}/Fiber1/signal$n.fits ${dirLocal}/Fiber1 >${OUT2} 2>&1
 | 
|---|
| 141 |    igetStatus=`$GREP "^ERROR" ${OUT2}`
 | 
|---|
| 142 |    if [ "<$igetStatus>" != "<>" ]; then
 | 
|---|
| 143 |        $ECHO "FATAL (${scriptName}): error while iget:"
 | 
|---|
| 144 |        $ECHO $igetStatus
 | 
|---|
| 145 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 146 | #       touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 147 |        exit 1
 | 
|---|
| 148 |    fi
 | 
|---|
| 149 |    iget -r -f -v -K ${dirIrod}/Fiber2/signal$n.fits ${dirLocal}/Fiber2 >${OUT2} 2>&1
 | 
|---|
| 150 |    igetStatus=`$GREP "^ERROR" ${OUT2}`
 | 
|---|
| 151 |    if [ "<$igetStatus>" != "<>" ]; then
 | 
|---|
| 152 |        $ECHO "FATAL (${scriptName}): error while iget:"
 | 
|---|
| 153 |        $ECHO $igetStatus
 | 
|---|
| 154 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 155 | #       touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 156 |        exit 1
 | 
|---|
| 157 |    fi
 | 
|---|
| 158 |    n=$(($n+1))
 | 
|---|
| 159 | done
 | 
|---|
| 160 | 
 | 
|---|
| 161 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
| 162 | #touch ${tmppublicpath}/getsignalfiles.finished
 | 
|---|
| 163 | exit 0 | 
|---|