source: BAORadio/AmasNancay/trunk/hdrfitsextractor.sh @ 629

Last change on this file since 629 was 629, checked in by torrento, 12 years ago

Added imeta tagging

File size: 5.0 KB
Line 
1#!/bin/sh
2#download SCA file, proceed to introspection, and upload results
3DATE=/bin/date
4GREP=/bin/grep
5AWK=/bin/awk
6ECHO=/bin/echo
7WC=/usr/bin/wc
8CAT=/bin/cat
9PRINTF=/usr/bin/printf
10MKDIR=/bin/mkdir
11XARGS=/usr/bin/xargs
12SORT=/bin/sort
13RM=/bin/rm
14defaultIFS=$IFS
15SED=/bin/sed
16
17#set Irods environment   
18. /usr/local/shared/bin/irods_env.sh -noverbose
19
20scriptName="`basename $0`"
21$ECHO "Processing script ${scriptName} at `date`"
22
23#which source to analyse
24sourceRadio=$1
25
26#Path to public backupable path
27publicpath="/afs/in2p3.fr/home/c/campagne/public"
28
29
30#Path where the job will do temporary IO
31. ${SCRIPTPATH}/set_iojobpath.sh
32iojobpath=$(set_iojobpath)
33cd ${iojobpath}
34
35localpath="${sourceRadio}"
36$MKDIR -p ./${localpath}
37cd ./${localpath}
38
39
40#Path of the utility scripts
41scriptpath=${SCRIPTPATH}
42
43
44#JEC 1/10/11 Use generic baodaqstatus name
45#get the daq current irod status
46#tag=`${DATE} +%F`
47#OUT1=${publicpath}/baodaqstatus-${tag}.txt
48OUT1=${publicpath}/baodaqstatus-current.txt
49
50if [ ! -e ${OUT1}  -o ! -r ${OUT1} ]; then
51    $ECHO "FATAL (${scriptName}): ${OUT1} has a problem"
52    exit 1
53fi
54
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
60if [ ! "<${sourceRadio}>" = "<>" ]; then
61    $ECHO "You have selected sourceRadio = $sourceRadio"
62#    tableau=( `$GREP -i ${sourceRadio} ${OUT1} | $AWK '( NF==4 ) { print $2 }' ` )
63    tableau=( `imeta qu -C status "=" hdrNOTDone | $AWK "/$sourceRadio/" | $AWK '{print $2}' ` )
64else
65#    tableau=( `$CAT ${OUT1} | $AWK '( NF==4 ) { print $2 }'`  )
66    tableau=( `imeta qu -C status "=" hdrNOTDone | $AWK '{print $2}' | $SED '/^$/d' ` )
67fi
68IFS='
69'
70tableau=( $( $PRINTF "%s\n" "${tableau[@]}" | $AWK 'x[$0]++ == 0' ) )
71
72
73workArea="headers"
74$MKDIR -p ./${workArea}
75cd ./${workArea}
76
77
78nloop4dbg=0
79
80
81for i in ${tableau[@]}
82do
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"
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='
109'
110          listOfsig=( $( $PRINTF "%s\n" "${listOfsig[@]}" | $AWK 'x[$0]++ == 0' ) )
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
158          imeta mod -C ${i}/${fibdir} status hdrNOTDone v:hdrDone
159      else
160          $ECHO "INFO (${scriptName}): nothing to do for ${i}/${fibdir}"
161      fi
162  done
163done
Note: See TracBrowser for help on using the repository browser.