| [507] | 1 | #!/bin/sh
 | 
|---|
 | 2 | #Get SCA file and summary + transformed date file
 | 
|---|
 | 3 | #
 | 
|---|
 | 4 | DATE=/bin/date
 | 
|---|
 | 5 | GREP=/bin/grep
 | 
|---|
 | 6 | AWK=/bin/awk
 | 
|---|
 | 7 | ECHO=/bin/echo
 | 
|---|
 | 8 | TR=/usr/bin/tr
 | 
|---|
 | 9 | MKDIR=/bin/mkdir
 | 
|---|
 | 10 | CAT=/bin/cat
 | 
|---|
 | 11 | PRINTF=/usr/bin/printf
 | 
|---|
 | 12 | RM=/bin/rm
 | 
|---|
 | 13 | LS=/bin/ls
 | 
|---|
 | 14 | DefaultIFS=$' \t\n'
 | 
|---|
 | 15 | IFS=$DefaultIFS
 | 
|---|
 | 16 | 
 | 
|---|
 | 17 | scriptName="`basename $0`"
 | 
|---|
 | 18 | $ECHO "Processing script ${scriptName} at `date`"
 | 
|---|
 | 19 | 
 | 
|---|
 | 20 | 
 | 
|---|
 | 21 | if [ ! $# = 2 ]; then
 | 
|---|
 | 22 |   $ECHO "usage: ${script
 | 
|---|
 | 23 | Name} <source:ex. Abell85> <date:YYYYMMDD>"
 | 
|---|
| [540] | 24 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 25 | #  touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
| [507] | 26 |   exit 0
 | 
|---|
 | 27 | fi
 | 
|---|
 | 28 | 
 | 
|---|
 | 29 | # Irods environment settings
 | 
|---|
 | 30 | #export PATH=$PATH:/home/bao/irods2.5_LinuxSL5
 | 
|---|
 | 31 | . /usr/local/shared/bin/irods_env.sh -noverbose
 | 
|---|
 | 32 | 
 | 
|---|
 | 33 | 
 | 
|---|
 | 34 | sourceRadio=$1
 | 
|---|
 | 35 | srclower=`${ECHO} ${sourceRadio} | ${TR} "[:upper:]" "[:lower:]" `
 | 
|---|
 | 36 | dateDAQ=$2
 | 
|---|
 | 37 | 
 | 
|---|
 | 38 | 
 | 
|---|
 | 39 | #Path to public backupable path
 | 
|---|
 | 40 | publicpath="/afs/in2p3.fr/home/c/campagne/public"
 | 
|---|
 | 41 | 
 | 
|---|
 | 42 | #temporary files to synchronize scripts
 | 
|---|
| [516] | 43 | tmppublicpath=${TMPPUBLICPATH}
 | 
|---|
| [507] | 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"
 | 
|---|
| [540] | 55 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 56 | #   touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
| [507] | 57 |    exit 1
 | 
|---|
 | 58 | fi
 | 
|---|
 | 59 | cd ${iojobpath}
 | 
|---|
 | 60 | 
 | 
|---|
 | 61 | localpath="${sourceRadio}/${dateDAQ}${srclower}"
 | 
|---|
 | 62 | $MKDIR -p ./${localpath}
 | 
|---|
 | 63 | cd ./${localpath}
 | 
|---|
 | 64 | 
 | 
|---|
 | 65 | 
 | 
|---|
 | 66 | #Path of the utility scripts
 | 
|---|
| [510] | 67 | scriptpath="/afs/in2p3.fr/home/c/campagne/private/work/AmasNancay"
 | 
|---|
| [507] | 68 | 
 | 
|---|
| [540] | 69 | #JEC 1/10/11 Use generic baodaqstatus name 
 | 
|---|
| [507] | 70 | #look if the run exists
 | 
|---|
| [540] | 71 | #tag=`${DATE} +%F`
 | 
|---|
 | 72 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt
 | 
|---|
 | 73 | OUT1=${publicpath}/baodaqstatus-current.txt
 | 
|---|
 | 74 | 
 | 
|---|
| [507] | 75 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then
 | 
|---|
 | 76 | #    $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..."
 | 
|---|
 | 77 | #    $RM -f ${tmppublicpath}/statusdaq.finished
 | 
|---|
 | 78 | #    ${scriptpath}/statusdaq.sh > ${OUT1}
 | 
|---|
 | 79 | #    while [ ! -f "${tmppublicpath}/statusdaq.finished" ]; do
 | 
|---|
 | 80 | #       $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/statusdaq.finished"
 | 
|---|
 | 81 | #       date +%T
 | 
|---|
 | 82 | #       sleep 30
 | 
|---|
 | 83 | #     done
 | 
|---|
 | 84 | #     $RM ${tmppublicpath}/statusdaq.finished
 | 
|---|
 | 85 |     $ECHO "FATAL (${scriptName}): ${OUT1} is missing or not readable..."
 | 
|---|
| [540] | 86 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 87 | #    touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
| [507] | 88 |     exit 1
 | 
|---|
 | 89 | fi
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 | nfiles=`${GREP} "${sourceRadio}.*${dateDAQ}" ${OUT1} | ${AWK} '(NF==4){print $4}'` 
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 | if [ "<${nfiles}>" = "<>" ]; then
 | 
|---|
 | 94 |     $ECHO "FATAL (${scriptName}): No run found for <${sourceRadio}> and date <${dateDAQ}>"
 | 
|---|
| [540] | 95 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 96 | #    touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
| [507] | 97 |     exit 1
 | 
|---|
 | 98 | fi
 | 
|---|
 | 99 | 
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 | #Look if the run should/can be prepared wrt SCA file transformation 
 | 
|---|
 | 102 | OUT2=./scaStatus.$$
 | 
|---|
| [540] | 103 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 104 | #$RM -f ${tmppublicpath}/scaextractor.finished
 | 
|---|
| [507] | 105 | ${scriptpath}/scaextractor.sh $sourceRadio > ${OUT2} 2>&1
 | 
|---|
| [540] | 106 | #while [ ! -f "${tmppublicpath}/scaextractor.finished" ]; do
 | 
|---|
 | 107 | #    $ECHO "INFO (${scriptName}); waiting for ${tmppublicpath}/scaextractor.finished"
 | 
|---|
 | 108 | #    date +%T
 | 
|---|
 | 109 | #    sleep 30
 | 
|---|
 | 110 | #done
 | 
|---|
 | 111 | #$RM ${tmppublicpath}/scaextractor.finished
 | 
|---|
| [507] | 112 | 
 | 
|---|
 | 113 | 
 | 
|---|
 | 114 | status=`$GREP "^FATAL.*${sourceRadio}.*${dateDAQ}" ${OUT2}`
 | 
|---|
 | 115 | 
 | 
|---|
 | 116 | if [ "<$status>" != "<>" ]; then
 | 
|---|
 | 117 |     $ECHO "FATAL (${scriptName}): connot proceed further with $sourceRadio $dateDAQ"
 | 
|---|
| [540] | 118 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 119 | #    touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
| [507] | 120 |     exit 1
 | 
|---|
 | 121 | fi
 | 
|---|
 | 122 | $RM $OUT2
 | 
|---|
 | 123 | 
 | 
|---|
 | 124 | #dowload sca files...
 | 
|---|
 | 125 | dirIrod="/baoradio/data/AmasNancay/${sourceRadio}/${dateDAQ}${srclower}"
 | 
|---|
 | 126 | dirLocal="."
 | 
|---|
 | 127 | 
 | 
|---|
 | 128 | if [ ! -e $dirLocal ]; then
 | 
|---|
 | 129 |  $MKDIR -p $dirLocal
 | 
|---|
 | 130 | fi
 | 
|---|
 | 131 | 
 | 
|---|
 | 132 | cd $dirLocal
 | 
|---|
 | 133 | 
 | 
|---|
 | 134 | OUT3=./scaFiles.$$
 | 
|---|
 | 135 | ils $dirIrod | $GREP -i "sca" > ${OUT3}
 | 
|---|
 | 136 | tableau=( `$CAT ${OUT3}`  )
 | 
|---|
 | 137 | IFS='
 | 
|---|
 | 138 | '
 | 
|---|
 | 139 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
 | 
|---|
 | 140 | IFS=$DefaultIFS
 | 
|---|
 | 141 | $RM $OUT3
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 | OUT4=./igetStatus.$$
 | 
|---|
 | 144 | for i in ${tableau[@]}
 | 
|---|
 | 145 | do
 | 
|---|
 | 146 |   if [ ! -e $i ]; then
 | 
|---|
 | 147 |     iget -r -f -v -K ${dirIrod}/$i ${dirLocal} > ${OUT4} 2>&1
 | 
|---|
 | 148 |   fi
 | 
|---|
 | 149 | done
 | 
|---|
 | 150 | 
 | 
|---|
 | 151 | igetStatus=`$GREP "^ERROR" ${OUT4}`
 | 
|---|
 | 152 | if [ "<$igetStatus>" != "<>" ]; then
 | 
|---|
 | 153 |   $ECHO "FATAL (${scriptName}): error while iget:"
 | 
|---|
 | 154 |   $ECHO $igetStatus
 | 
|---|
| [540] | 155 | #JEC 29/9/11 avoid finished stuff
 | 
|---|
 | 156 | #  touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
| [507] | 157 |   exit 1
 | 
|---|
 | 158 | fi
 | 
|---|
 | 159 | 
 | 
|---|
 | 160 | $RM -f $OUT4
 | 
|---|
 | 161 | 
 | 
|---|
 | 162 | touch ${tmppublicpath}/getscafiles.finished
 | 
|---|
 | 163 | exit 0
 | 
|---|