[507] | 1 | #!/bin/sh |
---|
| 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 | MKDIR=/bin/mkdir |
---|
| 11 | XARGS=/usr/bin/xargs |
---|
| 12 | SORT=/bin/sort |
---|
| 13 | RM=/bin/rm |
---|
| 14 | defaultIFS=$IFS |
---|
[629] | 15 | SED=/bin/sed |
---|
[507] | 16 | |
---|
| 17 | #set Irods environment |
---|
| 18 | . /usr/local/shared/bin/irods_env.sh -noverbose |
---|
| 19 | |
---|
| 20 | scriptName="`basename $0`" |
---|
| 21 | $ECHO "Processing script ${scriptName} at `date`" |
---|
| 22 | |
---|
| 23 | #which source to analyse |
---|
| 24 | sourceRadio=$1 |
---|
| 25 | |
---|
| 26 | #Path to public backupable path |
---|
| 27 | publicpath="/afs/in2p3.fr/home/c/campagne/public" |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #Path where the job will do temporary IO |
---|
[579] | 31 | . ${SCRIPTPATH}/set_iojobpath.sh |
---|
| 32 | iojobpath=$(set_iojobpath) |
---|
[507] | 33 | cd ${iojobpath} |
---|
| 34 | |
---|
| 35 | localpath="${sourceRadio}" |
---|
| 36 | $MKDIR -p ./${localpath} |
---|
| 37 | cd ./${localpath} |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | #Path of the utility scripts |
---|
[575] | 41 | scriptpath=${SCRIPTPATH} |
---|
[507] | 42 | |
---|
| 43 | |
---|
[540] | 44 | #JEC 1/10/11 Use generic baodaqstatus name |
---|
[507] | 45 | #get the daq current irod status |
---|
[540] | 46 | #tag=`${DATE} +%F` |
---|
| 47 | #OUT1=${publicpath}/baodaqstatus-${tag}.txt |
---|
| 48 | OUT1=${publicpath}/baodaqstatus-current.txt |
---|
[507] | 49 | |
---|
[540] | 50 | if [ ! -e ${OUT1} -o ! -r ${OUT1} ]; then |
---|
| 51 | $ECHO "FATAL (${scriptName}): ${OUT1} has a problem" |
---|
| 52 | exit 1 |
---|
[507] | 53 | fi |
---|
| 54 | |
---|
[540] | 55 | #if [ ! -e ${OUT1} ]; then |
---|
| 56 | # $ECHO "We should bring the DAQ status more up to date, this take 1 or 2sec..." |
---|
| 57 | # ${scriptpath}/statusdaq.sh > ${OUT1} |
---|
| 58 | #fi |
---|
| 59 | |
---|
[507] | 60 | if [ ! "<${sourceRadio}>" = "<>" ]; then |
---|
| 61 | $ECHO "You have selected sourceRadio = $sourceRadio" |
---|
[629] | 62 | # tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` ) |
---|
| 63 | tableau=( `imeta qu -C status "=" hdrNOTDone | $AWK "/$sourceRadio/" | $AWK '{print $2}' ` ) |
---|
[507] | 64 | else |
---|
[629] | 65 | # tableau=( `$CAT ${OUT1} | $AWK '( NF==4 ) { print $2 }'` ) |
---|
| 66 | tableau=( `imeta qu -C status "=" hdrNOTDone | $AWK '{print $2}' | $SED '/^$/d' ` ) |
---|
[507] | 67 | fi |
---|
| 68 | IFS=' |
---|
| 69 | ' |
---|
| 70 | tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 71 | |
---|
| 72 | |
---|
[510] | 73 | workArea="headers" |
---|
| 74 | $MKDIR -p ./${workArea} |
---|
| 75 | cd ./${workArea} |
---|
[507] | 76 | |
---|
| 77 | |
---|
| 78 | nloop4dbg=0 |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | for i in ${tableau[@]} |
---|
| 82 | do |
---|
| 83 | #look if the headers have been already extracted |
---|
| 84 | $ECHO "DEBUG (${scriptName}): irods root dir $i" |
---|
| 85 | for fibdir in Fiber1 Fiber2; do |
---|
| 86 | $ECHO "DEBUG (${scriptName}): Fiber $fibdir" |
---|
[629] | 87 | status=`imeta ls -C ${i}/${fibdir} status | $AWK '/value/{print $2}'` |
---|
| 88 | $ECHO ${status} |
---|
| 89 | ##NB: care should be taken to the fact that ILS returns all the instance of the file (HPSS, disk...) |
---|
| 90 | ## so one should use a trick to count unique instance |
---|
| 91 | # listOfsig=( `ils ${i}/${fibdir} | $GREP -i "signal" | $XARGS -i basename {} | $SORT -k1.7n` ) |
---|
| 92 | # IFS=' |
---|
| 93 | #' |
---|
| 94 | # listOfsig=( $( $PRINTF "%s\n" "${listOfsig[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 95 | # nblinesSIG=${#listOfsig[@]} |
---|
| 96 | # listOfhdr=( `ils ${i}/${fibdir} | $GREP -i "header" | $XARGS -i basename {} | $SORT -k1.7n` ) |
---|
| 97 | # IFS=' |
---|
| 98 | #' |
---|
| 99 | # listOfhdr=( $( $PRINTF "%s\n" "${listOfhdr[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
| 100 | # nblinesHDR=${#listOfhdr[@]} |
---|
| 101 | # $ECHO "(DEBUG) (${scriptName}: test if $nblinesHDR != $nblinesSIG " |
---|
| 102 | # if [ $nblinesHDR != $nblinesSIG ]; then |
---|
| 103 | if [ "<$status>" != "<hdrDone>" ]; then |
---|
| 104 | ##do the header extraction |
---|
| 105 | ##build signal files list |
---|
| 106 | ##loop on signal files |
---|
| 107 | listOfsig=( `ils ${i}/${fibdir} | $GREP -i "signal" | $XARGS -i basename {} | $SORT -k1.7n` ) |
---|
| 108 | IFS=' |
---|
[507] | 109 | ' |
---|
[629] | 110 | listOfsig=( $( $PRINTF "%s\n" "${listOfsig[@]}" | $AWK 'x[$0]++ == 0' ) ) |
---|
[507] | 111 | $ECHO "(DEBUG) (${scriptName}): ${listOfsig[@]}" |
---|
| 112 | |
---|
| 113 | for sigfname in ${listOfsig[@]} |
---|
| 114 | do |
---|
| 115 | filename=$(basename $sigfname) |
---|
| 116 | extension=${filename##*.} |
---|
| 117 | filename=${filename%.*} |
---|
| 118 | number=`$ECHO $filename | $AWK '{len=length("signal");len=len+1;a=substr($1,len);print a}'` |
---|
| 119 | hdrname="header${number}.txt" |
---|
| 120 | #look if header file already exists: if so skip it |
---|
| 121 | hdrIsthere=`ils ${i}/${fibdir}/${hdrname} 2>&1 | $GREP -i "^ERROR" | $WC -l` |
---|
| 122 | $ECHO "(DEBUG) (${scriptName}): look if ${hdrname} exist (${hdrIsthere})" |
---|
| 123 | if [ $hdrIsthere -eq 0 ]; then |
---|
| 124 | continue |
---|
| 125 | fi |
---|
| 126 | #get the signal file |
---|
| 127 | $ECHO "DEBUG (${scriptName}): iget $sigfname (dgg = ${nloop4dbg})" |
---|
| 128 | OUT3=./igetlog${nloop4dbg}.$$ |
---|
| 129 | iget -f -v -K ${i}/${fibdir}/${sigfname} . >${OUT3} 2>&1 |
---|
| 130 | igetStatus=`$GREP "^ERROR" ${OUT3}` |
---|
| 131 | if [ "<$igetStatus>" != "<>" ]; then |
---|
| 132 | $ECHO "INFO (${scriptName}): error while iget:" |
---|
| 133 | $ECHO $igetStatus |
---|
| 134 | continue |
---|
| 135 | fi |
---|
| 136 | $RM $OUT3 |
---|
| 137 | #extract the header part of the signal file |
---|
| 138 | $ECHO "DEBUG (${scriptName}): get header from ${sigfname} and put it in ${hdrname}" |
---|
| 139 | IFS=$defaultIFS |
---|
| 140 | while read -n80 L |
---|
| 141 | do |
---|
| 142 | [ "${L::3}" = "END" ] && break |
---|
| 143 | $ECHO $L |
---|
| 144 | done < ${sigfname} > ${hdrname} |
---|
| 145 | $RM ${sigfname} |
---|
| 146 | nhdrlines=`$WC -l ${hdrname} | $AWK '{print $1}' ` |
---|
| 147 | if [ "${nhdrlines}" = "0" ]; then |
---|
| 148 | $ECHO "WARNING (${scriptName}): ${sigfname} has no valid header" |
---|
| 149 | else |
---|
| 150 | #transfert to irod the header |
---|
| 151 | $ECHO "INFO (${scriptName}): transfert ${hdrname} to ${i}/${fibdir}" |
---|
| 152 | #use -f option ONLY to force override |
---|
| 153 | iput -v -K ${hdrname} ${i}/${fibdir} |
---|
| 154 | fi |
---|
| 155 | $RM ${hdrname} |
---|
| 156 | nloop4dbg=$(expr $nloop4dbg + 1) |
---|
| 157 | done |
---|
[629] | 158 | imeta mod -C ${i}/${fibdir} status hdrNOTDone v:hdrDone |
---|
[507] | 159 | else |
---|
| 160 | $ECHO "INFO (${scriptName}): nothing to do for ${i}/${fibdir}" |
---|
| 161 | fi |
---|
| 162 | done |
---|
| 163 | done |
---|